淘汰了自己的C写的makefile生成。主要的功能是对当前目录下的c文件做依赖解析。生成的目标依赖没有递归处理,还需要自己把隐含的依赖加完整,不过这个脚本做的事已经足够提高效率的了,剩下的事情就很少了。
传递多个参数可以生成多目标的程序。
#!/bin/sh
# gen basic dep info. wuxb, 2008-6-7
echo "CC = gcc"
echo "CFLAGS = -Wall"
echo
for arg in $@
do
if [ -n "$arg" ]; then
for i in `ls *.c`
do
if [ "$i" = "$arg"".c" ]; then
echo -n "$arg"" :" # | awk '{{printf"%s :",$0}}'
j=`grep '^#include.*"$' $i | sed 's/#include[ ]*\"\(.*\)\.h\"[ ]*$/\1\.o/' | awk '{{printf" %s",$0}}'`
if [ -z "`echo "$j" | grep " $arg"".o"`" ]; then
j="$j"" ""$arg"".o"
fi
echo "$j"
echo '\t$(CC) $(CFLAGS) -o '"$arg""$j"
break
fi
done
fi
done
# gen .o dep
for i in `ls *.c`
do
j=`echo $i | sed 's/\(.*\)\.c/\1/'`
echo -n "$j"'.o : '"$i"' '
grep '^#include.*"$' $i | sed 's/#include[ ]*\"\(.*\)\"[ ]*$/\1/' | awk '{{printf" %s",$0}}'
echo
j=`echo $i | sed 's/\(.*\)\.c/\1/'`
echo '\t$(CC) $(CFLAGS) -c -o '"$j"'.o '"$i"
done
echo ".PHONY : clean"
echo "clean :"
echo "\trm -f *.o $*"
|
阅读(1005) | 评论(0) | 转发(0) |