~adnano/astronaut-devel

Makefile: make POSIX-compliant v4 APPLIED

phoebos: 1
 Makefile: make POSIX-compliant

 4 files changed, 35 insertions(+), 17 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~adnano/astronaut-devel/patches/27522/mbox | git am -3
Learn more about email & git

[PATCH v4] Makefile: make POSIX-compliant Export this patch

The Makefile was marked as POSIX-compliant (first target is .POSIX), but made
use of a number of extensions, such as the GNU extensions $(shell ...) and ifeq,
and the widely-used, but not POSIX, += ?= != := etc.

Some of these other types of macro definitions _will_ be part of the next
version of POSIX, but they are not currently. For this Makefile, ?= and
:= were not required, and != is replaced by running the commands in a
configure script.

The RM macro was not defined, and it is not one of the predefined MACROS
required by POSIX.

The third version of the patch uses a POSIX sh configure script which
must be run before `make`. The script outputs local details into the file
config.mk, and now when a new version of astronaut is released, the RELEASE
variable in `configure` should be updated.
config.mk is included in the Makefile at a position such that if a specific
prefix was given to the configure script, then BINDIR, SHAREDIR, and MANDIR
are set correctly. However, a user may still write `make PREFIX=/my/prefix`
as before, because macros set on the command line take the highest precedence,
or now they can also write `./configure --prefix=/my/prefix`, then `make`.

A 4th version (hopefully the last!) to fix a typo in the printf statement for
PREFIX in configure. Now the configure script passes shellcheck.
---
 .gitignore |  1 +
 Makefile   | 28 +++++++++++-----------------
 README.md  |  1 +
 configure  | 22 ++++++++++++++++++++++
 4 files changed, 35 insertions(+), 17 deletions(-)
 create mode 100755 configure

diff --git a/.gitignore b/.gitignore
index 1d69caf..ec1284e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
astronaut
*.1
config.mk
diff --git a/Makefile b/Makefile
index 6645c33..fc76416 100644
--- a/Makefile
+++ b/Makefile
@@ -2,26 +2,20 @@
.SUFFIXES:
.SUFFIXES: .1 .1.scd

_git_version=$(shell git describe --tags --dirty 2>/dev/null)
ifeq ($(strip $(_git_version)),)
VERSION=0.1.0
else
VERSION=$(_git_version)
endif

PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin
SHAREDIR?=$(PREFIX)/share/astronaut
MANDIR?=$(PREFIX)/share/man
PREFIX=/usr/local

include config.mk

BINDIR=$(PREFIX)/bin
SHAREDIR=$(PREFIX)/share/astronaut
MANDIR=$(PREFIX)/share/man

VPATH=doc
GO?=go
GOFLAGS?=
GOSRC!=find . -name '*.go'
GOSRC+=go.mod go.sum
GOSRC+=about/*
RM=rm
GO=go
GOFLAGS=

DOCS := \
DOCS = \
	astronaut.1

all: astronaut doc
diff --git a/README.md b/README.md
index 4f5b56b..dde8405 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@ First install the dependencies:

Then compile:

	$ ./configure
	$ make
	# make install

diff --git a/configure b/configure
new file mode 100755
index 0000000..df666c9
--- /dev/null
+++ b/configure
@@ -0,0 +1,22 @@
#!/bin/sh -e

RELEASE=0.1.0
ver="$(git describe --tags --dirty 2>/dev/null || printf "%s" "$RELEASE")"
gosrc="$(find . -name '*.go' -print)"

exec > config.mk

for opt; do
    case "$opt" in
        (--prefix=*) printf "PREFIX = %s\n" "${opt#*=}" ;;
        (*) printf "warning: unknown option %s\n" "$opt" >&2 ;;
    esac
done

printf "VERSION = %s\n" "$ver"
printf "GOSRC = "

# word splitting is desired
# shellcheck disable=2086
printf "%s " $gosrc go.mod go.sum about/*
printf "\n"
-- 
2.34.1
Thanks!

To git@git.sr.ht:~adnano/astronaut
   c706a2f..03db8ec  master -> master