1+ GIT_LFS_SHA ?= $(shell git rev-parse --short HEAD)
2+ VERSION ?= $(shell git describe HEAD)
3+
14GO ?= go
25
36GO_TEST_EXTRA_ARGS =
47
8+ BUILTIN_LD_FLAGS =
9+ BUILTIN_LD_FLAGS += -X github.com/git-lfs/git-lfs/config.GitCommit=$(GIT_LFS_SHA )
10+ ifneq ("$(DWARF ) ","YesPlease")
11+ BUILTIN_LD_FLAGS += -s
12+ BUILTIN_LD_FLAGS += -w
13+ endif
14+ EXTRA_LD_FLAGS =
15+ LD_FLAGS = $(BUILTIN_LD_FLAGS ) $(EXTRA_LD_FLAGS )
16+
17+ BUILTIN_GC_FLAGS =
18+ EXTRA_GC_FLAGS =
19+ GC_FLAGS = $(BUILTIN_GC_FLAGS ) $(EXTRA_GC_FLAGS )
20+
521GLIDE ?= glide
622
723GREP ?= grep
@@ -33,6 +49,78 @@ PKGS += tools/kv
3349PKGS += tq
3450endif
3551
52+ ifeq ($(OS ) ,Windows_NT)
53+ X ?= .exe
54+ else
55+ X ?=
56+ endif
57+ .DEFAULT_GOAL := bin/git-lfs$(X )
58+
59+ BUILD = GOOS=$(1 ) GOARCH=$(2 ) \
60+ $(GO ) build \
61+ -ldflags="$(LD_FLAGS ) " \
62+ -gcflags="$(GC_FLAGS ) " \
63+ -o ./bin/git-lfs$(3 ) ./git-lfs.go
64+
65+ BUILD_TARGETS = bin/git-lfs-darwin-amd64 bin/git-lfs-darwin-386 \
66+ bin/git-lfs-linux-amd64 bin/git-lfs-linux-386 \
67+ bin/git-lfs-freebsd-amd64 bin/git-lfs-freebsd-386 \
68+ bin/git-lfs-windows-amd64.exe bin/git-lfs-windows-386.exe
69+
70+ .PHONY : all build
71+ all build : $(BUILD_TARGETS )
72+
73+ bin/git-lfs-darwin-amd64 : fmt
74+ $(call BUILD,darwin,amd64,-darwin-amd64)
75+ bin/git-lfs-darwin-386 : fmt
76+ $(call BUILD,darwin,386,-darwin-386)
77+ bin/git-lfs-linux-amd64 : fmt
78+ $(call BUILD,linux,amd64,-linux-amd64)
79+ bin/git-lfs-linux-386 : fmt
80+ $(call BUILD,linux,386,-linux-386)
81+ bin/git-lfs-freebsd-amd64 : fmt
82+ $(call BUILD,freebsd,amd64,-freebsd-amd64)
83+ bin/git-lfs-freebsd-386 : fmt
84+ $(call BUILD,freebsd,386,-freebsd-386)
85+ bin/git-lfs-windows-amd64.exe : version-info fmt
86+ $(call BUILD,windows,amd64,-windows-amd64.exe)
87+ bin/git-lfs-windows-386.exe : version-info fmt
88+ $(call BUILD,windows,386,-windows-386.exe)
89+
90+ bin/git-lfs : git-lfs.go $(PKGS )
91+ $(call BUILD,$(GOOS ) ,$(GOARCH ) ,)
92+
93+ bin/git-lfs.exe : git-lfs.go $(PKGS ) version-info
94+ $(call BUILD,$(GOOS ) ,$(GOARCH ) ,.exe)
95+
96+ .PHONY : version-info
97+ version-info :
98+ go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
99+ PATH=$$ PATH:$$ GOPATH/bin/windows_386 $(GO ) generate
100+
101+ RELEASE_TARGETS = bin/releases/git-lfs-darwin-amd64-$(VERSION ) .tar.gz \
102+ bin/releases/git-lfs-darwin-386-$(VERSION ) .tar.gz \
103+ bin/releases/git-lfs-linux-amd64-$(VERSION ) .tar.gz \
104+ bin/releases/git-lfs-linux-386-$(VERSION ) .tar.gz \
105+ bin/releases/git-lfs-freebsd-amd64-$(VERSION ) .tar.gz \
106+ bin/releases/git-lfs-freebsd-386-$(VERSION ) .tar.gz \
107+ bin/releases/git-lfs-windows-amd64-$(VERSION ) .zip \
108+ bin/releases/git-lfs-windows-386-$(VERSION ) .zip
109+
110+ RELEASE_INCLUDES = README.md CHANGELOG.md script/install.sh
111+
112+ .PHONY : release
113+ release : $(RELEASE_TARGETS )
114+ shasum -a 256 $(RELEASE_TARGETS )
115+
116+ bin/releases/git-lfs-% -$(VERSION ) .tar.gz : $(RELEASE_INCLUDES ) bin/git-lfs-%
117+ @mkdir -p bin/releases
118+ tar -s ' !bin/git-lfs-.*!git-lfs!' -s ' !script/!!' -czf $@ $^
119+
120+ bin/releases/git-lfs-% -$(VERSION ) .zip : $(RELEASE_INCLUDES ) bin/git-lfs-% .exe
121+ @mkdir -p bin/releases
122+ zip -j -l $@ $^
123+
36124TEST_TARGETS := test-bench test-verbose test-race
37125.PHONY : $(TEST_TARGETS ) test
38126$(TEST_TARGETS ) : test
@@ -53,9 +141,11 @@ vendor : glide.lock
53141 $(RM ) -r vendor/github.com/davecgh/go-spew
54142 $(RM ) -r vendor/github.com/pmezard/go-difflib
55143
144+ .PHONY : fmt
56145fmt : $(PKGS ) | lint
57146 $(GOIMPORTS ) $(GOIMPORTS_EXTRA_OPTS ) $?
58147
148+ .PHONY : lint
59149lint : $(PKGS )
60150 $(GO ) list -f ' {{ join .Deps "\n" }}' . \
61151 | $(XARGS ) $(GO ) list -f ' {{ if not .Standard }}{{ .ImportPath }}{{ end }}' \
0 commit comments