File: mingw-fetch-dependencies.sh

package info (click to toggle)
clutter-1.0 1.26.4%2Bgit2779b932%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,672 kB
  • sloc: ansic: 130,756; xml: 1,641; makefile: 1,607; sh: 980; perl: 192; ruby: 167
file content (432 lines) | stat: -rwxr-xr-x 10,534 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#!/bin/bash

# This script will download and setup a cross compilation environment
# for targetting Win32 from Linux. It can also be used to build on
# Windows under the MSYS/MinGW environment. It will use the GTK
# binaries from Tor Lillqvist.

TOR_URL="http://ftp.gnome.org/pub/gnome/binaries/win32";

TOR_BINARIES=( \
    gtk+/2.16/gtk+{-dev,}_2.16.6-2_win32.zip );

TOR_DEP_URL="http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies";

ZLIB_VERSION=1.2.4-2
FFI_VERSION=3.0.6
GLIB_VERSION=2.34.3
GLIB_MINOR_VERSION="${GLIB_VERSION%.*}"

TOR_DEPS=( \
    cairo{-dev,}_1.10.0-2_win32.zip \
    gettext-runtime-{dev-,}0.17-1.zip \
    fontconfig{-dev,}_2.8.0-2_win32.zip \
    freetype{-dev,}_2.3.12-1_win32.zip \
    expat_2.0.1-1_win32.zip \
    libpng{-dev,}_1.4.0-1_win32.zip \
    zlib{-dev,}_${ZLIB_VERSION}_win32.zip \
    libffi{-dev,}_${FFI_VERSION}-1_win32.zip \
    gettext-runtime{-dev,}_0.18.1.1-2_win32.zip );

GNOME_SOURCES_URL="http://ftp.gnome.org/pub/GNOME/sources/"
SOURCES_DEPS=(\
    glib/${GLIB_MINOR_VERSION}/glib-${GLIB_VERSION}.tar.xz \
    cogl/1.14/cogl-1.14.0.tar.xz \
    json-glib/0.16/json-glib-0.16.0.tar.xz \
    atk/2.8/atk-2.8.0.tar.xz \
    pango/1.34/pango-1.34.1.tar.xz );

GL_HEADER_URLS=( \
    http://cgit.freedesktop.org/mesa/mesa/plain/include/GL/gl.h \
    http://www.opengl.org/registry/api/glext.h );

GL_HEADERS=( gl.h glext.h );

CONFIG_GUESS_URL="http://git.savannah.gnu.org/gitweb/?p=automake.git;a=blob_plain;f=lib/config.guess"

function download_file ()
{
    local url="$1"; shift;
    local filename="$1"; shift;

    if test -f "$DOWNLOAD_DIR/$filename"; then
        echo "Skipping download of $filename because the file already exists";
        return 0;
    fi;

    case "$DOWNLOAD_PROG" in
	curl)
	    curl -o "$DOWNLOAD_DIR/$filename" "$url";
	    ;;
	*)
	    $DOWNLOAD_PROG -O "$DOWNLOAD_DIR/$filename" "$url";
	    ;;
    esac;

    if [ $? -ne 0 ]; then
	echo "Downloading ${url} failed.";
	exit 1;
    fi;
}

function guess_dir ()
{
    local var="$1"; shift;
    local suffix="$1"; shift;
    local msg="$1"; shift;
    local prompt="$1"; shift;
    local dir="${!var}";

    if [ -z "$dir" ]; then
	echo "Please enter ${msg}.";
	dir="$PWD/$suffix";
	read -r -p "$prompt [$dir] ";
	if [ -n "$REPLY" ]; then
	    dir="$REPLY";
	fi;
    fi;

    eval $var="\"$dir\"";

    if [ ! -d "$dir" ]; then
	if ! mkdir -p "$dir"; then
	    echo "Error making directory $dir";
	    exit 1;
	fi;
    fi;
}

function y_or_n ()
{
    local prompt="$1"; shift;

    while true; do
	read -p "${prompt} [y/n] " -n 1;
	echo;
	case "$REPLY" in
	    y) return 0 ;;
	    n) return 1 ;;
	    *) echo "Please press y or n" ;;
	esac;
    done;
}

function do_unzip ()
{
    do_unzip_d "$ROOT_DIR" "$@";
}

function do_unzip_d ()
{
    local exdir="$1"; shift;
    local zipfile="$1"; shift;

    unzip -o -q -d "$exdir" "$zipfile" "$@";

    if [ "$?" -ne 0 ]; then
	echo "Failed to extract $zipfile";
	exit 1;
    fi;
}

function do_untar_source ()
{
    do_untar_source_d "$BUILD_DIR" "$@";
}

