Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. VERSION ?= $(shell git describe --tags --abbrev=0 | sed 's/^v//')
  2. DISABLE_API_VERSION_CHECK ?= 0
  3. DISABLE_API_TOKEN_CRUD ?= 0
  4. DISABLE_ADMIN_FUNCTIONS ?= 0
  5. # Pass in a different value please. Please?
  6. TOKEN_OBFUSCATION_KEY ?= "eig0Ahcoi4phepoow2Wee8ahfoe3een4shebahz0Uhu8O"
  7. build: vendor clean test all ## Test and build binaries for local architecture into bin/
  8. .PHONY: docker_test
  9. docker_test: ## run a test build in docker
  10. docker/test.bash
  11. .PHONY: docker_release
  12. docker_release: ## Build all release binaries and checksums in docker
  13. docker/release.bash
  14. .PHONY: clean
  15. clean: ## Remove build products from bin/ and release/
  16. rm -rf bin
  17. rm -rf release
  18. vendor: ## Install dependencies
  19. dep ensure -v -vendor-only
  20. .PHONY: deps
  21. deps: ## Update dependencies to latest version
  22. dep ensure -v
  23. .PHONY: test
  24. test: ## Ensure that code matchs best practices and run tests
  25. staticcheck ./...
  26. go test -v ./pkg/conch ./pkg/util ./pkg/config ./pkg/conch/uuid
  27. .PHONY: tools
  28. tools: ## Download and install all dev/code tools
  29. @echo "==> Installing dev tools"
  30. go get -u github.com/golang/dep/cmd/dep
  31. go get -u honnef.co/go/tools/cmd/staticcheck
  32. .PHONY: tools
  33. cover_html:
  34. go test -coverprofile=/tmp/count.out -covermode=count ./pkg/conch
  35. go tool cover -html=/tmp/count.out
  36. ################################
  37. # Dynamic Fanciness #
  38. # aka Why GNU make Is Required #
  39. ################################
  40. PLATFORMS := darwin-amd64 linux-amd64 solaris-amd64 freebsd-amd64 openbsd-amd64 linux-arm
  41. BINARIES := conch conch-minimal tester corpus
  42. RELEASE_BINARIES := conch
  43. BINS := $(foreach bin,$(BINARIES),bin/$(bin))
  44. RELEASES := $(foreach bin,$(RELEASE_BINARIES),release/$(bin))
  45. GIT_REV := $(shell git describe --always --abbrev --dirty --long)
  46. FLAGS_PATH := github.com/joyent/conch-shell/pkg/util
  47. LD_FLAGS := -ldflags="-X github.com/joyent/conch-shell/pkg/config.ObfuscationKey=${TOKEN_OBFUSCATION_KEY} -X $(FLAGS_PATH).Version=$(VERSION) -X $(FLAGS_PATH).GitRev=$(GIT_REV) -X $(FLAGS_PATH).FlagsDisableApiVersionCheck=$(DISABLE_API_VERSION_CHECK) -X $(FLAGS_PATH).FlagsDisableApiTokenCRUD=$(DISABLE_API_TOKEN_CRUD) -X $(FLAGS_PATH).FlagsNoAdmin=$(DISABLE_ADMIN_FUNCTIONS)"
  48. BUILD := CGO_ENABLED=0 go build $(LD_FLAGS)
  49. ####
  50. all: $(BINS) ## Build all binaries
  51. .PHONY: release
  52. release: vendor test $(RELEASES) ## Build release binaries with checksums
  53. bin/%:
  54. @mkdir -p bin
  55. @echo "> Building bin/$(subst bin/,,$@)"
  56. @$(BUILD) -o bin/$(subst bin/,,$@) cmd/$(subst bin/,,$@)/*.go
  57. os = $(firstword $(subst -, ,$1))
  58. arch = $(lastword $(subst -, ,$1))
  59. define release_me
  60. $(eval BIN:=$(subst release/,,$@))
  61. $(eval GOOS:=$(call os, $(platform)))
  62. $(eval GOARCH:=$(call arch, $(platform)))
  63. $(eval RPATH:=release/$(BIN)-$(GOOS)-$(GOARCH))
  64. @echo "> Building $(RPATH)"
  65. @GOOS=$(GOOS) GOARCH=$(GOARCH) $(BUILD) -o $(RPATH) cmd/$(BIN)/*.go
  66. shasum -a 256 $(RPATH) > $(RPATH).sha256
  67. endef
  68. release/%:
  69. @mkdir -p release
  70. $(foreach platform,$(PLATFORMS),$(call release_me))
  71. .PHONY: help
  72. help: ## Display this help message
  73. @echo "GNU make(1) targets:"
  74. @grep -E '^[a-zA-Z_.-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'