Newer
Older
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
#!/bin/bash
# set -x #enable debug
SCRIPTPATH=$(readlink -f $0)
SCRIPTNAME=$(basename $SCRIPTPATH)
SCRIPTDIR=$(dirname $SCRIPTPATH)
git="git"
HAS_GIT=true
HEADER_DIR="$SCRIPTDIR/header"
DOCU_DIR="$SCRIPTDIR/doc"
INC_MAJOR=false
INC_MINOR=false
INC_BUGFIX=false
function log()
{
echo "$@" >&2
}
function cleaupAndExit()
{
if $HAS_GIT && [[ -n "$TAGNAME" ]] && [[ $1 -ne 0 ]]; then
log "remove git tag $TAGNAME"
$git tag -d $TAGNAME
fi
exit $1
}
function printHelp()
{
printf "script to build libShaderFile release
Usage:
$SCRIPTNAME [parameter]
[] optional parameters
() required parameters
Parameter:
--major | -m
increment major version and reset the minor version before creating git tag
--minor | -n
increment major version and reset the bugfix version before creating git tag
--bufgix | -b
increment bugfix version before creating git tag
--help | -h | -?
print this help
"
}
function getLastVersion()
{
POS="HEAD"
TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null)
RET=$?
while [[ $RET -eq 0 ]]; do
if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo $(echo $TAG | egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
return 0
fi
POS=$TAG"^"
TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null)
RET=$?
done
return 1
}
function incVersion()
{
read -r -a PARTS <<< $(echo "$1" | tr "." " ")
if $INC_MAJOR; then
((PARTS[0]++))
PARTS[1]=0
fi
if $INC_MINOR; then
((PARTS[1]++))
PARTS[2]=0
fi
if $INC_BUGFIX; then
((PARTS[2]++))
fi
((PARTS[3]++))
local tmp="${PARTS[@]}"
echo "${tmp// /.}"
}
function addGitTag()
{
local INC_VERSION=true
log "create git version tag"
CURRENT=$(getLastVersion)
if [ $? -ne 0 ]; then
CURRENT="0.0.0.0"
INC_VERSION=false
fi
local tmp="v$CURRENT"
LINES=$($git log --pretty=oneline $tmp..HEAD)
if [ $? -eq 0 ]; then
DIFF=$(echo $LINES | wc -l)
if [ $DIFF -eq 0 ] || [ -z "$LINES" ]; then
log "current commit already has a version tag: $tmp"
TAGNAME=$tmp
return 0
fi
fi
if $INC_VERSION; then
NEWVERSION=$(incVersion $CURRENT)
else
NEWVERSION="$CURRENT"
fi
log "current version: $CURRENT"
log "new version: $NEWVERSION"
local tmp="v$NEWVERSION"
$git tag $tmp
if [[ $? -ne 0 ]]; then
log "unable to create version tag: exit"
cleaupAndExit 100
fi
TAGNAME=$tmp
return 0
}
function BuildConfig()
{
CONFIG=$1
POSTFIX=$2
FILEEXT=$3
printf "\n== build project $CONFIG ==\n"
lazbuild --build-mode=$CONFIG --build-all --verbose $SCRIPTDIR/libTextSuite.lpi
if [ $? -ne 0 ]; then
echo "build failed! exit."
cleaupAndExit 1
fi
ZIPDIR="bin/$POSTFIX"
BINDIR="$ZIPDIR"
ZIPPATH="$SCRIPTDIR/libTextSuite-$POSTFIX.zip"
if [ -n "$TAGNAME" ]; then
mkdir -p "$SCRIPTDIR/$TAGNAME/"
ZIPPATH="$SCRIPTDIR/$TAGNAME/libTextSuite-$POSTFIX.zip"
fi
BINNAME="libTextSuite-$POSTFIX$FILEEXT"
if [ ! -f $BINNAME ]; then
echo "file not found: $EXENAME"
cleaupAndExit 2
fi
mkdir -p $BINDIR
mv "$BINNAME" "$BINDIR/" || { log "unable to copy linked binary"; cleaupAndExit 3; }
# use this to copy data folder instead of data archive: cp -R --preserve=links data $BINDIR || { log "unable to copy data folder"; cleaupAndExit 4; }
cp -r "$HEADER_DIR" "$BINDIR" || { log "unable to copy header files"; cleaupAndExit 4; }
cp -r "$DOCU_DIR" "$BINDIR/docu" || { log "unable to copy documentation files"; cleaupAndExit 5; }
pushd $ZIPDIR
rm -rf $ZIPPATH
zip -r $ZIPPATH ./* || { log "unable to create zip archive"; cleaupAndExit 6; }
popd
}
while [[ $# -gt 0 ]]; do
case $1 in
"--major" | "-m")
INC_MAJOR=true
;;
"--minor" | "-n")
INC_MINOR=true
;;
"--bufgix" | "-b")
INC_BUGFIX=true
;;
"--help" | "-h" | "-?")
printHelp
cleaupAndExit 0
;;
*)
echo "invalid parameter: $1"
echo "use --help to get further information"
;;
esac
shift
done
if $HAS_GIT; then
GIT_CHANGED=$($git status --untracked-files=all --verbose --porcelain)
if [[ -n "$GIT_CHANGED" ]]; then
log "git has uncommited changes. please commit before building a release"
cleaupAndExit 101
fi
addGitTag
fi
BuildConfig "Win32Release" "i386-win32" ".dll"
BuildConfig "Win64Release" "x86_64-win64" ".dll"
BuildConfig "Linux32Release" "i386-linux" ".so"
BuildConfig "Linux64Release" "x86_64-linux" ".so"
cleaupAndExit 0