File: configure

package info (click to toggle)
psi 0.9.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,524 kB
  • ctags: 10,934
  • sloc: cpp: 81,408; ansic: 18,998; sh: 1,555; xml: 1,304; makefile: 165
file content (1124 lines) | stat: -rwxr-xr-x 22,636 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
#!/bin/sh

show_usage() {
cat <<EOT
Usage: ./configure [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
  --libdir=[path]    Directory for libraries.  Default: PREFIX/share/psi
  --qtdir=[path]     Directory where Qt is installed.
  --debug            Enable debug output.
  --help             This help text.

Dependency options:
  --with-qca-inc=[path]     Path to QCA include files
  --with-qca-lib=[path]     Path to QCA library files
  --with-zlib-inc=[path]    Path to zlib include files
  --with-zlib-lib=[path]    Path to zlib library files
  --disable-xss             Disable use of the XScreenSaver extension
  --disable-dnotify         Disable use of Linux Directory Notification
  --disable-ghbnr           Disable use of gethostbyname_r()
  --disable-kde             Disable use of KDE

EOT
}

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

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

		--libdir=*)
			LIBDIR="${1#--libdir=}"
			shift
			;;

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

		--with-qca-inc=*)
			QC_WITH_QCA_INC="${1#--with-qca-inc=}"
			shift
			;;

		--with-qca-lib=*)
			QC_WITH_QCA_LIB="${1#--with-qca-lib=}"
			shift
			;;

		--with-zlib-inc=*)
			QC_WITH_ZLIB_INC="${1#--with-zlib-inc=}"
			shift
			;;

		--with-zlib-lib=*)
			QC_WITH_ZLIB_LIB="${1#--with-zlib-lib=}"
			shift
			;;

		--disable-xss)
			QC_DISABLE_xss="Y"
			shift
			;;

		--disable-dnotify)
			QC_DISABLE_dnotify="Y"
			shift
			;;

		--disable-ghbnr)
			QC_DISABLE_ghbnr="Y"
			shift
			;;

		--disable-kde)
			QC_DISABLE_kde="Y"
			shift
			;;

		--debug)
			QC_DEBUG="Y"
			shift
			;;
		--help) show_usage; exit ;;
		*) show_usage; exit ;;
	esac
done

PREFIX=${PREFIX:-/usr/local}
BINDIR=${BINDIR:-$PREFIX/bin}
LIBDIR=${LIBDIR:-$PREFIX/share/psi}

echo "Configuring Psi ..."

if [ "$QC_DEBUG" = "Y" ]; then
echo
echo PREFIX=$PREFIX
echo BINDIR=$BINDIR
echo LIBDIR=$LIBDIR
echo QTDIR=$QTDIR
echo QC_WITH_QCA_INC=$QC_WITH_QCA_INC
echo QC_WITH_QCA_LIB=$QC_WITH_QCA_LIB
echo QC_WITH_ZLIB_INC=$QC_WITH_ZLIB_INC
echo QC_WITH_ZLIB_LIB=$QC_WITH_ZLIB_LIB
echo QC_DISABLE_xss=$QC_DISABLE_xss
echo QC_DISABLE_dnotify=$QC_DISABLE_dnotify
echo QC_DISABLE_ghbnr=$QC_DISABLE_ghbnr
echo QC_DISABLE_kde=$QC_DISABLE_kde
echo
fi

printf "Verifying Qt 3.x Multithreaded (MT) build environment ... "

