Simplify the filtering code a bit and follow Geany style
[geany-mirror.git] / scripts / cross-build-mingw.sh
blob4483f94552c755deace438b60404ddbac2d4922b
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 GTK_BUNDLE_ZIP="https://download.geany.org/contrib/gtk/gtk+-bundle_3.8.2-20131001_win32.zip"
19 BUILDDIR=_build-cross-mingw
20 CONFIGUREFLAGS="--enable-nls"
21 MAKEFLAGS="${MAKEFLAGS:--j2}"
23 while getopts '32b:h' o; do
24 case "$o" in
25 b) BUILDDIR="$OPTARG";;
27 cat <<EOF
28 USAGE: $0 [-b DIR] [-h]
30 -b DIR Use DIR as build directory
31 -h Show this help and exit
32 EOF
33 exit 0;;
34 *) echo "Invalid option $o (see -h)">&2; exit 1;;
35 esac
36 done
37 shift $((OPTIND - 1))
39 # USAGE: fetch_and_unzip URL DEST_PREFIX
40 fetch_and_unzip()
42 local basename=${1##*/}
43 curl -L -# "$1" > "$basename"
44 unzip -qn "$basename" -d "$2"
45 rm -f "$basename"
48 if test -d "$BUILDDIR"; then
49 cat >&2 <<EOF
50 ** Directory "$BUILDDIR/" already exists.
51 If it was created by this tool and just want to build, simply run make:
52 $ make -C "$BUILDDIR/_build/"
54 If however you want to recreate it, please remove it first:
55 $ rm -rf "$BUILDDIR/"
56 EOF
57 exit 1
60 set -e
61 set -x
64 test -f configure
65 # check if the host tools are available, because configure falls back
66 # on default non-prefixed tools if they are missing, and it can spit
67 # quite a lot of subtle errors. also avoids going further if something
68 # is obviously missing.
69 type "$HOST-gcc"
71 SRCDIR="$PWD"
73 mkdir "$BUILDDIR"
74 cd "$BUILDDIR"
76 mkdir _deps
78 fetch_and_unzip "$GTK_BUNDLE_ZIP" _deps
80 # fixup the prefix= in the pkg-config files
81 sed -i "s%^\(prefix=\).*$%\1$PWD/_deps%" _deps/lib/pkgconfig/*.pc
83 export PKG_CONFIG_PATH="$PWD/_deps/lib/pkgconfig/"
84 export CPPFLAGS="-I$PWD/_deps/include"
85 export LDFLAGS="-L$PWD/_deps/lib"
87 mkdir _build
88 cd _build
89 "$SRCDIR/configure" \
90 --host=$HOST \
91 --disable-silent-rules \
92 --prefix="$PWD/../_install" \
93 $CONFIGUREFLAGS || {
94 cat config.log
95 exit 1
97 make $MAKEFLAGS
98 make $MAKEFLAGS install