xref: /freebsd/contrib/bmake/mk/whats.mk (revision c59c3bf34db360695f07735bebc76a768cac5afc)
1*c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
2*c59c3bf3SSimon J. Gerraty#
3*c59c3bf3SSimon J. Gerraty# $Id: whats.mk,v 1.12 2024/02/17 17:26:57 sjg Exp $
4db29cad8SSimon J. Gerraty#
549caa483SSimon J. Gerraty#	@(#) Copyright (c) 2014-2020, Simon J. Gerraty
6db29cad8SSimon J. Gerraty#
7db29cad8SSimon J. Gerraty#	This file is provided in the hope that it will
8db29cad8SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
9db29cad8SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
10db29cad8SSimon J. Gerraty#	use this file is hereby granted provided that
11db29cad8SSimon J. Gerraty#	the above copyright notice and this notice are
12db29cad8SSimon J. Gerraty#	left intact.
13db29cad8SSimon J. Gerraty#
14db29cad8SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
15db29cad8SSimon J. Gerraty#	sjg@crufty.net
16db29cad8SSimon J. Gerraty#
17db29cad8SSimon J. Gerraty
1849caa483SSimon J. Gerraty.if ${MK_WHATSTRING:Uno} == "yes"
19db29cad8SSimon J. Gerraty# it can be useful to embed a what(1) string in binaries
20db29cad8SSimon J. Gerraty# so that the build location can be seen from a core file.
2149caa483SSimon J. Gerraty.if defined(KMOD)
22db29cad8SSimon J. Gerratywhat_thing ?= ${KMOD}
2349caa483SSimon J. Gerraty.elif defined(LIB)
2449caa483SSimon J. Gerratywhat_thing ?= lib${LIB}
2549caa483SSimon J. Gerraty.elif defined(PROG)
2649caa483SSimon J. Gerratywhat_thing ?= ${PROG}
2749caa483SSimon J. GerratySRCS ?= ${PROG}.c
2849caa483SSimon J. Gerraty.elif defined(SHLIB)
2949caa483SSimon J. Gerratywhat_thing ?= lib${SHLIB}
30db29cad8SSimon J. Gerraty.endif
31db29cad8SSimon J. Gerraty
32db29cad8SSimon J. Gerraty.if !empty(what_thing)
33db29cad8SSimon J. Gerraty# a unique name that won't conflict with anything
34e22fef7dSSimon J. Gerratywhat_uuid = what_${what_thing}_${.CURDIR:T:hash}
35e22fef7dSSimon J. Gerratywhat_var = what_${.CURDIR:T:hash}
36db29cad8SSimon J. Gerraty
3749caa483SSimon J. GerratySRCS += ${what_uuid}.c
38db29cad8SSimon J. GerratyCLEANFILES += ${what_uuid}.c
39db29cad8SSimon J. Gerraty# we do not need to capture this
40db29cad8SSimon J. GerratySUPPRESS_DEPEND += *${what_uuid}.c
41db29cad8SSimon J. Gerraty
42db29cad8SSimon J. GerratySB ?= ${SRCTOP:H}
43db29cad8SSimon J. GerratySB_LOCATION ?= ${HOST}:${SB}
4449caa483SSimon J. Gerraty# make customization easy
4549caa483SSimon J. GerratyWHAT_LOCATION ?= ${.OBJDIR:S,${SB},${SB_LOCATION},}
4649caa483SSimon J. GerratyWHAT_1 ?= ${what_thing:tu} built ${%Y%m%d:L:localtime} by ${USER}
4749caa483SSimon J. GerratyWHAT_2 ?= ${what_location}
4849caa483SSimon J. GerratyWHAT_LINE_IDS ?= 1 2
4949caa483SSimon J. GerratyWHAT_NOCMP_LINE_IDS ?= 1
5049caa483SSimon J. Gerraty# you can add other WHAT_* just be sure to set WHAT_LINE_IDS
5149caa483SSimon J. Gerraty# and WHAT_NOCMP_LINE_IDS accordingly
52db29cad8SSimon J. Gerraty
53db29cad8SSimon J. Gerraty# this works with clang and gcc
5449caa483SSimon J. Gerratywhat_t = const char __attribute__ ((section(".data")))
5549caa483SSimon J. Gerratywhat_location := ${WHAT_LOCATION}
56db29cad8SSimon J. Gerraty
5749caa483SSimon J. Gerraty# this script is done in multiple lines so we can
5849caa483SSimon J. Gerraty# use the token ${.OODATE:MNO_META_CMP}
5949caa483SSimon J. Gerraty# to prevent the variable parts making this constantly out-of-date
60dc1b8c9aSSimon J. Gerraty${what_uuid}.c:	.NOTMAIN
6149caa483SSimon J. Gerraty	echo 'extern const char ${WHAT_LINE_IDS:@i@${what_var}_$i[]@:ts,};' > $@
6249caa483SSimon J. Gerraty.for i in ${WHAT_LINE_IDS}
6349caa483SSimon J. Gerraty.if ${WHAT_NOCMP_LINE_IDS:M$i} != ""
6449caa483SSimon J. Gerraty	echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@ ${.OODATE:MNO_META_CMP}
6549caa483SSimon J. Gerraty.else
6649caa483SSimon J. Gerraty	echo '${what_t} ${what_var}_$i[] = "@(#)${WHAT_$i}";' >> $@
6749caa483SSimon J. Gerraty.endif
6849caa483SSimon J. Gerraty.endfor
6949caa483SSimon J. Gerraty
70db29cad8SSimon J. Gerraty.endif
71db29cad8SSimon J. Gerraty.endif
72