~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to iris/example/conntest/configure

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2005-09-14 16:33:49 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050914163349-3zacov4afysz5cw5
Tags: 0.9.3-2ubuntu1
* Sync with debian
* Applied patch to psi.desktop to start psi without gpg-agent use (known
  issue)
* Updated README.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
show_usage() {
 
4
cat <<EOT
 
5
Usage: ./configure [OPTION]...
 
6
 
 
7
This script creates necessary configuration files to build/install.
 
8
 
 
9
Main options:
 
10
  --prefix=[path]    Base path for build/install.  Default: /usr/local
 
11
  --bindir=[path]    Directory for binaries.  Default: PREFIX/bin
 
12
  --qtdir=[path]     Directory where Qt is installed.
 
13
  --debug            Enable debug output.
 
14
  --help             This help text.
 
15
 
 
16
EOT
 
17
}
 
18
 
 
19
while [ $# -gt 0 ]; do
 
20
        case "$1" in
 
21
                --prefix=*)
 
22
                        PREFIX="${1#--prefix=}"
 
23
                        shift
 
24
                        ;;
 
25
 
 
26
                --bindir=*)
 
27
                        BINDIR="${1#--bindir=}"
 
28
                        shift
 
29
                        ;;
 
30
 
 
31
                --qtdir=*)
 
32
                        QTDIR="${1#--qtdir=}"
 
33
                        shift
 
34
                        ;;
 
35
 
 
36
                --debug)
 
37
                        QC_DEBUG="Y"
 
38
                        shift
 
39
                        ;;
 
40
                --help) show_usage; exit ;;
 
41
                *) show_usage; exit ;;
 
42
        esac
 
43
done
 
44
 
 
45
PREFIX=${PREFIX:-/usr/local}
 
46
BINDIR=${BINDIR:-$PREFIX/bin}
 
47
 
 
48
echo "Configuring Iris Conntest ..."
 
49
 
 
50
if [ "$QC_DEBUG" = "Y" ]; then
 
51
echo
 
52
echo PREFIX=$PREFIX
 
53
echo BINDIR=$BINDIR
 
54
echo QTDIR=$QTDIR
 
55
echo
 
56
fi
 
57
 
 
58
printf "Verifying Qt 3.x Multithreaded (MT) build environment ... "
 
59
 
 
60
if [ -z "$QTDIR" ]; then
 
61
        if [ "$QC_DEBUG" = "Y" ]; then
 
62
                echo \$QTDIR not set... trying to find Qt manually
 
63
        fi
 
64
        for p in /usr/lib/qt /usr/share/qt /usr/share/qt3 /usr/local/lib/qt /usr/local/share/qt /usr/lib/qt3 /usr/local/lib/qt3 /usr/X11R6/share/qt /usr/qt/3 ; do
 
65
                if [ -d "$p/mkspecs" ]; then
 
66
                        QTDIR=$p
 
67
                        break;
 
68
                fi;
 
69
        done
 
70
        if [ -z "$QTDIR" ]; then
 
71
                echo fail
 
72
                echo
 
73
                echo "Unable to find Qt 'mkspecs'.  Perhaps you need to"
 
74
                echo "install the Qt 3 development utilities.  You may download"
 
75
                echo "them either from the vendor of your operating system"
 
76
                echo "or from http://www.trolltech.com/"
 
77
                echo
 
78
                echo "If you're sure you have the Qt development utilities"
 
79
                echo "installed, you might try using the --qtdir option."
 
80
                echo
 
81
                exit 1;
 
82
        fi
 
83
        if [ ! -x "$QTDIR/bin/moc" ]; then
 
84
                m=`which moc 2>/dev/null`
 
85
                if [ ! -x "$m" ]; then
 
86
                        echo fail
 
87
                        echo
 
88
                        echo "We found Qt in $QTDIR, but we were unable to locate"
 
89
                        echo "the moc utility.  It was not found in $QTDIR/bin"
 
90
                        echo "nor in PATH.  This seems to be a very unusual setup."
 
91
                        echo "You might try using the --qtdir option."
 
92
                        echo
 
93
                        exit 1;
 
94
                fi
 
95
                qtpre=`echo $m | awk '{ n = index($0, "/bin/moc"); if (!n) { exit 1; } print substr($0, 0, n-1); exit 0; }' 2>/dev/null`
 
96
                ret="$?"
 
97
                if [ "$ret" != "0" ]; then
 
98
                        echo fail
 
99
                        echo
 
100
                        echo "We found Qt in $QTDIR, but the location of moc"
 
