diff --git a/.gitignore b/.gitignore index 5b450d4..71f18ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /bin/* +/build/* +!/build/.gitkeep diff --git a/.woodpecker.yml b/.woodpecker.yml index 56a85a5..b9e9875 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -16,6 +16,6 @@ pipeline: from_secret: gitnet_api_key base_url: https://gitnet.fr note: - files: bin/mugo + files: build/mugo when: event: [tag] diff --git a/Makefile b/Makefile index 44cae0c..79b7d35 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,60 @@ -build: fmt - CGO_ENABLED=0 go build -ldflags '-s -w' -v -o bin/mugo ./src +CGO_ENABLED = 0 +DIR = ./build +GOARCH = amd64 +GOARM = arm64 +GOOSWIN = windows +GOOSX = darwin +GOOSLINUX = linux +EXECUTABLE = mugo + +WINBIN = $(DIR)/$(EXECUTABLE)-win-$(GOARCH).exe +OSXBIN = $(DIR)/$(EXECUTABLE)-darwin-$(GOARCH) +LINUXBIN = $(DIR)/$(EXECUTABLE)-linux-$(GOARCH) +ARMBIN = $(DIR)/$(EXECUTABLE)-linux-$(GOARM) + +CC = go build +CFLAGS = -trimpath +LDFLAGS = all=-w -s +GCFLAGS = all= +ASMFLAGS = all= + +.PHONY: all +all: darwin linux win64 arm + +.PHONY: linux +linux: $(LINUXBIN) + chmod +x $(LINUXBIN) + +.PHONY: arm +arm: $(ARMBIN) + chmod +x $(ARMBIN) + +.PHONY: darwin +darwin: $(OSXBIN) + chmod +x $(OSXBIN) + +.PHONY: win64 +win64: $(WINBIN) + +.PHONY: $(OSXBIN) +$(OSXBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSX) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(OSXBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" ./src + +.PHONY: $(ARMBIN) +$(ARMBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSLINUX) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(ARMBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" ./src + +.PHONY: $(LINUXBIN) +$(LINUXBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSLINUX) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(LINUXBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" ./src + +.PHONY: $(WINBIN) +$(WINBIN): + GO111MODULE=$(GOMOD) GOARCH=$(GOARCH) GOOS=$(GOOSWIN) CGO_ENABLED=$(CGO_ENABLED) $(CC) $(CFLAGS) -o $(WINBIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)" ./src + +.PHONY: clean +clean: + rm -rf $(DIR)/* tool-gofumpt: which golangci-lint > /dev/null 2>&1 || go install mvdan.cc/gofumpt@latest diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29