- 论坛徽章:
- 0
|
与LZ的方法不同
我比较懒,不想自己去写出错函数,直接用apue作者的error.c和apue.h头文件
由于编译的时候常常加上error.c, -Wall, -o选项之类的,手指很累...
于是我写了一个小脚本,如下:
#!/bin/sh
#gg
#以下是修改的gg脚本,添加了一个函数,indent每一个.c和.h的功能
#wraper the gcc
#set -x
#用indent所有的c文件和头文件(因为我向ssh中拷代码的时候缩进总是出问题,所以需要indent)
go2indent()
{
for tt in $*
do
char=`echo $tt|cut -d. -f2`
if [ $char = "c" -o $char = "h" ]; then
char=""
#此处indent格式自己修改。
indent -ts2 -bli0 $tt
rm $tt~ >/dev/null 2>&1
fi
done
}
#不需要indent的话,直接注释下面这条语句
go2indent $*
exec_obj=`echo $1|cut -d. -f1`
if gcc error.c $* -Wall -o $exec_obj; then
echo "gcc Done! Create executable file \"$exec_obj\"."
else
echo "gcc failed!"
exit 1
fi
#end
把error.c和apue.h拷到当前目录
例,编译test.c文件,输入./gg test.c 就在当前目录生成test可执行文件
如果编译多个文件,1111.c, 2222.c, 3333.c,输入./gg 1111.c 2222.c 3333.c即可,生成的是1111可执行文件.
需要动态连接库libpthread.so?输入./gg test.c -lpthread就行
[ 本帖最后由 科技牛 于 2007-8-27 19:52 编辑 ] |
|