Stephen Cprek | e7254c7 | 2015-02-19 14:33:38 -0600 | [diff] [blame^] | 1 | ################################################################################ |
| 2 | # |
| 3 | # pkg-versions |
| 4 | # |
| 5 | # Read VERSION.readme in the current directory to learn about the version |
| 6 | # string structure |
| 7 | # |
| 8 | ################################################################################ |
| 9 | |
| 10 | define OPENPOWER_SUBPACKAGE_VERSION |
| 11 | |
| 12 | $(2)_VERSION_FILE = $$(OPENPOWER_VERSION_DIR)/$(1).version.txt |
| 13 | ALL_SUBPACKAGE_VERSIONS += $$($(2)_VERSION_FILE) |
| 14 | |
| 15 | ### Create subpackage patch file |
| 16 | define $(2)_OPENPOWER_PATCH_FILE |
| 17 | |
| 18 | mkdir -p "$$(OPENPOWER_VERSION_DIR)"; |
| 19 | |
| 20 | # Remove patch file to start off fresh |
| 21 | if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt ]; then \ |
| 22 | rm -rf $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt; \ |
| 23 | fi |
| 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 |
| 31 | if [ -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; \ |
| 35 | else \ |
| 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; \ |
| 40 | fi |
| 41 | |
| 42 | # Combine all the patches found in the package and global package directories |
| 43 | if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt ]; then \ |
| 44 | cat $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt | sha512sum | cut -c 1-7 | \ |
| 45 | xargs echo -n > $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt; \ |
| 46 | fi |
| 47 | |
| 48 | # Remove the tmp_patch file |
| 49 | if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt ]; then \ |
| 50 | rm -rf $$(OPENPOWER_VERSION_DIR)/$(1).tmp_patch.txt; \ |
| 51 | fi |
| 52 | |
| 53 | endef ### |
| 54 | |
| 55 | ### Create subpackage version file |
| 56 | define $(2)_OPENPOWER_VERSION_FILE |
| 57 | |
| 58 | mkdir -p "$$(OPENPOWER_VERSION_DIR)" |
| 59 | |
| 60 | # Add package name |
| 61 | echo -n " $(1)-" > $$($(2)_VERSION_FILE) |
| 62 | |
| 63 | # If site local |
| 64 | # Add site local and user, local commit, if local is dirty |
| 65 | # Else not local |
| 66 | # Add package version, op-build is dirty, op-build patches |
| 67 | if [ "$$($(2)_SITE_METHOD)" == "local" ]; then \ |
| 68 | echo -n "site_local-" >> $$($(2)_VERSION_FILE); \ |
| 69 | whoami | xargs echo -n >> $$($(2)_VERSION_FILE); \ |
| 70 | echo -n "-" >> $$($(2)_VERSION_FILE); \ |
| 71 | \ |
| 72 | cd "$$($(2)_SITE)"; (git describe --tags || git log -n1 --pretty=format:'%h' || echo "unknown") \ |
| 73 | | sed 's/\(.*\)-g\([0-9a-f]\{7\}\).*/\2/' | xargs echo -n \ |
| 74 | >> $$($(2)_VERSION_FILE); \ |
| 75 | \ |
| 76 | cd "$$($(2)_SITE)"; git describe --all --dirty | grep -e "-dirty" | sed 's/.*\(-dirty\)/\1/' | \ |
| 77 | xargs echo -n >> $$($(2)_VERSION_FILE); \ |
| 78 | else \ |
| 79 | \ |
| 80 | [ `echo -n $$($(2)_VERSION) | wc -c` == "40" ] && (echo -n $$($(2)_VERSION) | \ |
| 81 | sed "s/^\([0-9a-f]\{7\}\).*/\1/" >> $$($(2)_VERSION_FILE)) \ |
| 82 | || echo -n $$($(2)_VERSION) >> $$($(2)_VERSION_FILE); \ |
| 83 | \ |
| 84 | cd "$$(BR2_EXTERNAL)"; git describe --all --dirty | \ |
| 85 | if grep -e "-dirty"; then \ |
| 86 | echo -n "-opdirty" >> $$($(2)_VERSION_FILE); \ |
| 87 | fi; \ |
| 88 | \ |
| 89 | if [ -f $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt ]; then \ |
| 90 | echo -n "-" >> $$($(2)_VERSION_FILE); \ |
| 91 | cat $$(OPENPOWER_VERSION_DIR)/$(1).patch.txt >> $$($(2)_VERSION_FILE); fi \ |
| 92 | fi |
| 93 | |
| 94 | # Add new line to version.txt |
| 95 | echo "" >> $$($(2)_VERSION_FILE); |
| 96 | |
| 97 | endef ### |
| 98 | |
| 99 | # Add appropriate templates to hooks |
| 100 | $(2)_POST_PATCH_HOOKS += $(2)_OPENPOWER_PATCH_FILE |
| 101 | $(2)_PRE_BUILD_HOOKS += $(2)_OPENPOWER_VERSION_FILE |
| 102 | |
| 103 | # Top-level rule to print or generate a subpackage version |
| 104 | $(1)-version: $$(if $$(wildcard $$($(2)_VERSION_FILE)),$(1)-print-version,$(1)-build-version) |
| 105 | |
| 106 | # Rule to print out subpackage version |
| 107 | $(1)-print-version: |
| 108 | @echo "=== $(2)_VERSION ===" |
| 109 | @cat $$($(2)_VERSION_FILE) | xargs echo |
| 110 | |
| 111 | # Rule to generate subpackage version |
| 112 | $(1)-build-version: |
| 113 | @echo "=== $(2)_VERSION ===" |
| 114 | @echo " Searching for patches..." |
| 115 | @$$($(2)_OPENPOWER_PATCH_FILE) |
| 116 | @echo " End of patches..."; |
| 117 | @echo " Creating version string (various output may display)..." |
| 118 | @$$($(2)_OPENPOWER_VERSION_FILE) |
| 119 | @echo " End creating version string..." |
| 120 | @echo -n " version: "; cat $$($(2)_VERSION_FILE) | xargs echo |
| 121 | |
| 122 | endef |
| 123 | |
| 124 | define OPENPOWER_VERSION |
| 125 | |
| 126 | UPPER_CASE_PKG = $(call UPPERCASE,$(1)) |
| 127 | $$(UPPER_CASE_PKG)_VERSION_FILE = $$(OPENPOWER_VERSION_DIR)/$(1).version.txt |
| 128 | |
| 129 | |
| 130 | $$(eval $$(foreach pkg,$$(OPENPOWER_VERSIONED_SUBPACKAGES), \ |
| 131 | $$(call OPENPOWER_SUBPACKAGE_VERSION,$$(pkg),$$(call UPPERCASE,$$(pkg))))) |
| 132 | |
| 133 | ### Combine subpackage files into one version file |
| 134 | define $$(UPPER_CASE_PKG)_OPENPOWER_VERSION_FILE |
| 135 | |
| 136 | mkdir -p "$$(OPENPOWER_VERSION_DIR)" |
| 137 | |
| 138 | # Add vendor or default open-power |
| 139 | if [ "$$(OPBUILD_VENDOR)" != '' ]; then \ |
| 140 | echo -n "$$(OPBUILD_VENDOR)-" > $$($$(UPPER_CASE_PKG)_VERSION_FILE); \ |
| 141 | else \ |
| 142 | echo -n "open-power-" > $$($$(UPPER_CASE_PKG)_VERSION_FILE); \ |
| 143 | fi |
| 144 | |
| 145 | # Add platform or default from defconfig |
| 146 | if [ "$$(OPBUILD_PLATFORM)" != '' ]; then \ |
| 147 | echo -n "$$(OPBUILD_PLATFORM)-" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \ |
| 148 | else \ |
| 149 | echo -n "$$(BR2_OPENPOWER_CONFIG_NAME)-" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \ |
| 150 | fi |
| 151 | |
| 152 | # Add op-build version |
| 153 | # Order: OPBUILD_VERSION, tag, commit, unknown |
| 154 | if [ "$$(OPBUILD_VERSION)" != '' ]; then \ |
| 155 | echo -n "$$(OPBUILD_VERSION)" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \ |
| 156 | else \ |
| 157 | cd "$$(BR2_EXTERNAL)"; (git describe --tags || git log -n1 --pretty=format:'%h' || echo "unknown") \ |
| 158 | | sed 's/\(.*\)-g\([0-9a-f]\{7\}\).*/\2/' | xargs echo -n \ |
| 159 | >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); \ |
| 160 | fi |
| 161 | |
| 162 | # Check if op-build is dirty |
| 163 | cd "$$(BR2_EXTERNAL)"; git describe --all --dirty | grep -e "-dirty" | sed 's/.*\(-dirty\)/\1/' | \ |
| 164 | xargs echo -n >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); |
| 165 | |
| 166 | # Add new line to $$($$(UPPER_CASE_PKG)_VERSION_FILE) |
| 167 | echo "" >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); |
| 168 | |
| 169 | # Combing subpackage version files into $$($$(UPPER_CASE_PKG)_VERSION_FILE) |
| 170 | $$(foreach verFile,$$(ALL_SUBPACKAGE_VERSIONS), |
| 171 | if [ -f $$(verFile) ]; then cat $$(verFile) \ |
| 172 | >> $$($$(UPPER_CASE_PKG)_VERSION_FILE); fi ) |
| 173 | |
| 174 | endef ### |
| 175 | |
| 176 | $$(UPPER_CASE_PKG)_PRE_BUILD_HOOKS += $$(UPPER_CASE_PKG)_OPENPOWER_VERSION_FILE |
| 177 | |
| 178 | # Top-level rule to print or generate openpower-pnor version |
| 179 | $(1)-version: $$(if $$(wildcard $$($$(UPPER_CASE_PKG)_VERSION_FILE)),$(1)-print-version,$(1)-build-version) |
| 180 | |
| 181 | # Rule to print out pnor version |
| 182 | $(1)-print-version: |
| 183 | @echo "=== $$(UPPER_CASE_PKG)_VERSION ===" |
| 184 | @cat $$($$(UPPER_CASE_PKG)_VERSION_FILE) |
| 185 | @echo ""; echo "**See openpower/package/VERSION.readme for detailed info on package strings"; echo "" |
| 186 | |
| 187 | |
| 188 | # Rule to generate pnor version |
| 189 | $(1)-build-version: $$(foreach pkg,$$(OPENPOWER_VERSIONED_SUBPACKAGES), $$(pkg)-version) |
| 190 | @$$($$(UPPER_CASE_PKG)_OPENPOWER_VERSION_FILE) |
| 191 | @echo "=== $$(UPPER_CASE_PKG)_VERSION ===" |
| 192 | @cat $$($$(UPPER_CASE_PKG)_VERSION_FILE) |
| 193 | @echo ""; echo "**See openpower/package/VERSION.readme for detailed info on package strings"; echo "" |
| 194 | |
| 195 | endef |