栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux编译中的头文件路径大小写校验脚本

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux编译中的头文件路径大小写校验脚本

跨平台编译中,Windows开发的代码路径大小写不正确并不导致编译出错,但在Linux下编译时文件名是严格区分大小写的所以会出现很多因大小写问题导致的编译错误。所以通过编译前检测所有大小写问题,批量修改可以提升编译的效率。

思路上,通过grep工具检出所有的包含,然后逐个做locate校验,如果包含路径书写不规范也会导致存在性校验失败,可以对校验条件稍作修改。完整代码如下:

#!/bin/bash

workdir=.
modify=0

while [ $# -gt 0 ]
do
    case $1 in
    "--modify")
        modify=1
        ;;
    "--work-dir")
        shift
        workdir=$1
        ;;
    *)
        echo "USAGE: $0 [--work-dir ] [--modify] [--help]"
        exit 1
    esac
    shift
done

echo "work-dir: $workdir, modify: $modify"

#1 更新db,时间会稍长10多分钟
#uudatedb

#2 去重并导出所有待检测的头文件
touch channel
grep -IPrsnH '^s*#s*include' --include=*.{h,cpp,ui} $workdir | while read -e line;
do 
	header=$(echo $line | grep -Po '#include[s"<]*K([^>"]*)')
	if [ -z $header ] || [[ $header =~ "ui_" ]]; then
		continue 
	fi
	
	contained=0	
	for h in ${includes[*]};
	do 
		if [ $h == $header ]; then 
			contained=1
		fi
	done
	if [ $contained -eq 0 ]; then
		includes[$k]=$header
		(echo $line) >> channel
		k=$(($k+1))
	fi
done 

#3 对所有头文件做存在性校验,输出不存在的包含路径上下文
cat channel | while read ln; do 
	header=$(echo $ln | grep -Po '#include[s"<]*K([^>"]*)' | sed -r 's/[/\]+///g')
	if [ $(locate $header | wc -l) -eq 0 ]
	then 
		echo $ln
	fi
done
if [ -f "channel" ]; then
	rm "channel"
fi
echo Done!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/642914.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号