summaryrefslogtreecommitdiffstats
path: root/configure
blob: 1f403f2b84c0ee96461ff4b98769bd74c5428ecb (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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
#!/bin/sh
#############################################################################
##
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
## All rights reserved.
## Contact: Nokia Corporation (qt-info@nokia.com)
##
## This file is the build configuration utility of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:LGPL$
## No Commercial Usage
## This file contains pre-release code and may not be distributed.
## You may use this file in accordance with the terms and conditions
## contained in the Technology Preview License Agreement accompanying
## this package.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL included in the
## packaging of this file.  Please review the following information to
## ensure the GNU Lesser General Public License version 2.1 requirements
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## In addition, as a special exception, Nokia gives you certain additional
## rights.  These rights are described in the Nokia Qt LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
## If you have questions regarding the use of this file, please contact
## Nokia at qt-info@nokia.com.
##
##
##
##
##
##
##
##
## $QT_END_LICENSE$
##
#############################################################################

#-------------------------------------------------------------------------------
# script initialization
#-------------------------------------------------------------------------------

# the name of this script
relconf=`basename $0`
# the directory of this script is the "source tree"
relpath=`dirname $0`
relpath=`(cd "$relpath"; /bin/pwd)`
# the current directory is the "build tree" or "object tree"
outpath=`/bin/pwd`

#-------------------------------------------------------------------------------
# operating system detection
#-------------------------------------------------------------------------------

# need that throughout the script
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown

# detect the "echo without newline" style. usage: echo $ECHO_N "<string>$ECHO_C"
if echo '\c' | grep '\c' >/dev/null; then
    ECHO_N=-n
else
    ECHO_C='\c'
fi

PLATFORM_MAC=no
if [ -d /System/Library/Frameworks/Carbon.framework ]; then
    PLATFORM_MAC=yes
fi

#-------------------------------------------------------------------------------
# print some introductory text
#-------------------------------------------------------------------------------

cat <<EOF

This is the QtOpenCL configuration utility.

EOF

if [ ! -f "$relpath/opencl.pro" ] ; then
    echo "Could not find opencl.pro ... aborting"
    exit 1
fi

#-------------------------------------------------------------------------------
# initalize variables
#-------------------------------------------------------------------------------

# Use CC/CXX to run config.tests
mkdir -p "$outpath/config.tests"

# QTDIR may be set and point to an old or system-wide Qt installation
unset QTDIR

# initalize internal variables
CFG_OPENCL=yes
CFG_OPENCL_1_1=auto
CFG_OPENCLGL=auto
CFG_GCOV=no

OPT_SHADOW=maybe
OPT_QMAKE=
OPT_VERBOSE=no
OPT_HELP=
D_FLAGS=
I_FLAGS=
INCLUDEPATH=
L_FLAGS=
RPATH_FLAGS=
l_FLAGS=

#-------------------------------------------------------------------------------
# parse command line arguments
#-------------------------------------------------------------------------------

# parse the arguments, setting things to "yes" or "no"
while [ "$#" -gt 0 ]; do
    CURRENT_OPT="$1"
    UNKNOWN_ARG=no
    case "$1" in
    #Autoconf style options
    --enable-*)
        VAR=`echo $1 | sed "s,^--enable-\(.*\),\1,"`
        VAL=yes
        ;;
    --disable-*)
        VAR=`echo $1 | sed "s,^--disable-\(.*\),\1,"`
        VAL=no
        ;;
    --*=*)
        VAR=`echo $1 | sed "s,^--\(.*\)=.*,\1,"`
        VAL=`echo $1 | sed "s,^--.*=\(.*\),\1,"`
        ;;
    --no-*)
        VAR=`echo $1 | sed "s,^--no-\(.*\),\1,"`
        VAL=no
        ;;
    --*)
        VAR=`echo $1 | sed "s,^--\(.*\),\1,"`
        VAL=yes
        ;;
    #Qt style no options
    -no-*)
        VAR=`echo $1 | sed "s,^-no-\(.*\),\1,"`
        VAL=no
        ;;
    #Qt style yes options
    -opencl|-verbose|-v|-help|-h|-gcov)
        VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
        VAL=yes
        ;;
    -openclgl)
        VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
        VAL=yes
        ;;
    #Qt style options that pass an argument
    -qmake)
        VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
        shift
        VAL="$1"
        ;;
    #Qt style complex options in one command
    -enable-*|-disable-*)
        VAR=`echo $1 | sed "s,^-\([^-]*\)-.*,\1,"`
        VAL=`echo $1 | sed "s,^-[^-]*-\(.*\),\1,"`
        ;;
    -D?*|-D)
        VAR="add_define"
        if [ "$1" = "-D" ]; then
            shift
            VAL="$1"
        else
            VAL=`echo $1 | sed 's,-D,,'`
        fi
        ;;
    -I?*|-I)
        VAR="add_ipath"
        if [ "$1" = "-I" ]; then
            shift
            VAL="$1"
        else
            VAL=`echo $1 | sed 's,-I,,'`
        fi
        ;;
    -L?*|-L)
        VAR="add_lpath"
        if [ "$1" = "-L" ]; then
            shift
            VAL="$1"
        else
            VAL=`echo $1 | sed 's,-L,,'`
        fi
        ;;
    -R?*|-R)
        VAR="add_rpath"
        if [ "$1" = "-R" ]; then
            shift
            VAL="$1"
        else
            VAL=`echo $1 | sed 's,-R,,'`
        fi
        ;;
    -l?*)
        VAR="add_link"
        VAL=`echo $1 | sed 's,-l,,'`
        ;;
    -F?*|-F)
        VAR="add_fpath"
        if [ "$1" = "-F" ]; then
            shift
            VAL="$1"
        else
            VAL=`echo $1 | sed 's,-F,,'`
        fi
        ;;
    -fw?*|-fw)
        VAR="add_framework"
        if [ "$1" = "-fw" ]; then
            shift
            VAL="$1"
        else
            VAL=`echo $1 | sed 's,-fw,,'`
        fi
        ;;
    -*)
        VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
        VAL="unknown"
        ;;
    *)
        UNKNOWN_ARG=yes
        ;;
    esac
    if [ "$UNKNOWN_ARG" = "yes" ]; then
        echo "$1: unknown argument"
        OPT_HELP=yes
        ERROR=yes
        shift
        continue
     fi
    shift

    UNKNOWN_OPT=no
    case "$VAR" in
    opencl)
        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
            CFG_OPENCL="$VAL"
        else
            UNKNOWN_OPT=yes
        fi
        ;;
    openclgl)
        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
            CFG_OPENCLGL="$VAL"
        else
            UNKNOWN_OPT=yes
        fi
        ;;
    gcov)
        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
            CFG_GCOV="$VAL"
        else
            UNKNOWN_OPT=yes
        fi
        ;;
    qmake)
        OPT_QMAKE="$VAL"
	;;
    h|help)
        if [ "$VAL" = "yes" ]; then
            OPT_HELP="$VAL"
        else
            UNKNOWN_OPT=yes
        fi
        ;;
    v|verbose)
        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
            OPT_VERBOSE="$VAL"
        else
            UNKNOWN_OPT=yes
        fi
        ;;
    add_define)
        D_FLAGS="$D_FLAGS -D\"$VAL\""
        ;;
    add_ipath)
        I_FLAGS="$I_FLAGS -I\"${VAL}\""
        INCLUDEPATH="$INCLUDEPATH \"${VAL}\""
        ;;
    add_lpath)
        L_FLAGS="$L_FLAGS -L\"${VAL}\""
        ;;
    add_rpath)
        RPATH_FLAGS="$RPATH_FLAGS \"${VAL}\""
        ;;
    add_link)
        l_FLAGS="$l_FLAGS -l\"${VAL}\""
        ;;
    add_fpath)
        if [ "$PLATFORM_MAC" = "yes" ]; then
            L_FLAGS="$L_FLAGS -F\"${VAL}\""
            I_FLAGS="$I_FLAGS -F\"${VAL}\""
        else
            UNKNOWN_OPT=yes
        fi
        ;;
    add_framework)
        if [ "$PLATFORM_MAC" = "yes" ]; then
            l_FLAGS="$l_FLAGS -framework \"${VAL}\""
        else
            UNKNOWN_OPT=yes
        fi
        ;;
    *)
        UNKNOWN_OPT=yes
        ;;
    esac
    if [ "$UNKNOWN_OPT" = "yes" ]; then
        echo "${CURRENT_OPT}: invalid command-line switch"
        OPT_HELP=yes
        ERROR=yes
    fi
