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
7 .
include <bsd.shlib.mk
>
11 # Definitions and targets shared among all programs built by a single
16 realinstall
: proginstall scriptsinstall
21 .if defined
(DESTDIR
) && !empty
(DESTDIR
)
22 echo
"set solib-absolute-prefix ${DESTDIR}" > .gdbinit
26 .for __gdbinit in
${GDBINIT}
27 echo
"source ${__gdbinit}" >> .gdbinit
32 cleanprog
: .PHONY cleanobjs cleanextra
33 rm -f a.out
[Ee
]rrs mklog core
*.core .gdbinit
35 .if defined
(SHAREDSTRINGS
)
38 ${CC} -E
${CPPFLAGS} ${CFLAGS} ${.IMPSRC
} | xstr
-c
-
39 @
${CC} ${CPPFLAGS} ${CFLAGS} -c x.c
-o
${.TARGET
}
42 .
cc.o .
cpp.o .
cxx.o .C.o
:
43 ${CXX} -E
${CPPFLAGS} ${CXXFLAGS} ${.IMPSRC
} | xstr
-c
-
45 @
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c x.
cc -o
${.TARGET
}
49 .if defined
(MKPIE
) && (${MKPIE} != "no")
50 CFLAGS
+= ${PIE_CFLAGS}
51 AFLAGS
+= ${PIE_AFLAGS}
52 LDFLAGS
+= ${PIE_LDFLAGS}
56 .if empty
(CPPFLAGS
:M-nostdinc
)
57 CPPFLAGS
+= ${DESTDIR
:D-nostdinc
${CPPFLAG_ISYSTEM} ${DESTDIR}/usr
/include}
59 .if empty
(CXXFLAGS
:M-nostdinc
++)
60 CXXFLAGS
+= ${DESTDIR
:D-nostdinc
++ ${CPPFLAG_ISYSTEMXX} ${DESTDIR}/usr
/include/g
++}
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"
69 LIBCRTBEGIN
= ${DESTDIR}/usr
/lib
/crti.o
${_GCC_CRTBEGIN}
73 LIBCRTEND
= ${_GCC_CRTEND} ${DESTDIR}/usr
/lib
/crtn.o
76 _SHLINKER
= ${SHLINKDIR}/ld.elf_so
80 _SHLINKER
= ${SHLINKDIR}/ld.so
84 LIBCRT0
= ${DESTDIR}/usr
/lib
/crt0.o
88 ##### Installed system library definitions
91 # LIBC?=${DESTDIR}/usr/lib/libc.a
92 # LIBX11?=${DESTDIR}/usr/X11R7/lib/libX11.a
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
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}
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}
125 .if
(${MKSKEY} != "no")
126 PAM_STATIC_LDADD
+= -lskey
127 PAM_STATIC_DPADD
+= ${LIBSKEY}
129 PAM_STATIC_LDADD
+= -lradius
-lcrypt
-lrpcsvc
-lutil
130 PAM_STATIC_DPADD
+= ${LIBRADIUS} ${LIBCRYPT} ${LIBRPCSVC} ${LIBUTIL}
136 # These need + -> X transformations
138 LIBSTDCXX
= ${DESTDIR}/usr
/lib
/libstdc
++.a
143 LIBSUPCXX
= ${DESTDIR}/usr
/lib
/libsupc
++.a
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
158 .if defined
(RESCUEDIR
)
159 CPPFLAGS
+= -DRESCUEDIR
=\"${RESCUEDIR}\"
163 .if
${SHLINKDIR} != "/usr/libexec" # XXX: change or remove if ld.so moves
164 .if
${OBJECT_FMT} == "ELF"
165 _PROGLDOPTS
+= -Wl
,-dynamic-linker
=${_SHLINKER}
168 .if
${SHLIBDIR} != "/usr/lib"
169 _PROGLDOPTS
+= -Wl
,-rpath-link
,${DESTDIR}${SHLIBDIR} \
171 -L
${DESTDIR}${SHLIBDIR}
172 .elif
${SHLIBINSTALLDIR} != "/usr/lib"
173 _PROGLDOPTS
+= -Wl
,-rpath-link
,${DESTDIR}${SHLIBINSTALLDIR} \
174 -L
${DESTDIR}${SHLIBINSTALLDIR}
176 _PROGLDOPTS
+= -Wl
,-rpath-link
,${DESTDIR}/usr
/lib \
181 ${INSTALL_FILE} -o
${BINOWN} -g
${BINGRP} -m
${BINMODE} \
182 ${STRIPFLAG} ${.ALLSRC
} ${.TARGET
}
184 __progdebuginstall
: .USE
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.
201 _CCLINKFLAGS
+= -B
${_GCC_CRTDIR}/ -B
${DESTDIR}/usr
/lib
/
204 .if defined
(PROG_CXX
)
206 _CCLINK
= ${CXX} ${_CCLINKFLAGS}
210 _CCLINK?
= ${CC} ${_CCLINKFLAGS}
216 OBJS
= ${OBJS.
${PROG}}
218 . if defined
(PROGNAME
)
219 PROGNAME.
${PROG}= ${PROGNAME}
222 SRCS.
${PROG}= ${SRCS}
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
)
238 # Per-program definitions and targets.
241 # Definitions specific to C programs.
244 _CCLINK.
${_P}= ${CC} ${_CCLINKFLAGS}
247 # Definitions specific to C++ programs.
248 .for _P in
${PROGS_CXX}
249 SRCS.
${_P}?
= ${_P}.
cc
250 _CCLINK.
${_P}= ${CXX} ${_CCLINKFLAGS}
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
263 .if defined
(PAXCTL_FLAGS
)
264 PAXCTL_FLAGS.
${_P}?
= ${PAXCTL_FLAGS}
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
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
}
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}
297 ${DESTDIR
:D-Wl
,-nostdlib
} \
298 ${_LDFLAGS.
${_P}} ${_LDSTATIC.
${_P}} -o
${.TARGET
} \
299 ${OBJS.
${_P}} ${_LDADD.
${_P}} \
300 ${DESTDIR
:D-L
${_GCC_LIBGCCDIR}} \
302 .if defined
(PAXCTL_FLAGS.
${_P})
303 ${PAXCTL} ${PAXCTL_FLAGS.
${_P}} ${.TARGET
}
305 .if
${MKSTRIPIDENT} != "no"
306 ${OBJCOPY} -R .ident
${.TARGET
}
308 .
endif # !commands(${_P})
310 ${_P}.ro
: ${OBJS.
${_P}} ${DPADD}
312 ${CC} ${LDFLAGS} -nostdlib
-r
-Wl
,-dc
-o
${.TARGET
} ${OBJS.
${_P}}
314 .if defined
(_PROGDEBUG.
${_P})
315 ${_PROGDEBUG.
${_P}}: ${_P}
317 ${OBJCOPY} --only-keep-debug
${_P} ${_PROGDEBUG.
${_P}}
318 ${OBJCOPY} -R .gnu_debuglink
--add-gnu-debuglink
=${_PROGDEBUG.
${_P}} ${_P} \
319 ||
rm -f
${_PROGDEBUG.
${_P}}
322 .
endif # defined(OBJS.${_P}) && !empty(OBJS.${_P}) # }
324 .if
!defined
(MAN.
${_P})
326 .
endif # !defined(MAN.${_P})
327 .if
!empty
(_APPEND_MANS
:M
[Yy
][Ee
][Ss
])
331 realall
: ${_P} ${_PROGDEBUG.
${_P}}
333 cleanprog
: cleanprog-
${_P}
335 rm -f
${_P} ${_PROGDEBUG.
${_P}}
337 .if defined
(OBJS.
${_P}) && !empty
(OBJS.
${_P})
338 cleanobjs
: cleanobjs-
${_P}
340 rm -f
${OBJS.
${_P}} ${LOBJS.
${_P}}
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
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
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
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
372 .
endif # defined(_PROGDEBUG.${_P})
373 .
endif # MKUPDATE != no
375 .
endif # !target(proginstall-${_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}}
383 .endfor
# _P in ${PROGS} ${PROGS_CXX} # }
385 .if defined
(OBJS
) && !empty
(OBJS
) && \
386 (empty
(PROGS
) && empty
(PROGS_CXX
))
387 cleanobjs
: cleanobjs-plain
389 rm -f
${OBJS} ${LOBJS}
392 .if
!target
(proginstall
)
393 proginstall
:: ${_PROG_INSTALL}
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
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
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
432 .if
!target
(scriptsinstall
)
435 .PHONY
: scriptsinstall
437 ##### Pull in related .mk logic
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
>
450 .if defined
(CLEANFILES
) && !empty
(CLEANFILES
)
454 ${TARGETS}: # ensure existence