]> sigrok.org Git - sigrok-util.git/blob - cross-compile/mingw/sigrok-cross-mingw
sigrok-cross-mingw: Optionally emit progress messages.
[sigrok-util.git] / cross-compile / mingw / sigrok-cross-mingw
1 #!/bin/sh
2 ##
3 ## This file is part of the sigrok-util project.
4 ##
5 ## Copyright (C) 2013-2020 Uwe Hermann <uwe@hermann-uwe.de>
6 ##
7 ## This program is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
19 ##
20
21 set -e
22
23 # Build target: "i686" (32bit) or "x86_64" (64bit).
24 TARGET="i686"
25
26 # The path where your MXE directory is located.
27 MXE=$HOME/mxe-git
28
29 # The base path prefix where the cross-compiled packages will be installed.
30 PREFIXBASE=$HOME/sr_mingw
31
32 # The base path prefix where to download files to and where to build packages.
33 BUILDBASE=./build
34
35 # Edit this to control verbose build output.
36 # V="V=1 VERBOSE=1"
37
38 # Edit this to enable/disable/modify parallel compiles.
39 PARALLEL="-j 2"
40
41 # Edit this to enable/disable debug builds.
42 DEBUG=0
43
44 # Optionally show some progress as the script executes.
45 # ECHO=true
46 ECHO=echo
47
48 # You usually don't need to change anything below this line.
49
50 # -----------------------------------------------------------------------------
51
52 $ECHO "setting up fetch variables ..."
53
54 WGET="wget -c --quiet"
55 GIT_CLONE="git clone --depth=1"
56
57 REPO_BASE="git://sigrok.org"
58
59 # Construct the build and install directory pathnames.
60 if [ $TARGET = "i686" ]; then
61         SUFFIX="32"
62 else
63         SUFFIX="64"
64 fi
65 if [ $DEBUG = 1 ]; then
66         # CFLAGS/CXXFLAGS contains "-g" per default for autotools projects.
67         BUILD_TYPE="Debug"
68         PREFIX=$PREFIXBASE"_debug_"$SUFFIX
69         BUILDDIR=$BUILDBASE"_debug_"$SUFFIX
70 else
71         BUILD_TYPE="Release"
72         PREFIX=$PREFIXBASE"_release_"$SUFFIX
73         BUILDDIR=$BUILDBASE"_release_"$SUFFIX
74 fi
75
76 # -----------------------------------------------------------------------------
77
78 $ECHO "setting up toolchain variables ..."
79
80 # We need to find tools in the toolchain.
81 export PATH=$MXE/usr/bin:$PATH
82
83 TOOLCHAIN_TRIPLET="$TARGET-w64-mingw32.static.posix"
84
85 CMAKE="$TOOLCHAIN_TRIPLET-cmake"
86
87 P="$PREFIX/lib/pkgconfig"
88 P2="$MXE/usr/$TOOLCHAIN_TRIPLET/lib/pkgconfig"
89 C="--host=$TOOLCHAIN_TRIPLET --prefix=$PREFIX CPPFLAGS=-D__printf__=__gnu_printf__"
90 L="--disable-shared --enable-static"
91
92 if [ $TARGET = "i686" ]; then
93         export PKG_CONFIG_PATH_i686_w64_mingw32_static_posix="$P:$P2"
94 else
95         export PKG_CONFIG_PATH_x86_64_w64_mingw32_static_posix="$P:$P2"
96 fi
97
98 # Remove build directory contents (if any) and create a new build dir.
99 $ECHO "starting new build directory: $BUILDDIR"
100 rm -rf $BUILDDIR
101 mkdir $BUILDDIR
102 cd $BUILDDIR
103
104 # -----------------------------------------------------------------------------
105
106 mkdir -p $PREFIX
107
108 $ECHO "preparing Python dependency ..."
109
110 # Cross-compiling Python is highly non-trivial, so we avoid it for now.
111 # The download below is a repackaged tarball of the official Python 3.4.4 MSI
112 # installer for Windows:
113 #   - https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi
114 #   - https://www.python.org/ftp/python/3.4.4/python-3.4.4.amd64.msi
115 # The MSI file has been installed on a Windows box and then c:\Python34\libs
116 # and c:\Python34\include have been stored in the Python34_*.tar.gz tarball.
117 $WGET http://www.sigrok.org/tmp/Python34_$TARGET.tar.gz -O $PREFIX/Python34.tar.gz
118 tar xzf $PREFIX/Python34.tar.gz -C $PREFIX
119
120 # Fix for bug #1195.
121 if [ $TARGET = "x86_64" ]; then
122         patch -p1 $PREFIX/Python34/include/pyconfig.h < ../pyconfig.patch
123 fi
124
125 # Create a dummy python3.pc file so that pkg-config finds Python 3.
126 mkdir -p $PREFIX/lib/pkgconfig
127 cat >$PREFIX/lib/pkgconfig/python3.pc <<EOF 
128 prefix=$PREFIX
129 exec_prefix=\${prefix}
130 libdir=\${exec_prefix}/lib
131 includedir=\${prefix}/include
132 Name: Python
133 Description: Python library
134 Version: 3.4
135 Libs: $PREFIX/Python34/libs/libpython34.a
136 Cflags: -I$PREFIX/Python34/include
137 EOF
138
139 # The python34.dll and python34.zip files will be shipped in the NSIS
140 # Windows installers (required for protocol decoding to work).
141 # The file python34.dll (NOT the same as python3.dll) is copied from an
142 # installed Python 3.4.4 (see above) from c:\Windows\system32\python34.dll.
143 # The file python34.zip contains all files from the 'DLLs', 'Lib', and 'libs'
144 # subdirectories from an installed Python on Windows (c:\python34), i.e. some
145 # libraries and all Python stdlib modules.
146 $WGET http://www.sigrok.org/tmp/python34_$TARGET.dll -O $PREFIX/python34.dll
147 $WGET http://www.sigrok.org/tmp/python34_$TARGET.zip -O $PREFIX/python34.zip
148
149 # In order to link against Python we need libpython34.a.
150 # The upstream Python 32bit installer ships this, the x86_64 installer
151 # doesn't. Thus, we generate the file manually here.
152 if [ $TARGET = "x86_64" ]; then
153         cp $PREFIX/python34.dll .
154         $MXE/usr/$TARGET-w64-mingw32.static.posix/bin/gendef python34.dll
155         $MXE/usr/bin/$TARGET-w64-mingw32.static.posix-dlltool \
156                 --dllname python34.dll --def python34.def \
157                 --output-lib libpython34.a
158         mv -f libpython34.a $PREFIX/Python34/libs
159         rm -f python34.dll
160 fi
161
162 # We need to include the *.pyd files from python34.zip into the installers,
163 # otherwise importing certain modules (e.g. ctypes) won't work (bug #1409).
164 unzip -q $PREFIX/python34.zip *.pyd -d $PREFIX
165
166 # Zadig (we ship this with frontends for easy driver switching).
167 $ECHO "fetching zadig ..."
168 $WGET https://github.com/pbatard/libwdi/releases/download/b721/zadig-2.4.exe -O $PREFIX/zadig.exe
169 $WGET https://github.com/pbatard/libwdi/releases/download/v1.2.5/zadig_xp-2.2.exe -O $PREFIX/zadig_xp.exe
170
171 # libserialport
172 $ECHO "component libserialport ..."
173 $GIT_CLONE $REPO_BASE/libserialport
174 cd libserialport
175 ./autogen.sh
176 ./configure $C $L
177 make $PARALLEL $V
178 make install $V
179 cd ..
180
181 # libsigrok
182 $ECHO "component libsigrok ..."
183 $GIT_CLONE $REPO_BASE/libsigrok
184 cd libsigrok
185 ./autogen.sh
186 ./configure $C $L
187 make $PARALLEL $V
188 make install $V
189 cd ..
190
191 # libsigrokdecode
192 $ECHO "component libsigrokdecode ..."
193 $GIT_CLONE $REPO_BASE/libsigrokdecode
194 cd libsigrokdecode
195 ./autogen.sh
196 ./configure $C $L
197 make $PARALLEL $V
198 make install $V
199 cd ..
200
201 # sigrok-firmware
202 $ECHO "component sigrok-firmware ..."
203 $GIT_CLONE $REPO_BASE/sigrok-firmware
204 cd sigrok-firmware
205 ./autogen.sh
206 # Nothing gets cross-compiled here, we just need 'make install' basically.
207 ./configure --prefix=$PREFIX
208 make install $V
209 cd ..
210
211 # sigrok-firmware-fx2lafw
212 $ECHO "component sigrok-firmware-fx2lafw ..."
213 $GIT_CLONE $REPO_BASE/sigrok-firmware-fx2lafw
214 cd sigrok-firmware-fx2lafw
215 ./autogen.sh
216 # We're building the fx2lafw firmware on the host, no need to cross-compile.
217 ./configure --prefix=$PREFIX
218 make $PARALLEL $V
219 make install $V
220 cd ..
221
222 # sigrok-dumps
223 $ECHO "component sigrok-dumps ..."
224 $GIT_CLONE $REPO_BASE/sigrok-dumps
225 cd sigrok-dumps
226 make install DESTDIR=$PREFIX/share/sigrok-dumps $V
227 cd ..
228
229 # sigrok-cli
230 $ECHO "component sigrok-cli ..."
231 $GIT_CLONE $REPO_BASE/sigrok-cli
232 cd sigrok-cli
233 ./autogen.sh
234 ./configure $C
235 make $PARALLEL $V
236 make install $V
237 if [ $TARGET = "i686" ]; then
238         makensis contrib/sigrok-cli_cross.nsi
239 else
240         makensis -DPE64=1 contrib/sigrok-cli_cross.nsi
241 fi
242 cd ..
243
244 # PulseView
245 $ECHO "component pulseview ..."
246 $GIT_CLONE $REPO_BASE/pulseview
247 cd pulseview
248 cp ../../FileAssociation.nsh contrib
249 $CMAKE \
250         -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX \
251         -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
252         -DDISABLE_WERROR=y \
253         -DENABLE_TESTS=y \
254         .
255 make $PARALLEL $V
256 make manual
257 if [ $DEBUG = 1 ]; then
258         make install $V
259 else
260         make install/strip $V
261 fi
262
263 $ECHO "creating NSIS installer ..."
264 if [ $TARGET = "i686" ]; then
265         makensis contrib/pulseview_cross.nsi
266 else
267         makensis -DPE64=1 contrib/pulseview_cross.nsi
268 fi
269 cd ..
270
271 $ECHO "cross compile script done.""