Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. VERSION := $(shell git describe --tags --abbrev=0 | tr -d '[:alpha:]')
  2. LDFLAGS := "-s -w -X github.com/cloudflare/cfssl/cli/version.version=$(VERSION)"
  3. export GOFLAGS := -mod=vendor
  4. export GOPROXY := off
  5. .PHONY: all
  6. all: bin/cfssl bin/cfssl-bundle bin/cfssl-certinfo bin/cfssl-newkey bin/cfssl-scan bin/cfssljson bin/mkbundle bin/multirootca
  7. bin/%: $(shell find . -type f -name '*.go')
  8. @mkdir -p $(dir $@)
  9. go build -ldflags $(LDFLAGS) -o $@ ./cmd/$(@F)
  10. .PHONY: install
  11. install: install-cfssl install-cfssl-bundle install-cfssl-certinfo install-cfssl-newkey install-cfssl-scan install-cfssljson install-mkbundle install-multirootca
  12. .PHONY: install-%
  13. install-%:
  14. go install ./cmd/$(@F:install-%=%)
  15. .PHONY: serve
  16. serve: bin/cfssl
  17. serve:
  18. ./bin/cfssl serve
  19. bin/golint: $(shell find vendor -type f -name '*.go')
  20. @mkdir -p $(dir $@)
  21. go build -o $@ ./vendor/golang.org/x/lint/golint
  22. bin/goose: $(shell find vendor -type f -name '*.go')
  23. @mkdir -p $(dir $@)
  24. go build -o $@ ./vendor/bitbucket.org/liamstask/goose/cmd/goose
  25. .PHONY: clean
  26. clean:
  27. rm -rf bin *.deb *.rpm
  28. # Check that given variables are set and all have non-empty values,
  29. # die with an error otherwise.
  30. #
  31. # Params:
  32. # 1. Variable name(s) to test.
  33. # 2. (optional) Error message to print.
  34. #
  35. # cf: https://stackoverflow.com/questions/10858261/abort-makefile-if-variable-not-set
  36. check_defined = \
  37. $(strip $(foreach 1,$1, \
  38. $(call __check_defined,$1,$(strip $(value 2)))))
  39. __check_defined = \
  40. $(if $(value $1),, \
  41. $(error Undefined $1$(if $2, ($2))))
  42. .PHONY: snapshot
  43. snapshot:
  44. docker run --rm -v $(PWD):/workdir -w /workdir cbroglie/goreleaser-cgo:1.12.12-musl goreleaser --rm-dist --snapshot --skip-publish
  45. .PHONY: github-release
  46. github-release:
  47. @:$(call check_defined, GITHUB_TOKEN)
  48. docker run --rm --privileged \
  49. -e GITHUB_TOKEN=$(GITHUB_TOKEN) \
  50. -v $(PWD):/cross \
  51. -v /var/run/docker.sock:/var/run/docker.sock \
  52. -w /cross \
  53. ghcr.io/gythialy/golang-cross:v1.18 --rm-dist
  54. .PHONY: docker-build
  55. docker-build:
  56. docker build -f Dockerfile -t cfssl/cfssl:$(VERSION) .
  57. .PHONY: docker-push
  58. docker-push:
  59. docker push cfssl/cfssl:$(VERSION)
  60. .PHONY: release
  61. release: github-release docker-build docker-push
  62. BUILD_PATH := $(CURDIR)/build
  63. INSTALL_PATH := $(BUILD_PATH)/usr/local/bin
  64. FPM = fakeroot fpm -C $(BUILD_PATH) \
  65. -a $(shell uname -m) \
  66. -s dir \
  67. -v $(VERSION) \
  68. --url 'https://github.com/cloudflare/cfssl' \
  69. --vendor Cloudflare \
  70. -n cfssl
  71. .PHONY: package
  72. package: package-deb package-rpm
  73. .PHONY: package-deb
  74. package-deb: all
  75. $(RM) -r build
  76. mkdir -p $(INSTALL_PATH)
  77. cp bin/* $(INSTALL_PATH)
  78. $(FPM) -t deb .
  79. .PHONY: package-rpm
  80. package-rpm: all
  81. $(RM) -r build
  82. mkdir -p $(INSTALL_PATH)
  83. cp bin/* $(INSTALL_PATH)
  84. $(FPM) -t rpm .