Make GTK3 build default, and GTK2 build optional
[geany-mirror.git] / scripts / cross-build-mingw.sh
blob02ddcb4d26f7f19aad92699300ef590c2e89ab4d
1 #!/bin/sh
2 # A script to automate setup and build for Windows cross-compilation
4 # What it does:
5 # 1) prepare a build directory
6 # 2) download and unpacked the dependencies
7 # (see http://www.gtk.org/download/win32.php)
8 # 2.1) fixup the unpacked pkg-config file paths
9 # 3) setup the few required paths
10 # 4) configure with sensible options for this
11 # 5) build
12 # 6) install in a local directory
13 # 7) pack the installation in a ZIP file, ready to be used
14 # (but does not pack the dependencies)
16 # You may change those
17 HOST=i686-w64-mingw32
18 GTK2_BUNDLE_ZIP="https://download.geany.org/contrib/gtk/gtk+-bundle_2.24.10-20120208_win32.zip"
19 GTK3_BUNDLE_ZIP="https://download.geany.org/contrib/gtk/gtk+-bundle_3.8.2-20131001_win32.zip"
20 BUILDDIR=_build-cross-mingw
21 GTK3=yes
22 CONFIGUREFLAGS="--enable-nls"
23 MAKEFLAGS="${MAKEFLAGS:--j2}"
25 while getopts '32b:h' o; do
26 case "$o" in
27 3) GTK3=yes;;
28 2) GTK3=no;;
29 b) BUILDDIR="$OPTARG";;
31 cat <<EOF
32 USAGE: $0 [-2|-3] [-b DIR] [-h]
34 -2 Build against GTK2 (deprecated)
35 -3 Build against GTK3 (default)
36 -b DIR Use DIR as build directory
37 -h Show this help and exit
38 EOF
39 exit 0;;
40 *) echo "Invalid option $o (see -h)">&2; exit 1;;
41 esac
42 done
43 shift $((OPTIND - 1))
45 # USAGE: fetch_and_unzip URL DEST_PREFIX
46 fetch_and_unzip()
48 local basename=${1##*/}
49 curl -L -# "$1" > "$basename"
50 unzip -qn "$basename" -d "$2"
51 rm -f "$basename"
54 if test -d "$BUILDDIR"; then
55 cat >&2 <<EOF
56 ** Directory "$BUILDDIR/" already exists.
57 If it was created by this tool and just want to build, simply run make:
58 $ make -C "$BUILDDIR/_build/"
60 If however you want to recreate it, please remove it first:
61 $ rm -rf "$BUILDDIR/"
62 EOF
63 exit 1
66 set -e
67 set -x
70 test -f configure
71 # check if the host tools are available, because configure falls back
72 # on default non-prefixed tools if they are missing, and it can spit
73 # quite a lot of subtle errors. also avoids going further if something
74 # is obviously missing.
75 type "$HOST-gcc"
77 SRCDIR="$PWD"
79 mkdir "$BUILDDIR"
80 cd "$BUILDDIR"
82 mkdir _deps
84 # both the GTK2 and GTK3 build require files from the GTK3 bundle
85 # so download and unzip it unconditionally
86 fetch_and_unzip "$GTK3_BUNDLE_ZIP" _deps
88 if [ "$GTK3" = no ]; then
89 fetch_and_unzip "$GTK2_BUNDLE_ZIP" _deps
90 CONFIGUREFLAGS="$CONFIGUREFLAGS --enable-gtk2=yes"
93 # fixup the prefix= in the pkg-config files
94 sed -i "s%^\(prefix=\).*$%\1$PWD/_deps%" _deps/lib/pkgconfig/*.pc
96 export PKG_CONFIG_PATH="$PWD/_deps/lib/pkgconfig/"
97 export CPPFLAGS="-I$PWD/_deps/include"
98 export LDFLAGS="-L$PWD/_deps/lib"
100 mkdir _build
101 cd _build
102 "$SRCDIR/configure" \
103 --host=$HOST \
104 --disable-silent-rules \
105 --prefix="$PWD/../_install" \
106 $CONFIGUREFLAGS || {
107 cat config.log
108 exit 1
110 make $MAKEFLAGS
111 make $MAKEFLAGS install