summaryrefslogtreecommitdiffstats
path: root/WebKitTools/wx/build-wxwebkit
blob: 3e4c414de515ef90da8d84759fadead9ff889030 (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
#!/bin/bash

# Copyright (C) 2007 Robin Dunn, Kevin Ollivier  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
#
# Driver for the wxWebKit build process.

set -o errexit
#set -o xtrace

#----------------------------------------------------------------------
# Set up the environment

scriptDir="$(cd $(dirname $0);pwd)"
WK_ROOT=$scriptDir/../..
WK_ROOTDIR="$WK_ROOT"

cd $scriptDir

if [ -z $WEBKITOUTPUTDIR ]; then
    WEBKITOUTPUTDIR=`cd $WK_ROOT/WebKitTools/Scripts; perl -e "use webkitdirs; print productDir()"`
fi

WKWINLIBS=WebKitLibraries/win
WINDEPS="         $WKWINLIBS/lib/pthreadVC2.dll"
WINDEPS="$WINDEPS $WKWINLIBS/bin/icuuc40.dll $WKWINLIBS/bin/icudt40.dll $WKWINLIBS/bin/icuin40.dll"
WINDEPS="$WINDEPS $WKWINLIBS/bin/libcurl.dll $WKWINLIBS/bin/libeay32.dll $WKWINLIBS/bin/ssleay32.dll $WKWINLIBS/bin/zlib1.dll"
WINDEPS="$WINDEPS $WKWINLIBS/lib/sqlite3.dll"
WINDEPS="$WINDEPS $WKWINLIBS/bin/libxml2.dll $WKWINLIBS/bin/libxslt.dll" 
WINDEPS="$WINDEPS $WKWINLIBS/bin/iconv.dll" 

# TODO: check that we are running from the root of the source tree...

# cygpath will bork if the dir doesn't exist...
mkdir -p $WEBKITOUTPUTDIR

if [ $OSTYPE == cygwin ]; then
    EXE=.exe
    WK_ROOTDIR=`cygpath -d $WK_ROOT`
    WEBKITOUTPUTDIR=`cygpath -d $WEBKITOUTPUTDIR`
    export WEBKITOUTPUTDIR
    if [ -z $WXWIN ]; then
        echo "Error, you must set WXWIN to your wxWidgets root directory."
        exit 1
    fi
    if [ -z $WX_PREFIX ]; then
        WX_PREFIX=$WXWIN
    fi
    if [ -z $BAKEFILE_PATHS ]; then
        export BAKEFILE_PATHS=$WXWIN/build/bakefiles/wxpresets
    fi
    LINKER=`which link`
    if [ "$LINKER" = "/usr/bin/link" ]; then
        echo "WARNING: wxWebKit builds using MSVC on Windows, but it looks like"
        echo "you have the GCC linker on your path. If /usr/bin/link does NOT point"
        echo "to the MSVC linker, you need to move it or change your path to pick up"
        echo "Microsoft's link.exe program first."
    fi

else
    export WEBKITOUTPUTDIR
    WX_PREFIX=`wx-config --prefix`
    if [ ! -d "$WX_PREFIX" ]; then
        echo "ERROR: Cannot find your wxWidgets installation."
        echo "Make sure wx-config is on your PATH and points to a valid wxWidgets installation."
        exit 1
    fi
    
    CONFIG=`wx-config --selected-config`
    if [ "${CONFIG:0:4}" != "gtk2" -a "${CONFIG:0:3}" != "mac" ]; then
        echo "WARNING: This configuration '$CONFIG' is not currently supported by wxWebKit. Please use the win, mac, or gtk2 port depending on your platform."
    fi
    
    if [ ! -d "$WX_PREFIX/share/bakefile" ]; then
        echo "ERROR: wxWidgets installation does not have wxpresets."
        echo "wx-config is pointing to an installation that does not have Bakefile presets installed. Run `wx-config --version` to ensure your wxWidgets is of version 2.8+."
        exit 1
    fi    
    
    if [ -z $BAKEFILE_PATHS ]; then
        export BAKEFILE_PATHS=$WX_PREFIX/share/bakefile
    fi
fi

# after all that, make sure that BAKEFILE_PATHS was either set
# previously, or by the code above
if [ -z $BAKEFILE_PATHS ]; then
    echo "Error, you must set BAKEFILE_PATHS to the directory containing wxpresets."
    exit 1
fi

#----------------------------------------------------------------------
# process command line args
build_type_set=0

do_bake=0
do_prep=0
do_extras=0
do_build=0
do_clean=0
do_install=0
use_wxgc=0
debug=1
wxdebug=0
wxpython=0
make_args=''
other_args=''

for flag in $*; do
    case $flag in
    bake)   do_bake=1                                      ;;
    prep)   do_prep=1                                      ;;
    build)  do_build=1                                     ;;
    all)    do_extras=1; do_bake=1; do_prep=1; do_build=1  ;;
    clean)  other_args=clean; do_clean=1                   ;;
    wxgc)   use_wxgc=1                                     ;;
    wxdebug) wxdebug=1                                     ;;
    wxpython) wxpython=1                                   ;;
    wxpython-install) wxpython_install=1                   ;;
    *)      export $flag ;; #other_args='$other_args "$flag"'               ;;
    esac
