aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/mk/whats.mk
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/mk/whats.mk')
-rw-r--r--contrib/bmake/mk/whats.mk73
1 files changed, 39 insertions, 34 deletions
diff --git a/contrib/bmake/mk/whats.mk b/contrib/bmake/mk/whats.mk
index 4080c12e00f8..1dacb4c14365 100644
--- a/contrib/bmake/mk/whats.mk
+++ b/contrib/bmake/mk/whats.mk
@@ -1,6 +1,6 @@
-# $Id: whats.mk,v 1.3 2017/10/19 06:09:14 sjg Exp $
+# $Id: whats.mk,v 1.9 2020/05/09 19:48:53 sjg Exp $
#
-# @(#) Copyright (c) 2014, Simon J. Gerraty
+# @(#) Copyright (c) 2014-2020, Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
@@ -13,25 +13,18 @@
# sjg@crufty.net
#
-.if ${MK_WHATSTRING:Uno} != "no"
-what_build_exts?= o
+.if ${MK_WHATSTRING:Uno} == "yes"
# it can be useful to embed a what(1) string in binaries
# so that the build location can be seen from a core file.
-.if defined(PROG) && ${.MAKE.MAKEFILES:M*prog.mk} != ""
-what_thing?= ${PROGNAME:U${PROG}}
-what_build_thing?= ${PROG}
-.elif defined(LIB) && ${.MAKE.MAKEFILES:M*lib.mk} != ""
-# probably only makes sense for shared libs
-# and the plumbing needed varies depending on *lib.mk
-what_thing?= lib${LIB}
-.if !empty(SOBJS)
-_soe:= ${SOBJS:E:[1]}
-what_build_exts= ${_soe}
-SOBJS+= ${what_uuid}.${_soe}
-.endif
-.elif defined(KMOD) && ${.MAKE.MAKEFILES:M*kmod.mk} != ""
-what_thing?= ${KMOD}
-what_build_thing?= ${KMOD}.ko
+.if defined(KMOD)
+what_thing ?= ${KMOD}
+.elif defined(LIB)
+what_thing ?= lib${LIB}
+.elif defined(PROG)
+what_thing ?= ${PROG}
+SRCS ?= ${PROG}.c
+.elif defined(SHLIB)
+what_thing ?= lib${SHLIB}
.endif
.if !empty(what_thing)
@@ -39,26 +32,38 @@ what_build_thing?= ${KMOD}.ko
what_uuid = what_${what_thing}_${.CURDIR:T:hash}
what_var = what_${.CURDIR:T:hash}
-.if !empty(what_build_thing)
-${what_build_thing}: ${what_build_exts:@e@${what_uuid}.$e@}
-.endif
-OBJS+= ${what_uuid}.o
-CLEANFILES+= ${what_uuid}.c
-
+SRCS += ${what_uuid}.c
+CLEANFILES += ${what_uuid}.c
# we do not need to capture this
-SUPPRESS_DEPEND+= *${what_uuid}.c
+SUPPRESS_DEPEND += *${what_uuid}.c
-SB?= ${SRCTOP:H}
-SB_LOCATION?= ${HOST}:${SB}
-what_location:= ${.OBJDIR:S,${SB},${SB_LOCATION},}
+SB ?= ${SRCTOP:H}
+SB_LOCATION ?= ${HOST}:${SB}
+# make customization easy
+WHAT_LOCATION ?= ${.OBJDIR:S,${SB},${SB_LOCATION},}
+WHAT_1 ?= ${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER}
+WHAT_2 ?= ${what_location}
+WHAT_LINE_IDS ?= 1 2
+WHAT_NOCMP_LINE_IDS ?= 1
+# you can add other WHAT_* just be sure to set WHAT_LINE_IDS
+# and WHAT_NOCMP_LINE_IDS accordingly
# this works with clang and gcc
-_what_t= const char __attribute__ ((section(".data")))
-_what1:= @(\#)${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER}
-_what2:= @(\#)${what_location}
+what_t = const char __attribute__ ((section(".data")))
+what_location := ${WHAT_LOCATION}
+# this script is done in multiple lines so we can
+# use the token ${.OODATE:MNO_META_CMP}
+# to prevent the variable parts making this constantly out-of-date
${what_uuid}.c:
- echo '${_what_t} ${what_var}1[] = "${_what1}";' > $@ ${.OODATE:MNO_META_CMP}
- echo '${_what_t} ${what_var}2[] = "${_what2}";' >> $@
+ echo 'extern const char ${WHAT_LINE_IDS:@i@${what_var}_$i[]@:ts,};' > $@
+.for i in ${WHAT_LINE_IDS}
+.if ${WHAT_NOCMP_LINE_IDS:M$i} != ""
+ echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@ ${.OODATE:MNO_META_CMP}
+.else
+ echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@
+.endif
+.endfor
+
.endif
.endif