清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#!/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