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.

139 lines
3.2 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. DIST := dist
  2. IMPORT := code.gitea.io/gitea
  3. ifeq ($(OS), Windows_NT)
  4. EXECUTABLE := gitea.exe
  5. else
  6. EXECUTABLE := gitea
  7. endif
  8. BINDATA := modules/{options,public,templates}/bindata.go
  9. STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
  10. JAVASCRIPTS :=
  11. LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')"
  12. TARGETS ?= linux/*,darwin/*,windows/*
  13. PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
  14. SOURCES ?= $(shell find . -name "*.go" -type f)
  15. TAGS ?=
  16. ifneq ($(DRONE_TAG),)
  17. VERSION ?= $(subst v,,$(DRONE_TAG))
  18. else
  19. ifneq ($(DRONE_BRANCH),)
  20. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  21. else
  22. VERSION ?= master
  23. endif
  24. endif
  25. .PHONY: all
  26. all: build
  27. .PHONY: clean
  28. clean:
  29. go clean -i ./...
  30. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
  31. .PHONY: fmt
  32. fmt:
  33. find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
  34. .PHONY: vet
  35. vet:
  36. go vet $(PACKAGES)
  37. .PHONY: generate
  38. generate:
  39. @which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
  40. go get -u github.com/jteeuwen/go-bindata/...; \
  41. fi
  42. go generate $(PACKAGES)
  43. .PHONY: errcheck
  44. errcheck:
  45. @which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
  46. go get -u github.com/kisielk/errcheck; \
  47. fi
  48. errcheck $(PACKAGES)
  49. .PHONY: lint
  50. lint:
  51. @which golint > /dev/null; if [ $$? -ne 0 ]; then \
  52. go get -u github.com/golang/lint/golint; \
  53. fi
  54. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  55. .PHONY: test
  56. test:
  57. for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  58. .PHONY: test-mysql
  59. test-mysql:
  60. @echo "Not integrated yet!"
  61. .PHONY: test-pgsql
  62. test-pgsql:
  63. @echo "Not integrated yet!"
  64. .PHONY: check
  65. check: test
  66. .PHONY: install
  67. install: $(wildcard *.go)
  68. go install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  69. .PHONY: build
  70. build: $(EXECUTABLE)
  71. $(EXECUTABLE): $(SOURCES)
  72. go build -i -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  73. .PHONY: docker
  74. docker:
  75. docker run -ti --rm -v $(CURDIR):/srv/app/src/code.gitea.io/gitea -w /srv/app/src/code.gitea.io/gitea -e TAGS="$(TAGS)" webhippie/golang:edge make clean generate build
  76. docker build -t gitea/gitea:latest .
  77. .PHONY: release
  78. release: release-dirs release-build release-copy release-check
  79. .PHONY: release-dirs
  80. release-dirs:
  81. mkdir -p $(DIST)/binaries $(DIST)/release
  82. .PHONY: release-build
  83. release-build:
  84. @which xgo > /dev/null; if [ $$? -ne 0 ]; then \
  85. go get -u github.com/karalabe/xgo; \
  86. fi
  87. xgo -dest $(DIST)/binaries -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -targets '$(TARGETS)' -out $(EXECUTABLE)-$(VERSION) .
  88. ifeq ($(CI),drone)
  89. mv /build/* $(DIST)/binaries
  90. endif
  91. .PHONY: release-copy
  92. release-copy:
  93. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  94. .PHONY: release-check
  95. release-check:
  96. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  97. .PHONY: javascripts
  98. javascripts: public/js/index.js
  99. .IGNORE: public/js/index.js
  100. public/js/index.js: $(JAVASCRIPTS)
  101. cat $< >| $@
  102. .PHONY: stylesheets
  103. stylesheets: public/css/index.css
  104. .IGNORE: public/css/index.css
  105. public/css/index.css: $(STYLESHEETS)
  106. lessc $< $@
  107. .PHONY: assets
  108. assets: javascripts stylesheets