github.com/go-darwin/sys@v0.0.0-20220510002607-68fd01f054ca/Makefile (about)

     1  GO_TAGS := osusergo,netgo
     2  GO_LDFLAGS := -s -w "-extldflags=-static"
     3  GO_INSTALLSUFFIX := netgo
     4  GO_FLAGS = -trimpath -tags='${GO_TAGS}' -ldflags='${GO_LDFLAGS}' -installsuffix='${GO_INSTALLSUFFIX}'
     5  
     6  GO_ASM_PKGS := $(shell go list -f='{{ join .SFiles " " }}' ./... | grep -v -e 'crosscall2.s')
     7  
     8  GO_TEST ?= ${TOOLS_BIN}/gotestsum --
     9  GO_TEST_FLAGS ?= -race -count=1
    10  GO_TEST_FUNC ?= .
    11  GO_TEST_PACKAGE ?= ./...
    12  GO_LINT_PACKAGE ?= ./...
    13  
    14  TOOLS_DIR := ${CURDIR}/tools
    15  TOOLS_BIN := ${TOOLS_DIR}/bin
    16  TOOLS := $(shell cd ${TOOLS_DIR} && go list -v -x -f '{{ join .Imports " " }}' -tags=tools)
    17  
    18  JOBS := $(shell getconf _NPROCESSORS_CONF)
    19  
    20  ztypes_darwin_amd64.go:
    21  	@go tool cgo -srcdir . -godefs -import_runtime_cgo=false -import_syscall=false defs_darwin_amd64.go | tee ztypes_darwin_amd64.go; gofmt -s -w ztypes_darwin_amd64.go
    22  
    23  ##@ fmt, lint
    24  
    25  .PHONY: fmt
    26  fmt: tools/asmfmt  ## Run asmfmt.
    27  	$(call target)
    28  	${TOOLS_BIN}/asmfmt -w ${GO_ASM_PKGS}
    29  
    30  .PHONY: lint
    31  lint: lint/asmvet  ## Run all linter.
    32  
    33  .PHONY: lint/asmvet
    34  lint/asmvet: tools/asmvet  ## Run asmvet.
    35  	$(call target)
    36  	go vet -vettool=${TOOLS_BIN}/asmvet ${GO_ASM_PKGS}
    37  
    38  
    39  ##@ test
    40  
    41  define go_test
    42  ${GO_TEST} $(strip ${GO_FLAGS}) ${GO_TEST_FLAGS} -run=${GO_TEST_FUNC} ${GO_TEST_PACKAGE}
    43  endef
    44  
    45  .PHONY: test
    46  test: tools/gotestsum  ## Run test.
    47  	$(call go_test)
    48  
    49  .PHONY: coverage
    50  coverage: GO_TEST_FLAGS+=-covermode=atomic -coverpkg=./... -coverprofile=coverage.out
    51  coverage: tools/gotestsum  ## Run test and collect coverages.
    52  	$(call go_test)
    53  
    54  
    55  ##@ tools
    56  
    57  .PHONY: tools
    58  tools: tools/bin/''  ## Install all tools.
    59  
    60  .PHONY: tools/%
    61  tools/%:  ## Install an individual dependency tool.
    62  	@${MAKE} tools/bin/$* 1>/dev/null
    63  
    64  tools/bin/%: ${TOOLS_DIR}/go.mod ${TOOLS_DIR}/go.sum
    65  	@cd tools; \
    66  	  for bin in ${TOOLS}; do \
    67  			if [ -z '$*' ] || [ $$(basename $$bin) = '$*' ]; then \
    68  				echo "Install $$bin ..." >&2; \
    69  				GOBIN=${TOOLS_BIN} CGO_ENABLED=0 go install -mod=mod ${GO_FLAGS} "$${bin}"; \
    70  			fi \
    71  	  done
    72  
    73  
    74  ##@ clean
    75  
    76  .PHONY: clean
    77  clean:  ## Cleanups binaries and extra files in the package.
    78  	$(call target)
    79  	@$(RM) -rf *.out *.test *.prof trace.txt _obj ${TOOLS_BIN}
    80  
    81  
    82  # ----------------------------------------------------------------------------
    83  ##@ help
    84  
    85  .PHONY: help
    86  help:  ## Show make target help.
    87  	@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[33m<target>\033[0m\n"} /^[a-zA-Z_0-9\/_-]+:.*?##/ { printf "  \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
    88  
    89  .PHONY: env env/%
    90  env:  ## Print the value of MAKEFILE_VARIABLE. Use `make env/MAKEFILE_VARIABLE`.
    91  env/%:
    92  	@echo $($*)