Skip to content

Commit

Permalink
feat(Makefile): GO variable, several improvements
Browse files Browse the repository at this point in the history
* add GO variable to specify the path to the `go` binary
* 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 authored and axtloss committed Sep 12, 2024
1 parent 48c7244 commit 57f3315
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
PREFIX=/usr/
DESTDIR=/
BINARY_NAME=apx
PREFIX := /usr
DESTDIR := /
BINARY_NAME := apx

all: build
GO := go

build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o ${BINARY_NAME}
all: clean build

build: ${BINARY_NAME}

${BINARY_NAME}:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ${GO} build -a -tags netgo -ldflags '-w -extldflags "-static"' -o $@

install: build
install -Dm755 ${BINARY_NAME} ${DESTDIR}${PREFIX}/bin/${BINARY_NAME}
Expand All @@ -22,7 +26,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 +35,4 @@ uninstall-manpages:

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

0 comments on commit 57f3315

Please sign in to comment.