Files
katenary/Makefile

115 lines
3.1 KiB
Makefile
Raw Normal View History

2021-12-03 14:12:45 +01:00
CUR_SHA=$(shell git log -n1 --pretty='%h')
CUR_BRANCH=$(shell git branch --show-current)
VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA))
2021-12-01 09:09:30 +01:00
CTN:=$(shell which podman 2>&1 1>/dev/null && echo "podman" || echo "docker")
2021-12-02 12:36:32 +01:00
PREFIX=~/.local
2021-12-01 09:09:30 +01:00
2022-01-26 09:44:23 +01:00
GO=container
2022-01-26 09:43:01 +01:00
BLD_CMD=go build -o katenary -ldflags="-X 'main.Version=$(VERSION)'" .
2022-02-16 18:32:51 +01:00
GOOS=linux
GOARCH=amd64
BUILD_IMAGE=docker.io/golang:1.17
2022-01-26 09:43:01 +01:00
.PHONY: help clean build
2021-12-01 09:09:30 +01:00
.ONESHELL:
help:
@cat <<EOF
=== HELP ===
To avoid you to install Go, the build is made by podman or docker.
You can use:
$$ make install
This will build and install katenary inside the PREFIX(/bin) value (default is $(PREFIX))
To change the PREFIX to somewhere where only root or sudo users can save the binary, it is recommended to build before install:
$$ make build
$$ sudo make install PREFIX=/usr/local
2022-02-16 18:32:51 +01:00
Katenary is statically built (in Go), so there is no library to install.
To build for others OS:
$$ make GOOS=linux GOARCH=amd64
This will build the binary for linux amd64.
$$ make GOOS=linux GOARCH=arm
This will build the binary for linux arm.
$$ make GOOS=windows GOARCH=amd64
This will build the binary for windows amd64.
$$ make GOOS=darwin GOARCH=amd64
This will build the binary for darwin amd64.
Or you can build all versions:
$$ make build-all
2021-12-01 09:09:30 +01:00
EOF
2022-02-16 18:32:51 +01:00
build: pull katenary
build-all: pull dist dist/katenary-linux-amd64 dist/katenary-linux-arm64 dist/katenary.exe dist/katenary-darwin
pull:
@echo -e "\033[1;32mPulling $(BUILD_IMAGE) docker image\033[0m"
@$(CTN) pull $(BUILD_IMAGE)
dist:
mkdir -p dist
dist/katenary-linux-amd64:
@echo -e "\033[1;32mBuilding katenary for linux-amd64...\033[0m"
$(MAKE) katenary GOOS=linux GOARCH=amd64
strip katenary
mv katenary dist/katenary-linux-amd64
dist/katenary-linux-arm64:
@echo -e "\033[1;32mBuilding katenary for linux-arm...\033[0m"
$(MAKE) katenary GOOS=linux GOARCH=arm64
strip katenary
mv katenary dist/katenary-linux-arm64
dist/katenary.exe:
@echo -e "\033[1;32mBuilding katenary for windows...\033[0m"
$(MAKE) katenary GOOS=windows GOARCH=amd64
strip katenary
mv katenary dist/katenary-windows.exe
dist/katenary-darwin:
@echo -e "\033[1;32mBuilding katenary for darwin...\033[0m"
$(MAKE) katenary GOOS=darwin GOARCH=amd64
strip katenary
mv katenary dist/katenary-darwin
2022-01-26 09:21:36 +01:00
katenary: $(wildcard */*.go Makefile go.mod go.sum)
2022-02-16 18:32:51 +01:00
@echo -e "\033[1;33mBuilding katenary $(VERSION)...\033[0m"
2022-01-26 09:43:01 +01:00
ifeq ($(GO),local)
@echo "=> Build in host using go"
@echo
2021-12-01 09:09:30 +01:00
else
2022-01-26 09:43:01 +01:00
@echo "=> Build in container using" $(CTN)
@echo
endif
echo $(BLD_CMD)
2022-02-14 17:15:11 +01:00
ifeq ($(GO),local)
2022-01-26 09:43:01 +01:00
$(BLD_CMD)
else ifeq ($(CTN),podman)
2022-02-16 18:32:51 +01:00
@podman run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) --rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --userns keep-id -it docker.io/golang $(BLD_CMD)
2022-01-26 09:43:01 +01:00
else
2022-02-16 18:32:51 +01:00
@docker run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) --rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --user $(shell id -u):$(shell id -g) -e HOME=/tmp -it docker.io/golang $(BLD_CMD)
2021-12-01 09:09:30 +01:00
endif
2022-02-16 18:32:51 +01:00
2021-12-01 09:09:30 +01:00
install: build
cp katenary $(PREFIX)/bin/katenary
uninstall:
rm -f $(PREFIX)/bin/katenary
clean:
rm -f katenary
2022-02-14 14:36:43 +01:00