done


#----------------------------------------------------------------------

# if no arguments were passed, do a full build.
if [ $do_bake == 0 -a $do_prep == 0 -a $do_build == 0 -a $do_clean == 0 ]; then
    do_bake=1; do_prep=1; do_build=1
fi

if [ -f $WK_ROOT/WebKitBuild/Configuration ]; then
    BUILD_TYPE=`cat $WK_ROOT/WebKitBuild/Configuration`
    echo "Configuration is: $BUILD_TYPE"
    
    if [ $BUILD_TYPE == "Release" ]; then
        debug=0
    fi
    if [ $BUILD_TYPE == "Debug" ]; then
        debug=1
    fi
    
fi

function do_make {
    dir=$1
    cxxflags=$2
    olddir=$PWD
    shift
    shift
    # NOTE: If we try to do make clean after the Bakefiles were cleaned out, or before they were
    # first generated, we will get errors about missing files, so we need to check that the
    # makefile exists before running it. 
    if [ $OSTYPE == cygwin ]; then
        cd $dir
        if [ -f makefile.vc ]; then
            nmake -f makefile.vc CXXFLAGS="$cxxflags" $@
        fi
        cd $olddir
    else
        if [ -f $dir/GNUmakefile ]; then
            make -C $dir -f GNUmakefile $MAKE_ARGS CXXFLAGS="$cxxflags -fvisibility=hidden -fvisibility-inlines-hidden" $@
        fi
    fi
    if [ $? != 0 ]; then
        exit $? 
    fi
}

# output the first parameter that is a dir and exists
function find_existing_dir {
    for arg in $*; do
        tester=$arg
        if [ $OSTYPE == cygwin ]; then
            tester=`cygpath -u $arg`
        fi
        if [ -d $tester ]; then
            echo $arg
            return
        fi
    done
}


olddir=$PWD

