do_build_system global function

This commit is contained in:
Jörn-Michael Miehe 2019-09-24 14:12:06 +02:00
parent d7f6a1fb8d
commit 66731ee148
3 changed files with 60 additions and 45 deletions

View file

@ -7,6 +7,7 @@
g_bin="$(readlink -f "$(which "$0")")"
g_lib=${g_bin/"bin"/"lib"}
declare -a g_build_systems
declare -A g_build_systems_glob
#
# load base program

View file

@ -1,29 +1,5 @@
#!/bin/bash
# compile a directory
do_compile() { # $1:DIR $2:OBJECT $3:DONE
# extract params
local dir="$1"
local object="$2"
local done="${3:-0}"
# build systems
for build_system in ${g_build_systems[@]}; do
try_${build_system} "${dir}" "${object}" \
&& local done="1"
done
# never leave $g_watchroot
if [ "${dir}" != "${g_watchroot}" ]; then
# search parent dir for more build instructions
do_compile "$(dirname "${dir}")" "${object}" "${done}"
elif [ "${done}" == "0" ]; then
# hit $g_watchroot
echo "No build instructions found!"
fi
}
# process an inotify event
do_handle() { # $1:FLAGS $2:OBJECT
# extract params
@ -42,3 +18,55 @@ do_handle() { # $1:FLAGS $2:OBJECT
echo -n "'${object}': '${flags}' in '${dir}'. "
do_compile "${dir}" "${object}"
}
# compile a directory
do_compile() { # $1:DIR $2:OBJECT $3:DONE
# extract params
local dir="$1"
local object="$2"
local done="${3:-0}"
# build systems
for build_system in ${g_build_systems[@]}; do
do_build_system "${build_system}" "${dir}" "${object}" \
&& local done="1"
done
# never leave $g_watchroot
if [ "${dir}" != "${g_watchroot}" ]; then
# search parent dir for more build instructions
do_compile "$(dirname "${dir}")" "${object}" "${done}"
elif [ "${done}" == "0" ]; then
# hit $g_watchroot
echo "No build instructions found!"
fi
}
# use given BUILD_SYSTEM to process an OBJECT from a DIRectory
do_build_system() { # $1:BUILD_SYSTEM $2:DIR $3:OBJECT
# extract params
local build_system="$1"
local dir="$2"
local object="$3"
# not done yet
local result=1
# get glob pattern for plugin
for glob in ${g_build_systems_glob[${build_system}]}; do
# match glob in directory
for file in "${dir}"/${glob}; do
# check file readability
if [ -r "${file}" ]; then
# actually call into build system
echo -n "Found '${file}': "
do_${build_system} "$(basename "${file}")" "${dir}" "${object}" \
&& local result=0
echo ""
fi
done
done
return ${result}
}

View file

@ -1,12 +1,16 @@
#!/bin/bash
# plugin name
g_build_systems+=(make)
# build instruction file globs for this plugin
g_build_systems_glob[make]="Makefile *.mk"
# compile using bare make command
do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT
do_make() { # $1:MAKEFILE $2:DIR $3:OBJECT
# extract params
local dir="$1"
local makefile="$2"
local makefile="$1"
local dir="$2"
local object="$3"
# check Makefile 'source pattern'
@ -35,21 +39,3 @@ do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT
return 0
}
try_make() { # $1:DIR $2:OBJECT
# extract params
local dir="$1"
local object="$2"
local retval=1
for FILE in "${dir}"/Makefile "${dir}"/*.mk; do
if [ -r "${FILE}" ]; then
echo -n "Found '${FILE}': "
do_make "${dir}" "$(basename "${FILE}")" "${object}" \
&& local retval=0
echo ""
fi
done
return ${retval}
}