Files
katenary/Makefile

63 lines
1.6 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:43:01 +01:00
BLD_CMD=go build -o katenary -ldflags="-X 'main.Version=$(VERSION)'" .
.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
Katenary is statically built (in Go), so there is no library to install.
EOF
build: katenary
2022-01-26 09:21:36 +01:00
katenary: $(wildcard */*.go Makefile go.mod go.sum)
2022-01-26 09:43:01 +01:00
@echo "=> Building Katenary version" $(VERSION)
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
ifeq ($(GO),local)
echo $(BLD_CMD)
$(BLD_CMD)
else ifeq ($(CTN),podman)
@podman run --rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --userns keep-id -it golang $(BLD_CMD)
else
@docker run --rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --user $(shell id -u):$(shell id -g) -e HOME=/tmp -it golang $(BLD_CMD)
2021-12-01 09:09:30 +01:00
endif
2022-01-26 09:43:01 +01:00
echo
echo "Check the version"
echo "'./katenary -version' => $(shell ./katenary -version)"
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
2021-12-01 09:09:30 +01:00