summaryrefslogtreecommitdiff
path: root/tools/build-gtk-stack
blob: 85744063a23a28c7fedb68a94755078ff9ce5525 (plain)
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/bin/bash

which python >/dev/null 2>&1
if [ $? -ne 0 ] ; then
    echo "You do not have Python installed"
    exit 1
fi

function die () {
    echo $*
    exit 1
}

function fetch_as_is() {
    if uname -a | grep --silent arwin ; then
        curl -LO $1
    else
        wget --no-check-certificate $1
    fi
}

function fetch_as () {
    if uname -a | grep --silent arwin ; then
        curl -L -o $1 $2
    else
        wget --no-check-certificate -O $1 $2
    fi
}
    
clean=
makespace=
parallel=2
patch_gtk_osx=
PREFIX=$HOME/gtk/inst
unpatch=
this_script_dir="`/usr/bin/dirname \"$0\"`"

while [ $# -gt 0 ] ; do
    case $1 in
        --clean*) clean=1 ; shift ;;
        --space*) makespace=1 ; shift ;;
        --prefix*) PREFIX=`echo $1 | sed 's/--prefix=//'` ; shift ;;
        --patch*) patch_gtk_osx=1 ; shift ;;
        --unpatch*) patch_gtk_osx=1 ; unpatch=-R; shift ;;
        -j*) parallel=`echo $1 | sed 's/-j//'` ; shift ;;
        *) echo "Unknown argument $1" ; exit 1 ;;   
    esac
done

if [ x$clean != x -o x$makespace != x ] ; then
    if [ ! -d gtk+ ] ; then 
        echo "This doesn't appear to be your source directory. Don't run --clean or --space here."
        exit 1
    fi
    rm -rf `find . -maxdepth 1 -type d | grep -v -e "gtk+" -e "^.$"`
    # sudo required because of its use during the libxml2 install step
    if [ $clean ] ; then
        sudo rm -rf $PREFIX
    fi
    exit 0
fi

mkdir -p $PREFIX

export MAKEFLAGS=-j$parallel
PATH=$PREFIX/bin:$PATH

OSX=

if uname -a | grep --silent arwin ; then
    
    # its OS X! run for the hills !!

    OSX=1

    export DYLD_FALLBACK_LIBRARY_PATH=$PREFIX/lib${DYLD_FALLBACK_LIBRARY_PATH:+:$DYLD_FALLBACK_LIBRARY_PATH}
    # force compilation to use 10.4 APIs only. could be overkill, but better safe than sorry
    GLOBAL_CFLAGS="-DMAC_OSX_VERSION_MAX_ALLOWED=1040 -mmacosx-version-min=10.4 -O3"
    # for 10.5 and above, add to CFLAGS
    # -sysroot=/Developer/SDKs/MacOSX10.4u.sdk"
    GLOBAL_LDFLAGS="-headerpad_max_install_names"
    # for 10.5 and above, add to LDFLAGS
    # "-syslibroot /Developer/SDKs/MacOSX10.4u.sdk"
    export MACOSX_DEPLOYMENT_TARGET=10.4
    # If the default python is not new enough, set PYTHON to point to a 
    # suitably new (2.7 or later) version of Python's framework
    #
    # this is very crude versioning test
    if python --version | grep --silent '2\.7' ; then
        :
    else
        PYTHON=/Library/Frameworks/Python.framework/Versions/2.7
    fi

    CAIRO_CONF="--enable-xlib=no --enable-quartz=yes --enable-xcb=no"
    PANGO_CONF="--without-x"
    GTK_BACKEND=quartz
    AVOID_ICONV=
    need_iconv=yes

else 

    export LD_LIBRARY_PATH=$PREFIX/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
    GLOBAL_CFLAGS=
    GLOBAL_LDFLAGS=
    CAIRO_CONF=
    PANGO_CONF=
    GTK_BACKEND=x11
    AVOID_ICONV="--with-libiconv=no"
    
    # normal linux platforms won't need this
    need_iconv=

    # this is very crude versioning test
    python --version >/dev/null 2>&1
    if [ $? -ne 0 ] ; then
        echo "There's a problem with your Python installation"x
        exit 1
    fi
    if python --version | grep --silent '2\.7' ; then
        echo "You do not have a new enough version of Python"
        exit 1
    fi
    pythondir=`dirname $(which python)`
    if [ $pythondir != "/usr/bin" ] ; then
        PYTHON=`dirname $pythondir`
    fi
