blob: 5ad132352f86834a16ec2ede3e62c78b31577974 [file] [log] [blame]
Stephen Cpreke7254c72015-02-19 14:33:38 -06001################################################################################
2#
3# pkg-versions
4#
5# Read VERSION.readme in the current directory to learn about the version
6# string structure
7#
8################################################################################
9
10define OPENPOWER_SUBPACKAGE_VERSION
11
12$(2)_VERSION_FILE = $$(OPENPOWER_VERSION_DIR)/$(1).version.txt
13ALL_SUBPACKAGE_VERSIONS += $$($(2)_VERSION_FILE)
14
15### Create subpackage patch file
16define $(2)_OPENPOWER_PATCH_FILE
17
18mkdir -p "$$(OPENPOWER_VERSION_DIR)";
19
20# Remove patch file to start off fresh
21if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt ]; then \
22 rm -rf $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt; \
23fi
24
25# Check all global patch directories
26$$(foreach path, $$(BR2_GLOBAL_PATCH_DIR),if ls $$(path)/$(1)/*.patch 2>/dev/null; then \
27 sha512sum $$(path)/$(1)/*.patch | sha512sum | \
28 xargs echo >> $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt; fi;)
29
30# Check the package patch dir, $$(PKGDIR) doesn't exist when running the version rules
31if [ -n "$$(PKGDIR)" ]; then \
32 if ls $$(PKGDIR)*.patch 2>/dev/null; then sha512sum $$(PKGDIR)*.patch | sha512sum | \
33 xargs echo >> $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt; \
34 fi; \
35else \
36 if ls $$(BR2_EXTERNAL)/package/$(1)/*.patch 2>/dev/null; then sha512sum \
37 $$(BR2_EXTERNAL)/package/$(1)/*.patch | sha512sum | \
38 xargs echo >> $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt; \
39 fi; \
40fi
41
Sam Mendoza-Jonase56617a2016-03-09 11:59:08 +110042# If this is for linux, also check openpower/linux
43if [ $(filter "LINUX", "$(2)") == "$(2)" ]; then \
44 if ls $$(BR2_EXTERNAL)/$(1)/*.patch 2>/dev/null; then sha512sum \
45 $$(BR2_EXTERNAL)/$(1)/*.patch | sha512sum | \
46 xargs echo >> $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt; \
47 fi; \
48fi;
49
Stephen Cpreke7254c72015-02-19 14:33:38 -060050# Combine all the patches found in the package and global package directories
51if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt ]; then \
52 cat $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt | sha512sum | cut -c 1-7 | \
53 xargs echo -n > $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt; \
54fi
55
56# Remove the tmp_patch file
57if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt ]; then \
58 rm -rf $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt; \
59fi
60
61endef ###
62
63### Create subpackage version file
64define $(2)_OPENPOWER_VERSION_FILE
65
66mkdir -p "$$(OPENPOWER_VERSION_DIR)"
67
68# Add package name
69echo -n " $(1)-" > $$($(2)_VERSION_FILE)
70
71# If site local
72# Add site local and user, local commit, if local is dirty
73# Else not local
Sam Mendoza-Jonasddc5fab2016-03-11 14:37:04 +110074# Add package version, extraversion if linux, op-build is dirty, op-build patches
Stephen Cpreke7254c72015-02-19 14:33:38 -060075if [ "$$($(2)_SITE_METHOD)" == "local" ]; then \
76echo -n "site_local-" >> $$($(2)_VERSION_FILE); \
77whoami | xargs echo -n >> $$($(2)_VERSION_FILE); \
78echo -n "-" >> $$($(2)_VERSION_FILE); \
79\
80cd "$$($(2)_SITE)"; (git describe --tags || git log -n1 --pretty=format:'%h' || echo "unknown") \
Stewart Smith93157d12015-05-14 16:01:44 +100081 | sed 's/\(.*\)-g\([0-9a-f]\{7\}\).*/\2/;s/$(1)-//;' | xargs echo -n \
Stephen Cpreke7254c72015-02-19 14:33:38 -060082 >> $$($(2)_VERSION_FILE); \
83\
Stewart Smith93157d12015-05-14 16:01:44 +100084cd "$$($(2)_SITE)"; git describe --all --dirty | grep -e "-dirty" | sed 's/.*\(-dirty\)/\1/;' | \
Stephen Cpreke7254c72015-02-19 14:33:38 -060085 xargs echo -n >> $$($(2)_VERSION_FILE); \
86else \
87\
88[ `echo -n $$($(2)_VERSION) | wc -c` == "40" ] && (echo -n $$($(2)_VERSION) | \
Stewart Smith93157d12015-05-14 16:01:44 +100089 sed "s/^\([0-9a-f]\{7\}\).*/\1/;s/$(1)-//;" >> $$($(2)_VERSION_FILE)) \
90 || echo -n $$($(2)_VERSION) | sed -e 's/$(1)-//' >> $$($(2)_VERSION_FILE); \
Stephen Cpreke7254c72015-02-19 14:33:38 -060091\
Sam Mendoza-Jonasddc5fab2016-03-11 14:37:04 +110092if [ $(filter "LINUX", "$(2)") == "$(2)" ]; then \
93 if ls $$(BUILD_DIR)/$(1)-$$($(2)_VERSION)/Makefile 1>/dev/null; then \
94 head $$(BUILD_DIR)/$(1)-$$($(2)_VERSION)/Makefile | grep EXTRAVERSION \
95 | cut -d ' ' -f 3 | \
96 xargs echo -n >> $$($(2)_VERSION_FILE); \
97 fi; \
98fi; \
99\
Stephen Cpreke7254c72015-02-19 14:33:38 -0600100cd "$$(BR2_EXTERNAL)"; git describe --all --dirty | \
101 if grep -e "-dirty"; then \
102 echo -n "-opdirty" >> $$($(2)_VERSION_FILE); \
103 fi; \
104\
105if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt ]; then \
106 echo -n "-" >> $$($(2)_VERSION_FILE); \
107 cat $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt >> $$($(2)_VERSION_FILE); fi \
108fi
109
110# Add new line to version.txt
111echo "" >> $$($(2)_VERSION_FILE);
112
113endef ###
114
115# Add appropriate templates to hooks
116$(2)_POST_PATCH_HOOKS += $(2)_OPENPOWER_PATCH_FILE
Samuel Mendoza-Jonasd38455d2016-07-15 16:32:18 +1000117$(2)_PRE_CONFIGURE_HOOKS += $(2)_OPENPOWER_VERSION_FILE
Stephen Cpreke7254c72015-02-19 14:33:38 -0600118
119# Top-level rule to print or generate a subpackage version
120$(1)-version: $$(if $$(wildcard $$($(2)_VERSION_FILE)),$(1)-print-version,$(1)-build-version)
121
122# Rule to print out subpackage version
123$(1)-print-version:
124 @echo "=== $(2)_VERSION ==="
125 @cat $$($(2)_VERSION_FILE) | xargs echo
126
127# Rule to generate subpackage version
128$(1)-build-version:
129 @echo "=== $(2)_VERSION ==="
130 @echo " Searching for patches..."
131 @$$($(2)_OPENPOWER_PATCH_FILE)
132 @echo " End of patches...";
133 @echo " Creating version string (various output may display)..."
134 @$$($(2)_OPENPOWER_VERSION_FILE)
135 @echo " End creating version string..."
136 @echo -n " version: "; cat $$($(2)_VERSION_FILE) | xargs echo
137
138endef
139
140define OPENPOWER_VERSION
141
142UPPER_CASE_PKG = $(call UPPERCASE,$(1))
143$$(UPPER_CASE_PKG)_VERSION_FILE = $$(OPENPOWER_VERSION_DIR)/$(1).version.txt
144
145
146$$(eval $$(foreach pkg,$$(OPENPOWER_VERSIONED_SUBPACKAGES), \
147 $$(call OPENPOWER_SUBPACKAGE_VERSION,$$(pkg),$$(call UPPERCASE,$$(pkg)))))
148
149### Combine subpackage files into one version file
150define $$(UPPER_CASE_PKG)_OPENPOWER_VERSION_FILE
151
152mkdir -p "$$(OPENPOWER_VERSION_DIR)"
153
154# Add vendor or default open-power
155if [ "$$(OPBUILD_VENDOR)" != '' ]; then \
156echo -n "$$(OPBUILD_VENDOR)-" > $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
157else \
158echo -n "open-power-" > $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
159fi
160
161# Add platform or default from defconfig
162if [ "$$(OPBUILD_PLATFORM)" != '' ]; then \
163echo -n "$$(OPBUILD_PLATFORM)-" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
164else \
165echo -n "$$(BR2_OPENPOWER_CONFIG_NAME)-" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
166fi
167
168# Add op-build version
169# Order: OPBUILD_VERSION, tag, commit, unknown
170if [ "$$(OPBUILD_VERSION)" != '' ]; then \
171 echo -n "$$(OPBUILD_VERSION)" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
172else \
173cd "$$(BR2_EXTERNAL)"; (git describe --tags || git log -n1 --pretty=format:'%h' || echo "unknown") \
174 | sed 's/\(.*\)-g\([0-9a-f]\{7\}\).*/\2/' | xargs echo -n \
175 >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
176fi
177
178# Check if op-build is dirty
179cd "$$(BR2_EXTERNAL)"; git describe --all --dirty | grep -e "-dirty" | sed 's/.*\(-dirty\)/\1/' | \
180 xargs echo -n >> $$($$(UPPER_CASE_PKG)_VERSION_FILE);
181
182# Add new line to $$($$(UPPER_CASE_PKG)_VERSION_FILE)
183echo "" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE);
184
Sam Mendoza-Jonasdc7e2382016-03-09 16:13:02 +1100185# Add a specific line for op-build if it has been overwritten
186if [ "$$(OPBUILD_VENDOR)" != '' ]; then \
187echo -n " op-build-" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
188cd "$$(BR2_EXTERNAL)"; (git describe --tags || git log -n1 --pretty=format:'%h' || echo "unknown") \
189 | sed 's/\(.*\)-g\([0-9a-f]\{7\}\).*/\2/' | xargs echo -n \
190 >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
191cd "$$(BR2_EXTERNAL)"; git describe --all --dirty | grep -e "-dirty" | sed 's/.*\(-dirty\)/\1/' | \
192 xargs echo >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
193fi
194
195# Include the currently checked-out buildroot version
196echo -n " buildroot-" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE);
197cd "./buildroot"; (git describe --tags || git log -n1 --pretty=format:'%h' || echo "unknown") \
198 | sed 's/\(.*\)-g\([0-9a-f]\{7\}\).*/\2/' | xargs echo -n \
199 >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \
200git describe --all --dirty | grep -e "-dirty" | sed 's/.*\(-dirty\)/\1/' | \
201 xargs echo >> $$($$(UPPER_CASE_PKG)_VERSION_FILE);
202
203
Stephen Cpreke7254c72015-02-19 14:33:38 -0600204# Combing subpackage version files into $$($$(UPPER_CASE_PKG)_VERSION_FILE)
205$$(foreach verFile,$$(ALL_SUBPACKAGE_VERSIONS),
206 if [ -f $$(verFile) ]; then cat $$(verFile) \
207 >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); fi )
208
209endef ###
210
211$$(UPPER_CASE_PKG)_PRE_BUILD_HOOKS += $$(UPPER_CASE_PKG)_OPENPOWER_VERSION_FILE
212
213# Top-level rule to print or generate openpower-pnor version
214$(1)-version: $$(if $$(wildcard $$($$(UPPER_CASE_PKG)_VERSION_FILE)),$(1)-print-version,$(1)-build-version)
215
216# Rule to print out pnor version
217$(1)-print-version:
218 @echo "=== $$(UPPER_CASE_PKG)_VERSION ==="
219 @cat $$($$(UPPER_CASE_PKG)_VERSION_FILE)
220 @echo ""; echo "**See openpower/package/VERSION.readme for detailed info on package strings"; echo ""
221
Stephen Cpreke7254c72015-02-19 14:33:38 -0600222# Rule to generate pnor version
223$(1)-build-version: $$(foreach pkg,$$(OPENPOWER_VERSIONED_SUBPACKAGES), $$(pkg)-version)
224 @$$($$(UPPER_CASE_PKG)_OPENPOWER_VERSION_FILE)
225 @echo "=== $$(UPPER_CASE_PKG)_VERSION ==="
226 @cat $$($$(UPPER_CASE_PKG)_VERSION_FILE)
227 @echo ""; echo "**See openpower/package/VERSION.readme for detailed info on package strings"; echo ""
228
Stephen Cprekded98fb2015-04-15 17:11:52 -0500229# Rule to force re-generation of all versioned subpackages
230$(1)-build-version-all: $$(foreach pkg,$$(OPENPOWER_VERSIONED_SUBPACKAGES), $$(pkg)-build-version)
231 @$$($$(UPPER_CASE_PKG)_OPENPOWER_VERSION_FILE)
232 @echo "=== $$(UPPER_CASE_PKG)_VERSION ==="
233 @cat $$($$(UPPER_CASE_PKG)_VERSION_FILE)
234 @echo ""; echo "**See openpower/package/VERSION.readme for detailed info on package strings"; echo ""
235
Stephen Cpreke7254c72015-02-19 14:33:38 -0600236endef