From e16ab72fd29cd35bfbe823bf8a11858d6a335685 Mon Sep 17 00:00:00 2001 From: vigress8 <150687949+vigress8@users.noreply.github.com> Date: Wed, 11 Sep 2024 22:02:54 +0400 Subject: [PATCH] feat(Makefile): GO and SYSTEM_DISTROBOX variables, several improvements * add GO variable to specify the path to the `go` binary * add SYSTEM_DISTROBOX variable, and if it's defined, skip trying to install Distrobox * make `BINARY_NAME` a target, so `make install` only rebuilds if the binary is not present * assign variables using `:=` (simple expansion) to avoid potential gotchas caused by recursive expansion --- Makefile | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c5a732d9..8ca2affe 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,28 @@ -PREFIX=/usr/ -DESTDIR=/ -BINARY_NAME=apx +PREFIX := /usr +DESTDIR := / +BINARY_NAME := apx + +GO := go +SYSTEM_DISTROBOX := all: build -build: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o ${BINARY_NAME} +build: ${BINARY_NAME} + +${BINARY_NAME}: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ${GO} build -a -tags netgo -ldflags '-w -extldflags "-static"' -o $@ +ifdef SYSTEM_DISTROBOX install: build +else +install: build install-distrobox +endif install -Dm755 ${BINARY_NAME} ${DESTDIR}${PREFIX}/bin/${BINARY_NAME} mkdir -p ${DESTDIR}/etc/apx - sed -i 's|/usr/share/apx/distrobox|${PREFIX}/share/apx/distrobox|g' config/apx.json + sed -i 's|/usr/share/apx/distrobox|${DESTDIR}${PREFIX}/share/apx/distrobox|g' config/apx.json install -Dm644 config/apx.json ${DESTDIR}/etc/apx/apx.json + +install-distrobox: mkdir -p ${DESTDIR}${PREFIX}/share/apx/distrobox sh distrobox/install --prefix ${DESTDIR}${PREFIX}/share/apx/distrobox mv ${DESTDIR}${PREFIX}/share/apx/distrobox/bin/distrobox* ${DESTDIR}${PREFIX}/share/apx/distrobox/. @@ -22,7 +33,7 @@ install-manpages: chmod 644 ${DESTDIR}${PREFIX}/share/man/man1/apx* uninstall: uninstall-manpages - rm ${DESTDIR}${PREFIX}/bin/apx + rm ${DESTDIR}${PREFIX}/bin/${BINARY_NAME} rm -rf ${DESTDIR}/etc/apx rm -rf ${DESTDIR}${PREFIX}/share/apx @@ -31,4 +42,4 @@ uninstall-manpages: clean: rm -f ${BINARY_NAME} - go clean + ${GO} clean