101
                        echo "($m) is not suitable for use with this build system."
 
102
                        echo "This is a VERY unusual and likely-broken setup.  You"
 
103
                        echo "should contact the maintainer of your Qt package."
 
104
                        echo
 
105
                        exit 1;
 
106
                fi
 
107
                QTDIR=$qtpre
 
108
        fi
 
109
fi
 
110
 
 
111
if [ ! -x "$QTDIR/bin/qmake" ]; then
 
112
        if [ "$QC_DEBUG" = "Y" ]; then
 
113
                echo Warning: qmake not in \$QTDIR/bin/qmake
 
114
                echo trying to find it in \$PATH
 
115
        fi
 
116
        qm=`which qmake 2>/dev/null`
 
117
        if [ -x "$qm" ]; then
 
118
                if [ "$QC_DEBUG" = "Y" ]; then
 
119
                        echo qmake found in $qm
 
120
                fi
 
121
        else
 
122
                echo fail
 
123
                echo
 
124
                echo Sorry, you seem to have a very unusual setup,
 
125
                echo or I missdetected \$QTDIR=$QTDIR
 
126
                echo
 
127
                echo Please set \$QTDIR manually and make sure that
 
128
                echo \$QTDIR/bin/qmake exists.
 
129
                echo
 
130
                exit 1;
 
131
        fi
 
132
else
 
133
        qm=$QTDIR/bin/qmake
 
134
fi
 
135
 
 
136
gen_files() {
 
137
cat >$1/modules.cpp <<EOT
 
138
 
 
139
EOT
 
140
cat >$1/modules_new.cpp <<EOT
 
141
 
 
142
EOT
 
143
cat >$1/conf.cpp <<EOT
 
144
#include<stdio.h>
 
145
#include<stdlib.h>
 
146
#include<qstring.h>
 
147
#include<qdict.h>
 
148
#include<qptrlist.h>
 
149
#include<qfileinfo.h>
 
150
#include<qfile.h>
 
151
#include<qdir.h>
 
152
#include<qstringlist.h>
 
153
#include<qobject.h>
 
154
 
 
155
class MocTestObject : public QObject
 
156
{
 
157
        Q_OBJECT
 
158
public:
 
159
        MocTestObject() {}
 
160
};
 
161
 
 
162
class Conf;
 
163
 
 
164
class ConfObj
 
165
{
 
166
public:
 
167
        ConfObj(Conf *c);
 
168
        virtual ~ConfObj();
 
169
 
 
170
        virtual QString name() const=0;
 
171
        virtual QString shortname() const=0;
 
172
        virtual QString checkString() const;
 
173
        virtual QString resultString() const;
 
174
        virtual bool exec()=0;
 
175
 
 
176
        Conf *conf;
 
177
        bool required;
 
178
        bool disabled;
 
179
};
 
180
 
 
181
typedef QPtrList<ConfObj> ConfObjList;
 
182
typedef QPtrListIterator<ConfObj> ConfObjListIt;
 
183
 
 
184
class Conf
 
185
{
 
186
public:
 
187
        Conf() : vars(17)
 
188
        {
 
189
                list.setAutoDelete(true);
 
190
                vars.setAutoDelete(true);
 
191
 
 
192
                vars.insert("QMAKE_INCDIR_X11", new QString(X11_INC));
 
193
                vars.insert("QMAKE_LIBDIR_X11", new QString(X11_LIBDIR));
 
194
                vars.insert("QMAKE_LIBS_X11",   new QString(X11_LIB));
 
195
                vars.insert("QMAKE_CC",         new QString(CC));
 
196
 
 
197
                do_debug = false;
 
198
                done_debug = false;
 
199
        }
 
200
 
 
201
        ~Conf()
 
202
        {
 
203
        }
 
204
 
 
205
        void added(ConfObj *o)
 
206
        {
 
207
                list.append(o);
 
208
        }
 
209
 
 
210
        QString getenv(const QString &var)
 
211
        {
 
212
                char *p = ::getenv(var.latin1());
 
213
                if(!p)
 
214
                        return QString::null;
 
215
                return QString(p);
 
216
        }
 
217
 
 
218
        void debug(const QString &s)
 
219
        {
 
220
                if(do_debug) {
 
221
                        if(!done_debug)
 
222
                                printf("\n");
 
223
                        done_debug = true;
 
224
                        printf(" * %s\n", s.latin1());
 
225
                }
 
226
        }
 
227
 
 
228
        bool exec()
 
229
        {
 
230
                if(getenv("QC_DEBUG") == "Y")
 
231
                        do_debug = true;
 
232
 
 
233
                ConfObjListIt it(list);
 
234
                for(ConfObj *o; (o = it.current()); ++it) {
 
235
                        // if this was a disabled-by-default option, check if it was enabled
 
236
                        if(o->disabled) {
 
237
                                QString v = QString("QC_ENABLE_") + o->shortname();
 
238
                                if(getenv(v) != "Y")
 
239
                                        continue;
 
240
                        }
 
241
                        // and the opposite?
 
242
                        else {
 
243
                                QString v = QString("QC_DISABLE_") + o->shortname();
 
244
                                if(getenv(v) == "Y")
 
245
                                        continue;
 
246
                        }
 
247
 
 
248
                        QString check = o->checkString();
 
249
                        if(check.isEmpty())
 
250
                                check = QString("Checking for %1 ...").arg(o->name());
 
251
                        printf("%s", check.latin1());
 
252
                        fflush(stdout);
 
253
 
 
254
                        done_debug = false;
 
255
                        bool ok = o->exec();
 
256
 
 
257
                        QString result = o->resultString();
 
258
                        if(result.isEmpty()) {
 
259
                                if(ok)
 
260
                                        result = "yes";
 
261
                                else
 
262
                                        result = "no";
 
263
                        }
 
264
                        if(done_debug)
 
265
                                printf(" -> %s\n", result.latin1());
 
266
                        else
 
267
                                printf(" %s\n", result.latin1());
 
268
 
 
269
                        if(!ok && o->required) {
 
270
                                printf("\nError: need %s!\n", o->name().latin1());
 
271
                                return false;
 
272
                        }
 
273
                }
 
274
                return true;
 
275
        }
 
276
 
 
277
        const QString & qvar(const QString &s)
 
278
        {
 
279
                QString *p = vars.find(s);
 
280
                if(p)
 
281
                        return *p;
 
282
                else
 
283
                        return blank;
 
284
        }
 
285
 
 
286
        QString expandIncludes(const QString &inc)
 
287
        {
 
288
                return QString("-I") + inc;
 
289
        }
 
290
 
 
291
        QString expandLibs(const QString &lib)
 
292
        {
 
293
                return QString("-L") + lib;
 
294
        }
 
295
 
 
296
        int doCommand(const QString &s)
 
297
        {
 
298
                debug(QString("[%1]").arg(s));
 
299
                QString fullcmd;
 
300
                if(do_debug)
 
301
                        fullcmd = s;
 
302
                else
 
303
                        fullcmd = s + " 1>/dev/null 2>/dev/null";
 
304
                int r = system(fullcmd.latin1());
 
305
                debug(QString("returned: %1").arg(r));
 
306
                return r;
 
307
        }
 
308
 
 
309
        bool doCompileAndLink(const QString &filedata, const QString &flags, int *retcode=0)
 
310
        {
 
311
                QDir dir(".");
 
312
                QString fname = "atest.c";
 
313
                QString out = "atest";
 
314
                QFile f(fname);
 
315
                QCString cs = filedata.latin1();
 
316
                if(!f.open(IO_WriteOnly | IO_Truncate)) {
 
317
                        debug("unable to open atest.c for writing");
 
318
                        return false;
 
319
                }
 
320
                if(f.writeBlock(cs.data(), cs.length()) == -1) {
 
321
                        debug("error writing to atest.c");
 
322
                        return false;
 
323
                }
 
324
                f.close();
 
325
 
 
326
                debug(QString("Wrote atest.c:\n%1").arg(filedata));
 
327
 
 
328
                QString str = qvar("QMAKE_CC") + ' ' + fname + " -o " + out;
 
329
                if(!flags.isEmpty()) {
 
330
                        str += ' ';
 
331
                        str += flags;
 
332
                }
 
333
 
 
334
                int r = doCommand(str);
 
335
                if(r == 0 && retcode)
 
336
                        *retcode = doCommand(QString("./") + out);
 
337
                dir.remove(fname);
 
338
                dir.remove(out);
 
339
                if(r != 0)
 
340
                        return false;
 
341
                return true;
 
342
        }
 
343
 
 
344
        bool checkHeader(const QString &path, const QString &h)
 
345
        {
 
346
                QFileInfo fi(path + '/' + h);
 
347
                if(fi.exists())
 
348
                        return true;
 
349
                return false;
 
350
        }
 
351
 
 
352
        bool findHeader(const QString &h, const QStringList &ext, QString *inc)
 
353
        {
 
354
                if(checkHeader("/usr/include", h)) {
 
355
                        *inc = "";
 
356
                        return true;
 
357
                }
 
358
                QStringList dirs;
 
359
                dirs += "/usr/local/include";
 
360
                dirs += ext;
 
361
                for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) {
 
362
                        if(checkHeader(*it, h)) {
 
363
                                *inc = *it;
 
364
                                return true;
 
365
                        }
 
366
                }
 
367
                return false;
 
368
        }
 
369
 
 
370
        bool checkLibrary(const QString &path, const QString &name)
 
371
        {
 
372
                QString str =
 
373
                        "int main()\n"
 
374
                        "{\n"
 
375
                        "    return 0;\n"
 
376
                        "}\n";
 
377
 
 
378
                QString extra;
 
379
                if(!path.isEmpty())
 
380
                        extra += QString("-L") + path + ' ';
 
381
                extra += QString("-l") + name;
 
382
                if(!doCompileAndLink(str, extra))
 
383
                        return false;
 
384
                return true;
 
385
        }
 
386
 
 
387
        bool findLibrary(const QString &name, QString *lib)
 
388
        {
 
389
                if(checkLibrary("", name)) {
 
390
                        *lib = "";
 
391
                        return true;
 
392
                }
 
393
                if(checkLibrary("/usr/local/lib", name)) {
 
394
                        *lib = "/usr/local/lib";
 
395
                        return true;
 
396
                }
 
397
                return false;
 
398
        }
 
399
 
 
400
        void addDefine(const QString &str)
 
401
        {
 
402
                if(DEFINES.isEmpty())
 
403
                        DEFINES = str;
 
404
                else
 
405
                        DEFINES += QString(" ") + str;
 
406
                debug(QString("DEFINES += %1").arg(str));
 
407
        }
 
408
 
 
409
        void addLib(const QString &str)
 
410
        {
 
411
                if(LIBS.isEmpty())
 
412
                        LIBS = str;
 
413
                else
 
414
                        LIBS += QString(" ") + str;
 
415
                debug(QString("LIBS += %1").arg(str));
 
416
        }
 
417
 
 
418
        void addIncludePath(const QString &str)
 
419
        {
 
420
                if(INCLUDEPATH.isEmpty())
 
421
                        INCLUDEPATH = str;
 
422
                else
 
423
                        INCLUDEPATH += QString(" ") + str;
 
424
                debug(QString("INCLUDEPATH += %1").arg(str));
 
425
        }
 
426
 
 
427
        void addExtra(const QString &str)
 
428
        {
 
429
                extra += str + '\n';
 
430
                debug(QString("extra += %1").arg(str));
 
431
        }
 
432
 
 
433
        QString DEFINES;
 
434
        QString INCLUDEPATH;
 
435
        QString LIBS;
 
436
        QString extra;
 
437
 
 
438
private:
 
439
        ConfObjList list;
 
440
        QDict<QString> vars;
 
441
        QString blank;
 
442
        bool do_debug, done_debug;
 
443
};
 
444
 
 
445
ConfObj::ConfObj(Conf *c)
 
446
{
 
447
        conf = c;
 
448
        conf->added(this);
 
449
        required = false;
 
450
        disabled = false;
 
451
}
 
452
 
 
453
ConfObj::~ConfObj()
 
454
{
 
455
}
 
456
 
 
457
QString ConfObj::checkString() const
 
458
{
 
459
        return QString();
 
460
}
 
461
 
 
462
QString ConfObj::resultString() const
 
463
{
 
464
        return QString();
 
465
}
 
466
 
 
467
#include"modules.cpp"
 
468
 
 
469
//----------------------------------------------------------------------------
 
470
// main
 
471
//----------------------------------------------------------------------------
 
472
int main()
 
473
{
 
474
        Conf *conf = new Conf;
 
475
        ConfObj *o;
 
476
        o = 0;
 
477
#include"modules_new.cpp"
 
478
 
 
479
        printf("ok\n");
 
480
        bool success = false;
 
481
        if(conf->exec()) {
 
482
                QFile f("conf.pri");
 
483
                if(!f.open(IO_WriteOnly | IO_Truncate)) {
 
484
                        printf("Error writing %s\n", f.name().latin1());
 
485
                        return 1;
 
486
                }
 
487
 
 
488
                QString str;
 
489
                str += "# qconf\n";
 
490
                str += "QT_PATH_PLUGINS = " + QString(qInstallPathPlugins()) + '\n';
 
491
                if(!conf->DEFINES.isEmpty())
 
492
                        str += "DEFINES += " + conf->DEFINES + '\n';
 
493
                if(!conf->INCLUDEPATH.isEmpty())
 
494
                        str += "INCLUDEPATH += " + conf->INCLUDEPATH + '\n';
 
495
                if(!conf->LIBS.isEmpty())
 
496
                        str += "LIBS += " + conf->LIBS + '\n';
 
497
                if(!conf->extra.isEmpty())
 
498
                        str += conf->extra;
 
499
                str += '\n';
 
500
 
 
501
                char *p = getenv("BINDIR");
 
502
                if(p) {
 
503
                        str += QString("target.path = ") + p + '\n';
 
504
                        str += "INSTALLS += target\n";
 
505
                }
 
506
 
 
507
                QCString cs = str.latin1();
 
508
                f.writeBlock(cs.data(), cs.length());
 
509
                f.close();
 
510
                success = true;
 
511
        }
 
512
        delete conf;
 
513
 
 
514
        if(success)
 
515
                return 0;
 
516
        else
 
517
                return 1;
 
518
}
 
