1 # GIT_LFS_SHA is the '--short'-form SHA1 of the current revision of Git LFS.
2 GIT_LFS_SHA ?= $(shell git rev-parse --short HEAD)
3 # VERSION is the longer-form describe output of the current revision of Git LFS,
4 # used for identifying intermediate releases.
6 # If Git LFS is being built for a published release, VERSION and GIT_LFS_SHA
8 VERSION ?= $(shell git describe HEAD)
10 # GO is the name of the 'go' binary used to compile Git LFS.
13 # GO_TEST_EXTRA_ARGS are extra arguments given to invocations of 'go test'.
17 # make test GO_TEST_EXTRA_ARGS=-v
18 # make test GO_TEST_EXTRA_ARGS='-run TestMyExample'
21 # BUILTIN_LD_FLAGS are the internal flags used to pass to the linker. By default
22 # the config.GitCommit variable is always set via this variable, and
23 # DWARF-stripping is enabled unless DWARF=YesPlease.
25 BUILTIN_LD_FLAGS += -X github.com/git-lfs/git-lfs/config.GitCommit=$(GIT_LFS_SHA)
26 ifneq ("$(DWARF)","YesPlease")
27 BUILTIN_LD_FLAGS += -s
28 BUILTIN_LD_FLAGS += -w
30 # EXTRA_LD_FLAGS are given by the caller, and are passed to the Go linker after
31 # BUILTIN_LD_FLAGS are processed.
33 # LD_FLAGS is the union of the above two BUILTIN_LD_FLAGS and EXTRA_LD_FLAGS.
34 LD_FLAGS = $(BUILTIN_LD_FLAGS) $(EXTRA_LD_FLAGS)
36 # BUILTIN_GC_FLAGS are the internal flags used to pass compiler.
38 # EXTRA_GC_FLAGS are the caller-provided flags to pass to the compiler.
40 # GC_FLAGS are the union of the above two BUILTIN_GC_FLAGS and EXTRA_GC_FLAGS.
41 GC_FLAGS = $(BUILTIN_GC_FLAGS) $(EXTRA_GC_FLAGS)
43 # GLIDE is the name of the 'glide' binary used to manage vendored dependencies.
46 # RONN is the name of the 'ronn' program used to generate man pages.
48 # RONN_EXTRA_ARGS are extra arguments given to the $(RONN) program when invoked.
51 # GREP is the name of the program used for regular expression matching, or
54 # RM is the name of the program used removing files, or 'rm -f' if unset.
56 # XARGS is the name of the program used to turn stdin into program arguments, or
60 # GOIMPORTS is the name of the program formatter used before compiling.
61 GOIMPORTS ?= goimports
62 # GOIMPORTS_EXTRA_OPTS are the default options given to the $(GOIMPORTS)
64 GOIMPORTS_EXTRA_OPTS ?= -w -l
66 # SOURCES is a listing of all .go files in this and child directories, excluding
68 SOURCES = $(shell find . -type f -name '*.go' | grep -v vendor)
69 # PKGS is a listing of packages that are considered to be a part of Git LFS, and
70 # are used in package-specific commands, such as the 'make test' targets. For
73 # make test # run 'go test' in all packages
74 # make PKGS='config git/githistory' test # run 'go test' in config and
77 # By default, it is a listing of all packages in Git LFS. When new packages (or
78 # sub-packages) are created, they should be added here.
84 PKGS += filepathfilter
88 PKGS += git/githistory
96 PKGS += tools/humanize
101 # X is the platform-specific extension for Git LFS binaries. It is automatically
102 # set to .exe on Windows, and the empty string on all other platforms. It may be
105 # BUILD_MAIN is the main ".go" file that contains func main() for Git LFS. On
106 # macOS and other non-Windows platforms, it is required that a specific
107 # entrypoint be given, hence the below conditional. On Windows, it is required
108 # that an entrypoint not be given so that goversioninfo can successfully embed
109 # the resource.syso file (for more, see below).
110 ifeq ($(OS),Windows_NT)
115 BUILD_MAIN ?= ./git-lfs.go
118 # BUILD is a macro used to build a single binary of Git LFS using the above
119 # LD_FLAGS and GC_FLAGS.
121 # It takes three arguments:
123 # $(1) - a valid GOOS value, or empty-string
124 # $(2) - a valid GOARCH value, or empty-string
125 # $(3) - an optional program extension. If $(3) is given as '-foo', then the
126 # program will be written to bin/git-lfs-foo.
128 # It uses BUILD_MAIN as defined above to specify the entrypoint for building Git
130 BUILD = GOOS=$(1) GOARCH=$(2) \
132 -ldflags="$(LD_FLAGS)" \
133 -gcflags="$(GC_FLAGS)" \
134 -o ./bin/git-lfs$(3) $(BUILD_MAIN)
136 # BUILD_TARGETS is the set of all platforms and architectures that Git LFS is
138 BUILD_TARGETS = bin/git-lfs-darwin-amd64 bin/git-lfs-darwin-386 \
139 bin/git-lfs-linux-amd64 bin/git-lfs-linux-386 \
140 bin/git-lfs-freebsd-amd64 bin/git-lfs-freebsd-386 \
141 bin/git-lfs-windows-amd64.exe bin/git-lfs-windows-386.exe
143 # mangen is a shorthand for ensuring that commands/mancontent_gen.go is kept
144 # up-to-date with the contents of docs/man/*.ronn.
146 mangen : commands/mancontent_gen.go
148 # commands/mancontent_gen.go is generated by running 'go generate' on package
149 # 'commands' of Git LFS. It depends upon the contents of the 'docs' directory
150 # and converts those manpages into code.
151 commands/mancontent_gen.go : $(wildcard docs/man/*.ronn)
152 $(GO) generate github.com/git-lfs/git-lfs/commands
154 # Targets 'all' and 'build' build binaries of Git LFS for the above release
157 all build : $(BUILD_TARGETS)
159 # The following bin/git-lfs-% targets make a single binary compilation of Git
160 # LFS for a specific operating system and architecture pair.
162 # They function by translating target names into arguments for the above BUILD
163 # builtin, and appending the appropriate suffix to the build target.
165 # On Windows, they also depend on the resource.syso target, which installs and
166 # embeds the versioninfo into the binary.
167 bin/git-lfs-darwin-amd64 : $(SOURCES) mangen
168 $(call BUILD,darwin,amd64,-darwin-amd64)
169 bin/git-lfs-darwin-386 : $(SOURCES) mangen
170 $(call BUILD,darwin,386,-darwin-386)
171 bin/git-lfs-linux-amd64 : $(SOURCES) mangen
172 $(call BUILD,linux,amd64,-linux-amd64)
173 bin/git-lfs-linux-386 : $(SOURCES) mangen
174 $(call BUILD,linux,386,-linux-386)
175 bin/git-lfs-freebsd-amd64 : $(SOURCES) mangen
176 $(call BUILD,freebsd,amd64,-freebsd-amd64)
177 bin/git-lfs-freebsd-386 : $(SOURCES) mangen
178 $(call BUILD,freebsd,386,-freebsd-386)
179 bin/git-lfs-windows-amd64.exe : resource.syso $(SOURCES) mangen
180 $(call BUILD,windows,amd64,-windows-amd64.exe)
181 bin/git-lfs-windows-386.exe : resource.syso $(SOURCES) mangen
182 $(call BUILD,windows,386,-windows-386.exe)
184 # .DEFAULT_GOAL sets the operating system-appropriate Git LFS binary as the
185 # default output of 'make'.
186 .DEFAULT_GOAL := bin/git-lfs$(X)
188 # bin/git-lfs targets the default output of Git LFS on non-Windows operating
189 # systems, and respects the build knobs as above.
190 bin/git-lfs : $(SOURCES) fmt mangen
191 $(call BUILD,$(GOOS),$(GOARCH),)
193 # bin/git-lfs.exe targets the default output of Git LFS on Windows systems, and
194 # respects the build knobs as above.
195 bin/git-lfs.exe : $(SOURCES) resource.syso mangen
196 $(call BUILD,$(GOOS),$(GOARCH),.exe)
198 # resource.syso installs the 'goversioninfo' command and uses it in order to
199 # generate a binary that has information included necessary to create the
202 # Generating a new resource.syso is a pure function of the contents in the
203 # prerequisites listed below.
205 versioninfo.json script/windows-installer/git-lfs-logo.bmp \
206 script/windows-installer/git-lfs-logo.ico \
207 script/windows-installer/git-lfs-wizard-image.bmp
208 @$(GO) get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
211 # RELEASE_TARGETS is the set of all release artifacts that we generate over a
212 # particular release. They each have a corresponding entry in BUILD_TARGETS as
215 # Unlike BUILD_TARGETS above, each of the below create a compressed directory
216 # containing the matching binary, as well as the contents of RELEASE_INCLUDES
219 # To build a specific release, execute the following:
221 # make bin/releases/git-lfs-darwin-amd64-$(git describe HEAD).tar.gz
223 # To build a specific release with a custom VERSION suffix, run the following:
225 # make VERSION=my-version bin/releases/git-lfs-darwin-amd64-my-version.tar.gz
226 RELEASE_TARGETS = bin/releases/git-lfs-darwin-amd64-$(VERSION).tar.gz \
227 bin/releases/git-lfs-darwin-386-$(VERSION).tar.gz \
228 bin/releases/git-lfs-linux-amd64-$(VERSION).tar.gz \
229 bin/releases/git-lfs-linux-386-$(VERSION).tar.gz \
230 bin/releases/git-lfs-freebsd-amd64-$(VERSION).tar.gz \
231 bin/releases/git-lfs-freebsd-386-$(VERSION).tar.gz \
232 bin/releases/git-lfs-windows-amd64-$(VERSION).zip \
233 bin/releases/git-lfs-windows-386-$(VERSION).zip
235 # RELEASE_INCLUDES are the names of additional files that are added to each
237 RELEASE_INCLUDES = README.md CHANGELOG.md
239 # release is a phony target that builds all of the release artifacts, and then
240 # shows the SHA 256 signature of each.
242 # To build all of the release binaries for a given Git LFS release:
246 release : $(RELEASE_TARGETS)
247 shasum -a 256 $(RELEASE_TARGETS)
249 # bin/releases/git-lfs-%-$(VERSION).tar.gz generates a gzip-compressed TAR of
250 # the non-Windows release artifacts.
252 # It includes all of RELEASE_INCLUDES, as well as script/install.sh.
253 bin/releases/git-lfs-%-$(VERSION).tar.gz : \
254 $(RELEASE_INCLUDES) bin/git-lfs-% script/install.sh
255 @mkdir -p bin/releases
256 tar -s '!bin/git-lfs-.*!git-lfs!' -s '!script/!!' -czf $@ $^
258 # bin/releases/git-lfs-%-$(VERSION).zip generates a ZIP compression of all of
259 # the Windows release artifacts.
261 # It includes all of the RELEASE_INCLUDES, and converts LF-style line endings to
262 # CRLF in the non-binary components of the artifact.
263 bin/releases/git-lfs-%-$(VERSION).zip : $(RELEASE_INCLUDES) bin/git-lfs-%.exe
264 @mkdir -p bin/releases
267 # TEST_TARGETS is a list of all phony test targets. Each one of them corresponds
268 # to a specific kind or subset of tests to run.
269 TEST_TARGETS := test-bench test-verbose test-race
270 .PHONY : $(TEST_TARGETS) test
271 $(TEST_TARGETS) : test
273 # test-bench runs all Go benchmark tests, and nothing more.
274 test-bench : GO_TEST_EXTRA_ARGS=-run=__nothing__ -bench=.
275 # test-verbose runs all Go tests in verbose mode.
276 test-verbose : GO_TEST_EXTRA_ARGS=-v
277 # test-race runs all Go tests in race-detection mode.
278 test-race : GO_TEST_EXTRA_ARGS=-race
280 # test runs the Go tests with GO_TEST_EXTRA_ARGS in all specified packages,
281 # given by the PKGS variable.
283 # For example, a caller can invoke the race-detection tests in just the config
284 # package by running:
286 # make PKGS=config test-race
288 # Or in a series of packages, like:
290 # make PKGS="config lfsapi tools/kv" test-race
294 $(GO) test $(GO_TEST_EXTRA_ARGS) $(addprefix ./,$(PKGS))
296 # integration is a shorthand for running 'make' in the 't' directory.
298 integration : bin/git-lfs$(X)
301 # glide.lock is the permanent record of the glide.yaml file, and it is built by
302 # running 'glide update'.
303 glide.lock : glide.yaml
306 # vendor updates the glide.lock-file, and installs vendored dependencies into
307 # the vendor/ sub-tree, removing sub-packages (listed below) that are unused by
312 $(RM) -r vendor/github.com/ThomsonReutersEikon/go-ntlm/utils
313 $(RM) -r vendor/github.com/davecgh/go-spew
314 $(RM) -r vendor/github.com/pmezard/go-difflib
316 # fmt runs goimports over all files in Git LFS (as defined by $(SOURCES) above),
317 # and replaces their contents with a formatted one in-place.
319 # If $(GOIMPORTS) does not exist, or isn't otherwise executable, this recipe
320 # still performs the linting sequence, but gracefully skips over running a
321 # non-existent command.
323 ifeq ($(shell test -x "`which $(GOIMPORTS)`"; echo $$?),0)
324 fmt : $(SOURCES) | lint
325 @$(GOIMPORTS) $(GOIMPORTS_EXTRA_OPTS) $?;
327 fmt : $(SOURCES) | lint
328 @echo "git-lfs: skipping fmt, no goimports found at \`$(GOIMPORTS)\` ..."
331 # lint ensures that there are all dependencies outside of the standard library
332 # are vendored in via vendor (see: above).
335 @$(GO) list -f '{{ join .Deps "\n" }}' . \
336 | $(XARGS) $(GO) list -f '{{ if not .Standard }}{{ .ImportPath }}{{ end }}' \
337 | $(GREP) -v "github.com/git-lfs/git-lfs" || exit 0
339 # MAN_ROFF_TARGETS is a list of all ROFF-style targets in the man pages.
340 MAN_ROFF_TARGETS = man/git-lfs-checkout.1 \
341 man/git-lfs-clean.1 \
342 man/git-lfs-clone.1 \
343 man/git-lfs-config.5 \
346 man/git-lfs-fetch.1 \
347 man/git-lfs-filter-process.1 \
349 man/git-lfs-install.1 \
351 man/git-lfs-locks.1 \
353 man/git-lfs-ls-files.1 \
354 man/git-lfs-migrate.1 \
355 man/git-lfs-pointer.1 \
356 man/git-lfs-post-checkout.1 \
357 man/git-lfs-post-merge.1 \
358 man/git-lfs-pre-push.1 \
359 man/git-lfs-prune.1 \
362 man/git-lfs-smudge.1 \
363 man/git-lfs-status.1 \
364 man/git-lfs-track.1 \
365 man/git-lfs-uninstall.1 \
366 man/git-lfs-unlock.1 \
367 man/git-lfs-untrack.1 \
368 man/git-lfs-update.1 \
371 # MAN_HTML_TARGETS is a list of all HTML-style targets in the man pages.
372 MAN_HTML_TARGETS = man/git-lfs-checkout.1.html \
373 man/git-lfs-clean.1.html \
374 man/git-lfs-clone.1.html \
375 man/git-lfs-config.5.html \
376 man/git-lfs-env.1.html \
377 man/git-lfs-ext.1.html \
378 man/git-lfs-fetch.1.html \
379 man/git-lfs-filter-process.1.html \
380 man/git-lfs-fsck.1.html \
381 man/git-lfs-install.1.html \
382 man/git-lfs-lock.1.html \
383 man/git-lfs-locks.1.html \
384 man/git-lfs-logs.1.html \
385 man/git-lfs-ls-files.1.html \
386 man/git-lfs-migrate.1.html \
387 man/git-lfs-pointer.1.html \
388 man/git-lfs-post-checkout.1.html \
389 man/git-lfs-post-merge.1.html \
390 man/git-lfs-pre-push.1.html \
391 man/git-lfs-prune.1.html \
392 man/git-lfs-pull.1.html \
393 man/git-lfs-push.1.html \
394 man/git-lfs-smudge.1.html \
395 man/git-lfs-status.1.html \
396 man/git-lfs-track.1.html \
397 man/git-lfs-uninstall.1.html \
398 man/git-lfs-unlock.1.html \
399 man/git-lfs-untrack.1.html \
400 man/git-lfs-update.1.html \
403 # man generates all ROFF- and HTML-style manpage targets.
405 man : $(MAN_ROFF_TARGETS) $(MAN_HTML_TARGETS)
407 # man/% generates ROFF-style man pages from the corresponding .ronn file.
408 man/% : docs/man/%.ronn
410 $(RONN) $(RONN_EXTRA_ARGS) -r --pipe < $^ > $@
412 # man/%.html generates HTML-style man pages from the corresponding .ronn file.
413 man/%.html : docs/man/%.ronn
415 $(RONN) $(RONN_EXTRA_ARGS) -5 --pipe < $^ > $@