122 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			122 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
| VERSION?=$(shell git describe --abbrev=0)+$(shell date +'%Y%m%d%H%I%S')
 | |
| 
 | |
| EXECUTABLE:=flucky
 | |
| 
 | |
| DESTDIR?=
 | |
| PREFIX?=/usr/local
 | |
| 
 | |
| # BINARIES
 | |
| # ==============================================================================
 | |
| EXECUTABLE_TARGETS:= \
 | |
| 	bin/linux/amd64/${EXECUTABLE} \
 | |
| 	bin/linux/arm/5/${EXECUTABLE} \
 | |
| 	bin/linux/arm/7/${EXECUTABLE} \
 | |
| 	bin/tmp/${EXECUTABLE}
 | |
| 
 | |
| ${EXECUTABLE}: bin/tmp/${EXECUTABLE}
 | |
| 
 | |
| bin/linux/amd64/${EXECUTABLE}:
 | |
| 	CGO_ENABLED=1 \
 | |
| 	GOOS=linux \
 | |
| 	GOARCH=amd64 \
 | |
| 	GOPROXY=$(shell go env GOPROXY) \
 | |
| 	GOPRIVATE=$(shell go env GOPRIVATE) \
 | |
| 		go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
 | |
| 
 | |
| bin/linux/arm/5/${EXECUTABLE}:
 | |
| 	CGO_ENABLED=1 \
 | |
| 	GOOS=linux \
 | |
| 	GOARCH=arm \
 | |
| 	GOARM=5 \
 | |
| 	GOPROXY=$(shell go env GOPROXY) \
 | |
| 	GOPRIVATE=$(shell go env GOPRIVATE) \
 | |
| 		go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
 | |
| 
 | |
| bin/linux/arm/7/${EXECUTABLE}:
 | |
| 	CC=arm-linux-gnueabihf-gcc \
 | |
| 	CGO_ENABLED=1 \
 | |
| 	GOOS=linux \
 | |
| 	GOARCH=arm \
 | |
| 	GOARM=7 \
 | |
| 	GOPROXY=$(shell go env GOPROXY) \
 | |
| 	GOPRIVATE=$(shell go env GOPRIVATE) \
 | |
| 		go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
 | |
| 
 | |
| bin/tmp/${EXECUTABLE}:
 | |
| 	CGO_ENABLED=1 \
 | |
| 	GOPROXY=$(shell go env GOPROXY) \
 | |
| 	GOPRIVATE=$(shell go env GOPRIVATE) \
 | |
| 		go build -ldflags "-X main.version=${VERSION:v%=%}" -o ${@}
 | |
| 
 | |
| # COMPLETIONS
 | |
| # ==============================================================================
 | |
| bin/tmp/${EXECUTABLE}.sh: bin/tmp/${EXECUTABLE}
 | |
| 	bin/tmp/${EXECUTABLE} completion bash > ${@}
 | |
| 
 | |
| bin/tmp/${EXECUTABLE}.fish: bin/tmp/${EXECUTABLE}
 | |
| 	bin/tmp/${EXECUTABLE} completion fish > ${@}
 | |
| 
 | |
| bin/tmp/${EXECUTABLE}.zsh: bin/tmp/${EXECUTABLE}
 | |
| 	bin/tmp/${EXECUTABLE} completion zsh > ${@}
 | |
| 
 | |
| # UN/INSTALL
 | |
| # ==============================================================================
 | |
| PHONY+=install
 | |
| install: bin/tmp/${EXECUTABLE} bin/tmp/${EXECUTABLE}.sh bin/tmp/${EXECUTABLE}.fish bin/tmp/${EXECUTABLE}.zsh
 | |
| 	install --directory ${DESTDIR}${PREFIX}/bin
 | |
| 	install --mode 755 bin/tmp/${EXECUTABLE} ${DESTDIR}${PREFIX}/bin/${EXECUTABLE}
 | |
| 
 | |
| 	install --directory ${DESTDIR}/etc/bash_completion.d
 | |
| 	install --mode 755 bin/tmp/${EXECUTABLE}.sh ${DESTDIR}/etc/bash_completion.d/${EXECUTABLE}.sh
 | |
| 
 | |
| 	install --directory ${DESTDIR}/usr/share/fish/vendor_completions.d
 | |
| 	install --mode 644 bin/tmp/${EXECUTABLE}.fish ${DESTDIR}/usr/share/fish/vendor_completions.d/${EXECUTABLE}.fish
 | |
| 
 | |
| 	install --directory ${DESTDIR}/usr/lib/systemd/system
 | |
| 	install --mode 644 systemd/${EXECUTABLE}.service ${DESTDIR}/usr/lib/systemd/system/${EXECUTABLE}.service
 | |
| 
 | |
| 	install --directory ${DESTDIR}/usr/share/licenses/${EXECUTABLE}
 | |
| 	install --mode 644 LICENSE ${DESTDIR}/usr/share/licenses/${EXECUTABLE}/LICENSE
 | |
| 
 | |
| PHONY+=uninstall
 | |
| uninstall:
 | |
| 	-rm --recursive --force \
 | |
| 		${DESTDIR}${PREFIX}/bin/${EXECUTABLE} \
 | |
| 		${DESTDIR}/etc/bash_completion.d/${EXECUTABLE}.sh \
 | |
| 		${DESTDIR}/usr/lib/systemd/system/${EXECUTABLE}.service \
 | |
| 		${DESTDIR}/usr/share/fish/vendor_completions.d/${EXECUTABLE}.fish \
 | |
| 		${DESTDIR}/usr/share/licenses/${EXECUTABLE}/LICENSE
 | |
| 
 | |
| # CLEAN
 | |
| # ==============================================================================
 | |
| PHONY+=clean
 | |
| clean:
 | |
| 	rm --force --recursive bin/ || true
 | |
| 
 | |
| # TEST
 | |
| # ==============================================================================
 | |
| PHONY+=test/unit
 | |
| test/unit:
 | |
| 	go test -v -race -coverprofile=coverage.txt -covermode=atomic -timeout 600s -count=1 ./pkg/...
 | |
| 
 | |
| PHONY+=test/coverage
 | |
| test/coverage: test/unit
 | |
| 	go tool cover -html=coverage.txt
 | |
| 
 | |
| # GOLANGCI-LINT
 | |
| # ==============================================================================
 | |
| PHONY+=golangci-lint
 | |
| golangci-lint:
 | |
| 	golangci-lint run --concurrency=$(shell nproc)
 | |
| 
 | |
| # GOSEC
 | |
| # ==============================================================================
 | |
| PHONY+=gosec
 | |
| gosec:
 | |
| 	gosec $(shell pwd)/...
 | |
| 
 | |
| # PHONY
 | |
| # ==============================================================================
 | |
| # Declare the contents of the PHONY variable as phony.  We keep that information
 | |
| # in a variable so we can use it in if_changed.
 | |
| .PHONY: ${PHONY} |