mirror of
https://github.com/ldericher/autodoc.git
synced 2025-12-06 15:43:01 +00:00
Add "do_${build_system}_all" and "do_build_all"
This commit is contained in:
parent
078cafdc39
commit
76aa31c0c6
5 changed files with 127 additions and 36 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo -n "Loading '${0}': "
|
||||||
|
|
||||||
#
|
#
|
||||||
# hard globals
|
# hard globals
|
||||||
#
|
#
|
||||||
|
|
||||||
g_bin="$(readlink -f "$(which "$0")")"
|
g_bin="$(readlink -f "$(which "$0")")"
|
||||||
g_lib=${g_bin/"bin"/"lib"}
|
g_lib=${g_bin/"bin"/"lib"}
|
||||||
declare -a g_build_systems
|
|
||||||
declare -A g_build_systems_glob
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# load base program
|
# load base program
|
||||||
|
|
@ -16,16 +16,19 @@ declare -A g_build_systems_glob
|
||||||
source "${g_lib}/globals"
|
source "${g_lib}/globals"
|
||||||
source "${g_lib}/logging"
|
source "${g_lib}/logging"
|
||||||
source "${g_lib}/handle_inotify"
|
source "${g_lib}/handle_inotify"
|
||||||
|
|
||||||
for plugin in "${g_lib}/plugins/"*".sh"; do
|
for plugin in "${g_lib}/plugins/"*".sh"; do
|
||||||
source "${plugin}"
|
source "${plugin}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "program parsed."
|
||||||
|
|
||||||
#
|
#
|
||||||
# MAIN
|
# MAIN
|
||||||
#
|
#
|
||||||
|
echo "Building everything in '${g_watchroot}'."
|
||||||
|
do_build_all
|
||||||
|
|
||||||
echo "Booting '${g_bin}' in '${g_watchroot}'."
|
echo "Watching '${g_watchroot}'."
|
||||||
# setup inotify:
|
# setup inotify:
|
||||||
# -mrq monitor, recursive, quiet
|
# -mrq monitor, recursive, quiet
|
||||||
# -e events
|
# -e events
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# array of available build systems
|
||||||
|
declare -a g_build_systems
|
||||||
|
|
||||||
|
# map of file globs for build systems
|
||||||
|
declare -A g_build_systems_glob
|
||||||
|
|
||||||
|
# map of annotation patterns for build systems
|
||||||
|
declare -A g_build_systems_annotations
|
||||||
|
|
||||||
# $WATCHROOT (default: ".")
|
# $WATCHROOT (default: ".")
|
||||||
g_watchroot="$(readlink -f "${1:-.}")"
|
g_watchroot="$(readlink -f "${1:-.}")"
|
||||||
|
|
||||||
|
echo -n "globals ... "
|
||||||
|
|
@ -29,7 +29,7 @@ do_compile() { # $DIR $OBJECT $DONE
|
||||||
|
|
||||||
# build systems
|
# build systems
|
||||||
for build_system in ${g_build_systems[@]}; do
|
for build_system in ${g_build_systems[@]}; do
|
||||||
do_build_system "${dir}" "${object}" "${build_system}" \
|
do_build_system "${dir}" "${build_system}" "${object}" \
|
||||||
&& local done="1"
|
&& local done="1"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -44,25 +44,59 @@ do_compile() { # $DIR $OBJECT $DONE
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# use given BUILD_SYSTEM to process an OBJECT from a DIRectory
|
# check if defined source pattern matches OBJECT
|
||||||
do_build_system() { # $DIR $OBJECT $BUILD_SYSTEM
|
do_check_srcpat() { # $DIR $BUILD_DESC $ANNOTATION $OBJECT
|
||||||
# extract params
|
# extract params
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
local object="$2"
|
local build_desc="$2"
|
||||||
local build_system="$3"
|
local annotation="$3"
|
||||||
|
local object="$4"
|
||||||
|
|
||||||
|
# check 'source pattern'
|
||||||
|
local srcpat="$(grep -E "^${annotation}" "${dir}/${build_desc}" | tail -n 1 | sed -r "s/^${annotation}\s+//")"
|
||||||
|
|
||||||
|
if [ -z "${srcpat}" ]; then
|
||||||
|
# empty srcpat => fail
|
||||||
|
logline_append "Empty source pattern, check for '${annotation}' annotation!"
|
||||||
|
return 1
|
||||||
|
|
||||||
|
elif [ -z "${object}" ]; then
|
||||||
|
# empty object = "no specific object" => success
|
||||||
|
return 0
|
||||||
|
|
||||||
|
elif [[ "${object}" =~ ${srcpat} ]]; then
|
||||||
|
# nonempty object matches srcpat => success
|
||||||
|
return 0
|
||||||
|
|
||||||
|
else
|
||||||
|
# nonempty object does not match srcpat => fail
|
||||||
|
logline_append "SRCPAT '${srcpat}' mismatch."
|
||||||
|
return 1
|
||||||
|
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# use given BUILD_SYSTEM to process an OBJECT from a DIRectory
|
||||||
|
do_build_system() { # $DIR $BUILD_SYSTEM $OBJECT
|
||||||
|
# extract params
|
||||||
|
local dir="$1"
|
||||||
|
local build_system="$2"
|
||||||
|
local object="$3"
|
||||||
|
|
||||||
# not done yet
|
# not done yet
|
||||||
local result=1
|
local result=1
|
||||||
|
|
||||||
# get glob pattern for plugin
|
# get glob patterns for plugin
|
||||||
for glob in ${g_build_systems_glob[${build_system}]}; do
|
for glob in ${g_build_systems_glob[${build_system}]}; do
|
||||||
# match glob in directory
|
# match each glob in directory
|
||||||
for file in "${dir}"/${glob}; do
|
for file in "${dir}"/${glob}; do
|
||||||
# check file readability
|
# check file readability
|
||||||
if [ -r "${file}" ]; then
|
if [ -r "${file}" ]; then
|
||||||
# actually call into build system
|
# actually call into build system
|
||||||
logline_append "Found '${file}':"
|
logline_append "Found '${file}':"
|
||||||
do_${build_system} "${dir}" "${object}" "$(basename "${file}")" \
|
|
||||||
|
local file="$(basename "${file}")"
|
||||||
|
do_${build_system} "${dir}" "${file}" "${object}" \
|
||||||
&& local result=0
|
&& local result=0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
@ -70,3 +104,30 @@ do_build_system() { # $DIR $OBJECT $BUILD_SYSTEM
|
||||||
|
|
||||||
return ${result}
|
return ${result}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# force build using all systems
|
||||||
|
do_build_all() { #
|
||||||
|
# build systems
|
||||||
|
for build_system in ${g_build_systems[@]}; do
|
||||||
|
echo "Build system '${build_system}'."
|
||||||
|
for glob in ${g_build_systems_glob[${build_system}]}; do
|
||||||
|
|
||||||
|
# match each glob recursively
|
||||||
|
find "${g_watchroot}" -iname "${glob}" | \
|
||||||
|
while read file; do
|
||||||
|
if [ -r "${file}" ]; then
|
||||||
|
# force call into build system
|
||||||
|
logline_append "Found '${file}':"
|
||||||
|
|
||||||
|
local dir="$(dirname "${file}")"
|
||||||
|
local file="$(basename "${file}")"
|
||||||
|
do_${build_system}_all "${dir}" "$(basename "${file}")"
|
||||||
|
|
||||||
|
logline_flush
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
echo -n "main ... "
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,5 @@ logline_flush() {
|
||||||
echo "${g_logline}"
|
echo "${g_logline}"
|
||||||
g_logline=""
|
g_logline=""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo -n "logging ... "
|
||||||
|
|
|
||||||
|
|
@ -6,40 +6,54 @@ g_build_systems+=(make)
|
||||||
# build instruction file globs for this plugin
|
# build instruction file globs for this plugin
|
||||||
g_build_systems_glob[make]="Makefile *.mk"
|
g_build_systems_glob[make]="Makefile *.mk"
|
||||||
|
|
||||||
# compile using bare make command
|
# srcpat annotation prefix for this plugin
|
||||||
|
g_build_systems_annotations[make]='#%SRCPAT%'
|
||||||
|
|
||||||
|
# try to compile file OBJECT
|
||||||
do_make() { # $DIR $OBJECT $MAKEFILE
|
do_make() { # $DIR $OBJECT $MAKEFILE
|
||||||
# extract params
|
# extract params
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
local object="$2"
|
local makefile="$2"
|
||||||
local makefile="$3"
|
local object="$3"
|
||||||
|
|
||||||
# check Makefile 'source pattern'
|
# only run if "object" is source file
|
||||||
local srcpat="$(grep -E "^#%SRCPAT%" "${dir}/${makefile}" | tail -n 1 | sed -r "s/^#%SRCPAT%\s+//")"
|
if do_check_srcpat "${dir}" "${makefile}" "${g_build_systems_annotations[make]}" "${object}"; then
|
||||||
|
do_run_make "${dir}" "${makefile}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ -z "${srcpat}" ]; then
|
# try running make for MAKEFILE inside DIRectory
|
||||||
logline_append "Empty source pattern, check '#%SRCPAT%' annotation!"
|
do_make_all() { # $DIR $MAKEFILE
|
||||||
return 1
|
# extract params
|
||||||
|
local dir="$1"
|
||||||
|
local makefile="$2"
|
||||||
|
|
||||||
elif [[ "${object}" =~ ${srcpat} ]]; then
|
# only run if "makefile" is relevant for autodoc
|
||||||
# check for autodoc target
|
if do_check_srcpat "${dir}" "${makefile}" "${g_build_systems_annotations[make]}" ""; then
|
||||||
local target="$(grep -E "^autodoc:" "${dir}/${makefile}" | sed -r "s/:.*$//")"
|
do_run_make "${dir}" "${makefile}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ -z "${target}" ]; then
|
# actually run GNU Make with MAKEFILE inside DIRectory
|
||||||
logline_append "Running 'make'!"
|
do_run_make() { # $DIR $MAKEFILE
|
||||||
else
|
# extract params
|
||||||
logline_append "Making '${target}'!"
|
local dir="$1"
|
||||||
fi
|
local makefile="$2"
|
||||||
|
|
||||||
# actually run "make" and save (truncated) output
|
# check for autodoc target
|
||||||
local makelog="$(make --no-print-directory -C "${dir}" -f "${makefile}" -j ${target})"
|
local target="$(grep -E "^autodoc:" "${dir}/${makefile}" | sed -r "s/:.*$//")"
|
||||||
logline_append "$(echo "${makelog}" | head -n 10 | sed 's/$/;/g' | tr '\n' ' ' | sed 's/ *$//')"
|
|
||||||
|
|
||||||
logline_append "Done."
|
|
||||||
|
|
||||||
|
if [ -z "${target}" ]; then
|
||||||
|
logline_append "Running 'make'!"
|
||||||
else
|
else
|
||||||
logline_append "SRCPAT '${srcpat}' mismatch."
|
logline_append "Making '${target}'!"
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
# actually run "make" and save (truncated) output
|
||||||
|
local makelog="$(make --no-print-directory -C "${dir}" -f "${makefile}" -j ${target})"
|
||||||
|
logline_append "$(echo "${makelog}" | head -n 10 | sed 's/$/;/g' | tr '\n' ' ' | sed 's/ *$//')"
|
||||||
|
|
||||||
|
logline_append "Done."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo -n "GNU Make plugin ... "
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue