forked from qbittorrent/qBittorrent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·1637 lines (1450 loc) · 36.8 KB
/
configure
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
# Generated by qconf 1.4 ( http://delta.affinix.com/qconf/ )
#
show_usage() {
cat <<EOT
Usage: $0 [OPTION]...
This script creates necessary configuration files to build/install.
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
--qtdir=[path] Directory where Qt is installed.
--verbose Show extra configure output.
--help This help text.
Dependency options:
--enable-debug Enable debug mode
--disable-gui Disable qBittorrent
Graphical user interface for
headless running
--disable-qt-dbus Disable use of qt-dbus
--with-libboost-inc=[path] Path to libboost include
files
--with-libboost-lib=[path] Path to libboost library
files
--disable-geoip-database Disable use of geoip-database
--with-geoip-database-embedded Geoip Database will be
embedded in qBittorrent
executable (please follow
instructions in
src/geoip/README)
--with-qtsingleapplication=[system|shipped] Use the shipped
qtsingleapplication library
or the system one
EOT
}
# which/make detection adapted from Qt
which_command() {
OLD_HOME=$HOME
HOME=/dev/null
export HOME
WHICH=`which which 2>/dev/null`
if echo $WHICH | grep 'shell built-in command' >/dev/null 2>&1; then
WHICH=which
elif [ -z "$WHICH" ]; then
if which which >/dev/null 2>&1; then
WHICH=which
else
for a in /usr/ucb /usr/bin /bin /usr/local/bin; do
if [ -x $a/which ]; then
WHICH=$a/which
break;
fi
done
fi
fi
if [ -z "$WHICH" ]; then
OLD_IFS=$IFS
IFS=:
for a in $PATH; do
if [ -x $a/$1 ]; then
echo "$a/$1"
IFS=$OLD_IFS
export IFS
HOME=$OLD_HOME
export HOME
return 0
fi
done
IFS=$OLD_IFS
export IFS
else
a=`"$WHICH" "$1" 2>/dev/null`
if [ ! -z "$a" -a -x "$a" ]; then
echo "$a"
HOME=$OLD_HOME
export HOME
return 0
fi
fi
HOME=$OLD_HOME
export HOME
return 1
}
WHICH=which_command
# 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 "You don't seem to have 'make' or 'gmake' in your PATH."
echo "Cannot proceed."
exit 1
fi
fi
show_qt_info() {
printf "Be sure you have a proper Qt 4.0 build environment set up. This means not\n"
printf "just Qt, but also a C++ compiler, a make tool, and any other packages\n"
printf "necessary for compiling C++ programs.\n"
printf "\n"
printf "If you are certain everything is installed, then it could be that Qt 4 is not\n"
printf "being recognized or that a different version of Qt is being detected by\n"
printf "mistake (for example, this could happen if \$QTDIR is pointing to a Qt 3\n"
printf "installation). At least one of the following conditions must be satisfied:\n"
printf "\n"
printf " 1) --qtdir is set to the location of Qt\n"
printf " 2) \$QTDIR is set to the location of Qt\n"
printf " 3) QtCore is in the pkg-config database\n"
printf " 4) qmake is in the \$PATH\n"
printf "\n"
printf "This script will use the first one it finds to be true, checked in the above\n"
printf "order. #3 and #4 are the recommended options. #1 and #2 are mainly for\n"
printf "overriding the system configuration.\n"
printf "\n"
}
while [ $# -gt 0 ]; do
optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
case "$1" in
--prefix=*)
PREFIX=$optarg
shift
;;
--bindir=*)
BINDIR=$optarg
shift
;;
--datadir=*)
DATADIR=$optarg
shift
;;
--qtdir=*)
EX_QTDIR=$optarg
shift
;;
--enable-debug)
QC_ENABLE_DEBUG="Y"
shift
;;
--disable-gui)
QC_DISABLE_GUI="Y"
shift
;;
--disable-qt-dbus)
QC_DISABLE_qt_dbus="Y"
shift
;;
--with-libboost-inc=*)
QC_WITH_LIBBOOST_INC=$optarg
shift
;;
--with-libboost-lib=*)
QC_WITH_LIBBOOST_LIB=$optarg
shift
;;
--disable-geoip-database)
QC_DISABLE_geoip_database="Y"
shift
;;
--with-geoip-database-embedded)
QC_WITH_GEOIP_DATABASE_EMBEDDED="Y"
shift
;;
--with-qtsingleapplication=*)
QC_WITH_QTSINGLEAPPLICATION=$optarg
shift
;;
--verbose)
QC_VERBOSE="Y"
shift
;;
--help) show_usage; exit ;;
*) show_usage; exit ;;
esac
done
PREFIX=${PREFIX:-/usr/local}
BINDIR=${BINDIR:-$PREFIX/bin}
DATADIR=${DATADIR:-$PREFIX/share}
echo "Configuring qbittorrent ..."
if [ "$QC_VERBOSE" = "Y" ]; then
echo
echo PREFIX=$PREFIX
echo BINDIR=$BINDIR
echo DATADIR=$DATADIR
echo EX_QTDIR=$EX_QTDIR
echo QC_ENABLE_DEBUG=$QC_ENABLE_DEBUG
echo QC_DISABLE_GUI=$QC_DISABLE_GUI
echo QC_DISABLE_qt_dbus=$QC_DISABLE_qt_dbus
echo QC_WITH_LIBBOOST_INC=$QC_WITH_LIBBOOST_INC
echo QC_WITH_LIBBOOST_LIB=$QC_WITH_LIBBOOST_LIB
echo QC_DISABLE_geoip_database=$QC_DISABLE_geoip_database
echo QC_WITH_GEOIP_DATABASE_EMBEDDED=$QC_WITH_GEOIP_DATABASE_EMBEDDED
echo QC_WITH_QTSINGLEAPPLICATION=$QC_WITH_QTSINGLEAPPLICATION
echo
fi
printf "Verifying Qt 4 build environment ... "
# run qmake -v and check version
qmake_check_v4() {
if [ -x "$1" ]; then
if echo `$1 -v 2>&1` | grep "Qt version 4\." >/dev/null 2>&1; then
return 0
elif [ "$QC_VERBOSE" = "Y" ]; then
echo "Warning: $1 not for Qt 4"
fi
fi
return 1
}
if [ "$QC_VERBOSE" = "Y" ]; then
echo
fi
qm=""
names="qmake-qt4 qmake4 qmake"
# qt4 check: --qtdir
if [ -z "$qm" ] && [ ! -z "$EX_QTDIR" ]; then
for n in $names; do
qstr=$EX_QTDIR/bin/$n
if qmake_check_v4 "$qstr"; then
qm=$qstr
break;
fi
done
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
echo "Warning: qmake not found via --qtdir"
fi
# qt4 check: QTDIR
if [ -z "$qm" ] && [ ! -z "$QTDIR" ]; then
for n in $names; do
qstr=$QTDIR/bin/$n
if qmake_check_v4 "$qstr"; then
qm=$qstr
break;
fi
done
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
echo "Warning: qmake not found via \$QTDIR"
fi
# qt4 check: pkg-config
if [ -z "$qm" ]; then
str=`pkg-config QtCore --variable=exec_prefix 2>/dev/null`
if [ ! -z "$str" ]; then
for n in $names; do
qstr=$str/bin/$n
if qmake_check_v4 "$qstr"; then
qm=$qstr
break;
fi
done
fi
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
echo "Warning: qmake not found via pkg-config"
fi
# qt4 check: PATH
if [ -z "$qm" ]; then
for n in $names; do
qstr=`$WHICH $n 2>/dev/null`
if qmake_check_v4 "$qstr"; then
qm=$qstr
break;
fi
done
fi
if [ -z "$qm" ] && [ "$QC_VERBOSE" = "Y" ]; then
echo "Warning: qmake not found via \$PATH"
fi
if [ -z "$qm" ]; then
if [ "$QC_VERBOSE" = "Y" ]; then
echo " -> fail"
else
echo "fail"
fi
printf "\n"
printf "Reason: Unable to find the 'qmake' tool for Qt 4.\n"
printf "\n"
show_qt_info
exit 1;
fi
if [ "$QC_VERBOSE" = "Y" ]; then
echo qmake found in $qm
fi
gen_files() {
cat >$1/modules.cpp <<EOT
#line 1 "qt4.qcm"
/*
-----BEGIN QCMOD-----
name: Qt >= 4.6
arg: enable-debug, Enable debug mode
arg: disable-gui, Disable qBittorrent Graphical user interface for headless running
-----END QCMOD-----
*/
class qc_qt4 : public ConfObj
{
public:
qc_qt4(Conf *c) : ConfObj(c) {}
QString name() const { return "Qt >= 4.6"; }
QString shortname() const { return "Qt 4.6"; }
bool exec()
{
// NOX mode
if(!conf->getenv("QC_DISABLE_GUI").isEmpty()) {
conf->addExtra("CONFIG += nox");
}
// Debug mode
if(!conf->getenv("QC_ENABLE_DEBUG").isEmpty()) {
conf->addExtra("CONFIG -= release");
conf->addExtra("CONFIG += debug");
} else {
conf->addExtra("CONFIG -= debug");
conf->addExtra("CONFIG += release");
}
#ifdef Q_OS_FREEBSD
conf->addLib("-lexecinfo");
conf->addExtra("MANPREFIX = \$\$PREFIX");
#else
conf->addExtra("MANPREFIX = \$\$PREFIX/share");
#endif
return(QT_VERSION >= 0x040600);
}
};
#line 1 "qt-dbus.qcm"
/*
-----BEGIN QCMOD-----
name: qt-dbus
-----END QCMOD-----
*/
// see Conf::findPkgConfig
class qc_qt_dbus : public ConfObj
{
public:
qc_qt_dbus(Conf *c) : ConfObj(c) {}
QString name() const { return "QtDBus >= 4.5"; }
QString shortname() const { return "qt-dbus"; }
QString checkString() const {
if(!conf->getenv("QC_DISABLE_qt_dbus").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty())
return "";
return ConfObj::checkString();
}
bool exec(){
if(!conf->getenv("QC_DISABLE_qt_dbus").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty())
return false;
QStringList incs;
QString req_ver = "4.5.0";
QString version, libs, other;
VersionMode mode = VersionMin;
if(conf->findPkgConfig("QtDBus", mode, req_ver, &version, &incs, &libs, &other)) {
conf->addExtra("CONFIG += dbus");
return true;
}
return false;
}
};
#line 1 "pkg-config.qcm"
/*
-----BEGIN QCMOD-----
name: pkg-config
-----END QCMOD-----
*/
#include <QProcess>
class qc_pkg_config : public ConfObj
{
public:
qc_pkg_config(Conf *c) : ConfObj(c) {}
QString name() const { return "pkg-config executable"; }
QString shortname() const { return "pkg-config"; }
bool exec(){
return !conf->findProgram("pkg-config").isEmpty();
}
};
#line 1 "libtorrent-rasterbar.qcm"
/*
-----BEGIN QCMOD-----
name: libtorrent-rasterbar
-----END QCMOD-----
*/
// see Conf::findPkgConfig
class qc_libtorrent_rasterbar : public ConfObj
{
public:
qc_libtorrent_rasterbar(Conf *c) : ConfObj(c) {}
QString name() const { return "libtorrent-rasterbar >= 0.15.0"; }
QString shortname() const { return "libtorrent-rasterbar"; }
bool exec(){
QStringList incs;
QString req_ver = "0.15.0";
QString version, libs, other;
VersionMode mode = VersionMin;
if(!conf->findPkgConfig("libtorrent-rasterbar", mode, req_ver, &version, &incs, &libs, &other))
return false;
for(int n = 0; n < incs.count(); ++n)
conf->addIncludePath(incs[n]);
return true;
}
};
#line 1 "libboost.qcm"
/*
-----BEGIN QCMOD-----
name: libboost
arg: with-libboost-inc=[path], Path to libboost include files
arg: with-libboost-lib=[path], Path to libboost library files
-----END QCMOD-----
*/
#include <boost/version.hpp>
#include <libtorrent/version.hpp>
class qc_libboost : public ConfObj
{
public:
qc_libboost(Conf *c) : ConfObj(c) {}
QString name() const { return "libboost"; }
QString shortname() const { return "libboost"; }
QString findBoostLib(QString path, QString lib) const {
QString name;
QDir libDir(path);
QStringList filters;
filters << "libboost_"+lib+"*-mt*.so";
QStringList result = libDir.entryList(filters, QDir::Files);
if(!result.empty()) {
name = result.first().mid(3);
// Remove .so
name.chop(3);
} else {
// Fall back to non -mt boost lib
filters.clear();
filters << "libboost_"+lib+"*.so";
result = libDir.entryList(filters, QDir::Files);
if(!result.empty()) {
name = result.first().mid(3);
// Remove .so
name.chop(3);
}
}
return name;
}
bool exec(){
QStringList sl;
QString s = conf->getenv("QC_WITH_LIBBOOST_INC");
if (!s.isEmpty())
sl << s;
sl << "/usr/include";
sl << "/usr/local/include";
bool found = false;
foreach (s, sl) {
if (conf->checkHeader(s, "boost/format.hpp")
#if LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16
&& conf->checkHeader(s, "boost/filesystem/path.hpp")
#endif
) {
found = true;
break;
}
}
if (!found)
return false;
conf->addIncludePath(s);
// Find library
s = conf->getenv("QC_WITH_LIBBOOST_LIB");
QStringList required_libs;
#if BOOST_VERSION >= 103500
required_libs << "system";
#endif
#if LIBTORRENT_VERSION_MAJOR == 0 && LIBTORRENT_VERSION_MINOR < 16
required_libs << "filesystem" ;
#endif
//required_libs << "thread";
QStringList libDirs;
if (!s.isEmpty())
libDirs << s;
libDirs << "/usr/lib/" << "/usr/lib64/" << "/usr/local/lib/" << "/usr/local/lib64/";
foreach(const QString& lib, required_libs) {
bool found = false;
foreach(const QString& libDir, libDirs) {
QString detected_name = findBoostLib(libDir, lib);
if(!detected_name.isEmpty()) {
conf->addLib("-l"+detected_name);
found = true;
break;
}
}
if(!found) {
printf("Could not find boost %s library!\n", qPrintable(lib));
return false;
}
}
return true;
}
};
#line 1 "geoip-database.qcm"
/*
-----BEGIN QCMOD-----
name: geoip-database
arg: with-geoip-database-embedded, Geoip Database will be embedded in qBittorrent executable (please follow instructions in src/geoip/README)
-----END QCMOD-----
*/
// see Conf::findPkgConfig
class qc_geoip_database : public ConfObj
{
public:
qc_geoip_database(Conf *c) : ConfObj(c) {}
QString name() const { return "GeoIP Database (optional)"; }
QString shortname() const { return "GeoIP Database"; }
QString checkString() const {
if(!conf->getenv("QC_DISABLE_geoip_database").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty())
return "";
return ConfObj::checkString();
}
bool exec() {
if(!conf->getenv("QC_DISABLE_geoip_database").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) {
return false;
}
#ifdef Q_WS_X11
if(!conf->getenv("QC_WITH_GEOIP_DATABASE_EMBEDDED").isEmpty()) {
#endif
conf->addDefine("WITH_GEOIP_EMBEDDED");
printf(" embedded and");
return true;
#ifdef Q_WS_X11
}
if(QFile::exists("/usr/share/GeoIP/GeoIP.dat") || QFile::exists("/usr/local/share/GeoIP/GeoIP.dat") || QFile::exists("/var/lib/GeoIP/GeoIP.dat"))
return true;
printf("\nWarning: GeoIP database was not found at /usr/share/GeoIP/GeoIP.dat or /var/lib/GeoIP/GeoIP.dat\nCountry resolution will be slow.");
return false;
#endif
}
};
#line 1 "qtsingleapplication.qcm"
/*
-----BEGIN QCMOD-----
name: qtsingleapplication
arg: with-qtsingleapplication=[system|shipped], Use the shipped qtsingleapplication library or the system one
-----END QCMOD-----
*/
class qc_qtsingleapplication : public ConfObj
{
public:
qc_qtsingleapplication(Conf *c) : ConfObj(c) {}
QString name() const { return "qtsingleapplication library"; }
QString shortname() const { return "qtsingleapplication"; }
bool exec(){
QString s;
s = conf->getenv("QC_WITH_QTSINGLEAPPLICATION");
if(s.compare("system", Qt::CaseInsensitive) == 0) {
// System
conf->addExtra("CONFIG += usesystemqtsingleapplication");
printf(" [system] ");
} else {
printf(" [shipped] ");
}
return true;
}
};
EOT
cat >$1/modules_new.cpp <<EOT
o = new qc_qt4(conf);
o->required = true;
o->disabled = false;
o = new qc_qt_dbus(conf);
o->required = false;
o->disabled = false;
o = new qc_pkg_config(conf);
o->required = true;
o->disabled = false;
o = new qc_libtorrent_rasterbar(conf);
o->required = true;
o->disabled = false;
o = new qc_libboost(conf);
o->required = true;
o->disabled = false;
o = new qc_geoip_database(conf);
o->required = false;
o->disabled = false;
o = new qc_qtsingleapplication(conf);
o->required = true;
o->disabled = false;
EOT
cat >$1/conf4.h <<EOT
// For license information, see the COPYING file in the qconf base directory.
#ifndef QC_CONF4_H
#define QC_CONF4_H
#include <QtCore>
class Conf;
enum VersionMode { VersionMin, VersionExact, VersionMax, VersionAny };
// ConfObj
//
// Subclass ConfObj to create a new configuration module.
class ConfObj
{
public:
Conf *conf;
bool required;
bool disabled;
bool success;
ConfObj(Conf *c);
virtual ~ConfObj();
// long or descriptive name of what is being checked/performed
// example: "KDE >= 3.3"
virtual QString name() const = 0;
// short name
// example: "kde"
virtual QString shortname() const = 0;
// string to display during check
// default: "Checking for [name] ..."
virtual QString checkString() const;
// string to display after check
// default: "yes" or "no", based on result of exec()
virtual QString resultString() const;
// this is where the checking code goes
virtual bool exec() = 0;
};
// Conf
//
// Interact with this class from your ConfObj to perform detection
// operations and to output configuration parameters.
class Conf
{
public:
bool debug_enabled;
QString qmake_path;
QString maketool;
QString DEFINES;
QString INCLUDEPATH;
QString LIBS;
QString extra;
QList<ConfObj*> list;
QMap<QString,QString> vars;
Conf();
~Conf();
QString getenv(const QString &var);
QString qvar(const QString &s);
bool exec();
void debug(const QString &s);
QString expandIncludes(const QString &inc);
QString expandLibs(const QString &lib);
int doCommand(const QString &s, QByteArray *out = 0);
int doCommand(const QString &prog, const QStringList &args, QByteArray *out = 0);
bool doCompileAndLink(const QString &filedata, const QStringList &incs, const QString &libs, const QString &proextra, int *retcode = 0);
bool checkHeader(const QString &path, const QString &h);
bool findHeader(const QString &h, const QStringList &ext, QString *inc);
bool checkLibrary(const QString &path, const QString &name);
bool findLibrary(const QString &name, QString *lib);
QString findProgram(const QString &prog);
bool findSimpleLibrary(const QString &incvar, const QString &libvar, const QString &incname, const QString &libname, QString *incpath, QString *libs);
bool findFooConfig(const QString &path, QString *version, QStringList *incs, QString *libs, QString *otherflags);
bool findPkgConfig(const QString &name, VersionMode mode, const QString &req_version, QString *version, QStringList *incs, QString *libs, QString *otherflags);
void addDefine(const QString &str);
void addLib(const QString &str);
void addIncludePath(const QString &str);
void addExtra(const QString &str);
private:
bool first_debug;
friend class ConfObj;
void added(ConfObj *o);
};
#endif
EOT
cat >$1/conf4.cpp <<EOT
// For license information, see the COPYING file in the qconf base directory.
#include "conf4.h"
#include <stdio.h>
#include <stdlib.h>
class MocTestObject : public QObject
{
Q_OBJECT
public:
MocTestObject() {}
};
QString qc_getenv(const QString &var)
{
char *p = ::getenv(var.toLatin1().data());
if(!p)
return QString();
return QString(p);
}
QStringList qc_pathlist()
{
QStringList list;
QString path = qc_getenv("PATH");
if(!path.isEmpty())
list = path.split(':', QString::SkipEmptyParts);
return list;
}
QString qc_findprogram(const QString &prog)
{
QString out;
QStringList list = qc_pathlist();
for(int n = 0; n < list.count(); ++n)
{
QFileInfo fi(list[n] + '/' + prog);
if(fi.exists() && fi.isExecutable())
{
out = fi.filePath();
break;
}
}
return out;
}
QString qc_findself(const QString &argv0)
{
if(argv0.contains('/'))
return argv0;
else
return qc_findprogram(argv0);
}
int qc_runcommand(const QString &command, QByteArray *out, bool showOutput)
{
QString fullcmd = command;
if(!showOutput)
fullcmd += " 2>/dev/null";
FILE *f = popen(fullcmd.toLatin1().data(), "r");
if(!f)
return -1;
if(out)
out->clear();
while(1)
{
char c = (char)fgetc(f);
if(feof(f))
break;
if(out)
out->append(c);
if(showOutput)
fputc(c, stdout);
}
int ret = pclose(f);
if(ret == -1)
return -1;
return ret;
}
int qc_runprogram(const QString &prog, const QStringList &args, QByteArray *out, bool showOutput)
{
QString fullcmd = prog;
QString argstr = args.join(" ");
if(!argstr.isEmpty())
fullcmd += QString(" ") + argstr;
return qc_runcommand(fullcmd, out, showOutput);
// TODO: use QProcess once it is fixed
/*
QProcess process;
if(showOutput)
process.setReadChannelMode(ForwardedChannels);
process.start(prog, args);
process.waitForFinished(-1);
return process.exitCode();
*/
}
bool qc_removedir(const QString &dirPath)
{
QDir dir(dirPath);
if(!dir.exists())
return false;
QStringList list = dir.entryList();
foreach(QString s, list)
{
if(s == "." || s == "..")
continue;
QFileInfo fi(dir.filePath(s));
if(fi.isDir())
{
if(!qc_removedir(fi.filePath()))
return false;
}
else
{
if(!dir.remove(s))
return false;
}
}
QString dirName = dir.dirName();
if(!dir.cdUp())
return false;
if(!dir.rmdir(dirName))
return false;
return true;
}
void qc_splitcflags(const QString &cflags, QStringList *incs, QStringList *otherflags)
{
incs->clear();
otherflags->clear();
QStringList cflagsList = cflags.split(" ");
for(int n = 0; n < cflagsList.count(); ++n)
{
QString str = cflagsList[n];
if(str.startsWith("-I"))
{
// we want everything except the leading "-I"
incs->append(str.remove(0, 2));
}
else
{
// we want whatever is left
otherflags->append(str);
}
}
}
QString qc_escapeArg(const QString &str)
{
QString out;
for(int n = 0; n < (int)str.length(); ++n) {
if(str[n] == '-')
out += '_';
else
out += str[n];
}
return out;
}
//----------------------------------------------------------------------------
// ConfObj
//----------------------------------------------------------------------------
ConfObj::ConfObj(Conf *c)
{
conf = c;
conf->added(this);
required = false;
disabled = false;
success = false;
}
ConfObj::~ConfObj()
{
}
QString ConfObj::checkString() const
{
return QString("Checking for %1 ...").arg(name());
}
QString ConfObj::resultString() const
{
if(success)
return "yes";
else
return "no";
}
//----------------------------------------------------------------------------
// qc_internal_pkgconfig
//----------------------------------------------------------------------------
class qc_internal_pkgconfig : public ConfObj
{
public:
QString pkgname, desc;
VersionMode mode;
QString req_ver;
qc_internal_pkgconfig(Conf *c, const QString &_name, const QString &_desc, VersionMode _mode, const QString &_req_ver) : ConfObj(c)
{
pkgname = _name;
desc = _desc;
mode = _mode;
req_ver = _req_ver;
}
QString name() const { return desc; }
QString shortname() const { return pkgname; }
bool exec()
{
QStringList incs;
QString version, libs, other;
if(!conf->findPkgConfig(pkgname, mode, req_ver, &version, &incs, &libs, &other))
return false;
for(int n = 0; n < incs.count(); ++n)
conf->addIncludePath(incs[n]);
if(!libs.isEmpty())
conf->addLib(libs);
//if(!other.isEmpty())
// conf->addExtra(QString("QMAKE_CFLAGS += %1\n").arg(other));
return true;
}
};
//----------------------------------------------------------------------------
// Conf
//----------------------------------------------------------------------------
Conf::Conf()
{
// TODO: no more vars?
//vars.insert("QMAKE_INCDIR_X11", new QString(X11_INC));
//vars.insert("QMAKE_LIBDIR_X11", new QString(X11_LIBDIR));
//vars.insert("QMAKE_LIBS_X11", new QString(X11_LIB));
//vars.insert("QMAKE_CC", CC);
debug_enabled = false;
}
Conf::~Conf()
{
qDeleteAll(list);
}
void Conf::added(ConfObj *o)
{
list.append(o);
}
QString Conf::getenv(const QString &var)
{
return qc_getenv(var);
}
void Conf::debug(const QString &s)
{
if(debug_enabled)
{
if(first_debug)
printf("\n");
first_debug = false;
printf(" * %s\n", qPrintable(s));
}