选出参加工程编译的所有文件


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分别保存找到的包含文件和源文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值