File: configure

package info (click to toggle)
qbrew 0.4.1-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 1,724 kB
  • ctags: 1,355
  • sloc: cpp: 7,503; sh: 414; makefile: 18
file content (343 lines) | stat: -rwxr-xr-x 8,232 bytes parent folder | download | duplicates (3)
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
#!/bin/sh
# Copyright 2007-2008 David Johnson
# Configuration script for use with qt/qmake projects. This configure
# script is free software; the author gives unlimited permission to
# copy, distribute and modify it. Portions of this script adapted
# from the Qt configuration script.

PACKAGE=qbrew
PROFILE=qbrew.pro
PREFIX=/usr/local
QTMINVER=4.3.0
LOGFILE=config.log
BUILDDIR=.config

### Messages ########################################################

usage() {
cat <<EOT
Usage: $0 [OPTION]...

This script creates the necessary configuration files for building

Main options:
  --prefix=[path]     Base path for build/install.  Default: /usr/local
  --bindir=[path]     Directory for binaries.  Default: PREFIX/bin
  --datadir=[path]    Directory for data.  Default: PREFIX/share
  --docdir=[path]     Directory for docs.  Default: PREFIX/share/doc
  --qtdir=[path]      Directory where Qt is installed
  --spec=[spec]       Spec to use for QMAKESPEC
  --debug             Enable debug output
  --help              This help text

EOT
}

qt_info() {
cat <<EOF
Be sure you have a properly configured Qt build environment. This application
requires a Qt library version of $QTMINVER or greater. Some systems split Qt
into separate runtime and development packages. If this is your case, make sure
you have both. The 'qmake' command should be in your path, and you may need to
use either the QTDIR environment variable or the --qtdir configure option. It
may be necessary to use the --spec option if qmake cannot determine your build
system. If your qmake has been installed under a different name, then it may be
necessary to use the QMAKE variable.
EOF
}

### Tests ###########################################################

make_test() {
    if [ -z "$MAKE" ] ; then
	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 "ERROR: cannot find 'make' or 'gmake'. Exiting"
            echo "ERROR: cannot find 'make' or 'gmake'. Exiting" >> $LOGFILE
            exit 1
	fi
    fi
}

qmake_test() {
    echo -n "Checking for qmake..."

    # check QTDIR
    if [ -z "$QMAKE" ] ; then
        result=$QTDIR/bin/qmake
        if [ -x "$result" ] ; then
            QMAKE=$result
        fi
        result=$QTDIR/bin/lrelease
        if [ -x "$result" ] ; then
            LRELEASE=$result
        fi
    fi

    # check PATH
    if [ -z "$QMAKE" ] ; then
        result=`which qmake 2>/dev/null`
        if [ -x "$result" ] ; then
            QMAKE=$result
        fi
        result=`which lrelease 2>/dev/null`
        if [ -x "$result" ] ; then
            LRELEASE=$result
        fi
    fi

    # check common rename
    if [ -z "$QMAKE" ] ; then
        result=`which qmake-q4 2>/dev/null`
        if [ -x "$result" ] ; then
            QMAKE=$result
        fi
        result=`which lrelease-q4 2>/dev/null`
        if [ -x "$result" ] ; then
            LRELEASE=$result
        fi
    fi

    # check pkg-config
    if [ -z "$QMAKE" ] ; then
        result=`pkg-config QtCore --variable=exec_prefix 2>/dev/null`
        if [ ! -z "$result" ] ; then
            result=$result/bin/qmake
            if [ -x "$result" ] ; then
                QMAKE=$result
            fi
            result=$result/bin/lrelease
            if [ -x "$result" ] ; then
                LRELEASE=$result
            fi
        fi
    fi

    if [ -z "$QMAKE" ] ; then
        echo "no!"
        echo "ERROR: unable to find the 'qmake' tool"
        echo "ERROR: unable to find the 'qmake' tool" >> $LOGFILE
        qt_info
        exit 1;
    fi

    echo "yes"
    echo "found qmake at $QMAKE" >> $LOGFILE
    echo "found lrelease at $LRELEASE" >> $LOGFILE
}

qtversion_test() {
    echo -n "Checking Qt version..."

    result=`$QMAKE -query QT_VERSION`
    if [ "$result" '<' "$QTMINVER" ] ; then
        echo "no!"
        echo "ERROR: incorrect Qt version found: $result"
        echo "ERROR: incorrect Qt version found: $result" >> $LOGFILE
        qt_info
        exit 1;
    fi      
    echo "$result"
    echo "found Qt version $result" >> $LOGFILE
}

