-
Notifications
You must be signed in to change notification settings - Fork 21
/
release.sh
executable file
·226 lines (199 loc) · 8.03 KB
/
release.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
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
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
#
## file: release.sh
#
# This script create releases of xfemm for various platforms. Windows builds
# require MXE: http://mxe.cc/
#
# Run this script from the directory containing it
# stop on first error
set -xe
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
version="dev"
working_copy_dir=$(pwd)
run_tests=false
copy_win_libs=true
skip_mex=false
make_zip=false
matlab_cmd="matlab"
matlab_extra_cmds=""
make_win_mex=false
matlab_win_lib_dir=""
output_dir=/tmp
make_jobs=1
usage="$(basename "$0") [-h] [-v <version>] [-o] [-j] [-t] [-m] [-z] [-c] [-l <matlab_win_lib_dir>] [-e <matlab_extra_cmds>] -- creates xfemm release
where:
-h show this help text
-v set the release version string (default: $version)
-o set the output directory where the relase package will be created, default: ${output_dir}
-j number of make jobs, passed to make command, default: ${make_jobs}
-t run tests
-m skip building mex files (requires matlab)
-z create zip file
-c command to invoke matlab (default: matlab)
-w attempt to cross-build matlab mex files (requires -l option)
-l matlab windows libraries directory path
-e additional command(s) to be run by matlab before building the mex files"
while getopts "h?v:o:j:twmzc:wl:e:" opt; do
case "$opt" in
h|\?)
echo "$usage"
exit 0
;;
v) version=$OPTARG
echo "Version string changed to: $version"
;;
o) output_dir=$OPTARG
echo "Output directory changed to: $output_dir"
;;
j) make_jobs=$OPTARG
echo "Number of make jobs changed to: $make_jobs"
;;
t) run_tests=true
echo "run_tests: $run_tests"
;;
m) skip_mex=true
echo "skip_mex: $skip_mex"
;;
z) make_zip=true
echo "make_zip: $make_zip"
;;
c) matlab_cmd=$OPTARG
echo "matlab_cmd: $matlab_cmd"
;;
w) make_win_mex=true
echo "make_win_mex: $make_win_mex"
;;
l) matlab_win_lib_dir=$OPTARG
echo "matlab_win_lib_dir: $matlab_win_lib_dir"
;;
e) matlab_extra_cmds=$OPTARG
echo "matlab_extra_cmds: $matlab_extra_cmds"
;;
esac
done
echo "Working copy dir is: ${working_copy_dir}"
# create release directory
release_prefix=${output_dir}/xfemm_release
rm -r ${release_prefix}
mkdir -p ${release_prefix}
# linux 64 bit
#mkdir ${working_copy_dir}/release/xfemm_linux64
linux_64_common_dir_name="xfemm_linux64"
linux_64_release_dir="$release_prefix/${linux_64_common_dir_name}"
# export from the working directory to the release directory
#hg archive --rev stable ${linux_64_release_dir}
cd ${working_copy_dir}
mkdir -p ${linux_64_release_dir}
git archive --format=zip HEAD --output ${linux_64_release_dir}/../release.zip
cd ${linux_64_release_dir}
unzip ../release.zip
rm ../release.zip
# remove the release script and other things we don't need
rm ${linux_64_release_dir}/release.sh
rm ${linux_64_release_dir}/test_release.sh
rm -r ${linux_64_release_dir}/.github
rm ${linux_64_release_dir}/.gitignore
rm ${linux_64_release_dir}/.hgignore
# create version file for cmake to find
echo "${version}" > "${linux_64_release_dir}/cfemm/VERSION"
# create temp build directory
native_build_dir=/tmp/build_${linux_64_common_dir_name}
rm -rf ${native_build_dir}
mkdir -p ${native_build_dir}
# run cmake from temp dir and build
cd ${native_build_dir}
cmake -DCMAKE_BUILD_TYPE=Release ${linux_64_release_dir}/cfemm
make -j ${make_jobs}
#make package
if [ "$skip_mex" = false ]; then
if ! [ -x "$(command -v ${matlab_cmd})" ]; then
echo 'matlab is not installed, not building mex files using Matlab.' >&2
else
# buld the mex files using matlab
#${matlab_cmd} -nodesktop -r "restoredefaultpath; cd('${linux_64_release_dir}/mfemm'); mfemm_setup('Runtests', true, 'ForceMexRecompile', true); quit"
${matlab_cmd} -nodesktop -r "restoredefaultpath; cd('${linux_64_release_dir}/mfemm'); ${matlab_extra_cmds}; mfemm_setup('Runtests', true, 'ForceMexRecompile', true); quit"
if [ "$make_win_mex" = true ]; then
${matlab_cmd} -nodesktop -r "restoredefaultpath; cd('${linux_64_release_dir}/mfemm'); ${matlab_extra_cmds}; mfemm_setup('DoCrossBuildWin64', true, 'W64CrossBuildMexLibsDir', '${matlab_win_lib_dir}', 'Runtests', false, 'ForceMexRecompile', true); quit"
fi
#matlab -nodesktop -r "restoredefaultpath; cd('${linux_64_release_dir}/mfemm'); mfemm_setup('Runtests', false, 'ForceMexRecompile', true, 'CrossBuildW64', true); quit"
fi
else
echo 'not building mex files using Matlab as -m option has been used.' >&2
fi
# tar up the result in the release directory
cd ${release_prefix}
tar cvzf xfemm-${version}-Linux64.tar.gz ${linux_64_common_dir_name}/
rm -r ${linux_64_release_dir}/cfemm/bin
src_package_dir_name=$(dirname ${linux_64_release_dir})/xfemm
mv ${linux_64_release_dir} ${src_package_dir_name}
zip -r xfemm-${version}-Source.zip $(basename ${src_package_dir_name})
# repeat the above, but cross-compiling for windows, requires MXE: http://mxe.cc/
#
# win 32 -- i686-pc-mingw32
#svn export ${working_copy_dir} ${working_copy_dir}/release/xfemm_mingw_win32 --native-eol CRLF
#rm ${working_copy_dir}/release/xfemm_mingw_win32/release.sh
win_64_common_dir_name="xfemm_mingw_win64"
win_64_release_dir="${release_prefix}/${win_64_common_dir_name}"
# win 64 -- x86_64-w64-mingw32 MXE target
cd ${working_copy_dir}
mkdir -p ${win_64_release_dir}
git archive --format=zip HEAD --output ${win_64_release_dir}/../release.zip
cd ${win_64_release_dir}
unzip ../release.zip
rm ../release.zip
# remove release scripts
rm ${win_64_release_dir}/release.sh
rm ${win_64_release_dir}/test_release.sh
#rm -r ${win64_release_dir}/.github
#rm ${win64_release_dir}/.gitignore
#rm ${win64_release_dir}/.hgignore
# create version file for cmake to find
echo "${version}" > "${win_64_release_dir}/cfemm/VERSION"
# create temp build directory
win64_build_dir=/tmp/build_${win_64_common_dir_name}
rm -rf ${win64_build_dir}
mkdir -p ${win64_build_dir}
# run cmake from temp dir and build cfemm
cd ${win64_build_dir}
cmake -DCMAKE_BUILD_TYPE=Release \
-DEXTRA_CMAKE_CXX_FLAGS="-static -static-libgcc -static-libstdc++" \
-DEXTRA_CMAKE_EXE_LINKER_FLAGS="-static -static-libgcc -static-libstdc++" \
-DCMAKE_TOOLCHAIN_FILE=$(dirname $(which x86_64-w64-mingw32.static-g++))/../x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake ${win_64_release_dir}/cfemm
make -j ${make_jobs}
make package
make package_source
# source package (all platforms
#cp ${win64_build_dir}/xfemm-*-Source.zip ${release_prefix}/
# windows installer
cp ${win64_build_dir}/xfemm-*.exe ${release_prefix}/
# copy over the windows dlls, and delete from dist
#cp ${working_copy_dir}/release/xfemm_mingw_win64/windeps/* ${working_copy_dir}/release/xfemm_mingw_win64/cfemm/lib/
#cp ${working_copy_dir}/release/xfemm_mingw_win64/windeps/* ${working_copy_dir}/release/xfemm_mingw_win64/cfemm/bin/
#rm -r ${working_copy_dir}/release/xfemm_mingw_win64/windeps/
if [ "$skip_mex" = false ]; then
if ! [ -x "$(command -v ${matlab_cmd})" ]; then
echo 'matlab is not installed, not building mex files using Matlab.' >&2
else
# buld the mex files using matlab
${matlab_cmd} -nodesktop -r "restoredefaultpath; cd('${win_64_release_dir}/mfemm'); ${matlab_extra_cmds}; mfemm_setup('Runtests', true, 'ForceMexRecompile', true); quit"
if [ "$make_win_mex" = true ]; then
${matlab_cmd} -nodesktop -r "restoredefaultpath; cd('${win_64_release_dir}/mfemm'); ${matlab_extra_cmds}; mfemm_setup('DoCrossBuildWin64', true, 'W64CrossBuildMexLibsDir', '${matlab_win_lib_dir}', 'Runtests', false, 'ForceMexRecompile', true); quit"
fi
fi
else
echo 'not building mex files using Matlab as -m option has been used.' >&2
fi
# zip up the result in the release directory
cd ${release_prefix}
zip -r xfemm-${version}-mingw-win64.zip xfemm/ xfemm-*.exe
rm -r ${win_64_common_dir_name} xfemm/ xfemm-*.exe
if [ "$run_tests" = true ]; then
# test
cd ${working_copy_dir}
./test_release.sh ${release_dir}
else
echo "Skipping Tests"
fi