if [ -z "$QTDIR" ]; then
	if [ "$QC_DEBUG" = "Y" ]; then
		echo \$QTDIR not set... trying to find Qt manually
	fi
	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
		if [ -d "$p/mkspecs" ]; then
			QTDIR=$p
			break;
		fi;
	done
	if [ -z "$QTDIR" ]; then
		echo fail
		echo
		echo "Unable to find Qt 'mkspecs'.  Perhaps you need to"
		echo "install the Qt 3 development utilities.  You may download"
		echo "them either from the vendor of your operating system"
		echo "or from http://www.trolltech.com/"
		echo
		echo "If you're sure you have the Qt development utilities"
		echo "installed, you might try using the --qtdir option."
		echo
		exit 1;
	fi
	if [ ! -x "$QTDIR/bin/moc" ]; then
		m=`which moc 2>/dev/null`
		if [ ! -x "$m" ]; then
			echo fail
			echo
			echo "We found Qt in $QTDIR, but we were unable to locate"
			echo "the moc utility.  It was not found in $QTDIR/bin"
			echo "nor in PATH.  This seems to be a very unusual setup."
			echo "You might try using the --qtdir option."
			echo
			exit 1;
		fi
		qtpre=`echo $m | awk '{ n = index($0, "/bin/moc"); if (!n) { exit 1; } print substr($0, 0, n-1); exit 0; }' 2>/dev/null`
		ret="$?"
		if [ "$ret" != "0" ]; then
			echo fail
			echo
			echo "We found Qt in $QTDIR, but the location of moc"
			echo "($m) is not suitable for use with this build system."
			echo "This is a VERY unusual and likely-broken setup.  You"
			echo "should contact the maintainer of your Qt package."
			echo
			exit 1;
		fi
		QTDIR=$qtpre
	fi
fi

if [ ! -x "$QTDIR/bin/qmake" ]; then
	if [ "$QC_DEBUG" = "Y" ]; then
		echo Warning: qmake not in \$QTDIR/bin/qmake
		echo trying to find it in \$PATH
	fi
	qm=`which qmake 2>/dev/null`
	if [ -x "$qm" ]; then
		if [ "$QC_DEBUG" = "Y" ]; then
			echo qmake found in $qm
		fi
	else
		echo fail
		echo
		echo Sorry, you seem to have a very unusual setup,
		echo or I missdetected \$QTDIR=$QTDIR
		echo
		echo Please set \$QTDIR manually and make sure that
		echo \$QTDIR/bin/qmake exists.
		echo
		exit 1;
	fi
else
	qm=$QTDIR/bin/qmake
fi

