前几天在libev的代码时,发现里面的各种宏很是不方便(不知道作者怎么想的),就想了个办法批量展开宏。使用时,将文件后缀名去掉,因为没有后缀名不能上传。 无 #!/bin/sh#expans all the macro in source fileINCLUDE=""#get all the header files director
#!/bin/sh #expans all the macro in source file INCLUDE="" #get all the header files directory function get_include() { for file_t in `ls -l $1|grep -E "^d|\.([ch]|cpp)$"|awk '{print $8}'` do if [ -d $1"/"$file_t ] #the file is a dir then if [ "$file_t" == "include" ] then INCLUDE=$INCLUDE" -I./"$1"/"$file_t else get_include $1"/"$file_t fi fi done export CFLAGS=$INCLUDE } function macro_expansion() { oldpath=$1 newpath=$2 if [ ! -d $newpath ] then mkdir $newpath fi if [ $? -gt 0 ] then exit fi if [ $3 -eq 0 ] then get_include $oldpath echo $CFLAGS fi for file_t in `ls -l $1|grep -E "^d|\.([ch]|cpp)$"|awk '{print $8}'` do oldfile=$oldpath"/"$file_t newfile=$newpath"/"$file_t if [ -d $oldfile ] #the file is a dir then ./expan_macro $oldfile $newfile 1 else #echo $CFLAGS gcc -E $CFLAGS $oldfile -o $newfile fi done } #Show help when script started without arguments function showHelp() { echo "Usage: $0 source_dir dst_dir flag(be 0 all the time)" echo "example:$0 src dst 0" } if [ ! $# -eq 3 ] then showHelp exit fi macro_expansion $1 $2 $3