1# $Id: whats.mk,v 1.13 2025/08/09 22:42:24 sjg Exp $ 2# 3# @(#) Copyright (c) 2014-2020, Simon J. Gerraty 4# 5# SPDX-License-Identifier: BSD-2-Clause 6# 7# Please send copies of changes and bug-fixes to: 8# sjg@crufty.net 9# 10 11.if ${MK_WHATSTRING:Uno} == "yes" 12# it can be useful to embed a what(1) string in binaries 13# so that the build location can be seen from a core file. 14.if defined(KMOD) 15what_thing ?= ${KMOD} 16.elif defined(LIB) 17what_thing ?= lib${LIB} 18.elif defined(PROG) 19what_thing ?= ${PROG} 20SRCS ?= ${PROG}.c 21.elif defined(SHLIB) 22what_thing ?= lib${SHLIB} 23.endif 24 25.if !empty(what_thing) 26# a unique name that won't conflict with anything 27what_uuid = what_${what_thing}_${.CURDIR:T:hash} 28what_var = what_${.CURDIR:T:hash} 29 30SRCS += ${what_uuid}.c 31CLEANFILES += ${what_uuid}.c 32# we do not need to capture this 33SUPPRESS_DEPEND += *${what_uuid}.c 34 35SB ?= ${SRCTOP:H} 36SB_LOCATION ?= ${HOST}:${SB} 37# make customization easy 38WHAT_LOCATION ?= ${.OBJDIR:S,${SB},${SB_LOCATION},} 39WHAT_1 ?= ${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER} 40WHAT_2 ?= ${what_location} 41WHAT_LINE_IDS ?= 1 2 42WHAT_NOCMP_LINE_IDS ?= 1 43# you can add other WHAT_* just be sure to set WHAT_LINE_IDS 44# and WHAT_NOCMP_LINE_IDS accordingly 45 46# this works with clang and gcc 47what_t = const char __attribute__ ((section(".data"))) 48what_location := ${WHAT_LOCATION} 49 50# this script is done in multiple lines so we can 51# use the token ${.OODATE:MNO_META_CMP} 52# to prevent the variable parts making this constantly out-of-date 53${what_uuid}.c: .NOTMAIN 54 echo 'extern const char ${WHAT_LINE_IDS:@i@${what_var}_$i[]@:ts,};' > $@ 55.for i in ${WHAT_LINE_IDS} 56.if ${WHAT_NOCMP_LINE_IDS:M$i} != "" 57 echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@ ${.OODATE:MNO_META_CMP} 58.else 59 echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@ 60.endif 61.endfor 62 63.endif 64.endif 65