1*a34d5fb1SAntonio Huete Jimenez# $Id: whats.mk,v 1.10 2020/08/19 17:51:53 sjg Exp $ 26a91b982SJohn Marino# 3ca58f742SDaniel Fojt# @(#) Copyright (c) 2014-2020, Simon J. Gerraty 46a91b982SJohn Marino# 56a91b982SJohn Marino# This file is provided in the hope that it will 66a91b982SJohn Marino# be of use. There is absolutely NO WARRANTY. 76a91b982SJohn Marino# Permission to copy, redistribute or otherwise 86a91b982SJohn Marino# use this file is hereby granted provided that 96a91b982SJohn Marino# the above copyright notice and this notice are 106a91b982SJohn Marino# left intact. 116a91b982SJohn Marino# 126a91b982SJohn Marino# Please send copies of changes and bug-fixes to: 136a91b982SJohn Marino# sjg@crufty.net 146a91b982SJohn Marino# 156a91b982SJohn Marino 16ca58f742SDaniel Fojt.if ${MK_WHATSTRING:Uno} == "yes" 176a91b982SJohn Marino# it can be useful to embed a what(1) string in binaries 186a91b982SJohn Marino# so that the build location can be seen from a core file. 19ca58f742SDaniel Fojt.if defined(KMOD) 206a91b982SJohn Marinowhat_thing ?= ${KMOD} 21ca58f742SDaniel Fojt.elif defined(LIB) 22ca58f742SDaniel Fojtwhat_thing ?= lib${LIB} 23ca58f742SDaniel Fojt.elif defined(PROG) 24ca58f742SDaniel Fojtwhat_thing ?= ${PROG} 25ca58f742SDaniel FojtSRCS ?= ${PROG}.c 26ca58f742SDaniel Fojt.elif defined(SHLIB) 27ca58f742SDaniel Fojtwhat_thing ?= lib${SHLIB} 286a91b982SJohn Marino.endif 296a91b982SJohn Marino 306a91b982SJohn Marino.if !empty(what_thing) 316a91b982SJohn Marino# a unique name that won't conflict with anything 32ca58f742SDaniel Fojtwhat_uuid = what_${what_thing}_${.CURDIR:T:hash} 33ca58f742SDaniel Fojtwhat_var = what_${.CURDIR:T:hash} 346a91b982SJohn Marino 35ca58f742SDaniel FojtSRCS += ${what_uuid}.c 366a91b982SJohn MarinoCLEANFILES += ${what_uuid}.c 376a91b982SJohn Marino# we do not need to capture this 386a91b982SJohn MarinoSUPPRESS_DEPEND += *${what_uuid}.c 396a91b982SJohn Marino 406a91b982SJohn MarinoSB ?= ${SRCTOP:H} 416a91b982SJohn MarinoSB_LOCATION ?= ${HOST}:${SB} 42ca58f742SDaniel Fojt# make customization easy 43ca58f742SDaniel FojtWHAT_LOCATION ?= ${.OBJDIR:S,${SB},${SB_LOCATION},} 44ca58f742SDaniel FojtWHAT_1 ?= ${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER} 45ca58f742SDaniel FojtWHAT_2 ?= ${what_location} 46ca58f742SDaniel FojtWHAT_LINE_IDS ?= 1 2 47ca58f742SDaniel FojtWHAT_NOCMP_LINE_IDS ?= 1 48ca58f742SDaniel Fojt# you can add other WHAT_* just be sure to set WHAT_LINE_IDS 49ca58f742SDaniel Fojt# and WHAT_NOCMP_LINE_IDS accordingly 506a91b982SJohn Marino 516a91b982SJohn Marino# this works with clang and gcc 52ca58f742SDaniel Fojtwhat_t = const char __attribute__ ((section(".data"))) 53ca58f742SDaniel Fojtwhat_location := ${WHAT_LOCATION} 546a91b982SJohn Marino 55ca58f742SDaniel Fojt# this script is done in multiple lines so we can 56ca58f742SDaniel Fojt# use the token ${.OODATE:MNO_META_CMP} 57ca58f742SDaniel Fojt# to prevent the variable parts making this constantly out-of-date 586a91b982SJohn Marino${what_uuid}.c: 59ca58f742SDaniel Fojt echo 'extern const char ${WHAT_LINE_IDS:@i@${what_var}_$i[]@:ts,};' > $@ 60ca58f742SDaniel Fojt.for i in ${WHAT_LINE_IDS} 61ca58f742SDaniel Fojt.if ${WHAT_NOCMP_LINE_IDS:M$i} != "" 62ca58f742SDaniel Fojt echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@ ${.OODATE:MNO_META_CMP} 63ca58f742SDaniel Fojt.else 64ca58f742SDaniel Fojt echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@ 65ca58f742SDaniel Fojt.endif 66ca58f742SDaniel Fojt.endfor 67ca58f742SDaniel Fojt 686a91b982SJohn Marino.endif 696a91b982SJohn Marino.endif 70