github.com/robgonnella/ardi/v2@v2.4.5-0.20230102052001-11a49de978c3/Makefile (about)

     1  platform ?= $(shell uname -s)
     2  dest = build
     3  tag = $(shell git describe --tags $(shell git rev-list --tags --max-count=1))
     4  ci ?= false
     5  
     6  #### Build Objects ####
     7  component = ardi_$(tag)
     8  component_path = $(dest)/$(component)
     9  linux_objects = $(component_path)_linux_amd64 \
    10  $(component_path)_linux_arm_5 \
    11  $(component_path)_linux_arm_6 \
    12  $(component_path)_linux_arm_7 \
    13  $(component_path)_linux_arm64
    14  
    15  darwin_object = $(component_path)_darwin_amd64
    16  
    17  #### Zip File Objects ####
    18  
    19  # see gather objects section below
    20  zips =
    21  
    22  #### Gather Objects ####
    23  
    24  ifeq ($(platform),Linux)
    25  objects := $(linux_objects)
    26  else
    27  objects := $(darwin_object)
    28  endif
    29  
    30  $(foreach o,$(objects), $(eval zips += $(o).zip))
    31  
    32  #### Test Objects ####
    33  test_output_dir = test_artifacts
    34  coverage_out = $(test_output_dir)/coverage.txt
    35  
    36  #### Helper Functions ####
    37  
    38  define get_goos
    39  $(word 3, $(subst _, ,$1))
    40  endef
    41  
    42  define get_goarch
    43  $(word 4, $(subst _, ,$1))
    44  endef
    45  
    46  define get_goarm
    47  $(word 5, $(subst _, ,$1))
    48  endef
    49  
    50  #### Rules Section ####
    51  
    52  .PHONY: all
    53  all: $(objects)
    54  
    55  $(objects): $(shell find . -type f -name "*.go")
    56  	$(eval goos=$(call get_goos, $(@)))
    57  	$(eval goarch=$(call get_goarch, $(@)))
    58  	$(eval goarm=$(call get_goarm, $(@)))
    59  	GOOS=$(goos) GOARCH=$(goarch) GOARM=$(goarm) go build -ldflags '-s -w' -o $(@)
    60  
    61  $(zips): $(objects)
    62  	zip -j $(@) $(@:.zip=)
    63  
    64  .PHONY: release
    65  release: $(zips)
    66  
    67  .PHONY: mock
    68  mock:
    69  	go generate ./...
    70  
    71  .PHONY: lint
    72  lint:
    73  	golint -set_exit_status ./...
    74  
    75  .PHONY: test-unit-and-integration
    76  go-test:
    77  	mkdir -p $(test_output_dir)
    78  	rm -rf $(coverage_out)
    79  	go test \
    80  		-v \
    81  		-p 1 \
    82  		-coverprofile $(coverage_out) \
    83  		-covermode=atomic \
    84  		./...
    85  
    86  .PHONY: test-e2e
    87  test-e2e:
    88  	./scripts/run_e2e.sh
    89  
    90  .PHONY: test-all
    91  test-all: lint
    92  	$(MAKE) go-test
    93  	$(MAKE) test-e2e
    94  	$(MAKE) coverage
    95  
    96  .PHONY: coverage
    97  coverage:
    98  	go tool cover -func $(coverage_out)
    99  
   100  .PHONY: test-report
   101  test-report:
   102  	go tool cover -html=$(coverage_out)
   103  
   104  .PHONY: docs
   105  docs:
   106  	go run docs/gen.go
   107  
   108  .PHONY: deps
   109  deps:
   110  	go install github.com/golang/mock/mockgen@latest
   111  	go install golang.org/x/lint/golint@latest
   112  
   113  
   114  .PHONY: clean
   115  clean:
   116  	rm -rf build