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.

135 lines
3.2 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. DIST := dist
  2. BIN := bin
  3. EXECUTABLE := gitea
  4. IMPORT := github.com/go-gitea/gitea
  5. SHA := $(shell git rev-parse --short HEAD)
  6. DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')
  7. BINDATA := $(shell find conf | sed 's/ /\\ /g')
  8. STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
  9. JAVASCRIPTS :=
  10. LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildTime=$(DATE)"
  11. LDFLAGS += -X "github.com/go-gitea/gitea/modules/setting.BuildGitHash=$(SHA)"
  12. TARGETS ?= linux/*,darwin/*,windows/*
  13. PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
  14. TAGS ?=
  15. ifneq ($(TRAVIS_TAG),)
  16. VERSION ?= $(TRAVIS_TAG)
  17. else
  18. ifneq ($(TRAVIS_BRANCH),)
  19. VERSION ?= $(TRAVIS_BRANCH)
  20. else
  21. VERSION ?= master
  22. endif
  23. endif
  24. .PHONY: all
  25. all: clean test build
  26. .PHONY: clean
  27. clean:
  28. go clean -i ./...
  29. rm -rf $(BIN) $(DIST)
  30. .PHONY: deps
  31. deps:
  32. @which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
  33. go get -u github.com/jteeuwen/go-bindata/...; \
  34. fi
  35. .PHONY: fmt
  36. fmt:
  37. go fmt $(PACKAGES)
  38. .PHONY: vet
  39. vet:
  40. go vet $(PACKAGES)
  41. .PHONY: lint
  42. lint:
  43. @which golint > /dev/null; if [ $$? -ne 0 ]; then \
  44. go get -u github.com/golang/lint/golint; \
  45. fi
  46. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  47. .PHONY: test
  48. test:
  49. for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  50. .PHONY: check
  51. check: test
  52. .PHONY: install
  53. install: $(BIN)/$(EXECUTABLE)
  54. cp $< $(GOPATH)/bin/
  55. .PHONY: build
  56. build: $(BIN)/$(EXECUTABLE)
  57. $(BIN)/$(EXECUTABLE): $(wildcard *.go)
  58. go build -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  59. .PHONY: release
  60. release: release-build release-copy release-check
  61. .PHONY: release-build
  62. release-build:
  63. @which xgo > /dev/null; if [ $$? -ne 0 ]; then \
  64. go get -u github.com/karalabe/xgo; \
  65. fi
  66. xgo -dest $(BIN) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -targets '$(TARGETS)' -out $(EXECUTABLE)-$(VERSION) $(IMPORT)
  67. .PHONY: release-copy
  68. release-copy:
  69. mkdir -p $(DIST)/release
  70. $(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  71. .PHONY: release-check
  72. release-check:
  73. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  74. .PHONY: latest
  75. latest: release-build latest-copy latest-check
  76. .PHONY: latest-copy
  77. latest-copy:
  78. mkdir -p $(DIST)/latest
  79. $(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/latest/$(subst $(EXECUTABLE)-$(VERSION),$(EXECUTABLE)-latest,$(notdir $(file)));)
  80. .PHONY: latest-check
  81. latest-check:
  82. cd $(DIST)/latest; $(foreach file,$(wildcard $(DIST)/latest/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  83. .PHONY: publish
  84. publish: release latest
  85. .PHONY: bindata
  86. bindata: modules/bindata/bindata.go
  87. .IGNORE: modules/bindata/bindata.go
  88. modules/bindata/bindata.go: $(BINDATA)
  89. go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
  90. go fmt $@
  91. .PHONY: javascripts
  92. javascripts: public/js/index.js
  93. .IGNORE: public/js/index.js
  94. public/js/index.js: $(JAVASCRIPTS)
  95. cat $< >| $@
  96. .PHONY: stylesheets
  97. stylesheets: public/css/index.css
  98. .IGNORE: public/css/index.css
  99. public/css/index.css: $(STYLESHEETS)
  100. lessc $< $@
  101. .PHONY: generate
  102. generate: bindata javascripts stylesheets