summaryrefslogtreecommitdiffstats
path: root/20150505/mk/whats.mk
blob: d17c3ef290ea9fbed2cd7a5927b1cc50b3ce4dfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# $Id: whats.mk,v 1.1 2014/08/30 22:40:47 sjg Exp $
#
#	@(#) Copyright (c) 2014, Simon J. Gerraty
#
#	This file is provided in the hope that it will
#	be of use.  There is absolutely NO WARRANTY.
#	Permission to copy, redistribute or otherwise
#	use this file is hereby granted provided that 
#	the above copyright notice and this notice are
#	left intact. 
#      
#	Please send copies of changes and bug-fixes to:
#	sjg@crufty.net
#

.if ${MK_WHATSTRING:Uno} != "no"
what_build_exts?= o
# 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
.endif

.if !empty(what_thing)
# a unique name that won't conflict with anything
what_uuid = 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

# we do not need to capture this
SUPPRESS_DEPEND+= *${what_uuid}.c

SB?= ${SRCTOP:H}
SB_LOCATION?= ${HOST}:${SB}
what_location:= ${.OBJDIR:S,${SB},${SB_LOCATION},}

# 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_uuid}.c:
	echo '${_what_t} ${what_uuid}1[] = "${_what1}";' > $@ ${.OODATE:MNO_META_CMP}
	echo '${_what_t} ${what_uuid}2[] = "${_what2}";' >> $@
.endif
.endif
OpenPOWER on IntegriCloud