gen_files() {
cat >$1/modules.cpp <<EOT
#line 1 "qt31.qcm"
/*
-----BEGIN QCMOD-----
name: Qt >= 3.1
-----END QCMOD-----
*/
class qc_qt31 : public ConfObj
{
public:
	qc_qt31(Conf *c) : ConfObj(c) {}
	QString name() const { return "Qt >= 3.1"; }
	QString shortname() const { return "qt31"; }
	bool exec()
	{
		if(QT_VERSION >= 0x030100) {
			if(QT_VERSION < 0x030300)
				conf->addExtra("QXML_STATIC = Y");
			return true;
		}
		else
			return false;
	}
};
#line 1 "qca.qcm"
/*
-----BEGIN QCMOD-----
name: QCA 1.0
arg: with-qca-inc=[path],Path to QCA include files
arg: with-qca-lib=[path],Path to QCA library files
-----END QCMOD-----
*/

//----------------------------------------------------------------------------
// qc_qca
//----------------------------------------------------------------------------
class qc_qca : public ConfObj
{
public:
	qc_qca(Conf *c) : ConfObj(c) {}
	QString name() const { return "QCA 1.0"; }
	QString shortname() const { return "qca"; }
	bool exec()
	{
		QString inc, lib;
		QString s;

		s = conf->getenv("QC_WITH_QCA_INC");
		if(!s.isEmpty()) {
			if(!conf->checkHeader(s, "qca.h"))
				return false;
			inc = s;
		}
		else {
			if(!conf->findHeader("qca.h", QStringList(), &s))
				return false;
			inc = s;
		}

		s = conf->getenv("QC_WITH_QCA_LIB");
		if(!s.isEmpty()) {
			if(!conf->checkLibrary(s, "qca"))
				return false;
			lib = s;
		}
		else {
			if(!conf->findLibrary("qca", &s))
				return false;
			lib = s;
		}

		if(!inc.isEmpty())
			conf->addIncludePath(inc);
		if(!lib.isEmpty())
			conf->addLib(QString("-L") + s);
		conf->addLib("-lqca");

		return true;
	}
};
#line 1 "zlib.qcm"
/*
-----BEGIN QCMOD-----
name: zlib
arg: with-zlib-inc=[path],Path to zlib include files
arg: with-zlib-lib=[path],Path to zlib library files
-----END QCMOD-----
*/

//----------------------------------------------------------------------------
// qc_zlib
//----------------------------------------------------------------------------
class qc_zlib : public ConfObj
{
public:
	qc_zlib(Conf *c) : ConfObj(c) {}
	QString name() const { return "zlib"; }
	QString shortname() const { return "zlib"; }
	bool exec()
	{
		QString inc, lib;
		QString s;

		s = conf->getenv("QC_WITH_ZLIB_INC");
		if(!s.isEmpty()) {
			if(!conf->checkHeader(s, "zlib.h"))
				return false;
			inc = s;
		}
		else {
			if(!conf->findHeader("zlib.h", QStringList(), &s))
				return false;
			inc = s;
		}

		s = conf->getenv("QC_WITH_ZLIB_LIB");
		if(!s.isEmpty()) {
			if(!conf->checkLibrary(s, "z"))
				return false;
			lib = s;
		}
		else {
			if(!conf->findLibrary("z", &s))
				return false;
			lib = s;
		}

		if(!inc.isEmpty())
			conf->addIncludePath(inc);
		if(!lib.isEmpty())
			conf->addLib(QString("-L") + s);
		conf->addLib("-lz");

		return true;
	}
};
#line 1 "xss.qcm"
/*
-----BEGIN QCMOD-----
name: the XScreenSaver extension
-----END QCMOD-----
*/

//----------------------------------------------------------------------------
// qc_xss
//----------------------------------------------------------------------------
class qc_xss : public ConfObj
{
public:
	enum { OK, NEEDLIB, FAIL };
	qc_xss(Conf *c) : ConfObj(c)
	{
	}

	~qc_xss()
	{
		remove("xssprobe_test.c");
		remove("xssprobe_test.o");
		remove("xssprobe_test");
	}

	QString name() const
	{
		return "the XScreenSaver extension";
	}

	QString shortname() const { return "xss"; }

	int do_write()
	{
		char *xsstest =
			"#include<X11/Xlib.h>\n"
			"#include<X11/Xutil.h>\n"
			"#include<X11/extensions/scrnsaver.h>\n"
			"\n"
			"int main()\n"
			"{\n"
			"    XScreenSaverQueryExtension(NULL, NULL, NULL);\n"
			"    return 0;\n"
			"}\n";

		FILE *f;
		f = fopen("xssprobe_test.c", "w");
		if(!f)
			return 0;
		fwrite(xsstest, strlen(xsstest), 1, f);
		fclose(f);

		return 1;
	}

	int do_compile()
	{
		QString inc = conf->expandIncludes(conf->qvar("QMAKE_INCDIR_X11"));
		QString str = conf->qvar("QMAKE_CC") + " -c " + inc + " xssprobe_test.c -o xssprobe_test.o";
		int r = conf->doCommand(str);
		if(r == 0)
			return 1;
		else
			return 0;
	}

	int do_link()
	{
		QString lib = conf->expandLibs(conf->qvar("QMAKE_LIBDIR_X11"));
		QString inc = conf->expandIncludes(conf->qvar("QMAKE_INCDIR_X11"));
		QString str = conf->qvar("QMAKE_CC") + " xssprobe_test.o -o xssprobe_test " + lib + ' ' + conf->qvar("QMAKE_LIBS_X11");
		int r = conf->doCommand(str);
		if(r == 0)
			return 1;
		else
			return 0;
	}

	int do_linkLib()
	{
		QString lib = conf->expandLibs(conf->qvar("QMAKE_LIBDIR_X11"));
		QString inc = conf->expandIncludes(conf->qvar("QMAKE_INCDIR_X11"));
		QString str = conf->qvar("QMAKE_CC") + " xssprobe_test.o -o xssprobe_test " + lib + ' ' + conf->qvar("QMAKE_LIBS_X11") + " -lXss";
		int r = conf->doCommand(str);
		if(r == 0)
			return 1;
		else
			return 0;
	}

	int do_all()
	{
		if(!do_write())
			return FAIL;
		if(!do_compile())
			return FAIL;
		if(do_link())
			return OK;
		if(do_linkLib())
			return NEEDLIB;
		return FAIL;
	}

	bool exec()
	{
		int r = do_all();
		if(r == OK)
			return true;
		if(r == NEEDLIB) {
			conf->addLib("-lXss");
			return true;
		}
		else {
			conf->addDefine("NO_XSS");
			return false;
		}
	}
};
#line 1 "dnotify.qcm"
/*
-----BEGIN QCMOD-----
name: Linux Directory Notification
-----END QCMOD-----
*/

#include<unistd.h>
#include<fcntl.h>
#include<signal.h>
#include<sys/utsname.h>

//----------------------------------------------------------------------------
// qc_dnotify
//----------------------------------------------------------------------------
class qc_dnotify : public ConfObj
{
public:
	qc_dnotify(Conf *c) : ConfObj(c)
	{
	}

	~qc_dnotify()
	{
		remove("ftest.c");
		remove("ftest.o");
	}

	QString name() const { return "Linux Directory Notification"; }
	QString shortname() const { return "dnotify"; }

	bool do_write()
	{
		char *fdata =
			"#define _GNU_SOURCE\n"
			"#include<unistd.h>\n"
			"#include<fcntl.h>\n"
			"#include<signal.h>\n"
			"#include<sys/utsname.h>\n"
			"\n"
			"int main()\n"
			"{\n"
			"    DN_DELETE|DN_CREATE|DN_RENAME|DN_MULTISHOT|DN_MODIFY|DN_ATTRIB;\n"
			"    return 0;\n"
			"}\n";

		FILE *f;
		f = fopen("ftest.c", "w");
		if(!f)
			return false;
		fwrite(fdata, strlen(fdata), 1, f);
		fclose(f);

		return true;
	}

	bool do_compile()
	{
		QString str = conf->qvar("QMAKE_CC") + " -c ftest.c -o ftest.o";
		int r = conf->doCommand(str);
		if(r == 0)
			return true;
		else
			return false;
	}

	bool exec()
	{
		// taken from KDE
		bool supports_dnotify = true; // not guilty until proven guilty
		struct utsname uts;
		int major, minor, patch;
		if(uname(&uts) < 0)
			supports_dnotify = false; // *shrug*
		else if(sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
			supports_dnotify = false; // *shrug*
		else if( major * 1000000 + minor * 1000 + patch < 2004019 ) // <2.4.19
			supports_dnotify = false;
		if(!supports_dnotify)
			return false;

		if(!do_write())
			return false;
		if(!do_compile())
			return false;

		conf->addDefine("HAVE_DNOTIFY");
		return true;
	}
};
#line 1 "ghbnr.qcm"
/*
-----BEGIN QCMOD-----
name: gethostbyname_r()
-----END QCMOD-----
*/
class qc_ghbnr : public ConfObj
{
public:
	qc_ghbnr(Conf *c) : ConfObj(c)
	{
	}

	~qc_ghbnr()
	{
		remove("ftest.c");
		remove("ftest");
	}

	QString name() const { return "gethostbyname_r()"; }
	QString shortname() const { return "ghbnr"; }

	bool exec()
	{
		char *fdata =
			"#include<netdb.h>\n"
			"\n"
			"int main()\n"
			"{\n"
			"    gethostbyname_r(\"\", 0, 0, 0, 0, 0);\n"
			"    return 0;\n"
			"}\n";

		FILE *f;
		f = fopen("ftest.c", "w");	
		if(!f)
			return false;
		fwrite(fdata, strlen(fdata), 1, f);
		fclose(f);

		QString str = conf->qvar("QMAKE_CC") + " ftest.c -o ftest";
		int r = conf->doCommand(str);
		if(r == 0) {
			conf->addDefine("HAVE_GETHOSTBYNAME_R");
			return true;
		}
		else
			return false;
	}
};
#line 1 "kde.qcm"
/*
-----BEGIN QCMOD-----
name: KDE
-----END QCMOD-----
*/

//----------------------------------------------------------------------------
// qc_kde
//----------------------------------------------------------------------------
class qc_kde : public ConfObj
{
public:
	qc_kde(Conf *c) : ConfObj(c) {}
	QString name() const { return "KDE"; }
	QString shortname() const { return "kde"; }
	bool exec()
	{
		char *p = getenv("KDEDIR");
		if(!p)
			return false;

		conf->addExtra(QString("KDE = %1").arg(p));
		return true;
	}
};

EOT
cat >$1/modules_new.cpp <<EOT
    o = new qc_qt31(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_qca(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_zlib(conf);
    o->required = true;
    o->disabled = false;
    o = new qc_xss(conf);
    o->required = false;
    o->disabled = false;
    o = new qc_dnotify(conf);
    o->required = false;
    o->disabled = false;
    o = new qc_ghbnr(conf);
    o->required = false;
    o->disabled = false;
    o = new qc_kde(conf);
    o->required = false;
    o->disabled = false;

EOT
cat >$1/conf.cpp <<EOT
#include<stdio.h>
#include<stdlib.h>
#include<qstring.h>
#include<qdict.h>
#include<qptrlist.h>
#include<qfileinfo.h>
#include<qfile.h>
#include<qdir.h>
#include<qstringlist.h>
#include<qobject.h>

class MocTestObject : public QObject
{
	Q_OBJECT
public:
	MocTestObject() {}
};

class Conf;

class ConfObj
{
public:
	ConfObj(Conf *c);
	virtual ~ConfObj();

	virtual QString name() const=0;
	virtual QString shortname() const=0;
	virtual QString checkString() const;
	virtual QString resultString() const;
	virtual bool exec()=0;

	Conf *conf;
	bool required;
	bool disabled;
};

typedef QPtrList<ConfObj> ConfObjList;
typedef QPtrListIterator<ConfObj> ConfObjListIt;

class Conf
{
public:
	Conf() : vars(17)
	{
		list.setAutoDelete(true);
		vars.setAutoDelete(true);

		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",         new QString(CC));

		do_debug = false;
		done_debug = false;
	}

	~Conf()
	{
	}

	void added(ConfObj *o)
	{
		list.append(o);
	}

	QString getenv(const QString &var)
	{
		char *p = ::getenv(var.latin1());
		if(!p)
			return QString::null;
		return QString(p);
	}

	void debug(const QString &s)
	{
		if(do_debug) {
			if(!done_debug)
				printf("\n");
			done_debug = true;
			printf(" * %s\n", s.latin1());
		}
	}

	bool exec()
	{
		if(getenv("QC_DEBUG") == "Y")
			do_debug = true;

		ConfObjListIt it(list);
		for(ConfObj *o; (o = it.current()); ++it) {
			// if this was a disabled-by-default option, check if it was enabled
			if(o->disabled) {
				QString v = QString("QC_ENABLE_") + o->shortname();
				if(getenv(v) != "Y")
					continue;
			}
			// and the opposite?
			else {
				QString v = QString("QC_DISABLE_") + o->shortname();
				if(getenv(v) == "Y")
					continue;
			}

			QString check = o->checkString();
			if(check.isEmpty())
				check = QString("Checking for %1 ...").arg(o->name());
			printf("%s", check.latin1());
			fflush(stdout);

			done_debug = false;
			bool ok = o->exec();

			QString result = o->resultString();
			if(result.isEmpty()) {
				if(ok)
					result = "yes";
				else
					result = "no";
			}
			if(done_debug)
				printf(" -> %s\n", result.latin1());
			else
				printf(" %s\n", result.latin1());

			if(!ok && o->required) {
				printf("\nError: need %s!\n", o->name().latin1());
				return false;
			}
		}
		return true;
	}

	const QString & qvar(const QString &s)
	{
		QString *p = vars.find(s);
		if(p)
			return *p;
		else
			return blank;
	}

	QString expandIncludes(const QString &inc)
	{
		return QString("-I") + inc;
	}

	QString expandLibs(const QString &lib)
	{
		return QString("-L") + lib;
	}

	int doCommand(const QString &s)
	{
		debug(QString("[%1]").arg(s));
		QString fullcmd;
		if(do_debug)
			fullcmd = s;
		else
			fullcmd = s + " 1>/dev/null 2>/dev/null";
		int r = system(fullcmd.latin1());
		debug(QString("returned: %1").arg(r));
		return r;
	}

	bool doCompileAndLink(const QString &filedata, const QString &flags, int *retcode=0)
	{
		QDir dir(".");
		QString fname = "atest.c";
		QString out = "atest";
		QFile f(fname);
		QCString cs = filedata.latin1();
		if(!f.open(IO_WriteOnly | IO_Truncate)) {
			debug("unable to open atest.c for writing");
			return false;
		}
		if(f.writeBlock(cs.data(), cs.length()) == -1) {
			debug("error writing to atest.c");
			return false;
		}
		f.close();

		debug(QString("Wrote atest.c:\n%1").arg(filedata));

		QString str = qvar("QMAKE_CC") + ' ' + fname + " -o " + out;
		if(!flags.isEmpty()) {
			str += ' ';
			str += flags;
		}

		int r = doCommand(str);
		if(r == 0 && retcode)
			*retcode = doCommand(QString("./") + out);
		dir.remove(fname);
		dir.remove(out);
		if(r != 0)
			return false;
		return true;
	}

	bool checkHeader(const QString &path, const QString &h)
	{
		QFileInfo fi(path + '/' + h);
		if(fi.exists())
			return true;
		return false;
	}

	bool findHeader(const QString &h, const QStringList &ext, QString *inc)
	{
		if(checkHeader("/usr/include", h)) {
			*inc = "";
			return true;
		}
		QStringList dirs;
		dirs += "/usr/local/include";
		dirs += ext;
		for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) {
			if(checkHeader(*it, h)) {
				*inc = *it;
				return true;
			}
		}
		return false;
	}

	bool checkLibrary(const QString &path, const QString &name)
	{
		QString str =
			"int main()\n"
			"{\n"
			"    return 0;\n"
			"}\n";

		QString extra;
		if(!path.isEmpty())
			extra += QString("-L") + path + ' ';
		extra += QString("-l") + name;
		if(!doCompileAndLink(str, extra))
			return false;
		return true;
	}

	bool findLibrary(const QString &name, QString *lib)
	{
		if(checkLibrary("", name)) {
			*lib = "";
			return true;
		}
		if(checkLibrary("/usr/local/lib", name)) {
			*lib = "/usr/local/lib";
			return true;
		}
		return false;
	}

	void addDefine(const QString &str)
	{
		if(DEFINES.isEmpty())
			DEFINES = str;
		else
			DEFINES += QString(" ") + str;
		debug(QString("DEFINES += %1").arg(str));
	}

	void addLib(const QString &str)
	{
		if(LIBS.isEmpty())
			LIBS = str;
		else
			LIBS += QString(" ") + str;
		debug(QString("LIBS += %1").arg(str));
	}

	void addIncludePath(const QString &str)
	{
		if(INCLUDEPATH.isEmpty())
			INCLUDEPATH = str;
		else
			INCLUDEPATH += QString(" ") + str;
		debug(QString("INCLUDEPATH += %1").arg(str));
	}

	void addExtra(const QString &str)
	{
		extra += str + '\n';
		debug(QString("extra += %1").arg(str));
	}

	QString DEFINES;
	QString INCLUDEPATH;
	QString LIBS;
	QString extra;

private:
	ConfObjList list;
	QDict<QString> vars;
	QString blank;
	bool do_debug, done_debug;
};

ConfObj::ConfObj(Conf *c)
{
	conf = c;
	conf->added(this);
	required = false;
	disabled = false;
}

ConfObj::~ConfObj()
{
}

QString ConfObj::checkString() const
{
	return QString();
}

QString ConfObj::resultString() const
{
	return QString();
}

#include"modules.cpp"

//----------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------
int main()
{
	Conf *conf = new Conf;
	ConfObj *o;
	o = 0;
#include"modules_new.cpp"

	printf("ok\n");
	bool success = false;
	if(conf->exec()) {
		QFile f("conf.pri");
		if(!f.open(IO_WriteOnly | IO_Truncate)) {
			printf("Error writing %s\n", f.name().latin1());
			return 1;
		}

		QString str;
		str += "# qconf\n";
		str += "QT_PATH_PLUGINS = " + QString(qInstallPathPlugins()) + '\n';
		if(!conf->DEFINES.isEmpty())
			str += "DEFINES += " + conf->DEFINES + '\n';
		if(!conf->INCLUDEPATH.isEmpty())
			str += "INCLUDEPATH += " + conf->INCLUDEPATH + '\n';
		if(!conf->LIBS.isEmpty())
			str += "LIBS += " + conf->LIBS + '\n';
		if(!conf->extra.isEmpty())
			str += conf->extra;
		str += '\n';

		char *p = getenv("BINDIR");
		if(p) {
			str += QString("target.path = ") + p + '\n';
			str += "INSTALLS += target\n";
		}

		QCString cs = str.latin1();
		f.writeBlock(cs.data(), cs.length());
		f.close();
		success = true;
	}
	delete conf;

	if(success)
		return 0;
	else
		return 1;
}

#include"conf.moc"


EOT
cat >$1/conf.pro <<EOT
TEMPLATE = app
CONFIG += qt x11 thread console
TARGET = conf

DEFINES += X11_INC='"\$\$QMAKE_INCDIR_X11"'
DEFINES += X11_LIBDIR='"\$\$QMAKE_LIBDIR_X11"'
DEFINES += X11_LIB='"\$\$QMAKE_LIBS_X11"'
DEFINES += CC='"\$\$QMAKE_CC"'

SOURCES += conf.cpp

EOT
}

export PREFIX
export BINDIR
export LIBDIR
export QTDIR
export QC_WITH_QCA_INC
export QC_WITH_QCA_LIB
export QC_WITH_ZLIB_INC
export QC_WITH_ZLIB_LIB
export QC_DISABLE_xss
export QC_DISABLE_dnotify
export QC_DISABLE_ghbnr
export QC_DISABLE_kde
export QC_DEBUG
rm -rf .qconftemp
(
	mkdir .qconftemp
	gen_files .qconftemp
	cd .qconftemp
	$qm conf.pro >/dev/null
	QTDIR=$QTDIR make clean >/dev/null 2>&1
	QTDIR=$QTDIR make >../conf.log 2>&1
)

if [ "$?" != "0" ]; then
	rm -rf .qconftemp
	echo fail
	echo
	echo "There was an error compiling 'conf'.  Be sure you have a proper"
	echo "Qt 3.x Multithreaded (MT) build environment set up.  This"
	echo "means not just Qt, but also a C++ compiler, the 'make' command,"
	echo "and any other packages necessary to compile C++ programs."
	echo "See conf.log for details."
	if [ ! -f "$QTDIR/lib/libqt-mt.so.3" ]; then
		echo
		echo "One possible reason is that you don't have"
		echo "libqt-mt.so.3 installed in $QTDIR/lib/."
	fi
	echo
	exit 1;
fi

.qconftemp/conf
ret="$?"
if [ "$ret" = "1" ]; then
	rm -rf .qconftemp
	echo
	exit 1;
else
	if [ "$ret" != "0" ]; then
		rm -rf .qconftemp
		echo fail
		echo
		echo Unexpected error launching 'conf'
		echo
		exit 1;
	fi
fi
rm -rf .qconftemp

if [ -x "./qcextra" ]; then
	./qcextra
fi
# run qmake
$qm psi.pro
if [ "$?" != "0" ]; then
	echo
	exit 1;
fi
cat >Makefile.tmp <<EOT
export QTDIR = $QTDIR
export PATH = $QTDIR/bin:$PATH
EOT
cat Makefile >> Makefile.tmp
rm -f Makefile
cp -f Makefile.tmp Makefile
rm -f Makefile.tmp

echo
echo Good, your configure finished.  Now run \'make\'.
echo