You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
12 KiB

  1. ##
  2. # Extra checks, because we do not use autoconf. Set extra_check to false if it is bothering you.
  3. ##
  4. extra_check = true
  5. go_min_version = 1.8.3
  6. gpg_key = 2122CBE9
  7. ifeq ($(extra_check),true)
  8. ifndef GOPATH
  9. $(error GOPATH not set)
  10. else
  11. go_version := $(shell go version | sed "s/^.* go\([0-9\.]*\) .*$$/\1/" )
  12. $(info Found go version $(go_version))
  13. go_version_check := $(shell echo -e "$(go_min_version)\n$(go_version)" | sort -V | head -1)
  14. ifneq ($(go_min_version),$(go_version_check))
  15. $(error go version go_min_version or above is required)
  16. endif
  17. endif
  18. gpg_check := $(shell gpg -K | grep '/$(gpg_key) ' | sed 's,^.*/\($(gpg_key)\) .*$$,\1,')
  19. ifneq ($(gpg_check),$(gpg_key))
  20. $(error GPG key $(gpg_key) not found.)
  21. else
  22. $(info GPG key $(gpg_key) found)
  23. endif
  24. ifndef GPG_PASSPHRASE
  25. $(error GPG_PASSPHRASE not set)
  26. endif
  27. endif
  28. ###
  29. # Here comes the real deal
  30. ###
  31. binaries = tendermint basecoin ethermint
  32. build-binaries = build-tendermint build-basecoin build-ethermint
  33. package-rpm = package-rpm-tendermint package-rpm-basecoin package-rpm-ethermint
  34. install-rpm = install-rpm-tendermint install-rpm-basecoin install-rpm-ethermint
  35. package-deb = package-deb-tendermint package-deb-basecoin package-deb-ethermint
  36. install-deb = install-deb-tendermint install-deb-basecoin install-deb-ethermint
  37. all: $(binaries)
  38. build: $(build-binaries)
  39. package: $(package-rpm) $(package-deb)
  40. install: $(install-rpm) $(install-deb)
  41. $(binaries): %: build-% package-rpm-% package-deb-%
  42. ###
  43. # Building the binaries is not in the spec file, because in the spec file you already need to know the version number
  44. ###
  45. git-branch:
  46. $(eval $GIT_BRANCH=$(shell test -z "$(GIT_BRANCH)" && echo "master" || echo "$(GIT_BRANCH)" ))
  47. build-tendermint: git-branch
  48. @echo "*** Building tendermint"
  49. go get -d -u github.com/tendermint/tendermint/cmd/tendermint
  50. cd $(GOPATH)/src/github.com/tendermint/tendermint && git checkout "$(GIT_BRANCH)" && git pull
  51. $(MAKE) -C $(GOPATH)/src/github.com/tendermint/tendermint get_vendor_deps build
  52. cp $(GOPATH)/src/github.com/tendermint/tendermint/build/tendermint $(GOPATH)/bin
  53. @echo "*** Built tendermint"
  54. build-basecoin: git-branch
  55. @echo "*** Building basecoin"
  56. go get -d -u github.com/tendermint/basecoin/cmd/basecoin
  57. cd $(GOPATH)/src/github.com/tendermint/basecoin && git checkout "$(GIT_BRANCH)" && git pull
  58. $(MAKE) -C $(GOPATH)/src/github.com/tendermint/basecoin get_vendor_deps install
  59. @echo "*** Built basecoin"
  60. build-ethermint: git-branch
  61. @echo "*** Building ethermint"
  62. go get -d -u github.com/tendermint/ethermint/cmd/ethermint
  63. cd $(GOPATH)/src/github.com/tendermint/ethermint && git checkout "$(GIT_BRANCH)" && git pull
  64. $(MAKE) -C $(GOPATH)/src/github.com/tendermint/ethermint get_vendor_deps build
  65. cp $(GOPATH)/src/github.com/tendermint/ethermint/build/ethermint $(GOPATH)/bin
  66. @echo "*** Built ethermint"
  67. version-%: $(GOPATH)/bin/%
  68. if [ -z "$(BUILD_NUMBER)" ]; then echo "BUILD_NUMBER not set" ; false ; fi
  69. $(eval $*_version=$(shell $< version | cut -d- -f1 ))
  70. prepare-spec-%: version-%
  71. mkdir -p {SPECS,tmp}
  72. echo "Version: $($*_version)" > SPECS/$*.spec
  73. echo "Release: $(BUILD_NUMBER)" >> SPECS/$*.spec
  74. cat spectemplates/$*.spec >> SPECS/$*.spec
  75. package-rpm-%: prepare-spec-%
  76. @echo "*** Packaging RPM $* version $($*_version)"
  77. rpmbuild -bb SPECS/$*.spec
  78. ./sign RPMS/x86_64/$*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm
  79. rpm -Kv RPMS/x86_64/$*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm
  80. @echo "*** Packaged RPM $* version $($*_version)"
  81. package-deb-%: version-%
  82. @echo "*** Packaging DEB $* version $($*_version)-$(BUILD_NUMBER)"
  83. echo "BUILD/$*-$($*_version) folder is generated by package-rpm-$*"
  84. test -d BUILD/$*-$($*_version)
  85. rm -rf BUILD/$*-$($*_version)-$(BUILD_NUMBER) tmp/_gpg tmp/_gpgbuilder tmp/debian-binary tmp/control.tar.gz tmp/data.tar.xz
  86. cp -r BUILD/$*-$($*_version) BUILD/$*-$($*_version)-$(BUILD_NUMBER)
  87. cp -r extrafiles/DEBIAN-$* BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN
  88. sed -i "s/@VERSION@/$($*_version)-$(BUILD_NUMBER)/" BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/changelog
  89. sed -i "s/@STABILITY@/stable/" BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/changelog
  90. sed -i "s/@DATETIMESTAMP@/`date +%a,\ %d\ %b\ %Y\ %T\ %z`/" BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/changelog
  91. sed -i "s/@VERSION@/$($*_version)-$(BUILD_NUMBER)/" BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/control
  92. rm -rf BUILD/$*-$($*_version)-$(BUILD_NUMBER)/usr/share/licenses
  93. mkdir -p BUILD/$*-$($*_version)-$(BUILD_NUMBER)/usr/share/doc/$*
  94. cp BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/copyright BUILD/$*-$($*_version)-$(BUILD_NUMBER)/usr/share/doc/$*
  95. gzip -c BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/changelog > BUILD/$*-$($*_version)-$(BUILD_NUMBER)/usr/share/doc/$*/changelog.Debian.gz
  96. gzip -c BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/changelog > BUILD/$*-$($*_version)-$(BUILD_NUMBER)/usr/share/doc/$*/changelog.Debian.amd64.gz
  97. sed -i "s/@INSTALLEDSIZE@/`du -ks BUILD/$*-$($*_version)-$(BUILD_NUMBER) | cut -f 1`/" BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/control
  98. cd BUILD/$*-$($*_version)-$(BUILD_NUMBER) && tar --owner=root --group=root -cvJf ../../tmp/data.tar.xz --exclude DEBIAN *
  99. cd BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN && tar --owner=root --group=root -cvzf ../../../tmp/control.tar.gz *
  100. echo "2.0" > tmp/debian-binary
  101. cp extrafiles/_gpg tmp/
  102. cd tmp && sed -i "s/@DATETIMESTAMP@/`date +%a\ %b\ %d\ %T\ %Y`/" _gpg
  103. cd tmp && sed -i "s/@BINMD5@/`md5sum debian-binary | cut -d\ -f1`/" _gpg
  104. cd tmp && sed -i "s/@BINSHA1@/`sha1sum debian-binary | cut -d\ -f1`/" _gpg
  105. cd tmp && sed -i "s/@BINSIZE@/`stat -c %s debian-binary | cut -d\ -f1`/" _gpg
  106. cd tmp && sed -i "s/@CONMD5@/`md5sum control.tar.gz | cut -d\ -f1`/" _gpg
  107. cd tmp && sed -i "s/@CONSHA1@/`sha1sum control.tar.gz | cut -d\ -f1`/" _gpg
  108. cd tmp && sed -i "s/@CONSIZE@/`stat -c %s control.tar.gz | cut -d\ -f1`/" _gpg
  109. cd tmp && sed -i "s/@DATMD5@/`md5sum data.tar.xz | cut -d\ -f1`/" _gpg
  110. cd tmp && sed -i "s/@DATSHA1@/`sha1sum data.tar.xz | cut -d\ -f1`/" _gpg
  111. cd tmp && sed -i "s/@DATSIZE@/`stat -c %s data.tar.xz | cut -d\ -f1`/" _gpg
  112. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --clearsign tmp/_gpg
  113. mv tmp/_gpg.asc tmp/_gpgbuilder
  114. ar r tmp/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb tmp/debian-binary tmp/control.tar.gz tmp/data.tar.xz tmp/_gpgbuilder
  115. mv tmp/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb RPMS/
  116. rm tmp/debian-binary tmp/control.tar.gz tmp/data.tar.xz tmp/_gpgbuilder tmp/_gpg
  117. @echo "*** Packaged DEB $* version $($*_version)-$(BUILD_NUMBER)"
  118. install-rpm-%: version-%
  119. #Make sure your host has the IAM role to read/write the S3 bucket OR that you set up ~/.boto
  120. @echo "*** Uploading $*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm to AWS CentOS repository"
  121. aws s3 sync s3://tendermint-packages/centos/ tmp/s3/ --delete
  122. mkdir -p tmp/s3/7/os/x86_64/Packages
  123. cp RPMS/x86_64/$*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm tmp/s3/7/os/x86_64/Packages
  124. cp repofiles/RPM-GPG-KEY-Tendermint tmp/s3/7/os/x86_64/
  125. cp repofiles/tendermint.repo tmp/s3/7/os/x86_64/
  126. rm -f tmp/s3/7/os/x86_64/repodata/*.bz2 tmp/s3/7/os/x86_64/repodata/*.gz tmp/s3/7/os/x86_64/repodata/repomd.xml.asc
  127. createrepo tmp/s3/7/os/x86_64/Packages -u http://tendermint-packages.s3-website-us-west-1.amazonaws.com/centos/7/os/x86_64/Packages -o tmp/s3/7/os/x86_64 --update -S --repo Tendermint --content tendermint --content basecoin --content ethermint
  128. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --detach-sign -a tmp/s3/7/os/x86_64/repodata/repomd.xml
  129. aws s3 sync tmp/s3/ s3://tendermint-packages/centos/ --delete --acl public-read
  130. @echo "*** Uploaded $* to AWS CentOS repository"
  131. install-deb-%: version-%
  132. @echo "*** Uploading $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb to AWS Debian repository"
  133. @echo "Testing if $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb is already uploaded"
  134. test ! -f tmp/debian-s3/pool/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb
  135. aws s3 sync s3://tendermint-packages/debian/ tmp/debian-s3/ --delete
  136. @echo "Testing if $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb is already uploaded"
  137. test ! -f tmp/debian-s3/pool/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb
  138. mkdir -p tmp/debian-s3/pool tmp/debian-s3/dists/stable/main/binary-amd64
  139. cp RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb tmp/debian-s3/pool
  140. cp repofiles/Release_amd64 tmp/debian-s3/dists/stable/main/binary-amd64/Release
  141. #Packages / Packages.gz
  142. echo > tmp/Package
  143. echo "Filename: pool/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb" >> tmp/Package
  144. echo "MD5sum: `md5sum RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  145. echo "SHA1: `sha1sum RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  146. echo "SHA256: `sha256sum RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  147. echo "Size: `stat -c %s RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  148. cat BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/control >> tmp/Package
  149. cat tmp/Package >> tmp/debian-s3/dists/stable/main/binary-amd64/Packages
  150. rm -f tmp/debian-s3/dists/stable/main/binary-amd64/Packages.gz
  151. gzip -c tmp/debian-s3/dists/stable/main/binary-amd64/Packages > tmp/debian-s3/dists/stable/main/binary-amd64/Packages.gz
  152. rm -f tmp/Package
  153. #main / Release / InRelease / Release.gpg
  154. cp repofiles/Release tmp/debian-s3/dists/stable/main/Release
  155. rm -f tmp/debian-s3/dists/stable/main/InRelease
  156. rm -f tmp/debian-s3/dists/stable/main/Release.gpg
  157. echo "MD5Sum:" >> tmp/debian-s3/dists/stable/main/Release
  158. cd tmp/debian-s3/dists/stable/main && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; md5sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  159. echo "SHA1:" >> tmp/debian-s3/dists/stable/main/Release
  160. cd tmp/debian-s3/dists/stable/main && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha1sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  161. echo "SHA256:" >> tmp/debian-s3/dists/stable/main/Release
  162. cd tmp/debian-s3/dists/stable/main && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha256sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  163. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA256 -b -a tmp/debian-s3/dists/stable/main/Release
  164. mv tmp/debian-s3/dists/stable/main/Release.asc tmp/debian-s3/dists/stable/main/Release.gpg
  165. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA512 --clearsign tmp/debian-s3/dists/stable/main/Release
  166. mv tmp/debian-s3/dists/stable/main/Release.asc tmp/debian-s3/dists/stable/main/InRelease
  167. #stable / Release / InRelease / Release.gpg
  168. cp repofiles/Release tmp/debian-s3/dists/stable/Release
  169. rm -f tmp/debian-s3/dists/stable/InRelease
  170. rm -f tmp/debian-s3/dists/stable/Release.gpg
  171. echo "MD5Sum:" >> tmp/debian-s3/dists/stable/Release
  172. cd tmp/debian-s3/dists/stable && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; md5sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  173. echo "SHA1:" >> tmp/debian-s3/dists/stable/Release
  174. cd tmp/debian-s3/dists/stable && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha1sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  175. echo "SHA256:" >> tmp/debian-s3/dists/stable/Release
  176. cd tmp/debian-s3/dists/stable && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha256sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  177. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA256 -b -a tmp/debian-s3/dists/stable/Release
  178. mv tmp/debian-s3/dists/stable/Release.asc tmp/debian-s3/dists/stable/Release.gpg
  179. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA512 --clearsign tmp/debian-s3/dists/stable/Release
  180. mv tmp/debian-s3/dists/stable/Release.asc tmp/debian-s3/dists/stable/InRelease
  181. aws s3 sync tmp/debian-s3/ s3://tendermint-packages/debian/ --delete --acl public-read
  182. @echo "*** Uploaded $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb to AWS Debian repository"
  183. mostlyclean:
  184. rm -rf {BUILDROOT,SOURCES,SPECS,SRPMS,tmp}
  185. clean: mostlyclean
  186. rm -rf {BUILD,RPMS}
  187. distclean: clean
  188. rm -rf $(GOPATH)/src/github.com/tendermint/tendermint
  189. rm -rf $(GOPATH)/src/github.com/tendermint/basecoin
  190. rm -rf $(GOPATH)/src/github.com/tendermint/ethermint
  191. rm -rf $(GOPATH)/bin/tendermint
  192. rm -rf $(GOPATH)/bin/basecoin
  193. rm -rf $(GOPATH)/bin/basecli
  194. rm -rf $(GOPATH)/bin/ethermint
  195. .PHONY : clean