No empty .Rs/.Re
[netbsd-mini2440.git] / share / mk / bsd.prog.mk
blob02833f0a68f525288b21b85182a9dabe825f2f72
1 # $NetBSD: bsd.prog.mk,v 1.245 2009/12/14 01:00:46 matt Exp $
2 # @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
4 .ifndef HOSTPROG
6 .include <bsd.init.mk>
7 .include <bsd.shlib.mk>
8 .include <bsd.gcc.mk>
11 # Definitions and targets shared among all programs built by a single
12 # Makefile.
15 ##### Basic targets
16 realinstall: proginstall scriptsinstall
17 clean: cleanprog
19 .gdbinit:
20 rm -f .gdbinit
21 .if defined(DESTDIR) && !empty(DESTDIR)
22 echo "set solib-absolute-prefix ${DESTDIR}" > .gdbinit
23 .else
24 touch .gdbinit
25 .endif
26 .for __gdbinit in ${GDBINIT}
27 echo "source ${__gdbinit}" >> .gdbinit
28 .endfor
30 cleanobjs: .PHONY
32 cleanprog: .PHONY cleanobjs cleanextra
33 rm -f a.out [Ee]rrs mklog core *.core .gdbinit
35 .if defined(SHAREDSTRINGS)
36 CLEANFILES+=strings
37 .c.o:
38 ${CC} -E ${CPPFLAGS} ${CFLAGS} ${.IMPSRC} | xstr -c -
39 @${CC} ${CPPFLAGS} ${CFLAGS} -c x.c -o ${.TARGET}
40 @rm -f x.c
42 .cc.o .cpp.o .cxx.o .C.o:
43 ${CXX} -E ${CPPFLAGS} ${CXXFLAGS} ${.IMPSRC} | xstr -c -
44 @mv -f x.c x.cc
45 @${CXX} ${CPPFLAGS} ${CXXFLAGS} -c x.cc -o ${.TARGET}
46 @rm -f x.cc
47 .endif
49 .if defined(MKPIE) && (${MKPIE} != "no")
50 CFLAGS+= ${PIE_CFLAGS}
51 AFLAGS+= ${PIE_AFLAGS}
52 LDFLAGS+= ${PIE_LDFLAGS}
53 .endif
55 ##### Default values
56 .if empty(CPPFLAGS:M-nostdinc)
57 CPPFLAGS+= ${DESTDIR:D-nostdinc ${CPPFLAG_ISYSTEM} ${DESTDIR}/usr/include}
58 .endif
59 .if empty(CXXFLAGS:M-nostdinc++)
60 CXXFLAGS+= ${DESTDIR:D-nostdinc++ ${CPPFLAG_ISYSTEMXX} ${DESTDIR}/usr/include/g++}
61 .endif
62 CFLAGS+= ${COPTS}
63 OBJCFLAGS+= ${OBJCOPTS}
64 MKDEP_SUFFIXES?= .o .ln
66 # ELF platforms depend on crti.o, crtbegin.o, crtend.o, and crtn.o
67 .if ${OBJECT_FMT} == "ELF"
68 .ifndef LIBCRTBEGIN
69 LIBCRTBEGIN= ${DESTDIR}/usr/lib/crti.o ${_GCC_CRTBEGIN}
70 .MADE: ${LIBCRTBEGIN}
71 .endif
72 .ifndef LIBCRTEND
73 LIBCRTEND= ${_GCC_CRTEND} ${DESTDIR}/usr/lib/crtn.o
74 .MADE: ${LIBCRTEND}
75 .endif
76 _SHLINKER= ${SHLINKDIR}/ld.elf_so
77 .else
78 LIBCRTBEGIN?=
79 LIBCRTEND?=
80 _SHLINKER= ${SHLINKDIR}/ld.so
81 .endif
83 .ifndef LIBCRT0
84 LIBCRT0= ${DESTDIR}/usr/lib/crt0.o
85 .MADE: ${LIBCRT0}
86 .endif
88 ##### Installed system library definitions
90 # E.g.
91 # LIBC?=${DESTDIR}/usr/lib/libc.a
92 # LIBX11?=${DESTDIR}/usr/X11R7/lib/libX11.a
93 # etc..
95 .for _lib in \
96 archive asn1 bluetooth bsdmalloc bz2 c c_pic cdk com_err compat \
97 crypt crypto crypto_idea crypto_mdc2 crypto_rc5 \
98 curses dbm des edit event \
99 fetch form fl g2c gcc gnumalloc gssapi hdb heimntlm hx509 intl ipsec \
100 kadm5clnt kadm5srv kafs krb5 kvm l lber ldap ldap_r \
101 m magic menu objc ossaudio pam pcap pci pmc posix pthread pthread_dbg \
102 puffs radius resolv rmt roken rpcsvc rt rump rumpuser skey sl ss \
103 ssh ssl termcap usbhid util wrap y z bind9 dns lwres isccfg isccc isc \
105 rumpfs_cd9660fs rumpfs_efs rumpfs_ext2fs rumpfs_ffs rumpfs_hfs \
106 rumpfs_lfs rumpfs_msdosfs rumpfs_nfs rumpfs_ntfs rumpfs_syspuffs \
107 rumpfs_tmpfs rumpfs_udf rumpfs_ufs
108 .ifndef LIB${_lib:tu}
109 LIB${_lib:tu}= ${DESTDIR}/usr/lib/lib${_lib}.a
110 .MADE: ${LIB${_lib:tu}} # Note: ${DESTDIR} will be expanded
111 .endif
112 .endfor
114 # PAM applications, if linked statically, need more libraries
115 .if (${MKPIC} == "no")
116 .if (${MKCRYPTO} != "no")
117 PAM_STATIC_LDADD+= -lssh
118 PAM_STATIC_DPADD+= ${LIBSSH}
119 .endif
120 .if (${MKKERBEROS} != "no")
121 PAM_STATIC_LDADD+= -lkafs -lkrb5 -lhx509 -lasn1 -lroken -lcom_err -lcrypto
122 PAM_STATIC_DPADD+= ${LIBKAFS} ${LIBKRB5} ${LIBHX509} ${LIBASN1} ${LIBROKEN} \
123 ${LIBCOM_ERR} ${LIBCRYPTO}
124 .endif
125 .if (${MKSKEY} != "no")
126 PAM_STATIC_LDADD+= -lskey
127 PAM_STATIC_DPADD+= ${LIBSKEY}
128 .endif
129 PAM_STATIC_LDADD+= -lradius -lcrypt -lrpcsvc -lutil
130 PAM_STATIC_DPADD+= ${LIBRADIUS} ${LIBCRYPT} ${LIBRPCSVC} ${LIBUTIL}
131 .else
132 PAM_STATIC_LDADD=
133 PAM_STATIC_DPADD=
134 .endif
136 # These need + -> X transformations
137 .ifndef LIBSTDCXX
138 LIBSTDCXX= ${DESTDIR}/usr/lib/libstdc++.a
139 .MADE: ${LIBSTDCXX}
140 .endif
142 .ifndef LIBSUPCXX
143 LIBSUPCXX= ${DESTDIR}/usr/lib/libsupc++.a
144 .MADE: ${LIBSUPCXX}
145 .endif
147 .for _lib in \
148 dps expat fntstubs fontcache fontconfig fontenc freetype FS \
149 GL GLU ICE lbxutil SM X11 Xau Xaw Xdmcp Xext Xfont Xft \
150 Xi Xinerama xkbfile Xmu Xmuu Xpm Xrandr Xrender Xss Xt \
151 XTrap Xtst Xv Xxf86dga Xxf86misc Xxf86vm
152 .ifndef LIB${_lib:tu}
153 LIB${_lib:tu}= ${DESTDIR}${X11USRLIBDIR}/lib${_lib}.a
154 .MADE: ${LIB${_lib:tu}} # Note: ${DESTDIR} will be expanded
155 .endif
156 .endfor
158 .if defined(RESCUEDIR)
159 CPPFLAGS+= -DRESCUEDIR=\"${RESCUEDIR}\"
160 .endif
162 _PROGLDOPTS=
163 .if ${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves
164 .if ${OBJECT_FMT} == "ELF"
165 _PROGLDOPTS+= -Wl,-dynamic-linker=${_SHLINKER}
166 .endif
167 .endif
168 .if ${SHLIBDIR} != "/usr/lib"
169 _PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBDIR} \
170 -R${SHLIBDIR} \
171 -L${DESTDIR}${SHLIBDIR}
172 .elif ${SHLIBINSTALLDIR} != "/usr/lib"
173 _PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
174 -L${DESTDIR}${SHLIBINSTALLDIR}
175 .endif
176 _PROGLDOPTS+= -Wl,-rpath-link,${DESTDIR}/usr/lib \
177 -L${DESTDIR}/usr/lib
179 __proginstall: .USE
180 ${_MKTARGET_INSTALL}
181 ${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
182 ${STRIPFLAG} ${.ALLSRC} ${.TARGET}
184 __progdebuginstall: .USE
185 ${_MKTARGET_INSTALL}
186 ${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
187 ${.ALLSRC} ${.TARGET}
192 # Backwards compatibility with Makefiles that assume that bsd.prog.mk
193 # can only build a single binary.
196 _APPEND_MANS=yes
197 _APPEND_SRCS=yes
199 _CCLINKFLAGS=
200 .if defined(DESTDIR)
201 _CCLINKFLAGS+= -B${_GCC_CRTDIR}/ -B${DESTDIR}/usr/lib/
202 .endif
204 .if defined(PROG_CXX)
205 PROG= ${PROG_CXX}
206 _CCLINK= ${CXX} ${_CCLINKFLAGS}
207 .endif
209 .if defined(PROG)
210 _CCLINK?= ${CC} ${_CCLINKFLAGS}
211 . if defined(MAN)
212 MAN.${PROG}= ${MAN}
213 _APPEND_MANS= no
214 . endif
215 . if !defined(OBJS)
216 OBJS= ${OBJS.${PROG}}
217 . endif
218 . if defined(PROGNAME)
219 PROGNAME.${PROG}= ${PROGNAME}
220 . endif
221 . if defined(SRCS)
222 SRCS.${PROG}= ${SRCS}
223 _APPEND_SRCS= no
224 . endif
225 .endif
227 # Turn the single-program PROG and PROG_CXX variables into their multi-word
228 # counterparts, PROGS and PROGS_CXX.
229 .if defined(PROG_CXX) && !defined(PROGS_CXX)
230 PROGS_CXX= ${PROG_CXX}
231 .elif defined(PROG) && !defined(PROGS)
232 PROGS= ${PROG}
233 .endif
238 # Per-program definitions and targets.
241 # Definitions specific to C programs.
242 .for _P in ${PROGS}
243 SRCS.${_P}?= ${_P}.c
244 _CCLINK.${_P}= ${CC} ${_CCLINKFLAGS}
245 .endfor
247 # Definitions specific to C++ programs.
248 .for _P in ${PROGS_CXX}
249 SRCS.${_P}?= ${_P}.cc
250 _CCLINK.${_P}= ${CXX} ${_CCLINKFLAGS}
251 .endfor
253 # Language-independent definitions.
254 .for _P in ${PROGS} ${PROGS_CXX} # {
256 BINDIR.${_P}?= ${BINDIR}
257 PROGNAME.${_P}?= ${_P}
259 .if ${MKDEBUG} != "no" && ${OBJECT_FMT} == "ELF" && !commands(${_P})
260 _PROGDEBUG.${_P}:= ${PROGNAME.${_P}}.debug
261 .endif
263 .if defined(PAXCTL_FLAGS)
264 PAXCTL_FLAGS.${_P}?= ${PAXCTL_FLAGS}
265 .endif
267 ##### PROG specific flags.
269 _LDADD.${_P}= ${LDADD} ${LDADD.${_P}}
270 _LDFLAGS.${_P}= ${LDFLAGS} ${LDFLAGS.${_P}}
271 _LDSTATIC.${_P}= ${LDSTATIC} ${LDSTATIC.${_P}}
273 ##### Build and install rules
274 .if !empty(_APPEND_SRCS:M[Yy][Ee][Ss])
275 SRCS+= ${SRCS.${_P}} # For bsd.dep.mk
276 .endif
278 _YPSRCS.${_P}= ${SRCS.${_P}:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS.${_P}:M*.y:.y=.h}}
280 DPSRCS+= ${_YPSRCS.${_P}}
281 CLEANFILES+= ${_YPSRCS.${_P}}
283 .if !empty(SRCS.${_P}:N*.h:N*.sh:N*.fth)
284 OBJS.${_P}+= ${SRCS.${_P}:N*.h:N*.sh:N*.fth:R:S/$/.o/g}
285 LOBJS.${_P}+= ${LSRCS:.c=.ln} ${SRCS.${_P}:M*.c:.c=.ln}
286 .endif
288 .if defined(OBJS.${_P}) && !empty(OBJS.${_P}) # {
289 .NOPATH: ${OBJS.${_P}} ${_P} ${_YPSRCS.${_P}}
291 ${OBJS.${_P}} ${LOBJS.${_P}}: ${DPSRCS}
293 ${_P}: .gdbinit ${LIBCRT0} ${OBJS.${_P}} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
294 .if !commands(${_P})
295 ${_MKTARGET_LINK}
296 ${_CCLINK.${_P}} \
297 ${DESTDIR:D-Wl,-nostdlib} \
298 ${_LDFLAGS.${_P}} ${_LDSTATIC.${_P}} -o ${.TARGET} \
299 ${OBJS.${_P}} ${_LDADD.${_P}} \
300 ${DESTDIR:D-L${_GCC_LIBGCCDIR}} \
301 ${_PROGLDOPTS}
302 .if defined(PAXCTL_FLAGS.${_P})
303 ${PAXCTL} ${PAXCTL_FLAGS.${_P}} ${.TARGET}
304 .endif
305 .if ${MKSTRIPIDENT} != "no"
306 ${OBJCOPY} -R .ident ${.TARGET}
307 .endif
308 .endif # !commands(${_P})
310 ${_P}.ro: ${OBJS.${_P}} ${DPADD}
311 ${_MKTARGET_LINK}
312 ${CC} ${LDFLAGS} -nostdlib -r -Wl,-dc -o ${.TARGET} ${OBJS.${_P}}
314 .if defined(_PROGDEBUG.${_P})
315 ${_PROGDEBUG.${_P}}: ${_P}
316 ${_MKTARGET_CREATE}
317 ${OBJCOPY} --only-keep-debug ${_P} ${_PROGDEBUG.${_P}}
318 ${OBJCOPY} -R .gnu_debuglink --add-gnu-debuglink=${_PROGDEBUG.${_P}} ${_P} \
319 || rm -f ${_PROGDEBUG.${_P}}
320 .endif
322 .endif # defined(OBJS.${_P}) && !empty(OBJS.${_P}) # }
324 .if !defined(MAN.${_P})
325 MAN.${_P}= ${_P}.1
326 .endif # !defined(MAN.${_P})
327 .if !empty(_APPEND_MANS:M[Yy][Ee][Ss])
328 MAN+= ${MAN.${_P}}
329 .endif
331 realall: ${_P} ${_PROGDEBUG.${_P}}
333 cleanprog: cleanprog-${_P}
334 cleanprog-${_P}:
335 rm -f ${_P} ${_PROGDEBUG.${_P}}
337 .if defined(OBJS.${_P}) && !empty(OBJS.${_P})
338 cleanobjs: cleanobjs-${_P}
339 cleanobjs-${_P}:
340 rm -f ${OBJS.${_P}} ${LOBJS.${_P}}
341 .endif
343 _PROG_INSTALL+= proginstall-${_P}
345 .if !target(proginstall-${_P}) # {
346 proginstall-${_P}:: ${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}} \
347 ${_PROGDEBUG.${_P}:D${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}}
348 .PRECIOUS: ${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}} \
349 ${_PROGDEBUG.${_P}:D${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}}
351 .if ${MKUPDATE} == "no"
352 ${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}! ${_P} __proginstall
353 .if !defined(BUILD) && !make(all) && !make(${_P})
354 ${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}! .MADE
355 .endif
356 .if defined(_PROGDEBUG.${_P})
357 ${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}! ${_PROGDEBUG.${_P}} __progdebuginstall
358 .if !defined(BUILD) && !make(all) && !make(${_P})
359 ${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}! .MADE
360 .endif
361 .endif # define(_PROGDEBUG.${_P})
362 .else # MKUPDATE != no
363 ${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}: ${_P} __proginstall
364 .if !defined(BUILD) && !make(all) && !make(${_P})
365 ${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}: .MADE
366 .endif
367 .if defined(_PROGDEBUG.${_P})
368 ${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}: ${_PROGDEBUG.${_P}} __progdebuginstall
369 .if !defined(BUILD) && !make(all) && !make(${_P})
370 ${DESTDIR}${DEBUGDIR}${BINDIR.${_P}}/${_PROGDEBUG.${_P}}: .MADE
371 .endif
372 .endif # defined(_PROGDEBUG.${_P})
373 .endif # MKUPDATE != no
375 .endif # !target(proginstall-${_P}) # }
377 lint: lint-${_P}
378 lint-${_P}: ${LOBJS.${_P}}
379 .if defined(LOBJS.${_P}) && !empty(LOBJS.${_P})
380 ${LINT} ${LINTFLAGS} ${_LDFLAGS.${_P}:C/-L[ ]*/-L/Wg:M-L*} ${LOBJS.${_P}} ${_LDADD.${_P}}
381 .endif
383 .endfor # _P in ${PROGS} ${PROGS_CXX} # }
385 .if defined(OBJS) && !empty(OBJS) && \
386 (empty(PROGS) && empty(PROGS_CXX))
387 cleanobjs: cleanobjs-plain
388 cleanobjs-plain:
389 rm -f ${OBJS} ${LOBJS}
390 .endif
392 .if !target(proginstall)
393 proginstall:: ${_PROG_INSTALL}
394 .endif
395 .PHONY: proginstall
399 realall: ${SCRIPTS}
400 .if defined(SCRIPTS) && !target(scriptsinstall) # {
401 SCRIPTSDIR?=${BINDIR}
402 SCRIPTSOWN?=${BINOWN}
403 SCRIPTSGRP?=${BINGRP}
404 SCRIPTSMODE?=${BINMODE}
406 scriptsinstall:: ${SCRIPTS:@S@${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}@}
407 .PRECIOUS: ${SCRIPTS:@S@${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}@}
409 __scriptinstall: .USE
410 ${_MKTARGET_INSTALL}
411 ${INSTALL_FILE} \
412 -o ${SCRIPTSOWN_${.ALLSRC:T}:U${SCRIPTSOWN}} \
413 -g ${SCRIPTSGRP_${.ALLSRC:T}:U${SCRIPTSGRP}} \
414 -m ${SCRIPTSMODE_${.ALLSRC:T}:U${SCRIPTSMODE}} \
415 ${.ALLSRC} ${.TARGET}
417 .for S in ${SCRIPTS:O:u}
418 .if ${MKUPDATE} == "no"
419 ${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}! ${S} __scriptinstall
420 .if !defined(BUILD) && !make(all) && !make(${S})
421 ${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}! .MADE
422 .endif
423 .else
424 ${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}: ${S} __scriptinstall
425 .if !defined(BUILD) && !make(all) && !make(${S})
426 ${DESTDIR}${SCRIPTSDIR_${S}:U${SCRIPTSDIR}}/${SCRIPTSNAME_${S}:U${SCRIPTSNAME:U${S:T:R}}}: .MADE
427 .endif
428 .endif
429 .endfor
430 .endif # }
432 .if !target(scriptsinstall)
433 scriptsinstall::
434 .endif
435 .PHONY: scriptsinstall
437 ##### Pull in related .mk logic
438 LINKSOWN?= ${BINOWN}
439 LINKSGRP?= ${BINGRP}
440 LINKSMODE?= ${BINMODE}
441 .include <bsd.man.mk>
442 .include <bsd.nls.mk>
443 .include <bsd.files.mk>
444 .include <bsd.inc.mk>
445 .include <bsd.links.mk>
446 .include <bsd.sys.mk>
447 .include <bsd.dep.mk>
449 cleanextra: .PHONY
450 .if defined(CLEANFILES) && !empty(CLEANFILES)
451 rm -f ${CLEANFILES}
452 .endif
454 ${TARGETS}: # ensure existence
456 .endif # HOSTPROG