]> sigrok.org Git - sigrok-util.git/blob - cross-compile/msys2/sigrok-native-msys2
c3c1c47e53fb41c08613ba65dab3dcfbd825ef51
[sigrok-util.git] / cross-compile / msys2 / sigrok-native-msys2
1 #!/bin/sh
2 ##
3 ## This file is part of the sigrok-util project.
4 ##
5 ## Copyright (C) 2016-2018 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 # The base path prefix where the compiled packages will be installed.
24 PREFIXBASE=$HOME/sr_msys2
25
26 # The base path prefix where to download files to and where to build packages.
27 BUILDBASE=./build
28
29 # The $PREFIX subdir where the libsigrok Python bindings will be installed.
30 PYBASE=lib/python2.7/site-packages
31
32 # Edit this to control verbose build output.
33 # V="V=1 VERBOSE=1"
34
35 # Edit this to enable/disable/modify parallel compiles.
36 PARALLEL="-j 2"
37
38 # Edit this to enable/disable debug builds.
39 DEBUG=0
40
41 # You usually don't need to change anything below this line.
42
43 # -----------------------------------------------------------------------------
44
45 # Abort if the user runs the script in an "MSYS2 MSYS" shell.
46 if [ $MSYSTEM = "MSYS" ]; then
47         echo "Building in an 'MSYS2 MSYS' shell will not work, aborting."
48         echo "Please use the 'MSYS2 MinGW 64-bit' (or 32-bit) shell."
49         exit
50 fi
51
52 # The build target type: "i686" (32bit) or "x86_64" (64bit).
53 # This is selected based on which MSYS2 shell is being used to do the build.
54 TARGET=$MSYSTEM_CARCH
55
56 VER_SIGROK_FIRMWARE_FX2LAFW=0.1.6
57
58 WGET="wget -c --quiet"
59 GIT_CLONE="git clone --depth=1"
60
61 REPO_BASE="git://sigrok.org"
62
63 # Construct the build and install directory pathnames.
64 if [ $TARGET = "i686" ]; then
65         SUFFIX="32"
66 else
67         SUFFIX="64"
68 fi
69 if [ $DEBUG = 1 ]; then
70         # CFLAGS/CXXFLAGS contains "-g" per default for autotools projects.
71         BUILD_TYPE="Debug"
72         PREFIX=$PREFIXBASE"_debug_"$SUFFIX
73         BUILDDIR=$BUILDBASE"_debug_"$SUFFIX
74 else
75         BUILD_TYPE="Release"
76         PREFIX=$PREFIXBASE"_release_"$SUFFIX
77         BUILDDIR=$BUILDBASE"_release_"$SUFFIX
78 fi
79
80 PYPATH=$PREFIX/$PYBASE
81
82 # -----------------------------------------------------------------------------
83
84 P="$PREFIX/lib/pkgconfig"
85 C="$C --prefix=$PREFIX"
86 L="--disable-shared --enable-static"
87
88 # Path to Qt binaries (needed for cmake to find the Qt libs).
89 PATH="/mingw32/qt5-static/bin:$PATH"
90
91 W="mingw-w64-$TARGET"
92
93 mkdir -p $PYPATH
94
95 # Remove build directory contents (if any) and create a new build dir.
96 rm -rf $BUILDDIR
97 mkdir $BUILDDIR
98 cd $BUILDDIR
99
100 # -----------------------------------------------------------------------------
101
102 if [ "x$1" = "xprepare" ]; then
103   # Update package list, install/update all requirements.
104   pacman -Sy
105   pacman -S \
106         autoconf automake autoconf-archive libtool make pkg-config wget patch \
107         $W-toolchain $W-glib2 $W-glibmm $W-libusb $W-libftdi $W-check $W-boost \
108         $W-libzip $W-doxygen $W-python3 $W-python3-numpy $W-python3-gobject \
109         $W-python3-setuptools $W-swig $W-qt5-static $W-cmake $W-nsis
110   exit
111 fi
112
113 # -----------------------------------------------------------------------------
114
115 # libusb
116 $GIT_CLONE git://github.com/dickens/libusb -b event-abstraction-v4
117 cd libusb
118 ./bootstrap.sh
119 ./configure $C $L
120 make -j1 $V
121 make install $V
122 cd ..
123
124 # libserialport
125 $GIT_CLONE $REPO_BASE/libserialport
126 cd libserialport
127 ./autogen.sh
128 mkdir build
129 cd build
130 ../configure $C $L
131 $SB make $PARALLEL $V
132 make install $V
133 cd ../..
134
135 # libsigrok
136 $GIT_CLONE $REPO_BASE/libsigrok
137 cd libsigrok
138 ./autogen.sh
139 mkdir build
140 cd build
141 PKG_CONFIG_PATH=$P PYTHON=python3 ../configure $C $L --disable-python
142 $SB make $PARALLEL $V
143 PYTHONPATH=$PYPATH $SB make install $V
144 # $SB make check $V # TODO
145 cd ../..
146
147 # libsigrokdecode
148 $GIT_CLONE $REPO_BASE/libsigrokdecode
149 cd libsigrokdecode
150 ./autogen.sh
151 mkdir build
152 cd build
153 PKG_CONFIG_PATH=$P ../configure $C $L
154 $SB make $PARALLEL $V
155 make install $V
156 # $SB make check $V # TODO
157 cd ../..
158
159 # sigrok-firmware
160 $GIT_CLONE $REPO_BASE/sigrok-firmware
161 cd sigrok-firmware
162 ./autogen.sh
163 mkdir build
164 cd build
165 # Nothing gets cross-compiled here, we just need 'make install' basically.
166 ../configure $C
167 make install $V
168 cd ../..
169
170 # sigrok-firmware-fx2lafw
171 $WGET http://sigrok.org/download/binary/sigrok-firmware-fx2lafw/sigrok-firmware-fx2lafw-bin-$VER_SIGROK_FIRMWARE_FX2LAFW.tar.gz
172 tar xfz sigrok-firmware-fx2lafw-bin-$VER_SIGROK_FIRMWARE_FX2LAFW.tar.gz
173 cd sigrok-firmware-fx2lafw-bin-$VER_SIGROK_FIRMWARE_FX2LAFW
174 cp *.fw $PREFIX/share/sigrok-firmware/
175 cd ..
176
177 # TODO: Doesn't build, libsigrokdecode linking errors.
178 # # sigrok-cli
179 # $GIT_CLONE $REPO_BASE/sigrok-cli
180 # cd sigrok-cli
181 # ./autogen.sh
182 # mkdir build
183 # cd build
184 # PKG_CONFIG_PATH=$P ../configure $C $L
185 # $SB make $PARALLEL $V
186 # make install $V
187 # # makensis -DHOME=$HOME contrib/sigrok-cli_cross.nsi # TODO
188 # cd ../..
189
190 # TODO: Doesn't build, various linking errors.
191 # PulseView
192 $GIT_CLONE $REPO_BASE/pulseview
193 cd pulseview
194 mkdir build
195 cd build
196 PKG_CONFIG_PATH=$P $SB cmake \
197         -G "Unix Makefiles" \
198         -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX \
199         -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
200         -DDISABLE_WERROR=y \
201         -DENABLE_TESTS=n \
202         ..
203 $SB make $PARALLEL $V
204 make install $V
205 # $SB make test $V # TODO
206 # makensis -DHOME=$HOME contrib/pulseview_cross.nsi # TODO
207 cd ../..