build_test() {
    echo -n "Checking if a simple Qt program builds..."
    cwd=`pwd`
    rm -rf $BUILDDIR
    mkdir -p $BUILDDIR
    cd $BUILDDIR

# write it
cat >config.pro <<EOT
TARGET = config
CONFIG += qt $BUILDMODE
CONFIG -= app_bundle
QT -= gui
HEADERS += config.h
SOURCES += config.cpp
EOT

cat >config.h <<EOT
#include <QtCore>
class Config : public QCoreApplication {
public:
Config(int &argc, char **argv);
};
EOT

cat >config.cpp <<EOT
#include "config.h"
Config::Config(int &argc, char **argv)
: QCoreApplication(argc,argv) {setApplicationName("config");}
int main(int argc, char **argv)
{
Config app(argc,argv);
return 0;
}
EOT

    # build it
    $QMAKE config.pro > /dev/null
    $MAKE >>$LOGFILE 2>&1
    result=$?

    cd $cwd
    rm -rf $BUILDDIR

    if [ "$result" != "0" ] ; then
        echo "no!"
        echo "ERROR: could not build a simple Qt program. See config.log"
        echo "ERROR: could not build a simple Qt program" >> $LOGFILE
        qt_info
        exit 1;
    fi
    echo "yes"
    echo "built simple Qt program" >> $LOGFILE
}

### Parse options ###################################################

parse_options() {
    while [ $# -gt 0 ] ; do
        case "$1" in
            --prefix=*)
                PREFIX="${1#--prefix=}"
                shift
                ;;

            --bindir=*)
                BINDIR="${1#--bindir=}"
                shift
                ;;

            --datadir=*)
                DATADIR="${1#--datadir=}"
                shift
                ;;

            --docdir=*)
                DOCDIR="${1#--docdir=}"
                shift
                ;;

            --qtdir=*)
                QTDIR="${1#--qtdir=}"
                shift
                ;;

            --spec=*)
                QMAKESPEC="${1#--spec=}"
                shift
                ;;

            --debug=*)
                ENABLE_DEBUG="${1#--debug=}"
                shift
                ;;

            --debug)
                ENABLE_DEBUG="yes"
                shift
                ;;

            --help) usage; exit ;;
            *) usage; exit 1 ;;
        esac
    done
}

### Main ############################################################

echo "Configuring $PACKAGE package..."

### initialize

SOURCEPATH=`dirname $0`
SOURCEPATH=`(cd $SOURCEPATH; /bin/pwd)`
BUILDDIR=$SOURCEPATH/$BUILDDIR
LOGFILE=$SOURCEPATH/$LOGFILE

if [ -e $LOGFILE ] ; then rm $LOGFILE ; fi
echo "configure command: $0 $@" > $LOGFILE
echo `date` >>$LOGFILE

### parse command options

parse_options $@

QMAKE=${QMAKE:-}
LRELEASE=${LRELEASE:-}
PREFIX=${PREFIX:-/usr/local}
BINDIR=${BINDIR:-$PREFIX/bin}
DATADIR=${DATADIR:-$PREFIX/share/$PACKAGE}
DOCDIR=${DOCDIR:-$PREFIX/share/doc/$PACKAGE}

if [ "$ENABLE_DEBUG" = "yes" ] ; then
    BUILDMODE="debug"
else
    BUILDMODE="release"
fi

echo >> $LOGFILE
echo PREFIX=$PREFIX >> $LOGFILE
echo BINDIR=$BINDIR >> $LOGFILE
echo DATADIR=$DATADIR >> $LOGFILE
echo DOCDIR=$DOCDIR >> $LOGFILE
echo QTDIR=$QTDIR >> $LOGFILE
echo QMAKESPEC=$QMAKESPEC >> $LOGFILE
echo ENABLE_DEBUG=$ENABLE_DEBUG >> $LOGFILE
echo BUILDMODE=$BUILDMODE >> $LOGFILE
echo >> $LOGFILE

### tests

make_test
qmake_test
qtversion_test
build_test

### export variables

export BINDIR
export DATADIR
export DOCDIR
if [ ! -z $QTDIR ] ; then
    export QTDIR
fi
if [ ! -z $QMAKESPEC ] ; then
    export QMAKESPEC
fi

### create translation

echo "Creating translations"

$LRELEASE $PROFILE > /dev/null 2>> $LOGFILE

### create Makefile

echo "Creating Makefile"

$QMAKE "QMAKE_CXXFLAGS=\"$CXXFLAGS\"" "QMAKE_LFLAGS=\"$LDFLAGS\"" \
    -o $SOURCEPATH/Makefile "CONFIG+=$BUILDMODE configure" \
    $PROFILE > /dev/null 2>> $LOGFILE

if [ $? != "0" ] ; then
    echo "ERROR: could not create Makefile. See config.log"
    echo "ERROR: could not create Makefile." >> $LOGFILE
    echo "Command: $QMAKE -o $SOURCEPATH/Makefile \"CONFIG+=$BUILDMODE\" $PROFILE" >> $LOGFILE
    exit 1
fi

### finished

echo
echo "$PACKAGE configured successfully"
echo "Relax, don't worry, have a homebrew!"
echo