done

#-------------------------------------------------------------------------------
# build tree initialization
#-------------------------------------------------------------------------------

# where to find which..
unixtests="$relpath/config.tests/unix"
mactests="$relpath/config.tests/mac"
symbiantests="$relpath/config.tests/symbian"
WHICH="$unixtests/which.test"

### skip this if the user just needs help...
if [ "$OPT_HELP" != "yes" ]; then

# is this a shadow build?
if [ "$OPT_SHADOW" = "maybe" ]; then
    OPT_SHADOW=no
    if [ "$relpath" != "$outpath" ] && [ '!' -f "$outpath/configure" ]; then
        if [ -h "$outpath" ]; then
            [ "$relpath" -ef "$outpath" ] || OPT_SHADOW=yes
        else
            OPT_SHADOW=yes
        fi
    fi
fi

# find a make command
if [ -z "$MAKE" ]; then
    MAKE=
    for mk in gmake make; do
        if "$WHICH" $mk >/dev/null 2>&1; then
            MAKE=`"$WHICH" $mk`
            break
        fi
    done
    if [ -z "$MAKE" ]; then
        echo >&2 "You don't seem to have 'make' or 'gmake' in your PATH."
        echo >&2 "Cannot proceed."
        exit 1
    fi
    # export MAKE, we need it later in the config.tests
    export MAKE
