Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Set an output prefix, which is the local directory if not specified
  2. PREFIX?=$(shell pwd)
  3. # Used to populate version variable in main package.
  4. VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
  5. # Allow turning off function inlining and variable registerization
  6. ifeq (${DISABLE_OPTIMIZATION},true)
  7. GO_GCFLAGS=-gcflags "-N -l"
  8. VERSION:="$(VERSION)-noopt"
  9. endif
  10. GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)"
  11. .PHONY: clean all fmt vet lint build test binaries
  12. .DEFAULT: all
  13. all: fmt vet lint build test binaries
  14. AUTHORS: .mailmap .git/HEAD
  15. git log --format='%aN <%aE>' | sort -fu > $@
  16. # This only needs to be generated by hand when cutting full releases.
  17. version/version.go:
  18. ./version/version.sh > $@
  19. # Required for go 1.5 to build
  20. GO15VENDOREXPERIMENT := 1
  21. # Package list
  22. PKGS := $(shell go list -tags "${DOCKER_BUILDTAGS}" ./... | grep -v ^github.com/docker/distribution/vendor/)
  23. # Resolving binary dependencies for specific targets
  24. GOLINT := $(shell which golint || echo '')
  25. GODEP := $(shell which godep || echo '')
  26. ${PREFIX}/bin/registry: $(wildcard **/*.go)
  27. @echo "+ $@"
  28. @go build -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/registry
  29. ${PREFIX}/bin/digest: $(wildcard **/*.go)
  30. @echo "+ $@"
  31. @go build -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/digest
  32. ${PREFIX}/bin/registry-api-descriptor-template: $(wildcard **/*.go)
  33. @echo "+ $@"
  34. @go build -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/registry-api-descriptor-template
  35. docs/spec/api.md: docs/spec/api.md.tmpl ${PREFIX}/bin/registry-api-descriptor-template
  36. ./bin/registry-api-descriptor-template $< > $@
  37. vet:
  38. @echo "+ $@"
  39. @go vet -tags "${DOCKER_BUILDTAGS}" $(PKGS)
  40. fmt:
  41. @echo "+ $@"
  42. @test -z "$$(gofmt -s -l . 2>&1 | grep -v ^vendor/ | tee /dev/stderr)" || \
  43. (echo >&2 "+ please format Go code with 'gofmt -s'" && false)
  44. lint:
  45. @echo "+ $@"
  46. $(if $(GOLINT), , \
  47. $(error Please install golint: `go get -u github.com/golang/lint/golint`))
  48. @test -z "$$($(GOLINT) ./... 2>&1 | grep -v ^vendor/ | tee /dev/stderr)"
  49. build:
  50. @echo "+ $@"
  51. @go build -tags "${DOCKER_BUILDTAGS}" -v ${GO_LDFLAGS} $(PKGS)
  52. test:
  53. @echo "+ $@"
  54. @go test -test.short -tags "${DOCKER_BUILDTAGS}" $(PKGS)
  55. test-full:
  56. @echo "+ $@"
  57. @go test -tags "${DOCKER_BUILDTAGS}" $(PKGS)
  58. binaries: ${PREFIX}/bin/registry ${PREFIX}/bin/digest ${PREFIX}/bin/registry-api-descriptor-template
  59. @echo "+ $@"
  60. clean:
  61. @echo "+ $@"
  62. @rm -rf "${PREFIX}/bin/registry" "${PREFIX}/bin/digest" "${PREFIX}/bin/registry-api-descriptor-template"
  63. dep-save:
  64. @echo "+ $@"
  65. $(if $(GODEP), , \
  66. $(error Please install godep: go get github.com/tools/godep))
  67. @$(GODEP) save $(PKGS)
  68. dep-restore:
  69. @echo "+ $@"
  70. $(if $(GODEP), , \
  71. $(error Please install godep: go get github.com/tools/godep))
  72. @$(GODEP) restore -v
  73. dep-validate: dep-restore
  74. @echo "+ $@"
  75. @rm -Rf .vendor.bak
  76. @mv vendor .vendor.bak
  77. @rm -Rf Godeps
  78. @$(GODEP) save ./...
  79. @test -z "$$(diff -r vendor .vendor.bak 2>&1 | tee /dev/stderr)" || \
  80. (echo >&2 "+ borked dependencies! what you have in Godeps/Godeps.json does not match with what you have in vendor" && false)
  81. @rm -Rf .vendor.bak