]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/mk/bsd.prog.mk
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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 defined(PROG) && target(${PROG})
32 MK_DEBUG_FILES= no
33 .elif !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
34 MK_DEBUG_FILES= no
35 .endif
36
37 .if defined(CRUNCH_CFLAGS)
38 CFLAGS+=${CRUNCH_CFLAGS}
39 .else
40 .if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
41     empty(DEBUG_FLAGS:M-gdwarf-*)
42 CFLAGS+= -g
43 CTFFLAGS+= -g
44 .endif
45 .endif
46
47 .if !defined(DEBUG_FLAGS)
48 STRIP?= -s
49 .endif
50
51 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
52 LDFLAGS+= -static
53 .endif
54
55 .if defined(USEPRIVATELIB)
56 LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
57 .endif
58
59 .if ${MK_DEBUG_FILES} != "no"
60 PROG_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      )
68 DEBUGFILEDIR=   ${DEBUGDIR}${BINDIR}
69 .else
70 DEBUGFILEDIR?=  ${BINDIR}/.debug
71 DEBUGMKDIR=
72 .endif
73 .else
74 PROG_FULL=      ${PROG}
75 .endif
76
77 .if defined(PROG)
78 PROGNAME?=      ${PROG}
79
80 .if defined(SRCS)
81
82 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
83
84 .if target(beforelinking)
85 beforelinking: ${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)
102 SRCS=   ${PROG}.cc
103 .else
104 SRCS=   ${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.
112 OBJS+=  ${PROG}.o
113
114 .if target(beforelinking)
115 beforelinking: ${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)
144 MAN=    ${PROG}.1
145 MAN1=   ${MAN}
146 .endif
147 .endif # defined(PROG)
148
149 all: objwarn ${PROG} ${SCRIPTS}
150 .if ${MK_MAN} != "no"
151 all: _manpages
152 .endif
153
154 .if defined(PROG)
155 CLEANFILES+= ${PROG}
156 .if ${MK_DEBUG_FILES} != "no"
157 CLEANFILES+=    ${PROG_FULL} ${PROGNAME}.debug
158 .endif
159 .endif
160
161 .if defined(OBJS)
162 CLEANFILES+= ${OBJS}
163 .endif
164
165 .include <bsd.libnames.mk>
166
167 .if defined(PROG)
168 _EXTRADEPEND:
169 .if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
170 .if defined(DPADD) && !empty(DPADD)
171         echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
172 .endif
173 .else
174         echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
175 .if defined(PROG_CXX)
176 .if ${MK_CLANG_IS_CC} != "no" && empty(CXXFLAGS:M-stdlib=libstdc++)
177         echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
178 .else
179         echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
180 .endif
181 .endif
182 .endif
183 .endif
184
185 .if !target(install)
186
187 .if defined(PRECIOUSPROG)
188 .if !defined(NO_FSCHG)
189 INSTALLFLAGS+= -fschg
190 .endif
191 INSTALLFLAGS+= -S
192 .endif
193
194 _INSTALLFLAGS:= ${INSTALLFLAGS}
195 .for ie in ${INSTALLFLAGS_EDIT}
196 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
197 .endfor
198
199 .if !target(realinstall) && !defined(INTERNALPROG)
200 realinstall: _proginstall
201 .ORDER: beforeinstall _proginstall
202 _proginstall:
203 .if defined(PROG)
204         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
205             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
206 .if ${MK_DEBUG_FILES} != "no"
207 .if defined(DEBUGMKDIR)
208         ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
209 .endif
210         ${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
211             ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
212 .endif
213 .endif
214 .endif  # !target(realinstall)
215
216 .if defined(SCRIPTS) && !empty(SCRIPTS)
217 realinstall: _scriptsinstall
218 .ORDER: beforeinstall _scriptsinstall
219
220 SCRIPTSDIR?=    ${BINDIR}
221 SCRIPTSOWN?=    ${BINOWN}
222 SCRIPTSGRP?=    ${BINGRP}
223 SCRIPTSMODE?=   ${BINMODE}
224
225 .for script in ${SCRIPTS}
226 .if defined(SCRIPTSNAME)
227 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
228 .else
229 SCRIPTSNAME_${script:T}?=       ${script:T:R}
230 .endif
231 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
232 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
233 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
234 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
235 _scriptsinstall: _SCRIPTSINS_${script:T}
236 _SCRIPTSINS_${script:T}: ${script}
237         ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
238             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
239             ${.ALLSRC} \
240             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
241 .endfor
242 .endif
243
244 NLSNAME?=       ${PROG}
245 .include <bsd.nls.mk>
246
247 .include <bsd.files.mk>
248 .include <bsd.incs.mk>
249 .include <bsd.links.mk>
250
251 .if ${MK_MAN} != "no"
252 realinstall: _maninstall
253 .ORDER: beforeinstall _maninstall
254 .endif
255
256 .endif
257
258 .if !target(lint)
259 lint: ${SRCS:M*.c}
260 .if defined(PROG)
261         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
262 .endif
263 .endif
264
265 .if ${MK_MAN} != "no"
266 .include <bsd.man.mk>
267 .endif
268
269 .include <bsd.dep.mk>
270
271 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
272 ${OBJS}: ${SRCS:M*.h}
273 .endif
274
275 .include <bsd.obj.mk>
276
277 .include <bsd.sys.mk>
278
279 .if defined(PORTNAME)
280 .include <bsd.pkg.mk>
281 .endif