diff --git a/build/usr/local/bin/autodoc b/build/usr/local/bin/autodoc index 7677144..a9a33f2 100755 --- a/build/usr/local/bin/autodoc +++ b/build/usr/local/bin/autodoc @@ -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 diff --git a/build/usr/local/lib/autodoc/handle_inotify b/build/usr/local/lib/autodoc/handle_inotify index 1637f4a..97d751f 100644 --- a/build/usr/local/lib/autodoc/handle_inotify +++ b/build/usr/local/lib/autodoc/handle_inotify @@ -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} +} diff --git a/build/usr/local/lib/autodoc/plugins/make.sh b/build/usr/local/lib/autodoc/plugins/make.sh index af34c12..f150b9f 100644 --- a/build/usr/local/lib/autodoc/plugins/make.sh +++ b/build/usr/local/lib/autodoc/plugins/make.sh @@ -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} -}