Makefile 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. SHELL=/bin/bash
  2. # Build
  3. NAME :=mitmengine
  4. VERSION := $(shell git rev-list --count HEAD)-$(shell git rev-parse --short HEAD)
  5. TIMESTAMP := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
  6. LDFLAGS := "-X main.Version=$(VERSION) -X main.BuildTime=$(TIMESTAMP)"
  7. BUILD := build
  8. IMPORT_PATH := github.com/cloudflare/$(NAME)
  9. GO := go
  10. GOPATH = ./.GOPATH
  11. export GOPATH = $(CURDIR)/.GOPATH
  12. DEP := $(GOPATH)/bin/dep
  13. BIN_DIR := ./bin
  14. GOFILES := $(shell find . -name "*\.go")
  15. CMDS := $(notdir $(wildcard cmd/*))
  16. TARGETS = $(addprefix $(BIN_DIR)/,$(CMDS))
  17. .PHONY: vendor
  18. vendor: $(DEP)
  19. cd .GOPATH/src/$(IMPORT_PATH) && $(DEP) ensure
  20. $(DEP): .GOPATH/.ok
  21. $(GO) get -u github.com/golang/dep/cmd/dep
  22. .PHONY: init
  23. init: .GOPATH/.ok
  24. cd .GOPATH/src/$(IMPORT_PATH) && $(DEP) init
  25. $(BIN_DIR)/%: .GOPATH/.ok $(GOFILES)
  26. @if [ ! -d cmd/$* ]; then echo "Error: No directory at cmd/$*." && exit 1; fi
  27. $(GO) install -ldflags $(LDFLAGS) $(IMPORT_PATH)/cmd/$*
  28. .PHONY: install build
  29. install build: $(TARGETS)
  30. .GOPATH/.ok:
  31. mkdir -p "$(dir .GOPATH/src/$(IMPORT_PATH))"
  32. ln -s ../../../.. ".GOPATH/src/$(IMPORT_PATH)"
  33. mkdir -p .GOPATH/test .GOPATH/cover
  34. mkdir -p bin
  35. ln -s ../bin .GOPATH/bin
  36. touch $@
  37. # Test
  38. .PHONY: test unit
  39. test unit: .GOPATH/.ok
  40. cd $(GOPATH)/src/$(IMPORT_PATH) && $(GO) test -cover -v ./...
  41. # Misc
  42. .PHONY: clean
  43. clean:
  44. rm -rf build $(GOPATH) bin/*
  45. .PHONY: vet
  46. vet:
  47. $(GO) vet -v $(addprefix $(IMPORT_PATH)/,$(wildcard cmd/*))
  48. .PHONY: godoc
  49. godoc:
  50. godoc $(IMPORT_PATH)/$(PKG)
  51. .PHONY: lint
  52. lint:
  53. cd $(GOPATH)/src/$(IMPORT_PATH) && (golint ./... | grep -v vendor || true)
  54. .PHONY: cover
  55. cover:
  56. cd $(GOPATH)/src/$(IMPORT_PATH) && $(GO) test -coverprofile=cover.out ./...
  57. cd $(GOPATH)/src/$(IMPORT_PATH) && $(GO) tool cover -func=cover.out && rm cover.out