-
Notifications
You must be signed in to change notification settings - Fork 7
/
core.build.build-version-files.mk
84 lines (71 loc) · 2.21 KB
/
core.build.build-version-files.mk
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Adds 'BUILD' and 'VERSION' internal targets to generate the respective files,
# which include variables that can be sourced by shell scripts and Makefiles.
# The 'BUILD' and 'VERSION' targets are automatically included in the 'build' target via YP_BUILD_TARGETS.
#
# ------------------------------------------------------------------------------
#
# Adds a 'yp-substitute-version-vars-in-file' function
# that can generate files based on templates
# that reference variables in the BUILD or VERSION files.
# This is useful for referencing version information at runtime.
# Usage:
#
# some/version.js: some/tpl.version.js
# $(call yp-substitute-version-vars-in-file,$<,$@)
#
# where 'some/tpl.version.js' could be:
# export default {gitHash: '${BUILD_GIT_HASH}'};
#
# ------------------------------------------------------------------------------
YP_CLEAN_FILES += \
BUILD \
VERSION \
YP_BUILD_TARGETS += \
VERSION \
BUILD_DATE ?= $(MAKE_DATE)
BUILD_TIME ?= $(MAKE_TIME)
BUILD_HOSTNAME ?= $(shell hostname)
BUILD_USER ?= $(shell whoami)
$(foreach VAR,BUILD_HOSTNAME BUILD_USER,$(call make-lazy-once,$(VAR)))
BUILD_GIT_BRANCH ?= $(GIT_BRANCH_SHORT)
BUILD_GIT_DESCRIBE ?= $(GIT_DESCRIBE)
BUILD_GIT_HASH ?= $(GIT_HASH)
BUILD_GIT_TAGS ?= $(subst $( ),$(,),$(GIT_TAGS))
BUILD_OS ?= $(OS_SHORT)
BUILD_OS_ARCH ?= $(ARCH)
BUILD_OS_SYSTEM ?= $(shell $(UNAME) -a)
BUILD_VSN ?= $(PKG_VSN)_$(GIT_HASH)
YP_BUILD_VARS = \
BUILD_VSN \
BUILD_DATE \
BUILD_TIME \
BUILD_GIT_BRANCH \
BUILD_GIT_DESCRIBE \
BUILD_GIT_HASH \
BUILD_GIT_TAGS \
BUILD_OS \
BUILD_OS_ARCH \
BUILD_OS_SYSTEM \
BUILD_USER \
BUILD_HOSTNAME \
YP_VERSION_VARS = \
PKG_NAME \
PKG_VSN \
$(YP_BUILD_VARS)
define yp-substitute-version-vars-in-file
< $1 > $2 \
$(foreach VAR,$(YP_VERSION_VARS),$(VAR)=$($(VAR))) \
$(ENVSUBST) '$(foreach VAR,$(YP_VERSION_VARS),$${$(VAR)})'
endef
# ------------------------------------------------------------------------------
.PHONY: BUILD
BUILD:
$(ECHO_DO) "Generating $@..."
$(RM) $@
{ $(foreach VAR,$(YP_BUILD_VARS),$(ECHO) "$(VAR)=$($(VAR))" | $(TR) ' ' '_';) } > $@
$(ECHO_DONE)
VERSION: BUILD
$(ECHO_DO) "Generating $@..."
$(RM) $@
{ $(foreach VAR,$(YP_VERSION_VARS),$(ECHO) "$(VAR)=$($(VAR))" | $(TR) ' ' '_';) } > $@
$(ECHO_DONE)