Skip to content

Commit

Permalink
Simplify makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
orblazer committed Jul 19, 2024
1 parent cad774d commit 4215d6d
Showing 1 changed file with 20 additions and 46 deletions.
66 changes: 20 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,43 @@ VERSION := $(or ${GITHUB_TAG_NAME},$(shell git describe --tags --exact-match 2>

GOFILES=$(wildcard *.go)
GONAME=$(shell basename "$(PWD)")
GO_BUILDINFO= -X 'github.com/metal-stack/v.Version=$(VERSION)' \
GOOS := linux
GOARCH := amd64
BINARY := $(GONAME)-$(GOOS)-$(GOARCH)

build:
go build \
-trimpath \
-tags netgo \
-ldflags "-X 'github.com/metal-stack/v.Version=$(VERSION)' \
-X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \
-X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'
-X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)'" \
-o bin/$(BINARY) $(GOFILES)
strip bin/$(BINARY)
sha256sum bin/$(BINARY) > bin/$(BINARY).sha256

run:
$(MAKE) app-local
$(MAKE) build BINARY=$(GONAME)-dev
go run $(GOFILES) --config=$(shell pwd)/nftables_exporter.yaml

clean:
@echo "Cleaning"
go clean

##
# Build
##
app-local:
go build \
-trimpath \
-tags netgo \
-ldflags "$(GO_BUILDINFO)" \
-o bin/$(GONAME)-dev $(GOFILES)
strip bin/$(GONAME)-dev
app-local-goos-goarch:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-trimpath \
-tags netgo \
-ldflags "$(GO_BUILDINFO)" \
-o bin/$(GONAME)-$(GOOS)-$(GOARCH) $(GOFILES)
strip bin/$(GONAME)-$(GOOS)-$(GOARCH)
sha256sum bin/$(GONAME)-$(GOOS)-$(GOARCH) > bin/$(GONAME)-$(GOOS)-$(GOARCH).sha256

build: \
build-linux-amd64 \
build-linux-arm64

build-linux-amd64:
GOOS=linux GOARCH=amd64 $(MAKE) app-local-goos-goarch
build-linux-arm64:
GOOS=linux GOARCH=arm64 $(MAKE) app-local-goos-goarch

##
# Release
##

.PHONY: release-goos-goarch release
release: \
release-linux-amd64 \
release-linux-arm64

release-linux-amd64:
GOOS=linux GOARCH=amd64 $(MAKE) release-goos-goarch
release-linux-arm64:
GOOS=linux GOARCH=arm64 $(MAKE) release-goos-goarch

release-goos-goarch: build-$(GOOS)-$(GOARCH)
.PHONY: release
release: build
rm -rf rel
rm -f nftables-exporter.tgz
mkdir -p rel/usr/bin rel/etc/systemd/system
cp bin/nftables-exporter-$(GOOS)-$(GOARCH) rel/usr/bin/nftables-exporter
cp systemd/nftables-exporter.service rel/etc/systemd/system
cd rel \
&& tar --transform="flags=r;s|-$(GOOS)-$(GOARCH)||" -cvzf nftables-exporter-$(GOOS)-$(GOARCH).tgz \
usr/bin/nftables-exporter etc/systemd/system/nftables-exporter.service \
&& mv nftables-exporter-$(GOOS)-$(GOARCH).tgz .. \
&& cd -
&& tar --transform="flags=r;s|-$(GOOS)-$(GOARCH)||" -cvzf nftables-exporter-$(GOOS)-$(GOARCH).tgz \
usr/bin/nftables-exporter etc/systemd/system/nftables-exporter.service \
&& mv nftables-exporter-$(GOOS)-$(GOARCH).tgz .. \
&& cd -

0 comments on commit 4215d6d

Please sign in to comment.