fi

fi ### help

#-------------------------------------------------------------------------------
# find qmake and check that it is at least 4.6.0
#-------------------------------------------------------------------------------

if [ -z "$OPT_QMAKE" ]; then
    OPT_QMAKE=`$WHICH qmake 2>/dev/null`
    if [ -z "$OPT_QMAKE" ]; then
        echo "$0: could not find qmake; specify the -qmake option"
        exit 1
    fi
fi
QMAKE_VERSION=`$OPT_QMAKE -v 2>/dev/null | grep 'Using Qt version' | \
               sed 's/^Using Qt version //' | \
               sed 's/ in .*$//'`
case "$QMAKE_VERSION" in
    4.0.*|4.1.*|4.2.*|4.3.*|4.4.*|4.5.*) QMAKE_VERSION="" ;;
    4.*) ;;
    *) QMAKE_VERSION="" ;;
esac
if [ -z "$QMAKE_VERSION" ]; then
    echo "$0: $OPT_QMAKE must be at least version 4.6.0"
    echo "Specify the correct qmake binary with the -qmake option"
    exit 1
fi

#-------------------------------------------------------------------------------
# help - interactive parts of the script _after_ this section please
#-------------------------------------------------------------------------------

# next, emit a usage message if something failed.
if [ "$OPT_HELP" = "yes" ]; then
    [ "x$ERROR" = "xyes" ] && echo
    cat <<EOF
Usage:  $relconf [-h] [-qmake <path>] [-no-openclgl] [-verbose]

Configure options:

    -qmake <path> ...... Path to the qmake binary to use.
                         (default is "qmake" on the PATH)

    -no-openclgl ....... Do not use OpenCL/OpenGL interoperability.
 *  -openclgl .......... Use OpenCL/OpenGL interoperability.

    -gcov .............. Use gcov for coverage testing (g++ only).

    -I <string> ........ Add an explicit include path for OpenCL.
    -L <string> ........ Add an explicit library path for OpenCL.
    -l <string> ........ Change the library name for OpenCL.
    -fw <string> ....... Specify the Mac framework for OpenCL
                         (default is "OpenCL").

    -help, -h .......... Display this information.
    -verbose, -v ....... Print verbose information about each
                         step of the configure process.
EOF

   exit 0
fi # Help

#-------------------------------------------------------------------------------
# tests that need qmake
#-------------------------------------------------------------------------------

XQMAKESPEC=""
QMAKE_CONFIG=""

