Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. SHELL = bash
  2. # Branch we are working on
  3. BRANCH := $(or $(BUILD_SOURCEBRANCHNAME),$(lastword $(subst /, ,$(GITHUB_REF))),$(shell git rev-parse --abbrev-ref HEAD))
  4. # Tag of the current commit, if any. If this is not "" then we are building a release
  5. RELEASE_TAG := $(shell git tag -l --points-at HEAD)
  6. # Version of last release (may not be on this branch)
  7. VERSION := $(shell cat VERSION)
  8. # Last tag on this branch
  9. LAST_TAG := $(shell git describe --tags --abbrev=0)
  10. # Next version
  11. NEXT_VERSION := $(shell echo $(VERSION) | awk -F. -v OFS=. '{print $$1,$$2+1,0}')
  12. NEXT_PATCH_VERSION := $(shell echo $(VERSION) | awk -F. -v OFS=. '{print $$1,$$2,$$3+1}')
  13. # If we are working on a release, override branch to master
  14. ifdef RELEASE_TAG
  15. BRANCH := master
  16. LAST_TAG := $(shell git describe --abbrev=0 --tags $(VERSION)^)
  17. endif
  18. TAG_BRANCH := .$(BRANCH)
  19. BRANCH_PATH := branch/$(BRANCH)/
  20. # If building HEAD or master then unset TAG_BRANCH and BRANCH_PATH
  21. ifeq ($(subst HEAD,,$(subst master,,$(BRANCH))),)
  22. TAG_BRANCH :=
  23. BRANCH_PATH :=
  24. endif
  25. # Make version suffix -beta.NNNN.CCCCCCCC (N=Commit number, C=Commit)
  26. VERSION_SUFFIX := -beta.$(shell git rev-list --count HEAD).$(shell git show --no-patch --no-notes --pretty='%h' HEAD)
  27. # TAG is current version + commit number + commit + branch
  28. TAG := $(VERSION)$(VERSION_SUFFIX)$(TAG_BRANCH)
  29. ifdef RELEASE_TAG
  30. TAG := $(RELEASE_TAG)
  31. endif
  32. GO_VERSION := $(shell go version)
  33. GO_OS := $(shell go env GOOS)
  34. ifdef BETA_SUBDIR
  35. BETA_SUBDIR := /$(BETA_SUBDIR)
  36. endif
  37. BETA_PATH := $(BRANCH_PATH)$(TAG)$(BETA_SUBDIR)
  38. BETA_URL := https://beta.rclone.org/$(BETA_PATH)/
  39. BETA_UPLOAD_ROOT := memstore:beta-rclone-org
  40. BETA_UPLOAD := $(BETA_UPLOAD_ROOT)/$(BETA_PATH)
  41. # Pass in GOTAGS=xyz on the make command line to set build tags
  42. ifdef GOTAGS
  43. BUILDTAGS=-tags "$(GOTAGS)"
  44. LINTTAGS=--build-tags "$(GOTAGS)"
  45. endif
  46. .PHONY: rclone test_all vars version
  47. rclone:
  48. ifeq ($(GO_OS),windows)
  49. go run bin/resource_windows.go -version $(TAG) -syso resource_windows_`go env GOARCH`.syso
  50. endif
  51. go build -v --ldflags "-s -X github.com/rclone/rclone/fs.Version=$(TAG)" $(BUILDTAGS) $(BUILD_ARGS)
  52. ifeq ($(GO_OS),windows)
  53. rm resource_windows_`go env GOARCH`.syso
  54. endif
  55. mkdir -p `go env GOPATH`/bin/
  56. cp -av rclone`go env GOEXE` `go env GOPATH`/bin/rclone`go env GOEXE`.new
  57. mv -v `go env GOPATH`/bin/rclone`go env GOEXE`.new `go env GOPATH`/bin/rclone`go env GOEXE`
  58. test_all:
  59. go install --ldflags "-s -X github.com/rclone/rclone/fs.Version=$(TAG)" $(BUILDTAGS) $(BUILD_ARGS) github.com/rclone/rclone/fstest/test_all
  60. vars:
  61. @echo SHELL="'$(SHELL)'"
  62. @echo BRANCH="'$(BRANCH)'"
  63. @echo TAG="'$(TAG)'"
  64. @echo VERSION="'$(VERSION)'"
  65. @echo GO_VERSION="'$(GO_VERSION)'"
  66. @echo BETA_URL="'$(BETA_URL)'"
  67. btest:
  68. @echo "[$(TAG)]($(BETA_URL)) on branch [$(BRANCH)](https://github.com/rclone/rclone/tree/$(BRANCH)) (uploaded in 15-30 mins)" | xclip -r -sel clip
  69. @echo "Copied markdown of beta release to clip board"
  70. btesth:
  71. @echo "<a href="$(BETA_URL)">$(TAG)</a> on branch <a href="https://github.com/rclone/rclone/tree/$(BRANCH)">$(BRANCH)</a> (uploaded in 15-30 mins)" | xclip -r -sel clip -t text/html
  72. @echo "Copied beta release in HTML to clip board"
  73. version:
  74. @echo '$(TAG)'
  75. # Full suite of integration tests
  76. test: rclone test_all
  77. -test_all 2>&1 | tee test_all.log
  78. @echo "Written logs in test_all.log"
  79. # Quick test
  80. quicktest:
  81. RCLONE_CONFIG="/notfound" go test $(BUILDTAGS) ./...
  82. racequicktest:
  83. RCLONE_CONFIG="/notfound" go test $(BUILDTAGS) -cpu=2 -race ./...
  84. compiletest:
  85. RCLONE_CONFIG="/notfound" go test $(BUILDTAGS) -run XXX ./...
  86. # Do source code quality checks
  87. check: rclone
  88. @echo "-- START CODE QUALITY REPORT -------------------------------"
  89. @golangci-lint run $(LINTTAGS) ./...
  90. @echo "-- END CODE QUALITY REPORT ---------------------------------"
  91. # Get the build dependencies
  92. build_dep:
  93. go run bin/get-github-release.go -use-api -extract golangci-lint golangci/golangci-lint 'golangci-lint-.*\.tar\.gz'
  94. # Get the release dependencies we only install on linux
  95. release_dep_linux:
  96. go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
  97. # Update dependencies
  98. showupdates:
  99. @echo "*** Direct dependencies that could be updated ***"
  100. @GO111MODULE=on go list -u -f '{{if (and (not (or .Main .Indirect)) .Update)}}{{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}' -m all 2> /dev/null
  101. # Update direct dependencies only
  102. updatedirect:
  103. GO111MODULE=on go get -d $$(go list -m -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' all)
  104. GO111MODULE=on go mod tidy
  105. # Update direct and indirect dependencies and test dependencies
  106. update:
  107. GO111MODULE=on go get -d -u -t ./...
  108. GO111MODULE=on go mod tidy
  109. # Tidy the module dependencies
  110. tidy:
  111. GO111MODULE=on go mod tidy
  112. doc: rclone.1 MANUAL.html MANUAL.txt rcdocs commanddocs
  113. rclone.1: MANUAL.md
  114. pandoc -s --from markdown-smart --to man MANUAL.md -o rclone.1
  115. MANUAL.md: bin/make_manual.py docs/content/*.md commanddocs backenddocs rcdocs
  116. ./bin/make_manual.py
  117. MANUAL.html: MANUAL.md
  118. pandoc -s --from markdown-smart --to html MANUAL.md -o MANUAL.html
  119. MANUAL.txt: MANUAL.md
  120. pandoc -s --from markdown-smart --to plain MANUAL.md -o MANUAL.txt
  121. commanddocs: rclone
  122. XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="\$$HOME" USER="\$$USER" rclone gendocs docs/content/
  123. backenddocs: rclone bin/make_backend_docs.py
  124. XDG_CACHE_HOME="" XDG_CONFIG_HOME="" HOME="\$$HOME" USER="\$$USER" ./bin/make_backend_docs.py
  125. rcdocs: rclone
  126. bin/make_rc_docs.sh
  127. install: rclone
  128. install -d ${DESTDIR}/usr/bin
  129. install ${GOPATH}/bin/rclone ${DESTDIR}/usr/bin
  130. clean:
  131. go clean ./...
  132. find . -name \*~ | xargs -r rm -f
  133. rm -rf build docs/public
  134. rm -f rclone fs/operations/operations.test fs/sync/sync.test fs/test_all.log test.log
  135. website:
  136. rm -rf docs/public
  137. cd docs && hugo
  138. @if grep -R "raw HTML omitted" docs/public ; then echo "ERROR: found unescaped HTML - fix the markdown source" ; fi
  139. upload_website: website
  140. rclone -v sync docs/public memstore:www-rclone-org
  141. upload_test_website: website
  142. rclone -P sync docs/public test-rclone-org:
  143. validate_website: website
  144. find docs/public -type f -name "*.html" | xargs tidy --mute-id yes -errors --gnu-emacs yes --drop-empty-elements no --warn-proprietary-attributes no --mute MISMATCHED_ATTRIBUTE_WARN
  145. tarball:
  146. git archive -9 --format=tar.gz --prefix=rclone-$(TAG)/ -o build/rclone-$(TAG).tar.gz $(TAG)
  147. vendorball:
  148. go mod vendor
  149. tar -zcf build/rclone-$(TAG)-vendor.tar.gz vendor
  150. rm -rf vendor
  151. sign_upload:
  152. cd build && md5sum rclone-v* | gpg --clearsign > MD5SUMS
  153. cd build && sha1sum rclone-v* | gpg --clearsign > SHA1SUMS
  154. cd build && sha256sum rclone-v* | gpg --clearsign > SHA256SUMS
  155. check_sign:
  156. cd build && gpg --verify MD5SUMS && gpg --decrypt MD5SUMS | md5sum -c
  157. cd build && gpg --verify SHA1SUMS && gpg --decrypt SHA1SUMS | sha1sum -c
  158. cd build && gpg --verify SHA256SUMS && gpg --decrypt SHA256SUMS | sha256sum -c
  159. upload:
  160. rclone -P copy build/ memstore:downloads-rclone-org/$(TAG)
  161. rclone lsf build --files-only --include '*.{zip,deb,rpm}' --include version.txt | xargs -i bash -c 'i={}; j="$$i"; [[ $$i =~ (.*)(-v[0-9\.]+-)(.*) ]] && j=$${BASH_REMATCH[1]}-current-$${BASH_REMATCH[3]}; rclone copyto -v "memstore:downloads-rclone-org/$(TAG)/$$i" "memstore:downloads-rclone-org/$$j"'
  162. upload_github:
  163. ./bin/upload-github $(TAG)
  164. cross: doc
  165. go run bin/cross-compile.go -release current $(BUILD_FLAGS) $(BUILDTAGS) $(BUILD_ARGS) $(TAG)
  166. beta:
  167. go run bin/cross-compile.go $(BUILD_FLAGS) $(BUILDTAGS) $(BUILD_ARGS) $(TAG)
  168. rclone -v copy build/ memstore:pub-rclone-org/$(TAG)
  169. @echo Beta release ready at https://pub.rclone.org/$(TAG)/
  170. log_since_last_release:
  171. git log $(LAST_TAG)..
  172. compile_all:
  173. go run bin/cross-compile.go -compile-only $(BUILD_FLAGS) $(BUILDTAGS) $(BUILD_ARGS) $(TAG)
  174. ci_upload:
  175. sudo chown -R $$USER build
  176. find build -type l -delete
  177. gzip -r9v build
  178. ./rclone --config bin/travis.rclone.conf -v copy build/ $(BETA_UPLOAD)/testbuilds
  179. ifeq ($(or $(BRANCH_PATH),$(RELEASE_TAG)),)
  180. ./rclone --config bin/travis.rclone.conf -v copy build/ $(BETA_UPLOAD_ROOT)/test/testbuilds-latest
  181. endif
  182. @echo Beta release ready at $(BETA_URL)/testbuilds
  183. ci_beta:
  184. git log $(LAST_TAG).. > /tmp/git-log.txt
  185. go run bin/cross-compile.go -release beta-latest -git-log /tmp/git-log.txt $(BUILD_FLAGS) $(BUILDTAGS) $(BUILD_ARGS) $(TAG)
  186. rclone --config bin/travis.rclone.conf -v copy --exclude '*beta-latest*' build/ $(BETA_UPLOAD)
  187. ifeq ($(or $(BRANCH_PATH),$(RELEASE_TAG)),)
  188. rclone --config bin/travis.rclone.conf -v copy --include '*beta-latest*' --include version.txt build/ $(BETA_UPLOAD_ROOT)$(BETA_SUBDIR)
  189. endif
  190. @echo Beta release ready at $(BETA_URL)
  191. # Fetch the binary builds from GitHub actions
  192. fetch_binaries:
  193. rclone -P sync --exclude "/testbuilds/**" --delete-excluded $(BETA_UPLOAD) build/
  194. serve: website
  195. cd docs && hugo server -v -w --disableFastRender
  196. tag: retag doc
  197. bin/make_changelog.py $(LAST_TAG) $(VERSION) > docs/content/changelog.md.new
  198. mv docs/content/changelog.md.new docs/content/changelog.md
  199. @echo "Edit the new changelog in docs/content/changelog.md"
  200. @echo "Then commit all the changes"
  201. @echo git commit -m \"Version $(VERSION)\" -a -v
  202. @echo "And finally run make retag before make cross, etc."
  203. retag:
  204. @echo "Version is $(VERSION)"
  205. git tag -f -s -m "Version $(VERSION)" $(VERSION)
  206. startdev:
  207. @echo "Version is $(VERSION)"
  208. @echo "Next version is $(NEXT_VERSION)"
  209. echo -e "package fs\n\n// VersionTag of rclone\nvar VersionTag = \"$(NEXT_VERSION)\"\n" | gofmt > fs/versiontag.go
  210. echo -n "$(NEXT_VERSION)" > docs/layouts/partials/version.html
  211. echo "$(NEXT_VERSION)" > VERSION
  212. git commit -m "Start $(NEXT_VERSION)-DEV development" fs/versiontag.go VERSION docs/layouts/partials/version.html
  213. startstable:
  214. @echo "Version is $(VERSION)"
  215. @echo "Next stable version is $(NEXT_PATCH_VERSION)"
  216. echo -e "package fs\n\n// VersionTag of rclone\nvar VersionTag = \"$(NEXT_PATCH_VERSION)\"\n" | gofmt > fs/versiontag.go
  217. echo -n "$(NEXT_PATCH_VERSION)" > docs/layouts/partials/version.html
  218. echo "$(NEXT_PATCH_VERSION)" > VERSION
  219. git commit -m "Start $(NEXT_PATCH_VERSION)-DEV development" fs/versiontag.go VERSION docs/layouts/partials/version.html
  220. winzip:
  221. zip -9 rclone-$(TAG).zip rclone.exe
  222. # docker volume plugin
  223. PLUGIN_USER ?= rclone
  224. PLUGIN_TAG ?= latest
  225. PLUGIN_BASE_TAG ?= latest
  226. PLUGIN_ARCH ?= amd64
  227. PLUGIN_IMAGE := $(PLUGIN_USER)/docker-volume-rclone:$(PLUGIN_TAG)
  228. PLUGIN_BASE := $(PLUGIN_USER)/rclone:$(PLUGIN_BASE_TAG)
  229. PLUGIN_BUILD_DIR := ./build/docker-plugin
  230. PLUGIN_CONTRIB_DIR := ./contrib/docker-plugin/managed
  231. docker-plugin-create:
  232. docker buildx inspect |grep -q /${PLUGIN_ARCH} || \
  233. docker run --rm --privileged tonistiigi/binfmt --install all
  234. rm -rf ${PLUGIN_BUILD_DIR}
  235. docker buildx build \
  236. --no-cache --pull \
  237. --build-arg BASE_IMAGE=${PLUGIN_BASE} \
  238. --platform linux/${PLUGIN_ARCH} \
  239. --output ${PLUGIN_BUILD_DIR}/rootfs \
  240. ${PLUGIN_CONTRIB_DIR}
  241. cp ${PLUGIN_CONTRIB_DIR}/config.json ${PLUGIN_BUILD_DIR}
  242. docker plugin rm --force ${PLUGIN_IMAGE} 2>/dev/null || true
  243. docker plugin create ${PLUGIN_IMAGE} ${PLUGIN_BUILD_DIR}
  244. docker-plugin-push:
  245. docker plugin push ${PLUGIN_IMAGE}
  246. docker plugin rm ${PLUGIN_IMAGE}
  247. docker-plugin: docker-plugin-create docker-plugin-push