-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease
executable file
·213 lines (161 loc) · 3.64 KB
/
release
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/sh
set -e -u
buildProductsDir=$( pwd )
projectDir=$( dirname "$0" )
# Make projectDir absolute
case $projectDir in
/*) ;;
*) projectDir="$buildDir/$projectDir"
esac
. "$projectDir/shared.inc"
printHelp()
{
help='
SYNTAX
------
./release [options] ...
OPTIONS
-------
-help Show this help screen.
'
printf '%s\n' "$help"
exit "$1"
}
while [ $# -gt 0 ]
do
case $1 in
-help) printHelp 0 ;;
-*) syntaxError "Unkown option \"$1\"" ;;
*) syntaxError "Unkown command \"$1\"" ;;
esac
#shift
done
cfgFile="$projectDir/cfg/release.cfg"
srcDir="$projectDir/src/release"
buildDir="$buildProductsDir/release"
[ -d "$buildDir" ] && rm -r "$buildDir"
mkdir -p "$buildDir"
flagsFile=$( findCompileFlags "$srcDir" "$projectDir" )
flagsFileDir=
flagsFileContent=
if [ -n "$flagsFile" ]
then
parseCfgFile flagsFileContent "$flagsFile"
flagsFileDir=$( dirname "$flagsFile" )
fi
buildArgs=
parseCfgFile buildArgs "$cfgFile"
echo
echo '=== Creating Release Files ==='
echo
for inputFile in "$srcDir"/*
do
echo "Next: ${inputFile#"$srcDir/"}"
outputFileTemp="$buildDir/${inputFile#"$srcDir/"}"
outputFile="${outputFileTemp%.h}"
cp "$inputFile" "$outputFile"
pragmaOnceList=
depList=$( depListForSourceFile \
"$inputFile" "$flagsFileContent" "$flagsFileDir" )
while :
do
performedInclude=
mv "$outputFile" "$outputFileTemp"
while IFS= read -r line
do
include=
case $line in
*'#pragma'*'once'*) continue ;;
*'#include'*'"'*) include=$( extractInclude "$line" )
esac
if [ -z "$include" ]
then
printf '%s\n' "$line" >>"$outputFile"
continue
fi
case $pragmaOnceList in
*"$include"*) continue
esac
includeFile=
for dep in $( eval "printf '%s\n' $depList" )
do
case $dep in
*"$include") includeFile=$dep; break
esac
done
[ -z "$includeFile" ] \
&& error "Include file not found: \"$include\""
case $includeFile in
/*) ;;
*) includeFile="$flagsFileDir/$includeFile"
esac
cat "$includeFile" >>"$outputFile"
isPragmaOnce "$includeFile" \
&& pragmaOnceList="$pragmaOnceList $include"
performedInclude=true
done <"$outputFileTemp"
rm "$outputFileTemp"
[ -z "$performedInclude" ] && break
done
case $outputFile in
*.h)
mv "$outputFile" "$outputFileTemp"
printf '#pragma once\n\n' >"$outputFile"
cat "$outputFileTemp" >>"$outputFile"
rm "$outputFileTemp"
esac
echo "Created ${outputFile#"$buildProductsDir/"}"
echo
done
echo
echo '=== Testing ==='
echo
for file in "$buildDir"/*
do
echo "Next: ${file#"$buildDir/"}"
buildCmd="clang -x c -c -o /dev/null"
buildCmd="$buildCmd $buildArgs -Wno-pragma-once-outside-header"
buildCmd="$buildCmd $( quote "$file" )"
if ! eval "$buildCmd"
then
echo "Error: Building failed!" >&2
echo "Build command was: $buildCmd" >&2
exit 1
fi
echo 'Sucess.'
echo
done
echo
echo '=== Wrapping Up ==='
echo
echo "Copying license."
cp "$projectDir/LICENSE" "$buildDir/"
echo "Created ${buildDir#"$buildProductsDir/"}/LICENSE"
echo
echo "Compressing results."
filesToCompres=
for file in "$buildDir"/*
do
file=${file#"$buildDir/"}
filesToCompres="$filesToCompres $( quote "$file" )"
done
arcName='TinyUTF8'
if [ -n "$( command -v zip )" ]
then
cmpCmd="cd '$buildDir'"
cmpCmd="$cmpCmd && zip -9 '$arcName.zip' $filesToCompres"
eval "$cmpCmd" >/dev/null
echo "Created $arcName.zip"
else
echo "Skipping ZIP..."
fi
if [ -n "$( command -v bzip2 )" ] && [ -n "$( command -v tar )" ]
then
cmpCmd="cd '$buildDir'"
cmpCmd="$cmpCmd && tar -c $filesToCompres | bzip2 -9 >'$arcName.tar.bz2'"
eval "$cmpCmd" >/dev/null
echo "Created $arcName.tar.bz2"
else
echo "Skipping BZIP2..."
fi
echo