# if we don't have any -l flags, then assume -lOpenCL.
if [ -z "$l_FLAGS" ] ; then
    if [ "$UNAME_SYSTEM" = "Linux" ] ; then
        l_FLAGS=" -lOpenCL"
    fi
    if [ "$PLATFORM_MAC" = "yes" ] ; then
        l_FLAGS=" -framework OpenCL"
    fi
fi

# detect OpenCL
if "$unixtests/compile.test" "$OPT_QMAKE" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/opencl "opencl" $L_FLAGS $I_FLAGS $l_FLAGS $D_FLAGS; then
    CFG_OPENCL=yes
else
    CFG_OPENCL=no
fi

# detect OpenCL/OpenGL interoperation
if [ "${CFG_OPENCLGL}" = "auto" ]; then
    if "$unixtests/compile.test" "$OPT_QMAKE" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/openclgl "openclgl" $L_FLAGS $I_FLAGS $l_FLAGS $D_FLAGS; then
	CFG_OPENCLGL=yes
    else
	CFG_OPENCLGL=no
    fi
fi

# detect OpenCL 1.1
if [ "${CFG_OPENCL_1_1}" = "auto" ]; then
    if "$unixtests/compile.test" "$OPT_QMAKE" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/opencl11 "opencl11" $L_FLAGS $I_FLAGS $l_FLAGS $D_FLAGS; then
	CFG_OPENCL_1_1=yes
    else
	CFG_OPENCL_1_1=no
    fi
fi

#-------------------------------------------------------------------------------
# give feedback on configuration
#-------------------------------------------------------------------------------

echo "Qt version ............. $QMAKE_VERSION"
echo "qmake .................. $OPT_QMAKE"
echo "OpenCL 1.0 ............. $CFG_OPENCL"
echo "OpenCL 1.1 ............. $CFG_OPENCL_1_1"
echo "OpenCL/OpenGL interop .. $CFG_OPENCLGL"
echo "Extra QMAKE_CXXFLAGS ...$D_FLAGS" | sed 's/"//g'
echo "Extra INCLUDEPATH ......$INCLUDEPATH" | sed 's/"//g'
echo "Extra LIBS .............$L_FLAGS$l_FLAGS" | sed 's/"//g'
echo ""

if [ "x$CFG_OPENCL" != "xyes" ] ; then
    echo "Could not detect an OpenCL implementation ... aborting"
    if [ "x$OPT_VERBOSE" = "xno" ] ; then
        echo "Use the -verbose option for more information"
    fi
    exit 1
fi

#-------------------------------------------------------------------------------
# build makefiles based on the configuration
#-------------------------------------------------------------------------------

QMAKE_OPTIONS=""
if [ "x$CFG_OPENCLGL" != "xyes" ] ; then
    QMAKE_OPTIONS="$QMAKE_OPTIONS CONFIG+=no_cl_gl"
fi
if [ "x$CFG_OPENCL_1_1" = "xyes" ] ; then
    QMAKE_OPTIONS="$QMAKE_OPTIONS CONFIG+=opencl_1_1"
fi
if [ "x$CFG_GCOV" = "xyes" ] ; then
    QMAKE_OPTIONS="$QMAKE_OPTIONS LIBS*=-fprofile-arcs"
    QMAKE_OPTIONS="$QMAKE_OPTIONS LIBS*=-ftest-coverage"
    QMAKE_OPTIONS="$QMAKE_OPTIONS QMAKE_CXXFLAGS*=-fprofile-arcs"
    QMAKE_OPTIONS="$QMAKE_OPTIONS QMAKE_CXXFLAGS*=-ftest-coverage"
    QMAKE_OPTIONS="$QMAKE_OPTIONS CONFIG+=gcov"
fi
QMAKE_OPTIONS="$QMAKE_OPTIONS CONFIG+=opencl_configure"

if $OPT_QMAKE $QMAKE_OPTIONS \
        "LIBS*=$L_FLAGS" \
        "LIBS*=$l_FLAGS" \
        "INCLUDEPATH*=$INCLUDEPATH" \
        "QMAKE_CXXFLAGS*=$D_FLAGS" "$relpath/opencl.pro" ; then
    echo "QtOpenCL has been configured.  Run '$MAKE' to build."
    echo ""
    exit 0
else
    exit 1
fi