-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsigrok-cross-mingw
292 lines (243 loc) · 8.42 KB
/
sigrok-cross-mingw
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/sh
##
## This file is part of the sigrok-util project.
##
## Copyright (C) 2013-2020 Uwe Hermann <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
# https://www.diffchecker.com/kz7JKTlI/
set -e
#set -x
# Build target: "i686" (32bit) or "x86_64" (64bit).
TARGET="x86_64"
SELF_DIR=$(dirname "$(realpath $0)")
# The path where your MXE directory is located.
MXE=$HOME/mxe-git
# The base path prefix where the cross-compiled packages will be installed.
PREFIXBASE=$HOME/sr_mingw
# The base path prefix where to download files to and where to build packages.
BUILDBASE=./build
# Edit this to control verbose build output.
#V="V=1 VERBOSE=1"
# Edit this to enable/disable/modify parallel compiles.
PARALLEL="-j4"
# Edit this to enable/disable debug builds.
DEBUG=0
# Optionally show some progress as the script executes.
# ECHO=true
ECHO=echo
# You usually don't need to change anything below this line.
# -----------------------------------------------------------------------------
$ECHO "setting up fetch variables ..."
WGET="wget -c --quiet"
GIT_CLONE="git clone --depth=1"
REPO_BASE="git://sigrok.org"
# Construct the build and install directory pathnames.
if [ $TARGET = "i686" ]; then
SUFFIX="32"
else
SUFFIX="64"
fi
if [ $DEBUG = 1 ]; then
# CFLAGS/CXXFLAGS contains "-g" per default for autotools projects.
BUILD_TYPE="Debug"
PREFIX=$PREFIXBASE"_debug_"$SUFFIX
BUILDDIR=$BUILDBASE"_debug_"$SUFFIX
else
BUILD_TYPE="Release"
PREFIX=$PREFIXBASE"_release_"$SUFFIX
BUILDDIR=$BUILDBASE"_release_"$SUFFIX
fi
# -----------------------------------------------------------------------------
$ECHO "setting up toolchain variables ..."
# We need to find tools in the toolchain.
export PATH=$MXE/usr/bin:$PATH
TOOLCHAIN_TRIPLET="$TARGET-w64-mingw32.static.posix"
CMAKE="$TOOLCHAIN_TRIPLET-cmake"
P="$PREFIX/lib/pkgconfig"
P2="$MXE/usr/$TOOLCHAIN_TRIPLET/lib/pkgconfig"
C="--host=$TOOLCHAIN_TRIPLET --prefix=$PREFIX CPPFLAGS=-D__printf__=__gnu_printf__"
L="--disable-shared --enable-static"
if [ $TARGET = "i686" ]; then
export PKG_CONFIG_PATH_i686_w64_mingw32_static_posix="$P:$P2"
else
export PKG_CONFIG_PATH_x86_64_w64_mingw32_static_posix="$P:$P2"
fi
# Remove build directory contents (if any) and create a new build dir.
$ECHO "starting new build directory: $BUILDDIR"
rm -rf $BUILDDIR
mkdir $BUILDDIR
cd $BUILDDIR
# -----------------------------------------------------------------------------
mkdir -p $PREFIX
$ECHO "preparing Python dependency ..."
# This is a HACK which temporarily unbreaks Windows CI builds.
# TODO Remove this line as well as $WGET_SR references below
# when the Python34 download works again.
WGET_SR="$WGET --no-check-certificate"
# Cross-compiling Python is highly non-trivial, so we avoid it for now.
# The download below is a repackaged tarball of the official Python 3.4.4 MSI
# installer for Windows:
# - https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi
# - https://www.python.org/ftp/python/3.4.4/python-3.4.4.amd64.msi
# The MSI file has been installed on a Windows box and then c:\Python34\libs
# and c:\Python34\include have been stored in the Python34_*.tar.gz tarball.
$WGET_SR http://www.sigrok.org/tmp/Python34_$TARGET.tar.gz -O $PREFIX/Python34.tar.gz
tar xzf $PREFIX/Python34.tar.gz -C $PREFIX
# Fix for bug #1195.
if [ $TARGET = "x86_64" ]; then
patch -p1 $PREFIX/Python34/include/pyconfig.h < $SELF_DIR/pyconfig.patch
fi
# Create a dummy python3.pc file so that pkg-config finds Python 3.
mkdir -p $PREFIX/lib/pkgconfig
cat >$PREFIX/lib/pkgconfig/python3.pc <<EOF
prefix=$PREFIX
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include
Name: Python
Description: Python library
Version: 3.4
Libs: $PREFIX/Python34/libs/libpython34.a
Cflags: -I$PREFIX/Python34/include
EOF
# The python34.dll and python34.zip files will be shipped in the NSIS
# Windows installers (required for protocol decoding to work).
# The file python34.dll (NOT the same as python3.dll) is copied from an
# installed Python 3.4.4 (see above) from c:\Windows\system32\python34.dll.
# The file python34.zip contains all files from the 'DLLs', 'Lib', and 'libs'
# subdirectories from an installed Python on Windows (c:\python34), i.e. some
# libraries and all Python stdlib modules.
$WGET_SR http://www.sigrok.org/tmp/python34_$TARGET.dll -O $PREFIX/python34.dll
$WGET_SR http://www.sigrok.org/tmp/python34_$TARGET.zip -O $PREFIX/python34.zip
# In order to link against Python we need libpython34.a.
# The upstream Python 32bit installer ships this, the x86_64 installer
# doesn't. Thus, we generate the file manually here.
if [ $TARGET = "x86_64" ]; then
cp $PREFIX/python34.dll .
$MXE/usr/$TARGET-w64-mingw32.static.posix/bin/gendef python34.dll
$MXE/usr/bin/$TARGET-w64-mingw32.static.posix-dlltool \
--dllname python34.dll --def python34.def \
--output-lib libpython34.a
mv -f libpython34.a $PREFIX/Python34/libs
rm -f python34.dll
fi
# We need to include the *.pyd files from python34.zip into the installers,
# otherwise importing certain modules (e.g. ctypes) won't work (bug #1409).
unzip -q -o $PREFIX/python34.zip *.pyd -d $PREFIX
# Zadig (we ship this with frontends for easy driver switching).
$ECHO "fetching zadig ..."
$WGET https://github.com/pbatard/libwdi/releases/download/v1.5.1/zadig-2.9.exe -O $PREFIX/zadig.exe
$WGET https://github.com/pbatard/libwdi/releases/download/v1.2.5/zadig_xp-2.2.exe -O $PREFIX/zadig_xp.exe
# libserialport
$ECHO "component libserialport ..."
$GIT_CLONE $REPO_BASE/libserialport
cd libserialport
./autogen.sh
./configure $C $L
make $PARALLEL $V
make install $V
cd ..
# libsigrok
$ECHO "component libsigrok ..."
git clone $REPO_BASE/libsigrok
cd libsigrok
git reset --hard b503d24cdf56abf8c0d66d438ccac28969f01670
patch -p1 < $SELF_DIR/libsigrok-pr-148-add-cypress-fx3.patch
patch -p1 < $SELF_DIR/libsigrok-pr-242-run-USB-as-an-idle-task.patch
./autogen.sh
./configure $C $L
make $PARALLEL $V
make install $V
cd ..
# libsigrokdecode
$ECHO "component libsigrokdecode ..."
$GIT_CLONE $REPO_BASE/libsigrokdecode
cd libsigrokdecode
./autogen.sh
./configure $C $L
make $PARALLEL $V
make install $V
cd ..
# sigrok-firmware
$ECHO "component sigrok-firmware ..."
$GIT_CLONE $REPO_BASE/sigrok-firmware
cd sigrok-firmware
./autogen.sh
# Nothing gets cross-compiled here, we just need 'make install' basically.
./configure --prefix=$PREFIX
make install $V
cd ..
# sigrok-firmware-fx2lafw
$ECHO "component sigrok-firmware-fx2lafw ..."
$GIT_CLONE $REPO_BASE/sigrok-firmware-fx2lafw
cd sigrok-firmware-fx2lafw
./autogen.sh
# We're building the fx2lafw firmware on the host, no need to cross-compile.
./configure --prefix=$PREFIX
make $PARALLEL $V
make install $V
cd ..
# sigrok-firmware-fx3
[ -f "/host/cypress-fx3.fw" ] && cp -r /host/cypress-fx3.fw $PREFIX/share/sigrok-firmware
# sigrok-dumps
$ECHO "component sigrok-dumps ..."
$GIT_CLONE $REPO_BASE/sigrok-dumps
cd sigrok-dumps
make install PREFIX=$PREFIX $V
cd ..
# sigrok-cli
$ECHO "component sigrok-cli ..."
$GIT_CLONE $REPO_BASE/sigrok-cli
cd sigrok-cli
./autogen.sh
./configure $C
make $PARALLEL $V
make install $V
if [ $TARGET = "i686" ]; then
makensis contrib/sigrok-cli_cross.nsi
else
makensis -DPE64=1 contrib/sigrok-cli_cross.nsi
fi
cd ..
# PulseView
$ECHO "component pulseview ..."
$GIT_CLONE $REPO_BASE/pulseview
cd pulseview
patch -p1 < $SELF_DIR/pulseview-boost-numeric-literals.patch
patch -p1 < $SELF_DIR/pulseview-manual-pdf-hack.patch
cp $SELF_DIR/FileAssociation.nsh contrib
$CMAKE \
-DCMAKE_INSTALL_PREFIX:PATH=$PREFIX \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DDISABLE_WERROR=y \
-DENABLE_TESTS=n \
.
make $PARALLEL $V
#make manual
if [ $DEBUG = 1 ]; then
make install $V
else
make install/strip $V
fi
$ECHO "creating NSIS installer ..."
if [ $TARGET = "i686" ]; then
makensis contrib/pulseview_cross.nsi
else
makensis -DPE64=1 contrib/pulseview_cross.nsi
fi
[ -d "/host" ] && cp -r contrib/pulseview-*-installer.exe /host/
cd ..
$ECHO "cross compile script done."