xref: /dragonfly/share/mk/bsd.prog.mk (revision 984263bc)
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD: src/share/mk/bsd.prog.mk,v 1.86.2.17 2002/12/23 16:33:37 ru Exp $
3
4.include <bsd.init.mk>
5
6.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .s .S
7
8CFLAGS+=${COPTS} ${DEBUG_FLAGS}
9
10.if !defined(DEBUG_FLAGS)
11STRIP?=	-s
12.endif
13
14.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
15LDFLAGS+= -static
16.endif
17
18.if defined(PROG_CXX)
19PROG=	${PROG_CXX}
20.endif
21
22.if defined(PROG)
23.if defined(SRCS)
24
25# If there are Objective C sources, link with Objective C libraries.
26.if ${SRCS:M*.m} != ""
27OBJCLIBS?= -lobjc
28LDADD+=	${OBJCLIBS}
29.endif
30
31OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
32
33${PROG}: ${OBJS}
34.if defined(PROG_CXX)
35	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
36.else
37	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
38.endif
39
40.else !defined(SRCS)
41
42.if !target(${PROG})
43.if defined(PROG_CXX)
44SRCS=	${PROG}.cc
45.else
46SRCS=	${PROG}.c
47.endif
48
49# Always make an intermediate object file because:
50# - it saves time rebuilding when only the library has changed
51# - the name of the object gets put into the executable symbol table instead of
52#   the name of a variable temporary object.
53# - it's useful to keep objects around for crunching.
54OBJS=	${PROG}.o
55
56${PROG}: ${OBJS}
57.if defined(PROG_CXX)
58	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
59.else
60	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
61.endif
62.endif
63
64.endif
65
66.if	!defined(NOMAN) && !defined(MAN) && \
67	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
68	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
69	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
70	!defined(MAN1aout)
71MAN=	${PROG}.1
72MAN1=	${MAN}
73.endif
74.endif
75
76all: objwarn ${PROG} ${SCRIPTS}
77.if !defined(NOMAN)
78all: _manpages
79.endif
80
81CLEANFILES+= ${PROG} ${OBJS}
82
83.if defined(PROG)
84_EXTRADEPEND:
85.if ${OBJFORMAT} == aout
86	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} \
87	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
88.else
89	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
90.if defined(PROG_CXX)
91	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
92.endif
93.endif
94.endif
95
96.if !target(install)
97
98_INSTALLFLAGS:=	${INSTALLFLAGS}
99.for ie in ${INSTALLFLAGS_EDIT}
100_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
101.endfor
102
103.if !target(realinstall)
104realinstall: _proginstall
105.ORDER: beforeinstall _proginstall
106_proginstall:
107.if defined(PROG)
108.if defined(PROGNAME)
109	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
110	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
111.else
112	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
113	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
114.endif
115.endif
116.if defined(HIDEGAME)
117	(cd ${DESTDIR}${ORIGBINDIR}; ln -fs dm ${PROG}; \
118	    chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
119.endif
120.endif !target(realinstall)
121
122.if defined(SCRIPTS) && !empty(SCRIPTS)
123realinstall: _scriptsinstall
124.ORDER: beforeinstall _scriptsinstall
125
126SCRIPTSDIR?=	${BINDIR}
127SCRIPTSOWN?=	${BINOWN}
128SCRIPTSGRP?=	${BINGRP}
129SCRIPTSMODE?=	${BINMODE}
130
131.for script in ${SCRIPTS}
132.if defined(SCRIPTSNAME)
133SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
134.else
135SCRIPTSNAME_${script:T}?=	${script:T:R}
136.endif
137SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
138SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
139SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
140SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
141_scriptsinstall: _SCRIPTSINS_${script:T}
142_SCRIPTSINS_${script:T}: ${script}
143	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
144	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
145	    ${.ALLSRC} \
146	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
147.endfor
148.endif
149
150.include <bsd.files.mk>
151.include <bsd.incs.mk>
152.include <bsd.links.mk>
153
154.if !defined(NOMAN)
155realinstall: _maninstall
156.ORDER: beforeinstall _maninstall
157.endif
158
159.endif
160
161.if !target(lint)
162lint: ${SRCS}
163.if defined(PROG)
164	@${LINT} ${LINTFLAGS} ${.ALLSRC} | more 2>&1
165.endif
166.endif
167
168.if !defined(NOMAN)
169.include <bsd.man.mk>
170.endif
171
172.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
173.include <bsd.libnames.mk>
174.endif
175
176.include <bsd.dep.mk>
177
178.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
179${OBJS}: ${SRCS:M*.h}
180.endif
181
182.include <bsd.obj.mk>
183
184.include <bsd.sys.mk>
185