编译完的内核如何快速删除没有编译的.c 文件
source link: https://www.v2ex.com/t/796641
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
yanqiyu 1 天前 via Android
abutter 17 小时 52 分钟前
huangya 17 小时 14 分钟前
bfdh 15 小时 8 分钟前
#!/bin/bash
set -e
#set -x
#脚本说明
#该脚本用于在编译后的 Linux Kernel 目录中找出实际编译的全部.c 文件及其依赖的.h 文件,
#并将结果保存在 files.list 中,可直接导入到 sourceinsight 。
#执行方法:将脚本放到 Linux Kernel 编译目录直接执行即可。
TMPDIR=`mktemp -d`
MASTERDIR="$PWD"
OCMDFILE=$TMPDIR/file.ocmd
TFILE=$TMPDIR/file.t
AFILE=$TMPDIR/file.a
BFILE=$TMPDIR/file.b
CFILE=$TMPDIR/file.c
DFILE=$TMPDIR/file.d
HFILE=$TMPDIR/file.h
function get_header_file_from_ocmd()
{
local prefix=$(echo $MASTERDIR/ | sed 's/\//\\\//g')
oc=$1 #name of input file,input file is mixed content of all .o.cmd file
out=$2 #name of output file
echo "handle ocmd file $oc for header file"
grep -E "\.h)?$" $oc > $out
sed -i -e 's/\.h)$/.h/g' -e "s/^\([^\/]\)/${prefix}\1/g" $out
echo "handle ocmd file $oc for header file done"
}
function merge_result()
{
cat $@ > files.list
echo All .c and .h files are listed in files.list, now you can import them to sourceinsight project.
}
function get_defination_from_ocmd()
{
oc=$1 #name of input file,input file is mixed content of all .o.cmd file
out=$2 #name of output file
echo "handle ocmd file $oc for defination"
rm -fv $out
sort -u $oc > $out
cp -v $out $oc
grep "\-\bD" $oc |awk -F' ' '{for(i=1;i < NF;i++)printf("%s\n", $i);}' |grep "\-\bD"|sed -e "s/\-D/\#define\ /g" -e "s/=/\ /g" -e '/KBUILD_/'d | sort -u > $out
echo "handle ocmd file $oc for defination done"
}
find -name "*.o.cmd" | sed -e '/\.mod\./'d -e '/\.built-in\./d' > $OCMDFILE #no ".*.modmake -j24.cmd" and ".built-in.o.cmd"
cat $OCMDFILE | awk -F '.' '{printf("%s%s%s.c\n", "'$MASTERDIR'", $2, $3)}' > $TFILE #add $MASTERDIR to the start of line
sort -u $TFILE > $CFILE
echo "System:List of C file is in $CFILE"
echo "Mix content of all .o.cmd file"
while read line; do
cat $line
done < $OCMDFILE >> $AFILE
echo "Mix content of all .o.cmd file,done,$counts files has been handled"
echo "Genrate defination file"
cp -v $AFILE $BFILE
get_defination_from_ocmd $BFILE $DFILE
echo "Genrate defination file,done"
echo "System:List of D file is in $DFILE"
echo "Put all unit of information to single line mode"
sed 's/\ /\n/g' $AFILE > $TFILE
echo "Put all unit of information to single line mode,done"
echo "Sort and Uniq all unit of information"
sort -u $TFILE > $AFILE
echo "Sort and Uniq all unit of information,done"
echo "Get all name of header file"
get_header_file_from_ocmd $AFILE $TFILE
echo "Get all name of header file,done"
echo "Sort and Uniq all name of header file"
sort -u $TFILE > $AFILE
echo "Sort and Uniq all name of header file,done"
echo "Delete the name of header file of host"
sed '/^\/usr/d' $AFILE > $HFILE #delete line which start with "/usr",it's host's header file
echo "Delete the name of header file of host,done"
echo "System:List of H file is in $HFILE"
merge_result $CFILE $HFILE
rm -fr $TMPDIR
补充:如果不删 TMPDIR,还可以在 file.d 文件中查看通过命令行 /Makefile 传递进去的宏定义。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK