From 7d3bc2cfba0f65306cd323a4e17204e260190183 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Fri, 12 Feb 2016 20:32:14 +0100 Subject: [PATCH] Add carefully crafted Makefile for recursing into subdirectories... that is compatile with both real Make and GNU Make. --- configure.ac | 1 + mk/bld.mk | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 mk/bld.mk diff --git a/configure.ac b/configure.ac index 91a41f9..91b9a7e 100644 --- a/configure.ac +++ b/configure.ac @@ -246,6 +246,7 @@ AC_SUBST([CENVFLAGS]) AC_CONFIG_FILES([bld-kl/Makefile:mk/top.mk:mk/top-kl.mk:src/Makefile.mk bld-ks/Makefile:mk/top.mk:mk/top-ks.mk:src/Makefile.mk bld-ks-its/Makefile:mk/top.mk:mk/top-ks-its.mk:src/Makefile.mk + Makefile:mk/bld.mk ]) AC_OUTPUT diff --git a/mk/bld.mk b/mk/bld.mk new file mode 100644 index 0000000..936689a --- /dev/null +++ b/mk/bld.mk @@ -0,0 +1,28 @@ +# Makefile to build in the subdirectories. +# Designed to be both BSD Make and GNU Make compatible +# (as are all the other Makefiles). +# + +# The RECURSE macro uses a shell variable $TARGET for delayed expansion. +RECURSE=for d in bld-* ; \ + do \ + ${MAKE} -C $$d $${TARGET} ; \ + done + +# This carefully crafted rule will run Make in all subdirectories with +# the same target, no matter what it is (as long as it is just one +# target). +# +# .TARGETS is a BSD specific variable, and MAKECMDGOALS is the GNU version. +# .TARGETS becomes "rEmOvEmE" when no targets are given on the +# command line (because this is the default target). +# MAKECMDGOALS remains empty in that case. +# Do not use "all" as the extra target, since that fails when that is +# given as target on the command line (you get duplicate targets). +# The shell variable substitution removes "rEmOvEmE" if present. +# So when no target is given, the recursion uses no target either. + +${.TARGETS} ${MAKECMDGOALS} rEmOvEmE : +# set -x; T="${.TARGETS}${MAKECMDGOALS}"; echo "T=$$T"; TARGET="$${T%%rEmOvEmE}"; echo "TARGET=$$TARGET" + T="${.TARGETS}${MAKECMDGOALS}"; TARGET="$${T%%rEmOvEmE}"; ${RECURSE} +