if [ $do_clean != 1 ]; then

    mkdir -p $WEBKITOUTPUTDIR/build

    if [ $do_bake == 1 ]; then
        # bakefile stuff
        cd $WK_ROOT/WebKit/wx
        bakefile_gen
    
        # we need to do this because Bakefile doesn't know which
        # platform it's running on with GNU format, and so it defaults
        # to the standard Unix file endings and linker args.
        if [ "${OSTYPE:0:6}" = "darwin" ]; then    
            sed "s/libjscore.so/libjscore.dylib/" < $WK_ROOT/JavaScriptCore/GNUmakefile > temp
            mv temp $WK_ROOT/JavaScriptCore/GNUmakefile
            
            sed "s/\-shared/\-dynamiclib/" < $WK_ROOT/JavaScriptCore/GNUmakefile > temp
            mv temp $WK_ROOT/JavaScriptCore/GNUmakefile
            
            sed "s/\-shared/\-dynamiclib/" < $WK_ROOT/WebCore/GNUmakefile > temp
            mv temp $WK_ROOT/WebCore/GNUmakefile
            
            sed "s/libwxwebkit.so/libwxwebkit.dylib/" < $WK_ROOT/WebKit/wx/GNUmakefile > temp
            mv temp $WK_ROOT/WebKit/wx/GNUmakefile
            
            sed "s/\-shared/\-dynamiclib/" < $WK_ROOT/WebKit/wx/GNUmakefile > temp
            mv temp $WK_ROOT/WebKit/wx/GNUmakefile
        fi
    fi

    if [ $do_prep == 1 ]; then
        # Other preparation steps
        
        # since the buildbot will wipe the build tree clean sometimes, we need to reinstall
        # the dependencies if they aren't installed.
        if [ "${OSTYPE:0:6}" == "darwin" ]; then
            $WK_ROOT/WebKitTools/wx/install-unix-extras
        fi
        
        
        export CREATE_HASH_TABLE="$WK_ROOT/JavaScriptCore/create_hash_table"
        cd $WK_ROOT/JavaScriptCore
        mkdir -p DerivedSources/JavaScriptCore
        cd DerivedSources/JavaScriptCore
        
        make -f ../../DerivedSources.make JavaScriptCore=../.. BUILT_PRODUCTS_DIR=../.. all FEATURE_DEFINES="ENABLE_DATABASE ENABLE_XSLT ENABLE_JAVASCRIPT_DEBUGGER"
        if [ $? != 0 ]; then
            exit 1
        fi
    
        cd $WK_ROOT/WebCore
        mkdir -p DerivedSources/WebCore
        cd DerivedSources/WebCore
        make -f ../../DerivedSources.make all WebCore=../.. SOURCE_ROOT=../.. FEATURE_DEFINES="ENABLE_DATABASE ENABLE_XSLT ENABLE_JAVASCRIPT_DEBUGGER"
        if [ $? != 0 ]; then
            exit 1
        fi
    fi
fi


