|
1 | | -BINARY=gtm |
2 | | -VERSION=gtm-dev-$(shell date +'%Y.%m.%d-%H:%M:%S') |
3 | | - |
4 | | -LDFLAGS=-ldflags "-X main.Version=${VERSION}" |
| 1 | +BINARY = bin/gtm |
| 2 | +VERSION = gtm-dev-$(shell date +'%Y.%m.%d-%H:%M:%S') |
| 3 | +COMMIT = $(shell git show -s --format='%h' HEAD) |
| 4 | +LDFLAGS = -ldflags "-X main.Version=$(VERSION)-$(COMMIT)" |
| 5 | +GIT2GO_VERSION = v27 |
| 6 | +GIT2GO_PATH = $(GOPATH)/src/github.com/libgit2/git2go |
| 7 | +PKGS = $(shell go list ./... | grep -v vendor) |
| 8 | +BUILD_TAGS = static |
5 | 9 |
|
6 | 10 | build: |
7 | | - go build --tags static ${LDFLAGS} -o ${BINARY} |
| 11 | + go build --tags '$(BUILD_TAGS)' $(LDFLAGS) -o $(BINARY) |
8 | 12 |
|
9 | | -test: |
10 | | - go test --tags static $$(go list ./... | grep -v vendor) |
| 13 | +debug: BUILD_TAGS += debug |
| 14 | +debug: build |
| 15 | + |
| 16 | +profile: BUILD_TAGS += profile |
| 17 | +profile: build |
11 | 18 |
|
12 | | -vet: |
13 | | - go vet $$(go list ./... | grep -v vendor) |
| 19 | +debug-profile: BUILD_TAGS += debug profile |
| 20 | +debug-profile: build |
| 21 | + |
| 22 | +test: |
| 23 | + @go test $(TEST_OPTIONS) --tags '$(BUILD_TAGS)' $(PKGS) | grep --colour -E "FAIL|$$" |
14 | 24 |
|
15 | | -fmt: |
16 | | - go fmt $$(go list ./... | grep -v vendor) |
| 25 | +test-verbose: TEST_OPTIONS += -v |
| 26 | +test-verbose: test |
17 | 27 |
|
18 | | -install-git2go: |
19 | | - ./script/git2go-init.sh |
20 | | - ./script/build-libgit2-osx.sh |
| 28 | +lint: |
| 29 | + -@$(call color_echo, 4, "\nGo Vet"); \ |
| 30 | + go vet --all --tags '$(BUILD_TAGS)' $(PKGS) |
| 31 | + -@$(call color_echo, 4, "\nError Check"); \ |
| 32 | + errcheck -ignoretests -tags '$(BUILD_TAGS)' $(PKGS) |
| 33 | + -@$(call color_echo, 4, "\nIneffectual Assign"); \ |
| 34 | + ineffassign ./ |
| 35 | + -@$(call color_echo, 4, "\nStatic Check"); \ |
| 36 | + staticcheck --tests=false --tags '$(BUILD_TAGS)' $(PKGS) |
| 37 | + -@$(call color_echo, 4, "\nGo Simple"); \ |
| 38 | + gosimple --tests=false --tags '$(BUILD_TAGS)' $(PKGS) |
| 39 | + -@$(call color_echo, 4, "\nUnused"); \ |
| 40 | + unused --tests=false --tags '$(BUILD_TAGS)' $(PKGS) |
| 41 | + -@$(call color_echo, 4, "\nGo Format"); \ |
| 42 | + go fmt $(PKGS) |
| 43 | + -@$(call color_echo, 4, "\nLicense Check"); \ |
| 44 | + ag --go -L license . |grep -v vendor/ |
21 | 45 |
|
22 | 46 | install: |
23 | | - go install --tags static ${LDFLAGS} |
| 47 | + go install --tags '$(BUILD_TAGS)' $(LDFLAGS) |
24 | 48 |
|
25 | 49 | clean: |
26 | 50 | go clean |
| 51 | + rm bin/* |
| 52 | + |
| 53 | +git2go-install: |
| 54 | + [[ -d $(GIT2GO_PATH) ]] || git clone https://github.com/libgit2/git2go.git $(GIT2GO_PATH) && \ |
| 55 | + cd ${GIT2GO_PATH} && \ |
| 56 | + git pull && \ |
| 57 | + git checkout -qf $(GIT2GO_VERSION) && \ |
| 58 | + git submodule update --init |
| 59 | + |
| 60 | +git2go: git2go-install |
| 61 | + cd $(GIT2GO_PATH)/vendor/libgit2 && \ |
| 62 | + mkdir -p install/lib && \ |
| 63 | + mkdir -p build && \ |
| 64 | + cd build && \ |
| 65 | + cmake -DTHREADSAFE=ON \ |
| 66 | + -DBUILD_CLAR=OFF \ |
| 67 | + -DBUILD_SHARED_LIBS=OFF \ |
| 68 | + -DCMAKE_C_FLAGS=-fPIC \ |
| 69 | + -DUSE_SSH=OFF \ |
| 70 | + -DCURL=OFF \ |
| 71 | + -DUSE_HTTPS=OFF \ |
| 72 | + -DUSE_BUNDLED_ZLIB=ON \ |
| 73 | + -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ |
| 74 | + -DCMAKE_INSTALL_PREFIX=../install \ |
| 75 | + .. && \ |
| 76 | + cmake --build . |
| 77 | + |
| 78 | +git2go-clean: |
| 79 | + [[ -d $(GIT2GO_PATH) ]] && rm -rf $(GIT2GO_PATH) |
| 80 | + |
| 81 | +define color_echo |
| 82 | + @tput setaf $1 |
| 83 | + @echo $2 |
| 84 | + @tput sgr0 |
| 85 | +endef |
27 | 86 |
|
28 | | -.PHONY: test vet install clean fmt todo note |
| 87 | +.PHONY: build test vet fmt install clean git2go-install git2go-build all-tags profile debug |
0 commit comments