Multi-Makefile support

This commit is contained in:
Jörn-Michael Miehe 2019-09-20 11:02:01 +02:00
parent b4eb717608
commit 2772ea8663
2 changed files with 31 additions and 24 deletions

View file

@ -9,44 +9,46 @@ do_make() { # $1:DIR $2:OBJECT
local dir="$1" local dir="$1"
local object="$2" local object="$2"
# enter build directory
local olddir="$(pwd)"
cd "${dir}"
# extract Makefile 'source pattern' # extract Makefile 'source pattern'
local srcpat="$(grep -E "^#@SRCPAT" Makefile | sed -r "s/^#@SRCPAT\s+//")" local srcpat="$(grep -E "^#@SRCPAT" "${dir}/Makefile" | sed -r "s/^#@SRCPAT\s+//")"
if [ -z "${srcpat}" ]; then if [ -z "${srcpat}" ]; then
echo "Empty source pattern! Make sure Makefile has '#@SRCPAT' annotation!" echo "Empty source pattern! Makefile needs '#@SRCPAT' annotation!"
elif [[ "${object}" =~ ${srcpat} ]]; then
make -j # source pattern matched
else
echo "'${object}' does not match source pattern '${srcpat}'!"
fi
cd "${olddir}" elif [[ "${object}" =~ ${srcpat} ]]; then
echo "SRCPAT OK."
make --no-print-directory -C "${dir}" -j
else
echo "SRCPAT mismatch '${srcpat}'."
fi
} }
# compile a directory # compile a directory
do_compile() { # $1:DIR $2:OBJECT do_compile() { # $1:DIR $2:OBJECT $3:DONE
# extract params # extract params
local dir="$1" local dir="$1"
local object="$2" local object="$2"
local done="${3:-0}"
if [ -e "${dir}/Makefile" ]; then # build systems
# compile using Makefile
echo "using 'make' in '$(basename "${dir}")'." if [ -r "${dir}/Makefile" ]; then
# Makefile found
echo -n "Using '${dir}/Makefile'. "
do_make "${dir}" "${object}" do_make "${dir}" "${object}"
local done="1"
fi
elif [ "${dir}" != "${g_watchroot}" ]; then # search parent dir for more build instructions
# search parent dir for build instructions (don't leave g_watchroot) if [ "${dir}" != "${g_watchroot}" ]; then
# never leave $g_watchroot
local dir="$(dirname "${dir}")" local dir="$(dirname "${dir}")"
echo -n "moving up … " do_compile "${dir}" "${object}" "${done}"
do_compile "${dir}" "${object}"
else elif [ "${done}" == "0" ]; then
# stop otherwise # hit $g_watchroot
echo "no build instruction found!" echo "No build instructions found!"
fi fi
} }
@ -65,7 +67,7 @@ do_handle() { # $1:FLAGS $2:OBJECT
fi fi
# start using toolchain # start using toolchain
echo -n "Flags '${flags}' for '${object}' in '${dir}' … " echo -n "'${object}': '${flags}' in '${dir}'. "
do_compile "${dir}" "${object}" do_compile "${dir}" "${object}"
} }

View file

@ -0,0 +1,5 @@
#@SRCPAT .*
.PHONY: all
all:
@echo "Hello World!"