-
Notifications
You must be signed in to change notification settings - Fork 75
/
cleanincludes.sh
executable file
·58 lines (49 loc) · 1020 Bytes
/
cleanincludes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
trycompile() {
cd ./build
out=`make -j10 2>/dev/null`
cd ..
if [[ "$out" == *"recipe for target 'all' failed"* ]]; then
return 0
fi
return 1
}
disableInclude() {
pos=$1
file=$2
cmd='s/#include/\/\/#include/'$pos
sed -z -i $cmd $file
}
enableInclude() {
pos=$1
file=$2
cmd='s/\/\/#include/#include/'$pos
sed -z -i $cmd $file
}
cleanIncludes () {
file=$1
countDIncludes=`grep -o "//#include" $file | wc -l`
if [ countDIncludes > 0 ]; then
echo "Found existing commented include! Skipping: "$file
return
fi
countIncludes=`grep -o "#include" $file | wc -l`
for (( c=1; c<=$countIncludes; c++ ))
do
disableInclude $c $file
((countDIncludes += 1))
trycompile
if [ $? == 1 ]; then
continue
fi
enableInclude $countDIncludes $file
((countDIncludes -= 1))
done
}
folder=$1
sources=`find ./$1 | grep .cpp`
for eachfile in $sources
do
cleanIncludes $eachfile
echo "Processed "$eachfile"..."
done