function do_untar_source_d ()
{
    local exdir="$1"; shift;
    local tarfile="$1"; shift;

    tar -C "$exdir" -axvf "$tarfile" "$@";

    if [ "$?" -ne 0 ]; then
	echo "Failed to extract $tarfile";
	exit 1;
    fi;
}

function add_env ()
{
    echo "export $1=\"$2\"" >> $env_file;
}

function find_compiler ()
{
    local gccbin fullpath;

    if [ -z "$MINGW_TOOL_PREFIX" ]; then
	for gccbin in i{3,4,5,6}86{-pc,}-mingw32{,msvc}-gcc; do
	    fullpath="`which $gccbin 2>/dev/null`";
	    if [ "$?" -eq 0 ]; then
		MINGW_TOOL_PREFIX="${fullpath%%gcc}";
		break;
	    fi;
	done;
	if [ -z "$MINGW_TOOL_PREFIX" ]; then
	    echo;
	    echo "No suitable cross compiler was found.";
	    echo;
	    echo "If you already have a compiler installed,";
	    echo "please set the MINGW_TOOL_PREFIX variable";
	    echo "to point to its location without the";
	    echo "gcc suffix (eg: \"/usr/bin/i386-mingw32-\").";
	    echo;
	    echo "If you are using Ubuntu, you can install a";
	    echo "compiler by typing:";
	    echo;
	    echo " sudo apt-get install mingw32";
	    echo;
	    echo "Otherwise you can try following the instructions here:";
	    echo;
	    echo " http://www.libsdl.org/extras/win32/cross/README.txt";

	    exit 1;
	fi;
    fi;

    TARGET="${MINGW_TOOL_PREFIX##*/}";
    TARGET="${TARGET%%-}";

    echo "Using compiler ${MINGW_TOOL_PREFIX}gcc and target $TARGET";
}

function generate_pc_file ()
{
    local pcfile="$1"; shift;
    local libs="$1"; shift;
    local version="$1"; shift;
    local include="$1"; shift;
    local bn=`basename "$pcfile"`;

    if test -z "$include"; then
        include="\${prefix}/include";
    fi;

    if ! test -f "$pcfile"; then
        cat > "$pcfile" <<EOF
prefix=$ROOT_DIR
exec_prefix=\${prefix}
libdir=\${prefix}/lib
sharedlibdir=\${libdir}
includedir=$include

Name: $bn
Description: $bn

Requires:
Libs: -L\${libdir} $libs
Cflags: -I\${includedir}
Version: $version
EOF
    fi
}

function do_cross_compile ()
{
    local dep="$1"; shift;
    local builddir="$BUILD_DIR/$dep";

    cd "$builddir"
    ./configure --prefix="$ROOT_DIR" \
        --host="$TARGET" \
        --target="$TARGET" \
        --build="$build_config" \
        CFLAGS="-mms-bitfields -I${ROOT_DIR}/include" \
        LDFLAGS="-L${ROOT_DIR}/lib" \
        PKG_CONFIG="$RUN_PKG_CONFIG" \
        "$@";

    if [ "$?" -ne 0 ]; then
	echo "Failed to configure $dep";
	exit 1;
    fi;

    make all install

    if [ "$?" -ne 0 ]; then
	echo "Failed to build $dep";
	exit 1;
    fi;
}

# If a download directory hasn't been specified then try to guess one
# but ask for confirmation first
guess_dir DOWNLOAD_DIR "downloads" \
    "the directory to download to" "Download directory";

# Try to guess a download program if none has been specified
if [ -z "$DOWNLOAD_PROG" ]; then
    # If no download program has been specified then check if wget or
    # curl exists
    #wget first, because my curl can't download libsdl...
    for x in wget curl; do
	if [ "`type -t $x`" != "" ]; then
	    DOWNLOAD_PROG="$x";
	    break;
	fi;
    done;

    if [ -z "$DOWNLOAD_PROG" ]; then
	echo "No DOWNLOAD_PROG was set and neither wget nor curl is ";
	echo "available.";
	exit 1;
    fi;
fi;

# If a download directory hasn't been specified then try to guess one
# but ask for confirmation first
guess_dir ROOT_DIR "clutter-cross" \
    "the root prefix for the build environment" "Root dir";
SLASH_SCRIPT='s/\//\\\//g';
quoted_root_dir=`echo "$ROOT_DIR" | sed "$SLASH_SCRIPT" `;

# If a build directory hasn't been specified then try to guess one
# but ask for confirmation first
guess_dir BUILD_DIR "build" \
    "the directory to build source dependencies in" "Build directory";

##
# Download files
##

for bin in "${TOR_BINARIES[@]}"; do
    bn="${bin##*/}";
    download_file "$TOR_URL/$bin" "$bn"
done;

for dep in "${TOR_DEPS[@]}"; do
    download_file "$TOR_DEP_URL/$dep" "$dep";
done;

