bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/Makefile (about)

     1  # Go parameters
     2  GOCMD=go
     3  GOBUILD=$(GOCMD) build
     4  GOCLEAN=$(GOCMD) clean
     5  GOGENERATE=$(GOCMD) generate
     6  GOGET=$(GOCMD) get
     7  GOINSTALL=$(GOCMD) install
     8  GOLIST=$(GOCMD) list
     9  GOMOD=$(GOCMD) mod
    10  GOTEST=$(GOCMD) test
    11  GOVET=$(GOCMD) vet
    12  GOTOOL=$(GOCMD) tool
    13  BINARY_NAME=bosun
    14  BINARY_UNIX=$(BINARY_NAME)_unix
    15  BINARY_MAC=$(BINARY_NAME)_mac
    16  BINARY_WIN=$(BINARY_NAME)_win
    17  BOSUN_PACKAGE=bosun.org/cmd/bosun
    18  
    19  SCOLLECTOR_BINARY=scollector
    20  SCOLLECTOR_PACKAGE=bosun.org/cmd/scollector
    21  TSDBRELAY_BINARY=tsdbrelay
    22  TSDBRELAY_PACKAGE=bosun.org/cmd/tsdbrelay
    23  
    24  SRCS := $(shell find . -name '*.go')
    25  LINTERS := \
    26  	golang.org/x/lint/golint \
    27  	golang.org/x/tools/cmd/goimports \
    28  	github.com/kisielk/errcheck \
    29  	honnef.co/go/tools/cmd/staticcheck
    30  
    31  .PHONY: build
    32  build:
    33  	$(GOBUILD) -v bosun.org/...
    34  
    35  .PHONY: build-linux
    36  build-linux:
    37  	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -v bosun.org/...
    38  
    39  .PHONY: build-darwin
    40  build-darwin:
    41  	CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -v bosun.org/...
    42  
    43  .PHONY: build-windows
    44  build-windows:
    45  	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -v bosun.org/...
    46  
    47  .PHONY: deps
    48  deps:
    49  	$(GOGET) -d -v ./...
    50  	npm install
    51  
    52  .PHONY: updatedeps
    53  updatedeps:
    54  	$(GOGET) -d -v -u -f ./...
    55  
    56  .PHONY: testdeps
    57  testdeps:
    58  	$(GOGET) -d -v -t ./...
    59  	$(GOGET) -v $(LINTERS)
    60  
    61  .PHONY: updatetestdeps
    62  updatetestdeps:
    63  	$(GOGET) -d -v -t -u -f ./...
    64  	$(GOGET) -u -v $(LINTERS)
    65  
    66  .PHONY: install
    67  install: deps
    68  	$(GOINSTALL) ./...
    69  
    70  .PHONY: golint
    71  golint:
    72  	@for file in $(SRCS); do \
    73  		golint $${file}; \
    74  		if [ -n "$$(golint $${file})" ]; then \
    75  			exit 1; \
    76  		fi; \
    77  	done
    78  
    79  .PHONY: vet
    80  vet:
    81  	$(GOVET) ./...
    82  
    83  .PHONY: generate
    84  generate:
    85  	$(GOGENERATE) ./...
    86  	@if [ -n "$$(git diff --exit-code --name-only)" ]; then \
    87    		echo "The following files are uncommitted changes in the repository:"; \
    88    		git diff --name-only; \
    89    		echo "Please commit the files created by go generate."; \
    90    		echo "This may be a false positive if there were uncommitted files before running this target."; \
    91    		exit 1; \
    92    	fi
    93  
    94  .PHONY: goimports
    95  goimports:
    96  	goimports -format-only -w ${SRCS}
    97  
    98  .PHONY: goimports-check
    99  goimports-check:
   100  	@if [ ! -z "$$(goimports -format-only -l ${SRCS})" ]; then \
   101        		echo "Found unformatted source files. Please run"; \
   102        		echo "  make goimports"; \
   103        		echo "To automatically format your files"; \
   104        		exit 1; \
   105        	fi
   106  
   107  .PHONY: tidy
   108  tidy:
   109  	$(GOMOD) tidy
   110  
   111  .PHONY: tidy-check
   112  tidy-check: tidy
   113  	@if [ -n "$$(git diff-index --exit-code --ignore-submodules --name-only HEAD | grep -E '^go.(mod|sum)$$')" ]; then \
   114  		echo "go.mod or go.sum has changed after running go mod tidy for you."; \
   115  		echo "Please make sure you review and commit the changes."; \
   116  		exit 1; \
   117  	fi
   118  
   119  .PHONY: errcheck
   120  errcheck:
   121  	errcheck ./...
   122  
   123  .PHONY: staticcheck
   124  staticcheck:
   125  	staticcheck ./...
   126  
   127  .PHONY: test
   128  test:
   129  	$(GOTEST) -v ./...
   130  
   131  .PHONY: test-coverprofile
   132  test-coverprofile:
   133  	$(GOTEST) -covermode=count -coverprofile=coverage.out $$($(GOLIST) ./... | grep -v integration) -json > test-report.out
   134  
   135  .PHONY: coverage
   136  coverage:
   137  	$(GOTEST) -covermode=count -coverprofile=coverage.out  $$($(GOLIST) ./... | grep -v integration)
   138  	$(GOTOOL) cover -html=coverage.out
   139  
   140  .PHONY: checks
   141  checks: goimports-check vet generate tidy-check
   142  
   143  .PHONY: clean
   144  clean:
   145  	$(GOCLEAN) -v ./...
   146  	rm -f $(BINARY_NAME)
   147  	rm -f $(BINARY_UNIX)
   148  	rm -f $(BINARY_MAC)
   149  	rm -f $(BINARY_WIN)
   150  
   151  .PHONY: run
   152  run: bosun
   153  	./$(BINARY_NAME)
   154  
   155  # Cross compilation
   156  all-os: bosun-linux bosun-darwin bosun-windows
   157  bosun:
   158  	$(GOBUILD) -o $(BINARY_NAME) -v $(BOSUN_PACKAGE)
   159  bosun-linux:
   160  	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v $(BOSUN_PACKAGE)
   161  bosun-darwin:
   162  	CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_MAC) -v $(BOSUN_PACKAGE)
   163  bosun-windows:
   164  	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_WIN) -v $(BOSUN_PACKAGE)
   165  scollector:
   166  	$(GOBUILD) -o $(SCOLLECTOR_BINARY) -v $(SCOLLECTOR_PACKAGE)
   167  tsdbrelay:
   168  	$(GOBUILD) -o $(TSDBRELAY_BINARY) -v $(TSDBRELAY_PACKAGE)
   169  
   170  
   171  .PHONY: all
   172  all: deps testdeps checks build all-os build test bosun scollector tsdbrelay