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.

Makefile 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. DIST := dist
  2. IMPORT := git.kolaente.de/konrad/Library
  3. SED_INPLACE := sed -i
  4. ifeq ($(OS), Windows_NT)
  5. EXECUTABLE := Library.exe
  6. else
  7. EXECUTABLE := Library
  8. UNAME_S := $(shell uname -s)
  9. ifeq ($(UNAME_S),Darwin)
  10. SED_INPLACE := sed -i ''
  11. endif
  12. endif
  13. GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
  14. GOFMT ?= gofmt -s
  15. GOFLAGS := -i -v
  16. EXTRA_GOFLAGS ?=
  17. LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)"
  18. PACKAGES ?= $(filter-out git.kolaente.de/konrad/Library/integrations,$(shell go list ./... | grep -v /vendor/))
  19. SOURCES ?= $(shell find . -name "*.go" -type f)
  20. TAGS ?=
  21. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'kasino-temp')
  22. ifeq ($(OS), Windows_NT)
  23. EXECUTABLE := Library.exe
  24. else
  25. EXECUTABLE := Library
  26. endif
  27. ifneq ($(DRONE_TAG),)
  28. VERSION ?= $(subst v,,$(DRONE_TAG))
  29. else
  30. ifneq ($(DRONE_BRANCH),)
  31. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  32. else
  33. VERSION ?= master
  34. endif
  35. endif
  36. .PHONY: all
  37. all: build
  38. .PHONY: clean
  39. clean:
  40. go clean -i ./...
  41. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
  42. .PHONY: test
  43. test:
  44. go test -cover $(PACKAGES)
  45. required-gofmt-version:
  46. @go version | grep -q '\(1.7\|1.8\|1.9\|1.10\)' || { echo "We require go version 1.7, 1.8, 1.9 or 1.10 to format code" >&2 && exit 1; }
  47. .PHONY: lint
  48. lint:
  49. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  50. go get -u github.com/golang/lint/golint; \
  51. fi
  52. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  53. .PHONY: fmt
  54. fmt: required-gofmt-version
  55. $(GOFMT) -w $(GOFILES)
  56. .PHONY: fmt-check
  57. fmt-check: required-gofmt-version
  58. # get all go files and run go fmt on them
  59. @diff=$$($(GOFMT) -d $(GOFILES)); \
  60. if [ -n "$$diff" ]; then \
  61. echo "Please run 'make fmt' and commit the result:"; \
  62. echo "$${diff}"; \
  63. exit 1; \
  64. fi;
  65. .PHONY: install
  66. install: $(wildcard *.go)
  67. go install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  68. .PHONY: build
  69. build: $(EXECUTABLE)
  70. $(EXECUTABLE): $(SOURCES)
  71. go build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  72. .PHONY: release
  73. release: release-dirs release-windows release-linux release-darwin release-frontend release-copy release-check release-os-package
  74. .PHONY: release-dirs
  75. release-dirs:
  76. mkdir -p $(DIST)/binaries $(DIST)/release $(DIST)/zip
  77. .PHONY: release-frontend
  78. release-frontend:
  79. mv frontend/siteconfig.json frontend/siteconfig.json.old; \
  80. echo '{"API_URL": "/api/v1/"}' > frontend/siteconfig.json; \
  81. npm --prefix frontend run build; \
  82. rm frontend/dist/siteconfig.json; \
  83. mv frontend/siteconfig.json.old frontend/siteconfig.json;
  84. .PHONY: release-windows
  85. release-windows:
  86. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  87. go get -u github.com/karalabe/xgo; \
  88. fi
  89. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out Library-$(VERSION) .
  90. ifeq ($(CI),drone)
  91. mv /build/* $(DIST)/binaries
  92. endif
  93. .PHONY: release-linux
  94. release-linux:
  95. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  96. go get -u github.com/karalabe/xgo; \
  97. fi
  98. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out Library-$(VERSION) .
  99. ifeq ($(CI),drone)
  100. mv /build/* $(DIST)/binaries
  101. endif
  102. .PHONY: release-darwin
  103. release-darwin:
  104. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  105. go get -u github.com/karalabe/xgo; \
  106. fi
  107. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out Library-$(VERSION) .
  108. ifeq ($(CI),drone)
  109. mv /build/* $(DIST)/binaries
  110. endif
  111. .PHONY: release-copy
  112. release-copy:
  113. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  114. mkdir $(DIST)/release/frontend
  115. cp frontend/dist $(DIST)/release/frontend/ -R
  116. .PHONY: release-check
  117. release-check:
  118. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  119. .PHONY: release-os-package
  120. release-os-package:
  121. $(foreach file,$(filter-out %.sha256,$(wildcard $(DIST)/release/$(EXECUTABLE)-*)),mkdir $(file)-full;mv $(file) $(file)-full/; mv $(file).sha256 $(file)-full/; cp config.ini.sample $(file)-full/config.ini; cp $(DIST)/release/frontend $(file)-full/ -R; cp LICENSE $(file)-full/; )
  122. rm $(DIST)/release/frontend -rf
  123. .PHONY: release-zip
  124. release-zip:
  125. $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),cd $(file); zip -r ../../zip/$(shell basename $(file)).zip *; cd ../../../; )