fi

set -e

export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
GLOBAL_CONF="--prefix=$PREFIX"

if [ ! -f xz-5.0.3.tar.bz2 ] ; then
    echo xz
    fetch_as_is http://tukaani.org/xz/xz-5.0.3.tar.bz2
fi
if [ ! -f tar-1.26.tar.bz2 ] ; then
    echo tar
    fetch_as_is http://ftp.gnu.org/gnu/tar/tar-1.26.tar.bz2
fi
if [ ! -f m4-1.4.16.tar.bz2 ] ; then
    echo m4
    fetch_as_is http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.bz2
fi
if [ ! -f automake-1.11.3.tar.gz ] ; then
    echo automake
    fetch_as_is http://ftp.gnu.org/gnu/automake/automake-1.11.3.tar.gz
fi
if [ ! -f autoconf-2.68.tar.bz2 ] ; then
    echo autoconf
    fetch_as_is http://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.bz2
fi
if [ ! -f libtool-2.4.2.tar.gz ] ; then
    echo libtool
    fetch_as_is http://ftp.gnu.org/gnu/libtool/libtool-2.4.2.tar.gz
fi
if [ ! -f make-3.82.tar.bz2 ] ; then
    echo make
    fetch_as_is http://ftp.gnu.org/gnu/make/make-3.82.tar.bz2
fi
if [ ! -f flex-2.5.35.tar.gz ] ; then 
    echo flex
    fetch_as_is http://prdownloads.sourceforge.net/flex/flex-2.5.35.tar.gz
fi
if [ ! -f bison-2.5.tar.bz2 ] ; then
    echo bison
    fetch_as_is ftp://ftp.gnu.org/gnu/bison/bison-2.5.tar.bz2
fi
if [ ! -f glib-2.32.2.tar.xz ] ; then
    echo glib
    fetch_as_is http://ftp.gnome.org/pub/gnome/sources/glib/2.32/glib-2.32.2.tar.xz
fi
if [ ! -f pkg-config-0.26.tar.gz ] ; then
    echo pkg-config
    fetch_as_is http://pkgconfig.freedesktop.org/releases/pkg-config-0.26.tar.gz
fi
if [ ! -f readline-6.2.tar.gz ] ; then
    echo readline
    fetch_as_is ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz
fi
if [ ! -f zlib-1.2.7.tar.bz2 ] ; then
    echo zlib
    fetch_as_is http://zlib.net/zlib-1.2.7.tar.bz2
fi
if [ ! -f libiconv-1.14.tar.gz ] ; then
    echo libiconv
    fetch_as_is ftp://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
fi
if [ ! -f gettext-0.18.1.1.tar.gz ] ; then
    echo gettext
    fetch_as_is http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz
fi
if [ ! -f expat-2.1.0.tar.gz ] ; then 
    echo expat
    fetch_as_is http://prdownloads.sourceforge.net/expat/expat-2.1.0.tar.gz
fi
if [ ! -f libxml2-2.7.8.tar.gz ] ; then
    echo libxml2
    fetch_as_is ftp://xmlsoft.org/libxslt/libxml2-2.7.8.tar.gz
fi
if [ ! -f libxslt-1.1.26.tar.gz ] ; then
    echo libxslt
    fetch_as_is ftp://xmlsoft.org/libxslt/libxslt-1.1.26.tar.gz
fi
if [ ! -f tiff-4.0.1.tar.gz ] ; then
    echo tiff
    fetch_as_is ftp://ftp.remotesensing.org/pub/libtiff/tiff-4.0.1.tar.gz
fi
if [ ! -f libpng-1.5.13.tar.xz ] ; then
    echo png
    fetch_as_is ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.13.tar.xz
fi
if [ ! -f jpegsrc.v8d.tar.gz ] ; then
    echo jpeg
    fetch_as_is http://www.ijg.org/files/jpegsrc.v8d.tar.gz
