Added a script to assist building for w32
[pspp] / Windows / build-dependencies
1 #!/bin/sh
2
3 ## This program is not part of PSPP but is used to help build PSPP
4 ## Copyright (C) 2021 John Darrington
5 ##
6 ## This program is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
10 ##
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ## GNU General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 # This script downloads (if necessary) and builds the required
20 # dependencies of PSPP. You may find it useful when cross building.
21 # Sadly, it it very likely that you'll have to tweak the order of the
22 # packages, the versions of the packages, their CFLAGS and other
23 # details in order to succesfully build for any particular
24 # architecture.  In its current form, it has been tweaked for building
25 # for mingw archs.
26
27 required_native_programs="awk sha256sum tar sed gtk-encode-symbolic-svg ninja meson cat grep pkg-config"
28
29 for p in $required_native_programs; do
30     if ! type "$p" > /dev/null; then
31         echo $p must be installed and in PATH;
32         exit 1
33     fi
34 done
35
36 while test $# -gt 0; do
37     case $1 in
38         --arch=*)
39             arch=${1##--arch=};;
40         --sandbox=*)
41             SANDBOX=${1##--sandbox=};;
42         --tarballs=*)
43             SRC_TARBALL_DIR=${1##--tarballs=};;
44         *)
45             printf "Usage: $0 --arch=<arch> --sandbox=<dir> [--tarballs=<dir>]\n";
46             exit 1;
47         ;;
48     esac
49     shift 1;
50 done
51
52 if test -z "$SANDBOX" || -z "$arch"; then
53             printf "Usage: $0 --arch=<arch> --sandbox=<dir> [--tarballs=<dir>]\n";
54     exit 1;
55 fi
56
57 SANDBOX=`eval echo $SANDBOX`
58
59 if test -z "$SRC_TARBALL_DIR"; then
60     SRC_TARBALL_DIR="$SANDBOX/tarballs"
61 fi
62
63 SRC_TARBALL_DIR=`eval echo $SRC_TARBALL_DIR`
64
65 rm -rIf $SANDBOX
66
67 default_build_procs=$(expr $(cat /proc/cpuinfo | grep -c '^processor') + 1)
68
69 mkdir -p $SRC_TARBALL_DIR
70
71 mkdir -p $SANDBOX
72
73 export DESTDIR=""
74
75 cat > $SANDBOX/cross-file.txt <<EOF
76 [host_machine]
77 system = 'windows'
78 cpu_family = 'x86_64'
79 cpu = 'x86_64'
80 endian = 'little'
81
82 [binaries]
83 c = '$arch-gcc'
84 cpp = '$arch-g++'
85 ar = '$arch-ar'
86 ld = '$arch-ld'
87 objcopy = '$arch-objcopy'
88 strip = '$arch-strip'
89 pkgconfig = 'pkg-config'
90 windres = '$arch-windres'
91 EOF
92
93 tarballs="zlib-1.2.11.tar.gz"
94 tarballs="$tarballs libiconv-1.16.tar.gz"
95 tarballs="$tarballs gettext-0.21.tar.xz"
96 tarballs="$tarballs libffi-3.3.tar.gz"
97 tarballs="$tarballs pixman-0.40.0.tar.gz"
98 tarballs="$tarballs libpng-1.6.37.tar.gz"
99 tarballs="$tarballs libxml2-2.9.10.tar.gz"
100 tarballs="$tarballs freetype-2.10.4.tar.xz"
101 tarballs="$tarballs fribidi-1.0.10.tar.xz"
102 tarballs="$tarballs harfbuzz-2.7.4.tar.xz"
103 tarballs="$tarballs glib-2.67.6.tar.xz"
104 tarballs="$tarballs cairo-1.17.4.tar.xz"
105 tarballs="$tarballs pango-1.48.0.tar.xz"
106 tarballs="$tarballs atk-2.36.0.tar.xz"
107 tarballs="$tarballs gdk-pixbuf-2.42.2.tar.xz"
108 tarballs="$tarballs libepoxy-1.5.5.tar.xz"
109 tarballs="$tarballs gtk+-3.24.27.tar.xz"
110 tarballs="$tarballs gsl-2.6.tar.gz"
111 tarballs="$tarballs gtksourceview-3.24.9.tar.xz"
112 tarballs="$tarballs spread-sheet-widget-0.8.tar.gz"
113 tarballs="$tarballs hicolor-icon-theme-0.17.tar.xz"
114 tarballs="$tarballs adwaita-icon-theme-3.38.0.tar.xz"
115
116 mkdir -p $SANDBOX/Source
117 for t in $tarballs ; do
118     url=""
119     case $t in
120         ncurses-6.2.tar.gz)
121             url="ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.2.tar.gz";
122             hash=30306e0c76e0f9f1f0de987cf1c82a5c21e1ce6568b9227f7da5b71cbea86c9d;;
123         readline-8.1.tar.gz)
124             url="ftp://ftp.gnu.org/gnu/readline/readline-8.1.tar.gz";
125             hash=f8ceb4ee131e3232226a17f51b164afc46cd0b9e6cef344be87c65962cb82b02;;
126         termcap-1.3.1.tar.gz)
127             url="ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz";
128             hash=91a0e22e5387ca4467b5bcb18edf1c51b930262fd466d5fda396dd9d26719100;;
129         fontconfig-2.12.6.tar.bz2)
130             url="https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.12.6.tar.bz2";
131             hash=cf0c30807d08f6a28ab46c61b8dbd55c97d2f292cf88f3a07d3384687f31f017;;
132         adwaita-icon-theme-3.38.0.tar.xz)
133             url="https://download.gnome.org/sources/adwaita-icon-theme/3.38/adwaita-icon-theme-3.38.0.tar.xz";
134             hash=6683a1aaf2430ccd9ea638dd4bfe1002bc92b412050c3dba20e480f979faaf97;;
135         librsvg-2.31.0.tar.bz2)
136             url="https://ftp.acc.umu.se/pub/GNOME/sources/librsvg/2.31/librsvg-2.31.0.tar.bz2";
137             hash=320b61ef5e6d65624f3733a83134df012a4156ed7f7ae38a6ed19febe1bfa732;;
138         librsvg-2.49.5.tar.xz)
139             url="https://download.gnome.org/sources/librsvg/2.49/librsvg-2.49.5.tar.xz";
140             hash=daa64941bb4732bdf51b902a72c6e04063235cfce6986d910ba0759c76917795;;
141         librsvg-2.51.0.tar.xz)
142             url="https://ftp.acc.umu.se/pub/GNOME/sources/librsvg/2.51/librsvg-2.51.0.tar.xz";
143             hash=89d32e38445025e1b1d9af3dd9d3aeb9f6fce527aeecbecf38b369b34c80c038;;
144         hicolor-icon-theme-0.17.tar.xz)
145             url="https://icon-theme.freedesktop.org/releases/hicolor-icon-theme-0.17.tar.xz";
146             hash=317484352271d18cbbcfac3868eab798d67fff1b8402e740baa6ff41d588a9d8;;
147         gettext-0.21.tar.xz)
148             url="https://ftp.gnu.org/gnu/gettext/gettext-0.21.tar.xz";
149             hash=d20fcbb537e02dcf1383197ba05bd0734ef7bf5db06bdb241eb69b7d16b73192;;
150         spread-sheet-widget-0.8.tar.gz)
151             url="https://alpha.gnu.org/gnu/ssw/spread-sheet-widget-0.8.tar.gz"
152             hash=8589d8298fcf3b5850d0968b04801a4f40faf0555544f6cc9d954b0162e9954b;;
153         gtksourceview-3.24.9.tar.xz)
154             url="https://download.gnome.org/sources/gtksourceview/3.24/gtksourceview-3.24.9.tar.xz"
155             hash=699d76a453e6a3d3331906346e3dbfa25f2cbc9ec090e46635e9c6bb595e07c2;;
156         libepoxy-1.5.5.tar.xz)
157             url="https://github.com/anholt/libepoxy/releases/download/1.5.5/libepoxy-1.5.5.tar.xz"
158             hash=261663db21bcc1cc232b07ea683252ee6992982276536924271535875f5b0556;;
159         gdk-pixbuf-2.42.2.tar.xz)
160             url="https://download.gnome.org/sources/gdk-pixbuf/2.42/gdk-pixbuf-2.42.2.tar.xz";
161             hash=83c66a1cfd591d7680c144d2922c5955d38b4db336d7cd3ee109f7bcf9afef15;;
162         gobject-introspection-1.67.1.tar.xz)
163             url="https://download.gnome.org/sources/gobject-introspection/1.67/gobject-introspection-1.67.1.tar.xz";
164             ;;
165         atk-2.36.0.tar.xz)
166             url="https://download.gnome.org/sources/atk/2.36/atk-2.36.0.tar.xz";
167             hash=fb76247e369402be23f1f5c65d38a9639c1164d934e40f6a9cf3c9e96b652788;;
168         gtk+-3.24.27.tar.xz)
169             url="https://download.gnome.org/sources/gtk+/3.24/gtk%2B-3.24.27.tar.xz";
170             hash=f71c067570339f9f8efac7bb87717a2c52279cb50223fb8b5ba7085930757a26;;
171         cairo-1.17.4.tar.xz)
172             url="https://cairographics.org/snapshots/cairo-1.17.4.tar.xz";
173             hash=74b24c1ed436bbe87499179a3b27c43f4143b8676d8ad237a6fa787401959705;;
174         harfbuzz-2.7.4.tar.xz)
175             url="https://github.com/harfbuzz/harfbuzz/releases/download/2.7.4/harfbuzz-2.7.4.tar.xz";
176             hash=6ad11d653347bd25d8317589df4e431a2de372c0cf9be3543368e07ec23bb8e7;;
177         fribidi-1.0.10.tar.xz)
178             url="https://github.com/fribidi/fribidi/releases/download/v1.0.10/fribidi-1.0.10.tar.xz";
179             hash=7f1c687c7831499bcacae5e8675945a39bacbad16ecaa945e9454a32df653c01;;
180         fontconfig-2.13.0.tar.bz2)
181             url="https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.13.0.tar.bz2";
182             hash=91dde8492155b7f34bb95079e79be92f1df353fcc682c19be90762fd3e12eeb9;;
183         libffi-3.3.tar.gz)
184             url="ftp://sourceware.org/pub/libffi/libffi-3.3.tar.gz";
185             hash=72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056;;
186         zlib-1.2.11.tar.gz)
187             url="https://zlib.net/fossils/zlib-1.2.11.tar.gz";
188             hash=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1;;
189         pixman-0.40.0.tar.gz)
190             url="https://www.cairographics.org/releases/pixman-0.40.0.tar.gz";
191             hash=6d200dec3740d9ec4ec8d1180e25779c00bc749f94278c8b9021f5534db223fc;;
192         libpng-1.6.37.tar.gz)
193             url="https://download.sourceforge.net/libpng/libpng-1.6.37.tar.gz";
194             hash=daeb2620d829575513e35fecc83f0d3791a620b9b93d800b763542ece9390fb4;;
195         freetype-2.10.4.tar.xz)
196             url="https://download.savannah.gnu.org/releases/freetype/freetype-2.10.4.tar.xz";
197             hash=86a854d8905b19698bbc8f23b860bc104246ce4854dcea8e3b0fb21284f75784;;
198         glib-2.67.6.tar.xz)
199             url="https://download.gnome.org/sources/glib/2.67/glib-2.67.6.tar.xz";
200             hash=dd7f563509b410e8f94ef2d4cc7f74620a6b29d7c5d529fedec53c5e8018d9c5;;
201         pango-1.48.0.tar.xz)
202             url="https://download.gnome.org/sources/pango/1.48/pango-1.48.0.tar.xz";
203             hash=391f26f3341c2d7053e0fb26a956bd42360dadd825efe7088b1e9340a65e74e6;;
204         pango-1.40.0.tar.xz)
205             hash=da17985df314cb07d066ab5424f59c21ce973ece05b7de4df04d798ec8511c8b;;
206         gsl-2.6.tar.gz)
207             url="https://ftp.gnu.org/gnu/gsl/gsl-2.6.tar.gz";
208             hash=b782339fc7a38fe17689cb39966c4d821236c28018b6593ddb6fd59ee40786a8;;
209         libiconv-1.16.tar.gz)
210             url="https://ftp.gnu.org/gnu/libiconv/libiconv-1.16.tar.gz";
211             hash=e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04;;
212         libxml2-2.9.10.tar.gz)
213             url="ftp://xmlsoft.org/libxml2/libxml2-2.9.10.tar.gz";
214             hash=aafee193ffb8fe0c82d4afef6ef91972cbaf5feea100edc2f262750611b4be1f;;
215         *) hash=XX;;
216     esac
217
218     # Fetch the tarball if we don't already have it.
219     if ! test -e $SRC_TARBALL_DIR/$t; then
220         (cd $SRC_TARBALL_DIR && wget $url)
221     fi
222
223     case $t in
224         pspp-*)
225             # Don't check the hash for this since it's changing rapidly
226         ;;
227         *)    # Check that it hasn't been corrupted or compromised
228               h=`(cd $SRC_TARBALL_DIR && sha256sum $t) | awk '{print $1}'`
229               if ! test "$hash" = $h ; then
230                   echo "Hash for $t is invalid" ;
231                   exit 1
232               fi
233               ;;
234     esac
235 done
236
237 # No network access should be necessary after this point
238 for t in $tarballs ; do
239     # Unpack the tarballs into the Source directory
240     case $t in
241         *.zip)
242             pkg=${t%%.zip}
243             unarch="unzip -o"
244             ;;
245         *.tar.xz)
246             pkg=${t%%.tar.xz}
247             unarch="tar -xJf"
248             ;;
249         *.tar.gz)
250             pkg=${t%%.tar.gz}
251             unarch="tar -xzf"
252             ;;
253         *.tar.bz2)
254             pkg=${t%%.tar.bz2}
255             unarch="tar -xjf"
256             ;;
257         *)
258             echo "Unknown archive suffix: $t";
259             exit 1;
260             ;;
261     esac
262
263     (cd $SANDBOX/Source && $unarch  $SRC_TARBALL_DIR/$t)
264
265     # Build the package
266     rm  -rf $SANDBOX/Build/$pkg
267     mkdir -p $SANDBOX/Build/$pkg
268     build_procs=$default_build_procs
269     case $pkg in
270         # Deal with the special cases here
271         zlib-*)
272             cd $SANDBOX/Build/$pkg && \
273                 CC=$arch-gcc LDSHAREDLIBC="" $SANDBOX/Source/$pkg/configure --prefix="$SANDBOX/Install" && \
274                 make -j $build_procs && make install
275             ;;
276         # And now the generic cases
277         *)
278             depdir=$SANDBOX/Install
279             build_system="autoconf"
280             pre_configure=""
281             prefix=$SANDBOX/Install
282             case $pkg in
283                 librsvg-*)
284                     extra_config_flags="--disable-tools --enable-introspection=no --disable-gtk-doc-html"
285                     build_procs=1
286                     ;;
287                 libepoxy-*)
288                     build_system="meson";
289                     ;;
290                 gtk+-*)
291                     build_system="meson";
292                     meson_opts="-Dintrospection=false -Dtests=false -Ddemos=false -Dexamples=false";
293                     ;;
294                 gdk-pixbuf-*)
295                     build_system="meson";
296                     meson_opts="-Dintrospection=disabled -Dbuiltin_loaders=all -Dnative_windows_loaders=true -Dinstalled_tests=false -Dman=false";
297                     ;;
298                 gobject-introspection-*)
299                     build_system="meson";
300                     meson_opts=-Dpython=python3;
301                     ;;
302                 atk-*)
303                     build_system="meson";
304                     meson_opts=-Dintrospection=false;
305                     ;;
306                 glib-*)
307                     build_system="meson";
308                     meson_opts="-Dtests=false";
309                     extra_cflags=-Wno-format;  #no-format seems to be necessary for 32 bit builds
310                     ;;
311                 harfbuzz*)
312                     build_system="meson";
313                     meson_opts=-Dglib=disabled;
314                     ;;
315                 freetype-*)
316                     extra_config_flags="--enable-static=no";
317                     ;;
318                 fontconfig-*)
319                     extra_config_flags="--enable-libxml2 --disable-docs";
320                     ;;
321                 libxml2-*)
322                     extra_config_flags=--without-python;
323                     ;;
324                 gettext*)
325                     extra_config_flags="--enable-shared=yes";
326                     # We only need gettext-runtime
327                     pre_configure="sed -i -e /^SUBDIRS/s/libtextstyle.gettext-tools// $SANDBOX/Source/$pkg/Makefile.in";
328                     ;;
329                 pango-1.48.*)
330                     build_system="meson";
331                     ;;
332                 spread-sheet-widget-*)
333                     ;;
334                 pspp-*)
335                     extra_config_flags="--enable-relocatable";
336                     extra_build="make -j $build_procs install-html install-pdf";
337                     prefix=$SANDBOX/Bundle;
338                     ;;
339             esac
340             case $build_system in
341                 meson)
342                     PKG_CONFIG_LIBDIR="$SANDBOX/Install/lib/pkgconfig" \
343                                      meson setup --prefix=$prefix \
344                                      --libdir=lib \
345                                      --cross-file=$SANDBOX/cross-file.txt \
346                                      -Dc_link_args=-L$SANDBOX/Install/lib \
347                                      -Dc_args="-I$SANDBOX/Install/include $extra_cflags" \
348                                      --wrap-mode=nodownload \
349                                      $meson_opts \
350                                      $SANDBOX/Source/$pkg $SANDBOX/Build/$pkg &&
351                         ninja -j $build_procs -C $SANDBOX/Build/$pkg &&
352                         meson install -C $SANDBOX/Build/$pkg
353                     ;;
354                 autoconf)
355                     $pre_configure && \
356                         cd $SANDBOX/Build/$pkg && \
357                         $SANDBOX/Source/$pkg/configure \
358                             --host="$arch" \
359                             --prefix="$prefix" \
360                             $extra_config_flags \
361                             CPPFLAGS="-I $depdir/include" \
362                             LDFLAGS="-L$depdir/lib" \
363                             PKG_CONFIG_LIBDIR="$depdir/lib/pkgconfig" &&
364                         make -j $build_procs && make install && $extra_build
365                     ;;
366                 *)
367                     echo I have no idea how to build $SANDBOX/Source/$pkg
368                     false
369             esac
370             ;;
371     esac || exit 1;
372 echo Done $pkg;
373 done
374
375
376 printf "You can now configure pspp with a command similar to:\n"
377 printf "configure --host=\"$arch\" CPPFLAGS=\"-I $SANDBOX/Install/include\" LDFLAGS=\"-L$SANDBOX/Install/lib\" PKG_CONFIG_LIBDIR=\"$SANDBOX/Install/lib/pkgconfig\"\n"