519
 
 
520
#include"conf.moc"
 
521
 
 
522
 
 
523
EOT
 
524
cat >$1/conf.pro <<EOT
 
525
TEMPLATE = app
 
526
CONFIG += qt x11 thread console
 
527
TARGET = conf
 
528
 
 
529
DEFINES += X11_INC='"\$\$QMAKE_INCDIR_X11"'
 
530
DEFINES += X11_LIBDIR='"\$\$QMAKE_LIBDIR_X11"'
 
531
DEFINES += X11_LIB='"\$\$QMAKE_LIBS_X11"'
 
532
DEFINES += CC='"\$\$QMAKE_CC"'
 
533
 
 
534
SOURCES += conf.cpp
 
535
 
 
536
EOT
 
537
}
 
538
 
 
539
export PREFIX
 
540
export BINDIR
 
541
export QTDIR
 
542
export QC_DEBUG
 
543
rm -rf .qconftemp
 
544
(
 
545
        mkdir .qconftemp
 
546
        gen_files .qconftemp
 
547
        cd .qconftemp
 
548
        $qm conf.pro >/dev/null
 
549
        QTDIR=$QTDIR make clean >/dev/null 2>&1
 
550
        QTDIR=$QTDIR make >../conf.log 2>&1
 
551
)
 
552
 
 
553
if [ "$?" != "0" ]; then
 
554
        rm -rf .qconftemp
 
555
        echo fail
 
556
        echo
 
557
        echo "There was an error compiling 'conf'.  Be sure you have a proper"
 
558
        echo "Qt 3.x Multithreaded (MT) build environment set up.  This"
 
559
        echo "means not just Qt, but also a C++ compiler, the 'make' command,"
 
560
        echo "and any other packages necessary to compile C++ programs."
 
561
        echo "See conf.log for details."
 
562
        if [ ! -f "$QTDIR/lib/libqt-mt.so.3" ]; then
 
563
                echo
 
564
                echo "One possible reason is that you don't have"
 
565
                echo "libqt-mt.so.3 installed in $QTDIR/lib/."
 
566
        fi
 
567
        echo
 
568
        exit 1;
 
569
fi
 
570
 
 
571
.qconftemp/conf
 
572
ret="$?"
 
573
if [ "$ret" = "1" ]; then
 
574
        rm -rf .qconftemp
 
575
        echo
 
576
        exit 1;
 
577
else
 
578
        if [ "$ret" != "0" ]; then
 
579
                rm -rf .qconftemp
 
580
                echo fail
 
581
                echo
 
582
                echo Unexpected error launching 'conf'
 
583
                echo
 
584
                exit 1;
 
585
        fi
 
586
fi
 
587
rm -rf .qconftemp
 
588
 
 
589
if [ -x "./qcextra" ]; then
 
590
        ./qcextra
 
591
fi
 
592
# run qmake
 
593
$qm conntest.pro
 
594
if [ "$?" != "0" ]; then
 
595
        echo
 
596
        exit 1;
 
597
fi
 
598
cat >Makefile.tmp <<EOT
 
599
export QTDIR = $QTDIR
 
600
export PATH = $QTDIR/bin:$PATH
 
601
EOT
 
602
cat Makefile >> Makefile.tmp
 
603
rm -f Makefile
 
604
cp -f Makefile.tmp Makefile
 
605
rm -f Makefile.tmp
 
606
 
 
607
echo
 
608
echo Good, your configure finished.  Now run \'make\'.
 
609
echo