]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.prog.mk
Sync with HEAD.
[FreeBSD/FreeBSD.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(CRUNCH_CFLAGS)
28 CFLAGS+=${CRUNCH_CFLAGS}
29 .endif
30
31 .if !defined(DEBUG_FLAGS)
32 STRIP?= -s
33 .endif
34
35 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
36 LDFLAGS+= -static
37 .endif
38
39 .if defined(PROG_CXX)
40 PROG=   ${PROG_CXX}
41 .endif
42
43 .if defined(PROG)
44 .if defined(SRCS)
45
46 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
47
48 .if target(beforelinking)
49 beforelinking: ${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)
66 SRCS=   ${PROG}.cc
67 .else
68 SRCS=   ${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.
76 OBJS=   ${PROG}.o
77
78 .if target(beforelinking)
79 beforelinking: ${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)
99 MAN=    ${PROG}.1
100 MAN1=   ${MAN}
101 .endif
102 .endif # defined(PROG)
103
104 .if defined(_SKIP_BUILD)
105 all:
106 .else
107 all: objwarn ${PROG} ${SCRIPTS}
108 .if ${MK_MAN} != "no"
109 all: _manpages
110 .endif
111 .endif
112
113 .if defined(PROG)
114 CLEANFILES+= ${PROG}
115 .endif
116
117 .if defined(OBJS)
118 CLEANFILES+= ${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)
145 INSTALLFLAGS+= -fschg
146 .endif
147 INSTALLFLAGS+= -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)
156 realinstall: _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)
171 realinstall: _scriptsinstall
172 .ORDER: beforeinstall _scriptsinstall
173
174 SCRIPTSDIR?=    ${BINDIR}
175 SCRIPTSOWN?=    ${BINOWN}
176 SCRIPTSGRP?=    ${BINGRP}
177 SCRIPTSMODE?=   ${BINMODE}
178
179 STAGE_AS_SETS+= scripts
180 stage_as.scripts: ${SCRIPTS}
181 FLAGS.stage_as.scripts= -m ${SCRIPTSMODE}
182 STAGE_FILES_DIR.scripts= ${STAGE_OBJTOP}
183 .for script in ${SCRIPTS}
184 .if defined(SCRIPTSNAME)
185 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
186 .else
187 SCRIPTSNAME_${script:T}?=       ${script:T:R}
188 .endif
189 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
190 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
191 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
192 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
193 STAGE_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
203 NLSNAME?=       ${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"
211 realinstall: _maninstall
212 .ORDER: beforeinstall _maninstall
213 .endif
214
215 .endif
216
217 .if !target(lint)
218 lint: ${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
242 .if ${MK_STAGING} != "no"
243 .if defined(_SKIP_BUILD)
244 stage_files stage_as:
245 .else
246 # normally only libs and includes are staged
247 .if ${MK_STAGING_PROG:Uno} != "no"
248 STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR}
249
250 .if defined(PROGNAME)
251 STAGE_AS_SETS+= prog
252 STAGE_AS_${PROG}= ${PROGNAME}
253 stage_as.prog: ${PROG}
254 .else
255 STAGE_SETS+= prog
256 stage_files.prog: ${PROG}
257 .endif
258
259 .if !empty(LINKS)
260 all: stage_links
261 STAGE_LINKS.prog= ${LINKS}
262 .endif
263 .if !empty(SYMLINKS)
264 all: stage_symlinks
265 STAGE_SYMLINKS.prog= ${SYMLINKS}
266 .endif
267
268 .if !empty(STAGE_AS_SETS)
269 all: stage_as
270 .endif
271 .if !empty(STAGE_SETS)
272 all: stage_files
273 .endif
274
275 .endif
276 .include <meta.stage.mk>
277 .endif
278 .endif