From 0a509fb535273725dd2fdf0c2343d0c339ed1396 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Mon, 24 Jul 2023 23:08:18 +0100 Subject: [PATCH] Cleaned up with shellcheck, and corrected the description in the comment block at the top. --- autoconf/scripts/makemake.sh | 148 +++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 68 deletions(-) diff --git a/autoconf/scripts/makemake.sh b/autoconf/scripts/makemake.sh index 5bd967d..7769751 100755 --- a/autoconf/scripts/makemake.sh +++ b/autoconf/scripts/makemake.sh @@ -1,8 +1,9 @@ #!/bin/sh # -# Generate Makefile dependencies inclusion and module target file "depend.mk~" -# by scanning the directory "src" for files ending in ".c" and ".d", and for -# subdirectories not starting with "_". +# Generate Makefile components "filelist.mk~" (list source, object, and +# dependency files) and "modules.mk~" (linking rules for each directory's +# overall object file) by scanning the directory "src" for files ending in +# ".c", and for subdirectories not starting with "_". # # Modules live inside subdirectories called [^_]* - i.e. a directory "foo" will # have a rule created which links all code inside it to "foo.o". @@ -11,103 +12,114 @@ # directories. # -outlist=$1 -outlink=$2 +listingsFile="$1" +linkingRulesFile="$2" -FIND=find -GREP=grep -command -v gfind 2>/dev/null | grep /gfind >/dev/null && FIND=gfind -command -v which ggrep 2>/dev/null | grep /ggrep >/dev/null && GREP=ggrep +FIND="find" +GREP="grep" +command -v gfind 2>/dev/null | grep /gfind >/dev/null && FIND="gfind" +command -v which ggrep 2>/dev/null | grep /ggrep >/dev/null && GREP="ggrep" -echo '# Automatically generated file listings' > $outlist -echo '#' >> $outlist -echo "# Creation time: $(date)" >> $outlist -echo >> $outlist +{ +echo '# Automatically generated file listings' +echo '#' +echo "# Creation time: $(date)" +echo +} > "${listingsFile}" -echo '# Automatically generated module linking rules' > $outlink -echo '#' >> $outlink -echo "# Creation time: $(date)" >> $outlink -echo >> $outlink +{ +echo '# Automatically generated module linking rules' +echo '#' +echo "# Creation time: $(date)" +echo +} > "${linkingRulesFile}" -echo -n "Scanning for source files: " +printf "%s" "Scanning for source files: " -allsrc=$($FIND src -type f -name "*.c" -print) -allobj=$(echo $allsrc | tr ' ' '\n' | sed 's/\.c$/.o/') -alldep=$(echo $allsrc | tr ' ' '\n' | sed 's/\.c$/.d/') +allsrc=$("${FIND}" src -type f -name "*.c" -print) +allobj=$(echo "${allsrc}" | tr ' ' '\n' | sed 's/\.c$/.o/') +alldep=$(echo "${allsrc}" | tr ' ' '\n' | sed 's/\.c$/.d/') -echo $(echo $allsrc | wc -w | tr -d ' ') found +echo "$(echo "${allsrc}" | wc -w | tr -d ' ') found" -echo -n "Scanning for modules: " +printf "%s" "Scanning for modules: " -modules=$($FIND src -type d -print \ - | $GREP -v '^src$' \ - | $GREP -v '/_' \ - | $GREP -v '^src/include' \ - | $GREP -v 'CVS' \ - | $GREP -v '.svn' \ - | while read DIR; do \ - CONTENT=$(/bin/ls -d $DIR/* \ - | $GREP -v '.po$' \ - | $GREP -v '.gmo$' \ - | $GREP -v '.mo$' \ - | $GREP -v '.h$' \ +modules=$("${FIND}" src -type d -print \ + | "${GREP}" -v '^src$' \ + | "${GREP}" -v '/_' \ + | "${GREP}" -v '^src/include' \ + | "${GREP}" -v 'CVS' \ + | "${GREP}" -v '.svn' \ + | while read -r DIR; do \ + CONTENT=$(/bin/ls -d "${DIR}"/* \ + | "${GREP}" -v '.po$' \ + | "${GREP}" -v '.gmo$' \ + | "${GREP}" -v '.mo$' \ + | "${GREP}" -v '.h$' \ | sed -n '$p'); \ [ -n "$CONTENT" ] || continue; \ - echo $DIR; \ + echo "${DIR}"; \ done ) -echo up to $(echo $modules | wc -w | tr -d ' ') found +echo "up to $(echo "${modules}" | wc -w | tr -d ' ') found" echo "Writing module linking rules" -echo -n [ -for i in $modules; do echo -n ' '; done -echo -n -e ']\r[' +printf "%s" "[" +for i in ${modules}; do printf "%s" " "; done +printf "%s\r%s" "]" "[" -for i in $modules; do - echo -n '.' - allobj="$allobj $i.o" +for i in ${modules}; do + printf "%s" "." + allobj="${allobj} ${i}.o" deps="" - for j in $i/*.c; do - [ -f $j ] || continue - newobj=$(echo $j | sed -e 's@\.c$@.o@') + for j in "${i}"/*.c; do + [ -f "$j" ] || continue + newobj=$(echo "$j" | sed -e 's@\.c$@.o@') deps="$deps $newobj" done - for j in $i/*; do + for j in "${i}"/*; do [ -d "$j" ] || continue - [ $(basename $j) = "CVS" ] && continue - [ $(basename $j) = ".svn" ] && continue - CONTENT=$(/bin/ls -d $j/* \ - | $GREP -v '.po$' \ - | $GREP -v '.gmo$' \ - | $GREP -v '.mo$' \ - | $GREP -v '.h$' \ + [ "$(basename "$j")" = "CVS" ] && continue + [ "$(basename "$j")" = ".svn" ] && continue + CONTENT=$(/bin/ls -d "$j"/* \ + | "${GREP}" -v '.po$' \ + | "${GREP}" -v '.gmo$' \ + | "${GREP}" -v '.mo$' \ + | "${GREP}" -v '.h$' \ | sed -n '$p') [ -n "$CONTENT" ] || continue deps="$deps $j.o" done [ -n "$deps" ] || continue - echo "$i.o: $deps" >> $outlink - echo ' $(LD) $(LDFLAGS) -o $@' "$deps" >> $outlink - echo >> $outlink + { + echo "$i.o: $deps" + echo " \$(LD) \$(LDFLAGS) -o \$@ $deps" + echo + } >> "${linkingRulesFile}" done echo ']' echo "Listing source, object and dependency files" -echo -n "allsrc = " >> $outlist -echo $allsrc | sed 's,src/nls/cat-id-tbl.c,,' | sed -e 's/ / \\!/g'\ -| tr '!' '\n' >> $outlist -echo >> $outlist -echo -n "allobj = " >> $outlist -echo $allobj | sed -e 's/ / \\!/g' | tr '!' '\n' >> $outlist -echo >> $outlist -echo -n "alldep = " >> $outlist -echo $alldep | sed -e 's/ / \\!/g' | tr '!' '\n' >> $outlist +{ +printf "%s" "allsrc = " +echo "$allsrc" | tr '\n' ' ' | sed 's,src/nls/cat-id-tbl.c,,' | sed -e 's/ $//;s/ / \\!/g' \ +| tr '!' '\n' +echo +echo +printf "%s" "allobj = " +echo "$allobj" | tr '\n' ' ' | sed -e 's/ $//;s/ / \\!/g' | tr '!' '\n' +echo +echo +printf "%s" "alldep = " +echo "$alldep" | tr '\n' ' ' | sed -e 's/ $//;s/ / \\!/g' | tr '!' '\n' +echo +echo +} >> "${listingsFile}" -echo >> $outlist -echo >> $outlink +echo >> "${linkingRulesFile}" # EOF