for dep in "${OTHER_DEPS[@]}"; do
    bn="${dep##*/}";
    download_file "$dep" "$bn";
done;

for dep in "${GL_HEADER_URLS[@]}"; do
    bn="${dep##*/}";
    download_file "$dep" "$bn";
done;

for dep in "${SOURCES_DEPS[@]}"; do
    src="${dep##*/}";
    download_file "$GNOME_SOURCES_URL/$dep" "$src";
done;

download_file "$CONFIG_GUESS_URL" "config.guess";

##
# Extract files
##

for bin in "${TOR_BINARIES[@]}"; do
    echo "Extracting $bin...";
    bn="${bin##*/}";
    do_unzip "$DOWNLOAD_DIR/$bn";
done;

for dep in "${TOR_DEPS[@]}"; do
    echo "Extracting $dep...";
    do_unzip "$DOWNLOAD_DIR/$dep";
done;

for src in "${SOURCES_DEPS[@]}"; do
    echo "Extracting $src...";
    src="${src##*/}";
    do_untar_source "$DOWNLOAD_DIR/$src";
done;

echo "Fixing pkgconfig files...";
for x in "$ROOT_DIR/lib/pkgconfig/"*.pc; do
    sed "s/^prefix=.*\$/prefix=${quoted_root_dir}/" \
	< "$x" > "$x.tmp";
    mv "$x.tmp" "$x";
done;

# The Pango FT pc file hardcodes the include path for freetype, so it
# needs to be fixed separately
sed -e 's/^Cflags:.*$/Cflags: -I${includedir}\/pango-1.0 -I${includedir}\/freetype2/' \
    -e 's/^\(Libs:.*\)$/\1 -lfreetype -lfontconfig/' \
    < "$ROOT_DIR/lib/pkgconfig/pangoft2.pc" \
    > "$ROOT_DIR/lib/pkgconfig/pangoft2.pc.tmp";
mv "$ROOT_DIR/lib/pkgconfig/pangoft2.pc"{.tmp,};

echo "Copying GL headers...";
if ! ( test -d "$ROOT_DIR/include/GL" || \
    mkdir "$ROOT_DIR/include/GL" ); then
    echo "Failed to create GL header directory";
    exit 1;
fi;
for header in "${GL_HEADERS[@]}"; do
    if ! cp "$DOWNLOAD_DIR/$header" "$ROOT_DIR/include/GL/"; then
        echo "Failed to copy $header";
        exit 1;
    fi;
done;

# We need pkg-config files for zlib and ffi to build glib. The
# prepackaged binaries from tml doesn't seem to include them so we'll
# just generate it manually.
generate_pc_file "$ROOT_DIR/lib/pkgconfig/zlib.pc" "-lz" "$ZLIB_VERSION"
generate_pc_file "$ROOT_DIR/lib/pkgconfig/libffi.pc" "-lffi" "$FFI_VERSION" \
    "${ROOT_DIR}/lib/libffi-${FFI_VERSION}/include"

RUN_PKG_CONFIG="$BUILD_DIR/run-pkg-config.sh";

echo "Generating $BUILD_DIR/run-pkg-config.sh";

cat > "$RUN_PKG_CONFIG" <<EOF
# This is a wrapper script for pkg-config that overrides the
# PKG_CONFIG_LIBDIR variable so that it won't pick up the local system
# .pc files.

# The MinGW compiler on Fedora tries to do a similar thing except that
# it also unsets PKG_CONFIG_PATH. This breaks any attempts to add a
# local search path so we need to avoid using that script.

export PKG_CONFIG_LIBDIR="$ROOT_DIR/lib/pkgconfig"

exec pkg-config "\$@"
EOF

chmod a+x "$RUN_PKG_CONFIG";

##
# Build environment
##

find_compiler;

build_config=`bash $DOWNLOAD_DIR/config.guess`;

##
# Build source dependencies
##

for dep in "${SOURCES_DEPS[@]}"; do
    echo "Building $dep...";
    src="${dep##*/}";
    src="${src%%.tar.*}";

    if echo "$src" | grep -q '^glib'; then
        do_cross_compile "$src" --disable-modular-tests
    else
        do_cross_compile "$src"
    fi;
done;

echo
echo "Done!"
echo
echo "You should now have everything you need to cross compile Clutter"
echo
echo "To get started, you should be able to configure and build from"
echo "the top of your clutter source directory as follows:"
echo
echo "./configure --host=\"$TARGET\" --target=\"$TARGET\" --build=\"$build_config\" --with-flavour=win32 CFLAGS=\"-mms-bitfields -I$ROOT_DIR/include\" PKG_CONFIG=\"$RUN_PKG_CONFIG\""
echo "make"
echo
echo "Note: the explicit --build option is often necessary to ensure autoconf"
echo "realizes you are cross-compiling."