xref: /freebsd/share/mk/bsd.prog.mk (revision 8ce070c1b28cd5f33c098da43378d0239091bd00)
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD$
3
4.include <bsd.init.mk>
5
6.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
7
8# XXX The use of COPTS in modern makefiles is discouraged.
9.if defined(COPTS)
10CFLAGS+=${COPTS}
11.endif
12
13.if ${MK_ASSERT_DEBUG} == "no"
14CFLAGS+= -DNDEBUG
15NO_WERROR=
16.endif
17
18.if defined(DEBUG_FLAGS)
19CFLAGS+=${DEBUG_FLAGS}
20CXXFLAGS+=${DEBUG_FLAGS}
21
22.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
23CTFFLAGS+= -g
24.endif
25.endif
26
27.if defined(CRUNCH_CFLAGS)
28CFLAGS+=${CRUNCH_CFLAGS}
29.endif
30
31.if !defined(DEBUG_FLAGS)
32STRIP?=	-s
33.endif
34
35.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
36LDFLAGS+= -static
37.endif
38
39.if defined(PROG_CXX)
40PROG=	${PROG_CXX}
41.endif
42
43.if defined(PROG)
44.if defined(SRCS)
45
46OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
47
48.if target(beforelinking)
49${PROG}: ${OBJS} beforelinking
50.else
51${PROG}: ${OBJS}
52.endif
53.if defined(PROG_CXX)
54	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
55.else
56	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
57.endif
58.if ${MK_CTF} != "no"
59	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
60.endif
61
62.else	# !defined(SRCS)
63
64.if !target(${PROG})
65.if defined(PROG_CXX)
66SRCS=	${PROG}.cc
67.else
68SRCS=	${PROG}.c
69.endif
70
71# Always make an intermediate object file because:
72# - it saves time rebuilding when only the library has changed
73# - the name of the object gets put into the executable symbol table instead of
74#   the name of a variable temporary object.
75# - it's useful to keep objects around for crunching.
76OBJS=	${PROG}.o
77
78.if target(beforelinking)
79${PROG}: ${OBJS} beforelinking
80.else
81${PROG}: ${OBJS}
82.endif
83.if defined(PROG_CXX)
84	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
85.else
86	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
87.endif
88.if ${MK_CTF} != "no"
89	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
90.endif
91.endif
92
93.endif
94
95.if	${MK_MAN} != "no" && !defined(MAN) && \
96	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
97	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
98	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
99	!defined(MAN1aout)
100MAN=	${PROG}.1
101MAN1=	${MAN}
102.endif
103.endif
104
105all: objwarn ${PROG} ${SCRIPTS}
106.if ${MK_MAN} != "no"
107all: _manpages
108.endif
109
110.if defined(PROG)
111CLEANFILES+= ${PROG}
112.endif
113
114.if defined(OBJS)
115CLEANFILES+= ${OBJS}
116.endif
117
118.include <bsd.libnames.mk>
119
120.if defined(PROG)
121_EXTRADEPEND:
122.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
123.if defined(DPADD) && !empty(DPADD)
124	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
125.endif
126.else
127	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
128.if defined(PROG_CXX)
129	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
130.endif
131.endif
132.endif
133
134.if !target(install)
135
136.if defined(PRECIOUSPROG)
137.if !defined(NO_FSCHG)
138INSTALLFLAGS+= -fschg
139.endif
140INSTALLFLAGS+= -S
141.endif
142
143_INSTALLFLAGS:=	${INSTALLFLAGS}
144.for ie in ${INSTALLFLAGS_EDIT}
145_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
146.endfor
147
148.if !target(realinstall) && !defined(INTERNALPROG)
149realinstall: _proginstall
150.ORDER: beforeinstall _proginstall
151_proginstall:
152.if defined(PROG)
153.if defined(PROGNAME)
154	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
155	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
156.else
157	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
158	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
159.endif
160.endif
161.endif	# !target(realinstall)
162
163.if defined(SCRIPTS) && !empty(SCRIPTS)
164realinstall: _scriptsinstall
165.ORDER: beforeinstall _scriptsinstall
166
167SCRIPTSDIR?=	${BINDIR}
168SCRIPTSOWN?=	${BINOWN}
169SCRIPTSGRP?=	${BINGRP}
170SCRIPTSMODE?=	${BINMODE}
171
172.for script in ${SCRIPTS}
173.if defined(SCRIPTSNAME)
174SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
175.else
176SCRIPTSNAME_${script:T}?=	${script:T:R}
177.endif
178SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
179SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
180SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
181SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
182_scriptsinstall: _SCRIPTSINS_${script:T}
183_SCRIPTSINS_${script:T}: ${script}
184	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
185	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
186	    ${.ALLSRC} \
187	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
188.endfor
189.endif
190
191NLSNAME?=	${PROG}
192.include <bsd.nls.mk>
193
194.include <bsd.files.mk>
195.include <bsd.incs.mk>
196.include <bsd.links.mk>
197
198.if ${MK_MAN} != "no"
199realinstall: _maninstall
200.ORDER: beforeinstall _maninstall
201.endif
202
203.endif
204
205.if !target(lint)
206lint: ${SRCS:M*.c}
207.if defined(PROG)
208	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
209.endif
210.endif
211
212.if ${MK_MAN} != "no"
213.include <bsd.man.mk>
214.endif
215
216.include <bsd.dep.mk>
217
218.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
219${OBJS}: ${SRCS:M*.h}
220.endif
221
222.include <bsd.obj.mk>
223
224.include <bsd.sys.mk>
225
226.if defined(PORTNAME)
227.include <bsd.pkg.mk>
228.endif
229