refactor: reorganize project in order to include automation #1

Merged
Emmanuel BENOîT merged 19 commits from :master into master 2024-07-19 22:01:35 +02:00
2 changed files with 42 additions and 1 deletions
Showing only changes of commit 3ea8d81578 - Show all commits

1
.gitignore vendored
View file

@ -1 +1,2 @@
bin bin
dist

View file

@ -1,6 +1,8 @@
BINNAME = gomonop BINNAME = gomonop
BINDIR = $(CURDIR)/bin BINDIR = $(CURDIR)/bin
DISTDIR = $(CURDIR)/dist
TARGETS = linux/amd64 linux/386 linux/arm linux/arm64 TARGETS = linux/amd64 linux/386 linux/arm linux/arm64
STATICFILES = README.md
SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum
GOHOSTOS = $(shell go env GOHOSTOS) GOHOSTOS = $(shell go env GOHOSTOS)
@ -26,6 +28,9 @@ LDFLAGS += -X nocternity.net/gomonop/pkg/version.status=${GIT_STATUS}
.PHONY: all .PHONY: all
all: build all: build
# ---------------
# Basic building
.PHONY: build .PHONY: build
build: GOOS=$(GOHOSTOS) build: GOOS=$(GOHOSTOS)
build: GOARCH=$(GOHOSTARCH) build: GOARCH=$(GOHOSTARCH)
@ -47,12 +52,47 @@ $(BINDIR)/$(GOOS)-$(GOARCH)/$(BINNAME): $(SRC)
test: build test: build
@go test -v ./... @go test -v ./...
# ----------------
# Cross compiling
.PHONY: build-cross .PHONY: build-cross
build-cross: build-cross:
@for target in $(TARGETS); do \ @for target in $(TARGETS); do \
$(MAKE) build-target GOOS=`echo $$target | cut -d / -f 1` GOARCH=`echo $$target | cut -d / -f 2`; \ $(MAKE) build-target GOOS=`echo $$target | cut -d / -f 1` GOARCH=`echo $$target | cut -d / -f 2`; \
done done
# ----------
# Packaging
.PHONY: dist
dist: GOOS=$(GOHOSTOS)
dist: GOARCH=$(GOHOSTARCH)
dist: dist-target
.PHONY: dist-all
dist-all:
@for target in $(TARGETS); do \
$(MAKE) dist-target GOOS=`echo $$target | cut -d / -f 1` GOARCH=`echo $$target | cut -d / -f 2`; \
done
.PHONY: dist-target
dist-target: build-target
@set -e; \
if [ -z "$(BINARY_VERSION)" ]; then \
echo "No version set"; \
exit 1; \
fi; \
mkdir -p $(DISTDIR)/$(BINNAME)-$(BINARY_VERSION)-$(GOOS)-$(GOARCH); \
cp $(BINDIR)/$(GOOS)-$(GOARCH)/$(BINNAME) $(DISTDIR)/$(BINNAME)-$(BINARY_VERSION)-$(GOOS)-$(GOARCH); \
for f in $(STATICFILES); do \
cp $$f $(DISTDIR)/$(BINNAME)-$(BINARY_VERSION)-$(GOOS)-$(GOARCH); \
done; \
cd $(DISTDIR); \
tar cJf $(BINNAME)-$(BINARY_VERSION)-$(GOOS)-$(GOARCH).tar.xz $(BINNAME)-$(BINARY_VERSION)-$(GOOS)-$(GOARCH)
# --------
# Cleanup
.PHONY: clean .PHONY: clean
clean: clean:
@rm -rf $(BINDIR) @rm -rf $(BINDIR) $(DISTDIR)