fi
if [ ! -f XML-Parser-2.41.tar.gz ] ; then
    echo perl xml parser
    fetch_as XML-Parser-2.41.tar.gz http://search.cpan.org/CPAN/authors/id/T/TO/TODDR/XML-Parser-2.41.tar.gz
fi
if [ ! -f XML-Simple-2.18.tar.gz ] ; then
    echo perl xml
    fetch_as XML-Simple-2.18.tar.gz http://search.cpan.org/CPAN/authors/id/G/GR/GRANTM/XML-Simple-2.18.tar.gz
fi
if [ ! -f atk-2.2.0.tar.bz2 ] ; then
    echo atk
    fetch_as_is http://ftp.gnome.org/pub/GNOME/sources/atk/2.2/atk-2.2.0.tar.bz2
fi
if [ ! -f gnome-common-2.34.0.tar.bz2 ] ; then
    echo gnome-common
    fetch_as_is http://ftp.acc.umu.se/pub/gnome/sources/gnome-common/2.34/gnome-common-2.34.0.tar.bz2
fi
if [ ! -f gtk-doc-1.18.tar.bz2 ] ; then
    echo gtk-doc
    fetch_as_is http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/1.18/gtk-doc-1.18.tar.bz2
fi
if [ ! -f gnome-doc-utils-0.20.6.tar.bz2 ] ; then
    echo gnome-doc
    fetch_as_is http://ftp.acc.umu.se/pub/gnome/sources/gnome-doc-utils/0.20/gnome-doc-utils-0.20.6.tar.bz2
fi
if [ ! -f pixman-0.24.4.tar.gz ] ; then
    echo pixman
    fetch_as_is http://cgit.freedesktop.org/pixman/snapshot/pixman-0.24.4.tar.gz
fi
if [ ! -f libffi-3.0.10.tar.gz ] ; then
    echo ffi
    fetch_as_is ftp://sourceware.org/pub/libffi/libffi-3.0.10.tar.gz
fi
if [ ! -f freetype-2.4.8.tar.bz2 ] ; then
    echo freetype
    fetch_as freetype-2.4.8.tar.bz2 http://sourceforge.net/projects/freetype/files/freetype2/2.4.8/freetype-2.4.8.tar.bz2/download
fi
if [ ! -f fontconfig-2.8.0.tar.gz ] ; then
    echo fontconfig
    fetch_as_is http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.8.0.tar.gz
fi
if [ ! -f cairo-1.10.2.tar.gz ] ; then
    echo cairo
    fetch_as_is http://cairographics.org/releases/cairo-1.10.2.tar.gz
fi
if [ ! -f pango-1.29.5.tar.bz2 ] ; then
    echo pango
    fetch_as_is http://ftp.gnome.org/pub/GNOME/sources/pango/1.29/pango-1.29.5.tar.bz2
fi
if [ ! -f gdk-pixbuf-2.25.0.tar.xz ] ; then
    echo gdk-pixbuf
    fetch_as_is http://ftp.gnome.org/pub/GNOME/sources/gdk-pixbuf/2.25/gdk-pixbuf-2.25.0.tar.xz
fi
if [ ! -f intltool-0.50.2.tar.gz ] ; then
    echo intltool
    fetch_as_is http://launchpad.net/intltool/trunk/0.50.2/+download/intltool-0.50.2.tar.gz
fi
if [ ! -f gtk-osx-docbook-1.0.tar.gz ] ; then
    echo gtk-osx-docbook
    fetch_as gtk-osx-docbook-1.0.tar.gz http://sourceforge.net/projects/gtk-osx/files/GTK-OSX%20Build/gtk-osx-docbook-1.0.tar.gz/download
fi
if [ ! -f gobject-introspection-1.31.10.tar.xz ] ; then
    echo gobject-introspection
    fetch_as_is http://ftp.gnome.org/pub/GNOME/sources/gobject-introspection/1.31/gobject-introspection-1.31.10.tar.xz
fi

if [ ! -d gtk-engines ] ; then
    echo "gtk-engines (2.22 branch)"
    git clone git://git.gnome.org/gtk-engines
    (cd gtk-engines && git checkout --track -b gtk-engines-2-22 origin/gtk-engines-2-22)
fi