if [ $do_build == 1 -o $do_clean == 1 ]; then   
    WXGC_DEFINE=""
    EXTRA_CPPFLAGS=""
    
    if [ "${OSTYPE:0:6}" == "cygwin" ]; then
        PLATFORM_OS="win"
    elif [ "${OSTYPE:0:6}" == "darwin" ]; then
        PLATFORM_OS="mac"
        EXTRA_CPPFLAGS="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040"
        use_wxgc=1
    else
        PLATFORM_OS="linux"
        use_wxgc=1
    fi

    if [ $use_wxgc == 1 ]; then
        WXGC_DEFINE="-DWTF_USE_WXGC=1"
    fi
    WX_EXT=
    if [ "${OSTYPE:0:6}" == "cygwin" -a $wxdebug == 1 ]; then
        WX_EXT=d
    fi
    if [ $wxpython == 1 ]; then
        other_args=WX_PYTHON=1
        WX_EXT=h
        wxdebug=1
    fi

    WINDEPS="$WINDEPS $WXWIN/lib/vc_dll/wxmsw28u${WX_EXT}_core_vc.dll $WXWIN/lib/vc_dll/wxbase28u${WX_EXT}_vc.dll"
    
    do_make $WK_ROOT/JavaScriptCore      "-DBUILDING_WX__=1 $WXGC_DEFINE $EXTRA_CPPFLAGS" WX_DEBUG=$wxdebug DEBUG=$debug WEBKIT_ROOT=$WK_ROOTDIR PLATFORM_OS=$PLATFORM_OS $other_args 

    mkdir -p $WEBKITOUTPUTDIR/JavaScriptCore
    cp -p $WK_ROOT/JavaScriptCore/API/*.h $WEBKITOUTPUTDIR/JavaScriptCore/

    do_make $WK_ROOT/WebCore "-DBUILDING_WX__=1 $WXGC_DEFINE $EXTRA_CPPFLAGS" WX_DEBUG=$wxdebug WEBKIT_ROOT=$WK_ROOTDIR DEBUG=$debug PLATFORM_OS=$PLATFORM_OS $other_args
    do_make $WK_ROOT/WebKit/wx "-DBUILDING_WX__=1 -DWXMAKINGDLL_WEBKIT=1 $WXGC_DEFINE $EXTRA_CPPFLAGS" WX_DEBUG=$wxdebug DEBUG=$debug WEBKIT_ROOT=$WK_ROOTDIR PLATFORM_OS=$PLATFORM_OS $other_args 
    do_make $WK_ROOT/WebKitTools/wx/browser  "-DBUILDING_WX__=1 -DWXUSINGDLL_WEBKIT=1 $WXGC_DEFINE $EXTRA_CPPFLAGS" WX_DEBUG=$wxdebug DEBUG=$debug WEBKIT_ROOT=$WK_ROOTDIR PLATFORM_OS=$PLATFORM_OS $other_args 
    do_make $WK_ROOT/WebKitTools/DumpRenderTree/wx  "-DBUILDING_WX__=1 -DWXUSINGDLL_WEBKIT=1 $WXGC_DEFINE $EXTRA_CPPFLAGS" WX_DEBUG=$wxdebug DEBUG=$debug WEBKIT_ROOT=$WK_ROOTDIR PLATFORM_OS=$PLATFORM_OS $other_args

    if [ $do_clean == 1 ]; then
        rm -rf $WK_ROOT/JavaScriptCore/DerivedSources
        rm -rf $WK_ROOT/WebCore/DerivedSources
        rm -rf $WK_ROOT/WebCore/include/JavaScriptCore
    fi

    if [ $do_build == 1 ]; then 
        if [ "${OSTYPE:0:6}" = "darwin" ]; then
            cd  $WEBKITOUTPUTDIR
            mkdir -p wxBrowser.app/Contents/MacOS
            mkdir -p wxBrowser.app/Contents/Frameworks
            cp wxBrowser wxBrowser.app/Contents/MacOS
            install_name_tool -change libwxwebkit.dylib @executable_path/../Frameworks/libwxwebkit.dylib wxBrowser.app/Contents/MacOS/wxBrowser
            if [ ! -f "$WEBKITOUTPUTDIR/libwxwebkit.dylib" ]; then
                ln -s $WEBKITOUTPUTDIR/libwxwebkit.dylib wxBrowser.app/Contents/Frameworks
            fi
        fi
        
        if [ $wxpython == 1 ]; then
            if [ -z $SWIG ]; then
                SWIG=`which swig`
            fi

            if [ ! -f "$SWIG" ]; then
                echo "ERROR: Cannot find SWIG. Make sure that SWIG 1.3.29 is located on your path.";
                exit 1;
            fi
    
            cd $WK_ROOT/WebKit/wx/bindings/python
            
            SWIG_FLAGS=`python -c "import wx.build.config; import string; print string.join(wx.build.config.swig_args, ' ')"`
            WEBKIT_INCLUDE="-I$WK_ROOT/WebKit/wx"
            if [ "${OSTYPE:0:6}" == "cygwin" ]; then
                WEBKIT_INCLUDE="-I`cygpath -d $WK_ROOT/WebKit/wx`"
            fi
            
            # Determine which include path to use for wxPython's *.i files
            # Options are:
            #    wxPython installed on a posix system
            #    the wxPython win32 devel tarball
            #    a wx source tree from a tarball where wxPython is in the wx dir
            #    a wx source tree from SVN where wxPython is a sibling of the wx dir
            WXPY_INCLUDE=`find_existing_dir \
                $WX_PREFIX/include/wx-2.9/wx/wxPython/i_files \
                $WX_PREFIX/include/wx-2.8/wx/wxPython/i_files \
                $WX_PREFIX/include/wx/wxPython/i_files \
                $WX_PREFIX/wxPython/src \
                $WX_PREFIX/../wxPython/src`
            if [ -z $WXPY_INCLUDE ]; then
                echo "ERROR: Unable to find wxPython's *.i files"
                exit 1
            fi
            
            # Run SWIG
            $SWIG $SWIG_FLAGS -I$WXPY_INCLUDE $WEBKIT_INCLUDE -o webview.cpp webview.i
            cp webview.py $WEBKITOUTPUTDIR/webview.py
                                   
            PY_INCLUDE=`python -c "import sys,distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_inc())"`
            
            if [ "${OSTYPE:0:6}" == "cygwin" ]; then
                PY_LIBDIR=`python -c "import distutils.sysconfig; import sys; sys.stdout.write(distutils.sysconfig.PREFIX)"`
                PY_LIBDIR="$PY_LIBDIR\\Libs"
                PY_LIB=`python -c "import sys; sys.stdout.write('python' + sys.version[:3])"`
                PY_LIB=`python -c "import sys; sys.stdout.write('$PY_LIB'.replace('.', ''))"`
            else
                PY_LIB=`python-config --libs`
                PY_LIBDIR=`python-config --ldflags`
            fi
            
            do_make $WK_ROOT/WebKit/wx/bindings/python "-DBUILDING_WX__=1 -DWXUSINGDLL=1 -DWXUSINGDLL_WEBKIT=1 -I$PY_INCLUDE -I$WX_PREFIX/wxPython/include -I$WX_PREFIX/../wxPython/include $WXGC_DEFINE $EXTRA_CPPFLAGS" \
                WX_DEBUG=$wxdebug DEBUG=$debug WEBKIT_ROOT=$WK_ROOTDIR PLATFORM_OS=$PLATFORM_OS PYTHON_LIB=$PY_LIB PYTHON_LIBDIR=$PY_LIBDIR $other_args
            if [ "${OSTYPE:0:6}" == "cygwin" ]; then
                if [ -f $WEBKITOUTPUTDIR/_webview.pyd -a -f $WEBKITOUTPUTDIR/_webview.dll ]; then
                    rm $WEBKITOUTPUTDIR/_webview.pyd
                    mv $WEBKITOUTPUTDIR/_webview.dll $WEBKITOUTPUTDIR/_webview.pyd
                fi
            fi
        fi
        
    
        if [ "$OSTYPE" == "cygwin" ]; then
            echo "Copying necessary DLLs to run test and sample applications..."
            cd $WK_ROOT
            cp $WINDEPS `cygpath -u $WEBKITOUTPUTDIR`
            chmod +x `cygpath -u $WEBKITOUTPUTDIR/`*.dll
	    if [ -e `cygpath -u $WEBKITOUTPUTDIR/_webview.dll` ]; then
		mv `cygpath -u $WEBKITOUTPUTDIR/_webview.dll` `cygpath -u $WEBKITOUTPUTDIR/_webview.pyd`
	    fi
        fi
        
        BROWSERAPP="wxBrowser"
        
        if [ "${OSTYPE:0:6}" == "darwin" ]; then
            BROWSERAPP="wxBrowser.app/Contents/MacOS/wxBrowser"
        fi
    
        echo ""
        echo ""
        echo "--- BUILD COMPLETE ---"
        echo ""
        echo "Next steps:"
        echo ""
        echo "-- Run '$WK_ROOT/WebKitTools/Scripts/run-javascriptcore-tests --wx' to ensure JSCore tests pass."
        echo ""
        echo "-- Run $WEBKITOUTPUTDIR/$BROWSERAPP to test your wxWebKit build."
        echo ""
        echo ""
    fi
fi

if [ $do_clean == 1 ]; then
    cd $WK_ROOT/WebKit/wx
    bakefile_gen --clean
fi

cd $olddir