diff --git a/bash/smake/smake.sh b/bash/smake/smake.sh index 5a3e429..227b62a 100755 --- a/bash/smake/smake.sh +++ b/bash/smake/smake.sh @@ -48,6 +48,9 @@ done cat $HELP_FILE > Makefile echo >> Makefile +# ======= Test for target ======= +[ ! -f $REP_TARGET.c ] && echo "$REP_TARGET.c doesn't exist" && exit -1 + # ======= Environment ======= sed "s~REP_CC~$REP_CC~ ; s~REP_CXX~$REP_CXX~ ; \ s~REP_LIBRARIES~$REP_LIBRARIES~ ; s~REP_TARGET~$REP_TARGET~" $ENV_FILE >> Makefile @@ -85,33 +88,41 @@ cat $RULES_FILE >> Makefile REP_INCLUDE=`echo $REP_INCLUDE | sed "s~-I~~g ; s~\\$(HOME)~${HOME}~g"` flist[0]=$REP_TARGET.c +fpath[0]=$REP_TARGET.c nfiles=1 nparsed=0 fdeplist[0]=`remove_c_comments.pl $REP_TARGET.c | grep -P '^[\t ]*#include[\t ]*"' | sed 's~[^"]*"\([^"]*\)".*~\1~' | sort -u` files_not_found= while [ $nfiles != $nparsed ]; do for f in ${fdeplist[$nparsed]}; do - already_in_list=false - for i in `seq 0 $((nparsed))`; do - if [ "${flist[$i]}" == "$f" ]; then - already_in_list=false - break; - fi - done - [ $already_in_list == true ] && continue + extension=`basename $f | sed 's~.*\.~~g'` + f=`echo $f | sed "s~.$extension$~~"` + for ext in "$extension" c cxx cpp; do + already_in_list=false + for i in `seq 0 $((nfiles))`; do + if [ "${flist[$i]}" == "$f.$ext" ]; then + already_in_list=true + break; + fi + done + [ $already_in_list == true ] && continue - found=false - for d in . $REP_INCLUDE; do - if [ -f "$d/$f" ]; then - found=true - flist[$nfiles]=$f - fdeplist[$nfiles]=`remove_c_comments.pl $d/$f | grep -P '^[\t ]*#include[\t ]*"' | sed 's~[^"]*"\([^"]*\)".*~\1~' | sort -u` - let nfiles++ - break - fi + F= + for d in . $REP_INCLUDE; do + if [ -f "$d/$f.$ext" ]; then + F="$d/$f.$ext" + fi + if [ "$F" != "" ]; then + flist[$nfiles]=$f.$ext + fpath[$nfiles]=$F + fdeplist[$nfiles]=`remove_c_comments.pl $F | grep -P '^[\t ]*#include[\t ]*"' | sed 's~[^"]*"\([^"]*\)".*~\1~' | sort -u` + let nfiles++ + break + fi + done + [[ "$F" == "" && "$ext" == "$extension" ]] && files_not_found=`echo "$files_not_found\n$f.$ext" | sort -u` + [[ "$F" != "" && "$ext" != "$extension" ]] && break done - - [ found == false ] && files_not_found=`echo "$files_not_found\n$f" | sort -u` done let nparsed++ done