Skip to content

Commit

Permalink
feat(Makefile): GO and SYSTEM_DISTROBOX variables, several improvements
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vigress8 committed Sep 11, 2024
1 parent 48c7244 commit bfbab91
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
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/.
Expand All @@ -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

Expand All @@ -31,4 +42,4 @@ uninstall-manpages:

clean:
rm -f ${BINARY_NAME}
go clean
${GO} clean

0 comments on commit bfbab91

Please sign in to comment.