Makefile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. ifneq ($(and $(TARGETOS),$(TARGETARCH)),)
  10. GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -ldflags $(LDFLAGS) -o $@ ./cmd/$(@F)
  11. else
  12. go build -ldflags $(LDFLAGS) -o $@ ./cmd/$(@F)
  13. endif
  14. .PHONY: install
  15. install: install-cfssl install-cfssl-bundle install-cfssl-certinfo install-cfssl-newkey install-cfssl-scan install-cfssljson install-mkbundle install-multirootca
  16. .PHONY: install-%
  17. install-%:
  18. go install ./cmd/$(@F:install-%=%)
  19. .PHONY: serve
  20. serve: bin/cfssl
  21. serve:
  22. ./bin/cfssl serve
  23. bin/goose: $(shell find vendor -type f -name '*.go')
  24. @mkdir -p $(dir $@)
  25. ifneq ($(and $(TARGETOS),$(TARGETARCH)),)
  26. GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -o $@ ./vendor/bitbucket.org/liamstask/goose/cmd/goose
  27. else
  28. go build -o $@ ./vendor/bitbucket.org/liamstask/goose/cmd/goose
  29. endif
  30. .PHONY: clean
  31. clean:
  32. rm -rf bin *.deb *.rpm
  33. # Check that given variables are set and all have non-empty values,
  34. # die with an error otherwise.
  35. #
  36. # Params:
  37. # 1. Variable name(s) to test.
  38. # 2. (optional) Error message to print.
  39. #
  40. # cf: https://stackoverflow.com/questions/10858261/abort-makefile-if-variable-not-set
  41. check_defined = \
  42. $(strip $(foreach 1,$1, \
  43. $(call __check_defined,$1,$(strip $(value 2)))))
  44. __check_defined = \
  45. $(if $(value $1),, \
  46. $(error Undefined $1$(if $2, ($2))))
  47. .PHONY: snapshot
  48. snapshot:
  49. docker run \
  50. --rm \
  51. -v $(PWD):/cross \
  52. -w /cross \
  53. ghcr.io/goreleaser/goreleaser-cross:latest --clean --snapshot --skip-publish
  54. .PHONY: github-release
  55. github-release:
  56. @:$(call check_defined, GITHUB_TOKEN)
  57. docker run \
  58. --rm \
  59. -e GITHUB_TOKEN=$(GITHUB_TOKEN) \
  60. -v $(PWD):/cross \
  61. -w /cross \
  62. ghcr.io/goreleaser/goreleaser-cross:latest --clean
  63. .PHONY: docker-build
  64. docker-build:
  65. docker build -f Dockerfile -t cfssl/cfssl:$(VERSION) .
  66. .PHONY: docker-push
  67. docker-push:
  68. docker push cfssl/cfssl:$(VERSION)
  69. .PHONY: release
  70. release: github-release docker-build docker-push
  71. BUILD_PATH := $(CURDIR)/build
  72. INSTALL_PATH := $(BUILD_PATH)/usr/local/bin
  73. FPM = fakeroot fpm -C $(BUILD_PATH) \
  74. -a $(shell uname -m) \
  75. -s dir \
  76. -v $(VERSION) \
  77. --url 'https://github.com/cloudflare/cfssl' \
  78. --vendor Cloudflare \
  79. -n cfssl
  80. .PHONY: package
  81. package: package-deb package-rpm
  82. .PHONY: package-deb
  83. package-deb: all
  84. $(RM) -r build
  85. mkdir -p $(INSTALL_PATH)
  86. cp bin/* $(INSTALL_PATH)
  87. $(FPM) -t deb .
  88. .PHONY: package-rpm
  89. package-rpm: all
  90. $(RM) -r build
  91. mkdir -p $(INSTALL_PATH)
  92. cp bin/* $(INSTALL_PATH)
  93. $(FPM) -t rpm .