xref: /freebsd/share/mk/bsd.prog.mk (revision 4fd0d10e0fe684211328bc148edf89a792425b39)
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(PROG_CXX)
28PROG=	${PROG_CXX}
29.endif
30
31.if defined(PROG) && target(${PROG})
32MK_DEBUG_FILES=	no
33.elif !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
34MK_DEBUG_FILES=	no
35.endif
36
37.if defined(CRUNCH_CFLAGS)
38CFLAGS+=${CRUNCH_CFLAGS}
39.else
40.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
41    empty(DEBUG_FLAGS:M-gdwarf-*)
42CFLAGS+= -g
43CTFFLAGS+= -g
44.endif
45.endif
46
47.if !defined(DEBUG_FLAGS)
48STRIP?=	-s
49.endif
50
51.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
52LDFLAGS+= -static
53.endif
54
55.if defined(USEPRIVATELIB)
56LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
57.endif
58
59.if ${MK_DEBUG_FILES} != "no"
60PROG_FULL=${PROG}.full
61# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
62.if defined(BINDIR) && (\
63    ${BINDIR} == "/bin" ||\
64    ${BINDIR} == "/libexec" ||\
65    ${BINDIR} == "/sbin" ||\
66    ${BINDIR:C%/usr/(bin|bsdinstall|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\
67     )
68DEBUGFILEDIR=	${DEBUGDIR}${BINDIR}
69.else
70DEBUGFILEDIR?=	${BINDIR}/.debug
71DEBUGMKDIR=
72.endif
73.else
74PROG_FULL=	${PROG}
75.endif
76
77.if defined(PROG)
78PROGNAME?=	${PROG}
79
80.if defined(SRCS)
81
82OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
83
84.if target(beforelinking)
85beforelinking: ${OBJS}
86${PROG_FULL}: beforelinking
87.endif
88${PROG_FULL}: ${OBJS}
89.if defined(PROG_CXX)
90	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
91.else
92	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
93.endif
94.if ${MK_CTF} != "no"
95	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
96.endif
97
98.else	# !defined(SRCS)
99
100.if !target(${PROG})
101.if defined(PROG_CXX)
102SRCS=	${PROG}.cc
103.else
104SRCS=	${PROG}.c
105.endif
106
107# Always make an intermediate object file because:
108# - it saves time rebuilding when only the library has changed
109# - the name of the object gets put into the executable symbol table instead of
110#   the name of a variable temporary object.
111# - it's useful to keep objects around for crunching.
112OBJS+=	${PROG}.o
113
114.if target(beforelinking)
115beforelinking: ${OBJS}
116${PROG_FULL}: beforelinking
117.endif
118${PROG_FULL}: ${OBJS}
119.if defined(PROG_CXX)
120	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
121.else
122	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
123.endif
124.if ${MK_CTF} != "no"
125	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
126.endif
127.endif # !target(${PROG})
128
129.endif # !defined(SRCS)
130
131.if ${MK_DEBUG_FILES} != "no"
132${PROG}: ${PROG_FULL} ${PROGNAME}.debug
133	${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \
134	    ${PROG_FULL} ${.TARGET}
135
136${PROGNAME}.debug: ${PROG_FULL}
137	${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
138.endif
139
140.if	${MK_MAN} != "no" && !defined(MAN) && \
141	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
142	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
143	!defined(MAN7) && !defined(MAN8) && !defined(MAN9)
144MAN=	${PROG}.1
145MAN1=	${MAN}
146.endif
147.endif # defined(PROG)
148
149.if defined(_SKIP_BUILD)
150all:
151.else
152all: objwarn ${PROG} ${SCRIPTS}
153.if ${MK_MAN} != "no"
154all: _manpages
155.endif
156.endif
157
158.if defined(PROG)
159CLEANFILES+= ${PROG}
160.if ${MK_DEBUG_FILES} != "no"
161CLEANFILES+=	${PROG_FULL} ${PROGNAME}.debug
162.endif
163.endif
164
165.if defined(OBJS)
166CLEANFILES+= ${OBJS}
167.endif
168
169.include <bsd.libnames.mk>
170
171.if defined(PROG)
172_EXTRADEPEND:
173.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
174.if defined(DPADD) && !empty(DPADD)
175	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
176.endif
177.else
178	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
179.if defined(PROG_CXX)
180.if ${MK_CLANG_IS_CC} != "no" && empty(CXXFLAGS:M-stdlib=libstdc++)
181	echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
182.else
183	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
184.endif
185.endif
186.endif
187.endif
188
189.if !target(install)
190
191.if defined(PRECIOUSPROG)
192.if !defined(NO_FSCHG)
193INSTALLFLAGS+= -fschg
194.endif
195INSTALLFLAGS+= -S
196.endif
197
198_INSTALLFLAGS:=	${INSTALLFLAGS}
199.for ie in ${INSTALLFLAGS_EDIT}
200_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
201.endfor
202
203.if !target(realinstall) && !defined(INTERNALPROG)
204realinstall: _proginstall
205.ORDER: beforeinstall _proginstall
206_proginstall:
207.if defined(PROG)
208	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
209	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
210.if ${MK_DEBUG_FILES} != "no"
211.if defined(DEBUGMKDIR)
212	${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
213.endif
214	${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
215	    ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
216.endif
217.endif
218.endif	# !target(realinstall)
219
220.if defined(SCRIPTS) && !empty(SCRIPTS)
221realinstall: _scriptsinstall
222.ORDER: beforeinstall _scriptsinstall
223
224SCRIPTSDIR?=	${BINDIR}
225SCRIPTSOWN?=	${BINOWN}
226SCRIPTSGRP?=	${BINGRP}
227SCRIPTSMODE?=	${BINMODE}
228
229STAGE_AS_SETS+= scripts
230stage_as.scripts: ${SCRIPTS}
231FLAGS.stage_as.scripts= -m ${SCRIPTSMODE}
232STAGE_FILES_DIR.scripts= ${STAGE_OBJTOP}
233.for script in ${SCRIPTS}
234.if defined(SCRIPTSNAME)
235SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
236.else
237SCRIPTSNAME_${script:T}?=	${script:T:R}
238.endif
239SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
240SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
241SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
242SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
243STAGE_AS_${script:T}=		${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
244_scriptsinstall: _SCRIPTSINS_${script:T}
245_SCRIPTSINS_${script:T}: ${script}
246	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
247	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
248	    ${.ALLSRC} \
249	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
250.endfor
251.endif
252
253NLSNAME?=	${PROG}
254.include <bsd.nls.mk>
255
256.include <bsd.files.mk>
257.include <bsd.incs.mk>
258.include <bsd.links.mk>
259
260.if ${MK_MAN} != "no"
261realinstall: _maninstall
262.ORDER: beforeinstall _maninstall
263.endif
264
265.endif
266
267.if !target(lint)
268lint: ${SRCS:M*.c}
269.if defined(PROG)
270	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
271.endif
272.endif
273
274.if ${MK_MAN} != "no"
275.include <bsd.man.mk>
276.endif
277
278.include <bsd.dep.mk>
279
280.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
281${OBJS}: ${SRCS:M*.h}
282.endif
283
284.include <bsd.obj.mk>
285
286.include <bsd.sys.mk>
287
288.if defined(PORTNAME)
289.include <bsd.pkg.mk>
290.endif
291