1、找出所有参加编译的c文件、汇编文件
在内核源代码的目录下创建compiler目录,找到的c文件保存在cfile.txt,汇编文件分别为big_s-file.txt和little_s-file.txt
尖括号<>包含的文件保存在abs-header.txt、引号""包含的文件在rel-header.txt#!/bin/bash
#
# find total .c files. .S files. .s files which will be compiled into image
#
#
#
echo "=============create store result files=========="
rm -rf compiler
mkdir -p compiler
echo > cfile.txt;
#find the .c files
echo "=============finding .c files...=========="
find -name *.c > tmp.txt
files=`cat tmp.txt`
for i in $files; do
temp=${i/.c/.o};
# echo $temp;
if [ -f $temp ]; then echo $i >> cfile.txt; fi
done
cfiles_counts=`cat cfile.txt | wc -l`
echo "The total c files counts is $cfiles_counts"
#find the .s files
echo "=============finding .s files...=========="
echo > little_s-file.txt
find -name *.s > tmp.txt
files=`cat tmp.txt`
for i in $files; do
temp=${i/.s/.o};
# echo $temp;
if [ -f $temp ]; then echo $i >> little_s-file.txt; fi
done
sfiles_counts=`cat little_s-file.txt | wc -l`
echo "The total s files counts is $sfiles_counts"
#find the .S files
echo "=============finding .S files...=========="
echo > big_s-file.txt
find -name *.S > tmp.txt
files=`cat tmp.txt`
for i in $files; do
temp=${i/.S/.o};
# echo $temp;
if [ -f $temp ]; then echo $i >> big_s-file.txt; fi
done
Sfiles_counts=`cat big_s-file.txt | wc -l`
echo "The total S files counts is $Sfiles_counts"
echo > total-file.txt
cat cfile.txt >> total-file.txt
cat little_s-file.txt >> total-file.txt
cat big_s-file.txt >> total-file.txt
echo "The total files are `expr $cfiles_counts + $sfiles_counts + $Sfiles_counts`"
echo '======================================='
echo '| |'
echo '|======find header files==============|'
echo '| |'
echo '======================================='
headers=`cat total-file.txt`
echo > total-header.txt
for i in $headers; do
sed -n '/^#/p' $i | grep include >> total-header.txt
done
mv cfile.txt compiler
mv little_s-file.txt compiler
mv big_s-file.txt compiler
mv total-file.txt compiler
mv total-header.txt compiler
cd compiler
cp total-header.txt temp.txt
sed -i '/"/d' temp.txt
cat temp.txt | sort -u > cache
mv cache abs-header.txt
rm -f cache temp.txt
cp total-header.txt temp.txt
sed -i '/</d' temp.txt
mv temp.txt rel-header.txt
rm -f temp.txt
#sed -n '/^#/p' tmpfile.txt > temp.cache
#sed 's/ /@/g' temp.cache > tmpfile.txt
#sed 's/</"/g' tmpfile.txt > temp.cache
#sed 's/>/"/g' temp.cache > tmpfile.txt
#echo > temp.cache
#headers=`cat tmpfile.txt`
#for i in $headers; do
# echo $i | cut -d"\"" -f2 >>temp.cache
#done
#mv temp.cache headers.file
#cat headers.file | sort -u > temp.cache
#mv temp.cache headers.file
#rm -f temp.cache
2、找出所有被引号包含的文件
#!/bin/bash
#
# find the header files which are contained by relative path
#
#
#
#
header=`cat $1`
echo > total_rel_header.txt
for i in $header; do
sed -n '/^#/p' $i | grep include > cache
incl=`sed 's/ /@/g' cache`
for j in $incl; do
tmp=`dirname $i`
echo $j | grep "\"" 1>/dev/null && \
tmp=$tmp/`echo $j | cut -d"\"" -f2 ` && \
echo $tmp && \
echo $tmp >> total_rel_header.txt
tmp=
done
done
cat total_rel_header.txt | sort -u > cache
mv cache compiler/total_rel_header.txt
3、找出所有被尖括号包含的文件
#!/bin/bash
#
# find the total header files which locate in system include-paths
#
#
#
ARCH=arm
echo > total_abs_header.txt
sed 's/ /@/g' $1 > cache.1
sed 's/\t/@/g' cache.1 > cache.2
sed 's/</"/g' cache.2 > cache.3
sed 's/>/"/g' cache.3 > cache.4
mv cache.4 cache
rm -f cache.1 cache.2 cache.3 cache.4
header=`cat cache`
for i in $header; do
#echo $i
tmp=`echo $i | cut -d"\"" -f2`
if [ -f arch/$ARCH/include/$tmp ]
then
echo "arch/$ARCH/include/$tmp" >> total_abs_header.txt
else
if [ -f include/$tmp ]
then
echo "include/$tmp" >> total_abs_header.txt
else
echo "cannot find $tmp"
fi
fi
done
cat total_abs_header.txt | sort -u > cache
mv cache compiler/total_abs_header.txt
在内核源代码目录下依次运行以上三个脚本,就会在compiler目录下生产total_rel_header.txt,total_abs_header.txt和total-file.txt分别保存找到的包含文件和源文件