1 |
#!/bin/bash |
---|
2 |
|
---|
3 |
#GDC codegen workaround: |
---|
4 |
#Add GDC_BUG_WORKAROUND as an undefined member to each enum with initialized |
---|
5 |
#members on the first line inside its scope. |
---|
6 |
|
---|
7 |
SRCDIR="`pwd`/src" |
---|
8 |
|
---|
9 |
function ParseFile() |
---|
10 |
{ |
---|
11 |
echo "Parsing: $1" |
---|
12 |
#Magic! ...Or not. This won't work for all cases because there can be comments after |
---|
13 |
#the bracket '{', and in fact, there are. So close! |
---|
14 |
#sed -i -e '/enum .*/ { n; s/{/&/; t a; b; :a; n; s/.* = .*/\tGDC_BUG_WORKAROUND,\n&/ }' "$1" |
---|
15 |
#Ah, this is more like it: |
---|
16 |
sed -i -re ' |
---|
17 |
/enum .*/ { |
---|
18 |
n; |
---|
19 |
s/\{/&/; |
---|
20 |
t a; |
---|
21 |
b; |
---|
22 |
:a; |
---|
23 |
#We need to check for comment blocks here, |
---|
24 |
#and skip them |
---|
25 |
:com; |
---|
26 |
n; |
---|
27 |
/(^(\/\*|\/\+)|^[[:blank:]]*(\/\*|\/\+))/,/(\*\/|\+\/)/ b com; |
---|
28 |
/(^\/\/|^[[:blank:]]*\/\/)/ b com; |
---|
29 |
s/.* = .*/\tGDC_BUG_WORKAROUND,\n&/; |
---|
30 |
}' "$1" |
---|
31 |
} |
---|
32 |
|
---|
33 |
function ScanDir() |
---|
34 |
{ |
---|
35 |
local previousdir="`pwd`" |
---|
36 |
|
---|
37 |
cd "$1" |
---|
38 |
for entry in $( ls -b ); do |
---|
39 |
if [ -f "${entry}" ]; then |
---|
40 |
ParseFile "$1"/"${entry}" |
---|
41 |
elif [ -d "${entry}" ]; then |
---|
42 |
ScanDir "$1"/"${entry}" |
---|
43 |
fi |
---|
44 |
done |
---|
45 |
|
---|
46 |
cd "${previousdir}" |
---|
47 |
} |
---|
48 |
|
---|
49 |
echo |
---|
50 |
echo "The following script will parse all your D source files and hopefully" |
---|
51 |
echo "workaround the awful GDC bug that keeps preventing gtkD apps from linking." |
---|
52 |
echo "NO backups will be made. You now have 5 seconds to abort." |
---|
53 |
sleep 5 |
---|
54 |
echo |
---|
55 |
echo "Source directory: ${SRCDIR}" |
---|
56 |
echo |
---|
57 |
|
---|
58 |
ScanDir "${SRCDIR}" |
---|
59 |
|
---|
60 |
echo "Done!" |
---|