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