surpass_li 发表于 2013-1-27 06:25:57

shell小试

初学shell和make,今天,尝试写了一个为每本C源程序生成编译的makefile脚本:)
#!/bin/sh

rootdir=/BTMU/$1
if [ "$1" = "" ];then
    echo "arg error,not input version!!!"
    exit 1;
fi   
if [ "$2" = "" ];then
    echo "arg error,not input source file list file!!!"
    exit 1;
fi   
export rootdir
if [ ! -d "$rootdir" ];then
    echo "rootdir is not dir"
    exit 1;
fi
cmddir=`pwd`

echo $rootdir

cat /dev/null > sys.txt
cat /dev/null > compileok.txt
cat /dev/null > cmd.txt
ALLINC="-I \
/BeTRAN/include/"

cd $cmddir
rm -f log/*.txt

if [ ! -d "$cmddir/mak/" ];then
    cd $cmddir
    mkdir mak
fi
cd $cmddir
rm -f mak/*.mak

cmdR="xlc"
CFLAG="-c -qsuppress=1506-342"
INCFLAG="-I"

cat $2 |while read line
do   
    file="$rootdir/$line"
    filename=`basename "$file"`
    dirname=`dirname "$file"`
    echo commpar:$file
    if [ ! -f "$file" ];then
        echo "$file" >>$cmddir/sys.txt
        echo "$file is not file" >$cmddir/log/$filename.txt
        cat $cmddir/log/$filename.txt
        sleep 10
    else
        cd $dirname
        echo path:`pwd`
        echo "$filename.o : $file">$cmddir/mak/$filename.mak
        echo "    cd $dirname; $cmdR $CFLAG $INCFLAG../inc/ $ALLINC $file">>$cmddir/mak/$filename.mak
        make -f $cmddir/mak/$filename.mak 2>> $cmddir/commpar.log
        tfile=`cat $cmddir/commpar.log`
        if [ "$tfile" = "" ];then
            echo result :$file ok!!!
            echo $file is ok!!! >>$cmddir/compileok.txt
            echo "ok" >$cmddir/log/$filename.txt
        else
            cp $cmddir/commpar.log $cmddir/log/$filename.txt
        fi
        rm $cmddir/commpar.log
    fi
done
页: [1]
查看完整版本: shell小试