]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/mk/whats.mk
Update to bmake-20200902
[FreeBSD/FreeBSD.git] / contrib / bmake / mk / whats.mk
1 # $Id: whats.mk,v 1.10 2020/08/19 17:51:53 sjg Exp $
2 #
3 #       @(#) Copyright (c) 2014-2020, 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} == "yes"
17 # it can be useful to embed a what(1) string in binaries
18 # so that the build location can be seen from a core file.
19 .if defined(KMOD)
20 what_thing ?= ${KMOD}
21 .elif defined(LIB)
22 what_thing ?= lib${LIB}
23 .elif defined(PROG)
24 what_thing ?= ${PROG}
25 SRCS ?= ${PROG}.c
26 .elif defined(SHLIB)
27 what_thing ?= lib${SHLIB}
28 .endif
29
30 .if !empty(what_thing)
31 # a unique name that won't conflict with anything
32 what_uuid = what_${what_thing}_${.CURDIR:T:hash}
33 what_var = what_${.CURDIR:T:hash}
34
35 SRCS += ${what_uuid}.c
36 CLEANFILES += ${what_uuid}.c
37 # we do not need to capture this
38 SUPPRESS_DEPEND += *${what_uuid}.c
39
40 SB ?= ${SRCTOP:H}
41 SB_LOCATION ?= ${HOST}:${SB}
42 # make customization easy
43 WHAT_LOCATION ?= ${.OBJDIR:S,${SB},${SB_LOCATION},}
44 WHAT_1 ?= ${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER}
45 WHAT_2 ?= ${what_location}
46 WHAT_LINE_IDS ?= 1 2
47 WHAT_NOCMP_LINE_IDS ?= 1
48 # you can add other WHAT_* just be sure to set WHAT_LINE_IDS
49 # and WHAT_NOCMP_LINE_IDS accordingly
50
51 # this works with clang and gcc
52 what_t = const char __attribute__ ((section(".data")))
53 what_location := ${WHAT_LOCATION}
54
55 # this script is done in multiple lines so we can
56 # use the token ${.OODATE:MNO_META_CMP}
57 # to prevent the variable parts making this constantly out-of-date
58 ${what_uuid}.c:
59         echo 'extern const char ${WHAT_LINE_IDS:@i@${what_var}_$i[]@:ts,};' > $@
60 .for i in ${WHAT_LINE_IDS}
61 .if ${WHAT_NOCMP_LINE_IDS:M$i} != ""
62         echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@ ${.OODATE:MNO_META_CMP}
63 .else
64         echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@
65 .endif
66 .endfor
67
68 .endif
69 .endif