xref: /freebsd/share/mk/bsd.prog.mk (revision 7cf3a1c6b250b3d5403c89c485b8a9ae77d2d89d)
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)
49beforelinking: ${OBJS}
50${PROG}: beforelinking
51.endif
52${PROG}: ${OBJS}
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)
79beforelinking: ${OBJS}
80${PROG}: beforelinking
81.endif
82${PROG}: ${OBJS}
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 # !defined(SRCS)
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)
99MAN=	${PROG}.1
100MAN1=	${MAN}
101.endif
102.endif # defined(PROG)
103
104.if defined(_SKIP_BUILD)
105all:
106.else
107all: objwarn ${PROG} ${SCRIPTS}
108.if ${MK_MAN} != "no"
109all: _manpages
110.endif
111.endif
112
113.if defined(PROG)
114CLEANFILES+= ${PROG}
115.endif
116
117.if defined(OBJS)
118CLEANFILES+= ${OBJS}
119.endif
120
121.include <bsd.libnames.mk>
122
123.if defined(PROG)
124_EXTRADEPEND:
125.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
126.if defined(DPADD) && !empty(DPADD)
127	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
128.endif
129.else
130	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
131.if defined(PROG_CXX)
132.if !empty(CXXFLAGS:M-stdlib=libc++)
133	echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
134.else
135	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
136.endif
137.endif
138.endif
139.endif
140
141.if !target(install)
142
143.if defined(PRECIOUSPROG)
144.if !defined(NO_FSCHG)
145INSTALLFLAGS+= -fschg
146.endif
147INSTALLFLAGS+= -S
148.endif
149
150_INSTALLFLAGS:=	${INSTALLFLAGS}
151.for ie in ${INSTALLFLAGS_EDIT}
152_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
153.endfor
154
155.if !target(realinstall) && !defined(INTERNALPROG)
156realinstall: _proginstall
157.ORDER: beforeinstall _proginstall
158_proginstall:
159.if defined(PROG)
160.if defined(PROGNAME)
161	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
162	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
163.else
164	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
165	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
166.endif
167.endif
168.endif	# !target(realinstall)
169
170.if defined(SCRIPTS) && !empty(SCRIPTS)
171realinstall: _scriptsinstall
172.ORDER: beforeinstall _scriptsinstall
173
174SCRIPTSDIR?=	${BINDIR}
175SCRIPTSOWN?=	${BINOWN}
176SCRIPTSGRP?=	${BINGRP}
177SCRIPTSMODE?=	${BINMODE}
178
179STAGE_AS_SETS+= scripts
180stage_as.scripts: ${SCRIPTS}
181FLAGS.stage_as.scripts= -m ${SCRIPTSMODE}
182STAGE_FILES_DIR.scripts= ${STAGE_OBJTOP}
183.for script in ${SCRIPTS}
184.if defined(SCRIPTSNAME)
185SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
186.else
187SCRIPTSNAME_${script:T}?=	${script:T:R}
188.endif
189SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
190SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
191SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
192SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
193STAGE_AS_${script:T}=		${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
194_scriptsinstall: _SCRIPTSINS_${script:T}
195_SCRIPTSINS_${script:T}: ${script}
196	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
197	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
198	    ${.ALLSRC} \
199	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
200.endfor
201.endif
202
203NLSNAME?=	${PROG}
204.include <bsd.nls.mk>
205
206.include <bsd.files.mk>
207.include <bsd.incs.mk>
208.include <bsd.links.mk>
209
210.if ${MK_MAN} != "no"
211realinstall: _maninstall
212.ORDER: beforeinstall _maninstall
213.endif
214
215.endif
216
217.if !target(lint)
218lint: ${SRCS:M*.c}
219.if defined(PROG)
220	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
221.endif
222.endif
223
224.if ${MK_MAN} != "no"
225.include <bsd.man.mk>
226.endif
227
228.include <bsd.dep.mk>
229
230.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
231${OBJS}: ${SRCS:M*.h}
232.endif
233
234.include <bsd.obj.mk>
235
236.include <bsd.sys.mk>
237
238.if defined(PORTNAME)
239.include <bsd.pkg.mk>
240.endif
241