]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/mk/whats.mk
Update mandoc to 1.14.5
[FreeBSD/FreeBSD.git] / contrib / bmake / mk / whats.mk
1 # $Id: whats.mk,v 1.3 2017/10/19 06:09:14 sjg Exp $
2 #
3 #       @(#) Copyright (c) 2014, Simon J. Gerraty
4 #
5 #       This file is provided in the hope that it will
6 #       be of use.  There is absolutely NO WARRANTY.
7 #       Permission to copy, redistribute or otherwise
8 #       use this file is hereby granted provided that 
9 #       the above copyright notice and this notice are
10 #       left intact. 
11 #      
12 #       Please send copies of changes and bug-fixes to:
13 #       sjg@crufty.net
14 #
15
16 .if ${MK_WHATSTRING:Uno} != "no"
17 what_build_exts?= o
18 # it can be useful to embed a what(1) string in binaries 
19 # so that the build location can be seen from a core file.
20 .if defined(PROG) && ${.MAKE.MAKEFILES:M*prog.mk} != ""
21 what_thing?= ${PROGNAME:U${PROG}}
22 what_build_thing?= ${PROG}
23 .elif defined(LIB) && ${.MAKE.MAKEFILES:M*lib.mk} != ""
24 # probably only makes sense for shared libs
25 # and the plumbing needed varies depending on *lib.mk
26 what_thing?= lib${LIB}
27 .if !empty(SOBJS)
28 _soe:= ${SOBJS:E:[1]}
29 what_build_exts= ${_soe}
30 SOBJS+= ${what_uuid}.${_soe}
31 .endif
32 .elif defined(KMOD) && ${.MAKE.MAKEFILES:M*kmod.mk} != ""
33 what_thing?= ${KMOD}
34 what_build_thing?= ${KMOD}.ko
35 .endif
36
37 .if !empty(what_thing)
38 # a unique name that won't conflict with anything
39 what_uuid = what_${what_thing}_${.CURDIR:T:hash}
40 what_var = what_${.CURDIR:T:hash}
41
42 .if !empty(what_build_thing)
43 ${what_build_thing}: ${what_build_exts:@e@${what_uuid}.$e@}
44 .endif
45 OBJS+= ${what_uuid}.o
46 CLEANFILES+= ${what_uuid}.c
47
48 # we do not need to capture this
49 SUPPRESS_DEPEND+= *${what_uuid}.c
50
51 SB?= ${SRCTOP:H}
52 SB_LOCATION?= ${HOST}:${SB}
53 what_location:= ${.OBJDIR:S,${SB},${SB_LOCATION},}
54
55 # this works with clang and gcc
56 _what_t= const char __attribute__ ((section(".data")))
57 _what1:= @(\#)${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER}
58 _what2:= @(\#)${what_location}
59
60 ${what_uuid}.c:
61         echo '${_what_t} ${what_var}1[] = "${_what1}";' > $@ ${.OODATE:MNO_META_CMP}
62         echo '${_what_t} ${what_var}2[] = "${_what2}";' >> $@
63 .endif
64 .endif