#! /bin/bash # Checks the timestamps on the .exe, .o, and .c files in this directory. # If a .c file is newer than its .o, recompile the .c file. # If a .o file is newer than the .exe file, relink. # Takes one optional argument: "rebuild" # If specified, forces a rebuild of the entire application. # N.B. There is a very important Unix utility that is much preferable # for this task than customzied bashs scripts. I wrote this one # as a way of moving us towards using that utility (which is called # make). APPNAME="myApp.exe" CC="gcc" # compile but do not link CFLAGS="-c" LINK="gcc" LFLAGS="-o $APPNAME -lncurses" SRCS="main.c a.c b.c" OBJS="main.o a.o b.o" if [[ $1 = rebuild ]]; then touch *.c $0 exit $? fi for cFile in $SRCS; do oFile=${cFile%.c}.o oFiles="$oFiles $oFile" if [ $oFile -ot $cFile ]; then echo Compiling $cFile... if ! eval $CC $CFLAGS $cFile; then # quit if any file doesn't compile echo Error exit 1 fi fi done for oFile in $OBJS; do if [ $APPNAME -ot $oFile ]; then echo Linking $oFiles... if eval $LINK $oFiles $LFLAGS ; then echo Built $APPNAME exit 0 else echo Build failed exit 1 fi fi done echo $APPNAME is up to date