1 # $Id: whats.mk,v 1.10 2020/08/19 17:51:53 sjg Exp $
3 # @(#) Copyright (c) 2014-2020, Simon J. Gerraty
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
12 # Please send copies of changes and bug-fixes to:
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.
22 what_thing ?= lib${LIB}
27 what_thing ?= lib${SHLIB}
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}
35 SRCS += ${what_uuid}.c
36 CLEANFILES += ${what_uuid}.c
37 # we do not need to capture this
38 SUPPRESS_DEPEND += *${what_uuid}.c
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}
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
51 # this works with clang and gcc
52 what_t = const char __attribute__ ((section(".data")))
53 what_location := ${WHAT_LOCATION}
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
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}
64 echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@