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.

132 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: install
  51. install: $(BIN)/$(EXECUTABLE)
  52. cp $< $(GOPATH)/bin/
  53. .PHONY: build
  54. build: $(BIN)/$(EXECUTABLE)
  55. $(BIN)/$(EXECUTABLE): $(wildcard *.go)
  56. go build -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  57. .PHONY: release
  58. release: release-build release-copy release-check
  59. .PHONY: release-build
  60. release-build:
  61. @which xgo > /dev/null; if [ $$? -ne 0 ]; then \
  62. go get -u github.com/karalabe/xgo; \
  63. fi
  64. xgo -dest $(BIN) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -targets '$(TARGETS)' -out $(EXECUTABLE)-$(VERSION) $(IMPORT)
  65. .PHONY: release-copy
  66. release-copy:
  67. mkdir -p $(DIST)/release
  68. $(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  69. .PHONY: release-check
  70. release-check:
  71. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  72. .PHONY: latest
  73. latest: release-build latest-copy latest-check
  74. .PHONY: latest-copy
  75. latest-copy:
  76. mkdir -p $(DIST)/latest
  77. $(foreach file,$(wildcard $(BIN)/$(EXECUTABLE)-*),cp $(file) $(DIST)/latest/$(subst $(EXECUTABLE)-$(VERSION),$(EXECUTABLE)-latest,$(notdir $(file)));)
  78. .PHONY: latest-check
  79. latest-check:
  80. cd $(DIST)/latest; $(foreach file,$(wildcard $(DIST)/latest/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  81. .PHONY: publish
  82. publish: release latest
  83. .PHONY: bindata
  84. bindata: modules/bindata/bindata.go
  85. .IGNORE: modules/bindata/bindata.go
  86. modules/bindata/bindata.go: $(BINDATA)
  87. go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
  88. go fmt $@
  89. .PHONY: javascripts
  90. javascripts: public/js/index.js
  91. .IGNORE: public/js/index.js
  92. public/js/index.js: $(JAVASCRIPTS)
  93. cat $< >| $@
  94. .PHONY: stylesheets
  95. stylesheets: public/css/index.css
  96. .IGNORE: public/css/index.css
  97. public/css/index.css: $(STYLESHEETS)
  98. lessc $< $@
  99. .PHONY: generate
  100. generate: bindata javascripts stylesheets