For the record, I'm writing according to the NEXT - Version 5 of Single Unix Specification, which is Issue 8 if you count the days when it was named XPG. In this new standard, a few new already-common-place features are being added, such as delayed and immediate expansion macros, and re-making of include files. Parts of the proposed changes are available here.
My end-goal is to include something generated by more complex scripts, and this is just me practicing. For example, I want to create a "make" prerequisite listing of C/C++ include files; Or I want to extract a list of contributors to my project, and put this list in the "make" target for documentations.
What I'm trying to achieve, is to include a file in the main Makefile, and this file is always generated on-demand whenever the build targets are requested to make (thus excluding auxiliary targets such as clean, install, etc.)
Here's my Makefile
.PHONY: all clean timestamping
all: main.c
${CC} -o main -D LIB_RET=1${lib_ret} main.c
clean:
rm -f main include.mk time.stamp
all: timestamping
timestamping:
date -u '+%Y-%m-%d T %H:%M:%S %Z' > time.stamp
time.stamp:; :
include.mk: time.stamp
printf 'lib_ret='`date +%S` > include.mk
include include.mk
Here's "main.c":
#include <stdio.h>
int main(void){ return LIB_RET; }
I'm quite satisfied with the current form of it, but I'm sure suggests for improvements will be plenty. I'm mostly concerned about the portability of this Makefile on FOSS makes, such as GNU make and pmake.
One part I'm not satisified is that the commands for timestamping
and time.stamp
gets executed twice on the make supplied by the Xcode toolchains (which uses GNU Make version 3.81 as of Xcode Version 14.2 (14C18) 2022-12-27).