46 lines
1.6 KiB
Makefile
46 lines
1.6 KiB
Makefile
APP := netstable
|
|
DIST := dist
|
|
VERSION ?= dev
|
|
PLATFORMS := linux/amd64 linux/arm64
|
|
|
|
.PHONY: test build package release update-ip-db clean
|
|
|
|
test:
|
|
go test ./...
|
|
|
|
build:
|
|
mkdir -p $(DIST)
|
|
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o $(DIST)/$(APP) ./cmd/netstable
|
|
|
|
package:
|
|
mkdir -p $(DIST)
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o $(DIST)/$(APP)-linux-amd64 ./cmd/netstable
|
|
mkdir -p $(DIST)/$(APP)-$(VERSION)-linux-amd64
|
|
cp $(DIST)/$(APP)-linux-amd64 $(DIST)/$(APP)-$(VERSION)-linux-amd64/$(APP)
|
|
cp README.md THIRD_PARTY.md deploy/netstable.service $(DIST)/$(APP)-$(VERSION)-linux-amd64/
|
|
cp -R LICENSES $(DIST)/$(APP)-$(VERSION)-linux-amd64/
|
|
COPYFILE_DISABLE=1 tar --no-xattrs -czf $(DIST)/$(APP)-$(VERSION)-linux-amd64.tar.gz -C $(DIST)/$(APP)-$(VERSION)-linux-amd64 .
|
|
|
|
release: clean test
|
|
mkdir -p $(DIST)
|
|
set -e; \
|
|
for platform in $(PLATFORMS); do \
|
|
os=$${platform%/*}; \
|
|
arch=$${platform#*/}; \
|
|
name="$(APP)-$(VERSION)-$${os}-$${arch}"; \
|
|
mkdir -p "$(DIST)/$${name}"; \
|
|
CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} go build -trimpath -ldflags "-s -w" -o "$(DIST)/$${name}/$(APP)" ./cmd/netstable; \
|
|
cp README.md THIRD_PARTY.md deploy/netstable.service "$(DIST)/$${name}/"; \
|
|
cp -R LICENSES "$(DIST)/$${name}/"; \
|
|
COPYFILE_DISABLE=1 tar --no-xattrs -czf "$(DIST)/$${name}.tar.gz" -C "$(DIST)/$${name}" .; \
|
|
done
|
|
cd $(DIST) && shasum -a 256 *.tar.gz > checksums.txt
|
|
|
|
update-ip-db:
|
|
mkdir -p data
|
|
curl -L --fail --retry 3 -o data/ip2region_v4.xdb https://raw.githubusercontent.com/lionsoul2014/ip2region/master/data/ip2region_v4.xdb
|
|
shasum -a 256 data/ip2region_v4.xdb
|
|
|
|
clean:
|
|
rm -rf $(DIST)
|