if [ ! -d gtk+ ] ; then
    echo "GTK+ (2.24 branch)"
    git clone git://git.gnome.org/gtk+
    (cd gtk+ && git checkout --track -b gtk-2-24 origin/gtk-2-24)
fi

if [ x$patch_gtk_osx != x ] ; then

    cd gtk+
    echo "Testing ($unpatch) patches ... "

    patches=`ls $this_script_dir/current-gtk-patches/*.patch`
    for patch in $patches ; do
        if patch $unpatch --dry-run -p1 < $patch ; then
	    :
	else
            echo "$? : Patch $patch no longer applies ($unpatch) cleanly."
	    exit 1
        fi
    done

    echo "Applying ($unpatch) patches ..."
    for patch in $patches ; do
        patch $unpatch -p1 < $patch
    done
    exit 0
fi

export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig


tar jxf xz-5.0.3.tar.bz2 && (cd xz-5.0.3 && LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure $GLOBAL_CONF && make && make install) || die "xz build failed"
tar jxf tar-1.26.tar.bz2 && (cd tar-1.26 && LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure $GLOBAL_CONF && make && make install) || die "tar build failed"
#
# now we have a working, modern tar we can drop the compression-type flag
#
hash tar
#
# well, we do now ..
#
tar xf m4-1.4.16.tar.bz2 && (cd m4-1.4.16 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "m4 build failed"
tar xf make-3.82.tar.bz2 && (cd make-3.82 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "make build failed"
tar xf zlib-1.2.7.tar.bz2 && (cd zlib-1.2.7 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && PATH=/usr/bin:$PATH make && make install) || die "zlib build failed"
tar xf autoconf-2.68.tar.bz2 && (cd autoconf-2.68 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "autoconf build failed"
tar  xf automake-1.11.3.tar.gz && (cd automake-1.11.3 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "automake build failed"
tar  xf libtool-2.4.2.tar.gz && (cd libtool-2.4.2 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "libtool build failed"
tar  xf make-3.82.tar.bz2 && (cd make-3.82 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "make build failed"
tar  xf flex-2.5.35.tar.gz && (cd flex-2.5.35  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "flex build failed"
tar  xf bison-2.5.tar.bz2 && (cd bison-2.5  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "bison build failed"
tar  xf expat-2.1.0.tar.gz && (cd expat-2.1.0  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "expat build failed"
#
# libxml2 tries to install python modules in the system python folders and thus needs sudo for the install step. 
# clean up afterwards to reset ownership on dirs and files created under $PREFIX as root
# 
tar  xf libxml2-2.7.8.tar.gz && (cd libxml2-2.7.8 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF --with-zlib=$PREFIX ${PYTHON:+--with-python=$PYTHON} && make && sudo make install && sudo chown -R `whoami` $PREFIX) || die "libxml2 build failed"
tar  xf libxslt-1.1.26.tar.gz && (cd libxslt-1.1.26 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "libxslt build failed"
tar  xf readline-6.2.tar.gz && (cd readline-6.2  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS -lncurses" ./configure $GLOBAL_CONF && make && make install) || die "readline build failed"

#
# Don't build and install libiconv on systems where it is part of glibc
#
if [ x$need_iconv != x ] ; then 
    tar  xf libiconv-1.14.tar.gz && (cd libiconv-1.14  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "libiconv build failed"
fi

tar  xf intltool-0.50.2.tar.gz && (cd intltool-0.50.2  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "intltool build failed"
if [ x$need_iconv != x ] ; then 
    tar  xf gettext-0.18.1.1.tar.gz && (cd gettext-0.18.1.1  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure --with-included-gettext --with-libiconv-prefix=$PREFIX --enable-shared $GLOBAL_CONF && make && make install) || die "gettext build failed"
else
    tar  xf gettext-0.18.1.1.tar.gz && (cd gettext-0.18.1.1  && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure --with-included-gettext --enable-shared $GLOBAL_CONF && make && make install) || die "gettext build failed"
fi

tar  xf tiff-4.0.1.tar.gz && (cd tiff-4.0.1 && CFLAGS="$GLOBAL_CFLAGS -DHAVE_APPLE_OPENGL_FRAMEWORK" LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "tiff build failed"
tar  xf libpng-1.5.13.tar.xz && (cd libpng-1.5.13 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "libpng build failed"
tar  xf jpegsrc.v8d.tar.gz && (cd jpeg-8d && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "jpegsrc build failed"
tar xf XML-Parser-2.41.tar.gz && (cd XML-Parser-2.41 && unset MACOSX_DEPLOYMENT_TARGET && perl Makefile.PL EXPATINCPATH=$PREFIX/include EXPATLIBPATH=$PREFIX/lib PREFIX=$PREFIX && make && make install) || die "XML-Parser build failed"
tar xf XML-Simple-2.18.tar.gz && (cd XML-Simple-2.18 && unset MACOSX_DEPLOYMENT_TARGET && perl Makefile.PL PREFIX=$PREFIX && make && make install) || die "XML-Simple build failed"

if uname -a | grep --silent arwin ; then
#
# libffi has a bug that is caused by it depending on the output format of GNU wc(1)
# it can be avoided by changing into the target build directory, re-running configure and then running make from there.
# the target dir gets built by the first invocation of configure, and is the newest dir, so we find its name with ls and awk.
#
    tar xf libffi-3.0.10.tar.gz && (cd libffi-3.0.10 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && cd `ls -ltd * | awk '/^d/ {print $9; exit}'` && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ../configure $GLOBAL_CONF && make && make install) || die "libffi build failed"
else 
    tar xf libffi-3.0.10.tar.gz && (cd libffi-3.0.10 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "libffi build failed"
fi
# time to bootstrap the circular dependency between pkg-config and glib.
#
# step one: build glib with everything specified so that pkg-config is not used or required
#
tar xf glib-2.32.2.tar.xz && (cd glib-2.32.2 && LDFLAGS=-L$PREFIX/lib CFLAGS=-I$PREFIX/include ZLIB_CFLAGS=-I$PREFIX/include ZLIB_LIBS="-L$PREFIX/lib -lz" LIBFFI_CFLAGS=-I$PREFIX/lib/libffi-3.0.10/include LIBFFI_LIBS="-L$PREFIX/lib -lffi" ./configure $GLOBAL_CONF --with-pcre=internal $AVOID_ICONV --disable-silent-rules && make && make install) && rm -rf glib-2.32.2 || die "glib build1 failed"
#
# step two: build pkg-config with glib flags specified so that pkg-config is not used or required
#
tar xf pkg-config-0.26.tar.gz && (cd pkg-config-0.26 && GLIB_CFLAGS="-I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include" GLIB_LIBS="-L$PREFIX/lib -lglib-2.0 -lintl" ./configure --prefix=$HOME/gtk/inst && make && make install) && rm -rf pkg-config-0.26 || die "pkg-config build1 failed"
# 
# step three: rebuild glib (still need CFLAGS in order to find libintl)
#
tar xf glib-2.32.2.tar.xz && (cd glib-2.32.2 && LDFLAGS="$GLOBAL_LDFLAGS -L$PREFIX/lib -lintl" CFLAGS="$GLOBAL_CFLAGS -I$PREFIX/include" ./configure --prefix=$HOME/gtk/inst && make && make install) || die "glib build failed"
#
# step four: rebuilding pkg-config now that glib is all set
#
tar xf pkg-config-0.26.tar.gz && (cd pkg-config-0.26 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "pkg build failed"
#
# now we can start on the GTK stack itself
# 

tar xf atk-2.2.0.tar.bz2 && (cd atk-2.2.0 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "atk build failed"
tar xf gnome-common-2.34.0.tar.bz2 && (cd gnome-common-2.34.0 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && export MAKEFLAGS= make && MAKEFLAGS= make install) || die "gnome build failed"
tar xf gtk-osx-docbook-1.0.tar.gz && (cd gtk-osx-docbook-1.0 && JHBUILD_PREFIX=$PREFIX make install) || die "gtk build failed"
# gnome-doc-utils is not parallel-build safe so turn off make -j2
tar xf gnome-doc-utils-0.20.6.tar.bz2 && (cd gnome-doc-utils-0.20.6 && PYTHONPATH=$PREFIX/lib/python2.7/site-packages CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF --disable-scrollkeeper && PYTHONPATH=$PREFIX/lib/python2.7/site-packages MAKEFLAGS= make && PYTHONPATH=$PREFIX/lib/python2.7/site-packages MAKEFLAGS= make install) || die "gnome build failed"
tar xf gtk-doc-1.18.tar.bz2 && (cd gtk-doc-1.18 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure --disable-scrollkeeper --with-xml-catalog=$PREFIX/etc/xml/catalog --prefix=$PREFIX && PYTHONPATH=$PREFIX/lib/python2.7/site-packages make && make install) || die "gtk build failed"
tar xf pixman-0.24.4.tar.gz && (cd pixman-0.24.4 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" sh ./autogen.sh --prefix=$PREFIX && make && make install) || die "pixman build failed"

if [ x$OSX = x ] ; then
    freetype_bytecode_patch=$this_script_dir/misc-patches/freetype-bytecode.patch
    tar xf freetype-2.4.8.tar.bz2 && (cd freetype-2.4.8 && patch -p0 < $freetype_bytecode_patch && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "freetype build failed"
else 
    tar xf freetype-2.4.8.tar.bz2 && (cd freetype-2.4.8 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "freetype build failed"
fi

tar xf fontconfig-2.8.0.tar.gz && (cd fontconfig-2.8.0 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "fontconfig build failed"

if [ x$OSX = x ] ; then 
    #
    # some linux nvidia drivers have buggy support for gradients. this patch
    # lets the user set an environment variable that will force a Cairo workaround
    # to the issue.
    #
    cairo_gradient_patch=$this_script_dir/misc-patches/cairo-gradients.patch
    tar xf cairo-1.10.2.tar.gz && (cd cairo-1.10.2 && patch -p4 < $cairo_gradient_patch && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF $CAIRO_CONF && make && make install) || die "cairo build failed"
else 
    tar xf cairo-1.10.2.tar.gz && (cd cairo-1.10.2 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF $CAIRO_CONF && make && make install) || die "cairo build failed"
fi

tar xf pango-1.29.5.tar.bz2 && (cd pango-1.29.5 && CFLAGS=$GLOBAL_CFLAGS LDFLAGS="$GLOBAL_LDFLAGS" ./configure $GLOBAL_CONF $PANGO_CONF && make && make install) || die "pango build failed"

tar xf gdk-pixbuf-2.25.0.tar.xz && (cd gdk-pixbuf-2.25.0 && LDFLAGS="$GLOBAL_LDFLAGS -L$PREFIX/lib" CFLAGS="-I$PREFIX/include $GLOBAL_CFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "gdk build failed"
# gobject-introspection uses #include <libintl.h> and there's no way to force the "scanner" to look outside the system tree
remove_libintl_h=
if [ ! -f /usr/include/libintl.h ] ; then 
    sudo ln -s $PREFIX/include/libintl.h /usr/include
    remove_libintl_h=yes
fi
tar xf gobject-introspection-1.31.10.tar.xz && (cd gobject-introspection-1.31.10 && LDFLAGS="$GLOBAL_LDFLAGS -L$PREFIX/lib -lintl" CFLAGS="-I$PREFIX/include $GLOBAL_CFLAGS" ./configure $GLOBAL_CONF && make && make install) || die "gobject build failed"
if [ x$remove_libintl_h != x ] ; then
    sudo rm /usr/include/libintl.h
fi
#
# now gtk itself
# 
#
(cd gtk+ && CFLAGS="$GLOBAL_CFLAGS" LDFLAGS="$GLOBAL_LDFLAGS" sh autogen.sh --enable-maintainer-mode --prefix=$PREFIX --libdir=$PREFIX/lib --disable-cups --disable-papi --disable-introspection --with-gdktarget=$GTK_BACKEND && make && make install) || die "GTK build failed"

#
# now gtk-engines
# 
#
(cd gtk-engines && CFLAGS="$GLOBAL_CFLAGS" LDFLAGS="$GLOBAL_LDFLAGS" sh autogen.sh --enable-maintainer-mode --prefix=$PREFIX --libdir=$PREFIX/lib && make && make install) || die "GTK-engines build failed"