~adnano/astronaut

762f8a694bcb2af1c4fca0a67ea4a52e8ba7b159 — phoebos 1 year, 9 months ago 03db8ec
Makefile: make POSIX-compliant

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.
4 files changed, 35 insertions(+), 17 deletions(-)

M .gitignore
M Makefile
M README.md
A configure
M .gitignore => .gitignore +1 -0
@@ 1,2 1,3 @@
astronaut
*.1
config.mk

M Makefile => Makefile +11 -17
@@ 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

M README.md => README.md +1 -0
@@ 13,6 13,7 @@ First install the dependencies:

Then compile:

	$ ./configure
	$ make
	# make install


A configure => configure +22 -0
@@ 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"