2020-11-10 03:31:02 -05:00
|
|
|
# Go parameters
|
|
|
|
GOCMD=go
|
|
|
|
MODULENAME=github.com/h44z/wg-portal
|
|
|
|
GOFILES:=$(shell go list ./... | grep -v /vendor/)
|
|
|
|
BUILDDIR=dist
|
|
|
|
BINARIES=$(subst cmd/,,$(wildcard cmd/*))
|
2020-11-10 05:06:04 -05:00
|
|
|
IMAGE=h44z/wg-portal
|
2020-11-10 03:31:02 -05:00
|
|
|
|
|
|
|
.PHONY: all test clean phony
|
|
|
|
|
2020-12-17 10:10:05 -05:00
|
|
|
all: dep build
|
2020-11-10 03:31:02 -05:00
|
|
|
|
2021-02-24 16:16:03 -05:00
|
|
|
build: dep
|
|
|
|
mkdir -p $(BUILDDIR)
|
2020-12-17 10:10:05 -05:00
|
|
|
cp scripts/wg-portal.service $(BUILDDIR)
|
|
|
|
cp scripts/wg-portal.env $(BUILDDIR)
|
2021-02-24 16:40:35 -05:00
|
|
|
GOX_linux_arm_LDFLAGS="-linkmode external -extldflags -static" GOX_linux_arm_CC=arm-linux-gnueabihf-gcc GOX_linux_arm64_LDFLAGS="-linkmode external -extldflags -static" GOX_linux_arm64_CC=aarch64-linux-gnu-gcc gox -rebuild -parallel=1 -verbose -cgo -os="linux" -arch="amd64 arm arm64" -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.Version=`git rev-parse --short HEAD`" -verbose ./...
|
2020-11-10 03:31:02 -05:00
|
|
|
|
|
|
|
dep:
|
2021-02-24 16:40:35 -05:00
|
|
|
$(GOCMD) get github.com/necrose99/gox
|
2020-11-10 03:31:02 -05:00
|
|
|
$(GOCMD) mod download
|
|
|
|
|
2020-11-10 05:06:04 -05:00
|
|
|
validate: dep
|
2020-11-10 03:31:02 -05:00
|
|
|
$(GOCMD) fmt $(GOFILES)
|
|
|
|
$(GOCMD) vet $(GOFILES)
|
|
|
|
$(GOCMD) test -race $(GOFILES)
|
|
|
|
|
2020-11-10 05:06:04 -05:00
|
|
|
coverage: dep
|
2020-11-10 03:31:02 -05:00
|
|
|
$(GOCMD) fmt $(GOFILES)
|
|
|
|
$(GOCMD) test $(GOFILES) -v -coverprofile .testCoverage.txt
|
|
|
|
$(GOCMD) tool cover -func=.testCoverage.txt # use total:\s+\(statements\)\s+(\d+.\d+\%) as Gitlab CI regextotal:\s+\(statements\)\s+(\d+.\d+\%)
|
|
|
|
|
|
|
|
coverage-html: coverage
|
|
|
|
$(GOCMD) tool cover -html=.testCoverage.txt
|
|
|
|
|
2020-11-10 05:06:04 -05:00
|
|
|
test: dep
|
2020-11-10 03:31:02 -05:00
|
|
|
$(GOCMD) test $(MODULENAME)/... -v -count=1
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(GOCMD) clean $(GOFILES)
|
|
|
|
rm -rf .testCoverage.txt
|
|
|
|
rm -rf $(BUILDDIR)
|
|
|
|
|
2020-11-10 05:06:04 -05:00
|
|
|
docker-build:
|
|
|
|
docker build -t $(IMAGE) .
|
|
|
|
|
|
|
|
docker-push:
|
|
|
|
docker push $(IMAGE)
|
|
|
|
|
2020-12-17 10:23:55 -05:00
|
|
|
$(BUILDDIR)/%-amd64: cmd/%/main.go dep phony
|
|
|
|
GOOS=linux GOARCH=amd64 $(GOCMD) build -o $@ $<
|
|
|
|
|
|
|
|
# On arch-linux install aarch64-linux-gnu-gcc to crosscompile for arm64
|
|
|
|
$(BUILDDIR)/%-arm64: cmd/%/main.go dep phony
|
|
|
|
CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOOS=linux GOARCH=arm64 $(GOCMD) build -ldflags "-linkmode external -extldflags -static" -o $@ $<
|
|
|
|
|
|
|
|
# On arch-linux install arm-linux-gnueabihf-gcc to crosscompile for arm
|
|
|
|
$(BUILDDIR)/%-arm: cmd/%/main.go dep phony
|
|
|
|
CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc GOOS=linux GOARCH=arm GOARM=7 $(GOCMD) build -ldflags "-linkmode external -extldflags -static" -o $@ $<
|