summaryrefslogtreecommitdiffstats
path: root/configure
blob: 4a4e304dce43d20ff85030c90ae59cc582859095 (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
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
#!/bin/sh

show_usage() {
cat <<EOT
Usage: ./configure [OPTION]...

This script creates necessary configuration files to build/install.

Main options:
  --qtdir=[path]    Directory where Qt is installed.
  --help            This help text.

Dependency options:
  --with-openssl-inc=[path]    Path to OpenSSL include files
  --with-openssl-lib=[path]    Path to OpenSSL library files

EOT
}

while [ $# -gt 0 ]; do
	case "$1" in
		--qtdir=*)
			QTDIR=`expr "${1}" : "--qtdir=\(.*\)"`
			shift
			;;

		--with-openssl-inc=*)
			QC_WITH_OPENSSL_INC=`expr "${1}" : "--with-openssl-inc=\(.*\)"`
			shift
			;;

		--with-openssl-lib=*)
			QC_WITH_OPENSSL_LIB=`expr "${1}" : "--with-openssl-lib=\(.*\)"`
			shift
			;;

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


echo "Configuring qca-tls ..."

if [ "$QC_DEBUG" = "Y" ]; then
echo
echo QTDIR=$QTDIR
echo QC_WITH_OPENSSL_INC=$QC_WITH_OPENSSL_INC
echo QC_WITH_OPENSSL_LIB=$QC_WITH_OPENSSL_LIB
echo
fi

printf "Verifying TQt 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/tqt /usr/share/tqt /usr/share/tqt3 /usr/local/lib/tqt /usr/local/share/tqt /usr/lib/tqt3 /usr/local/lib/tqt3 /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'. Please set QTDIR
		echo manually. Perhaps you need to install Qt 3
		echo development utilities. You may download them either
		echo from the vendor of your operating system or from
		echo www.trolltech.com
		echo
		exit 1;
	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=`type -p qmake`
	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
/*
-----BEGIN QCMOD-----
name: OpenSSL
arg: with-openssl-inc=[path],Path to OpenSSL include files
arg: with-openssl-lib=[path],Path to OpenSSL library files
-----END QCMOD-----
*/
class qc_openssl : public ConfObj
{
public:
	qc_openssl(Conf *c) : ConfObj(c) {}
	TQString name() const { return "OpenSSL"; }
	TQString shortname() const { return "openssl"; }
	bool exec()
	{
		TQString inc, lib;
		TQString s;
		bool kb = false;
		TQString kbdir = "/usr/kerberos/include";

		// Redhat 9?
		if(TQFileInfo(kbdir).exists())
			kb = true;

		s = conf->getenv("QC_WITH_OPENSSL_INC");
		if(!s.isEmpty()) {
			if(!conf->checkHeader(s, "openssl/ssl.h"))
				return false;
			inc = s;
		}
		else {
			if(!conf->findHeader("openssl/ssl.h", TQStringList(), &s))
				return false;
			inc = s;
		}

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

		// is it at least openssl 0.9.7?
		TQString str =
			"#include<openssl/opensslv.h>\n"
			"int main()\n"
			"{\n"
			"  unsigned long x = OPENSSL_VERSION_NUMBER;\n"
			"  if(x >= 0x00907000) return 0; else return 1;\n"
			"}\n";
		TQString ext;
		if(!inc.isEmpty())
			ext += TQString("-I") + inc + ' ';
		if(kb)
			ext += TQString("-I") + kbdir + ' ';
		if(!lib.isEmpty())
			ext += TQString("-L") + lib + " -lssl -lcrypto ";
		int ret;
		if(!conf->doCompileAndLink(str, ext, &ret))
			return false;
		if(ret == 0)
			conf->addDefine("OSSL_097");

		if(!inc.isEmpty())
			conf->addIncludePath(inc);
		if(kb)
			conf->addIncludePath(kbdir);
		if(!lib.isEmpty())
			conf->addLib(TQString("-L") + s);
		conf->addLib("-lssl -lcrypto");

		// Make sure tqtinterface can be found
		conf->addIncludePath("/usr/include/tqt");

		return true;
	}
};

EOT
cat >$1/modules_new.cpp <<EOT
    o = new qc_openssl(conf);
    o->required = true;
    o->disabled = false;

EOT
cat >$1/conf.cpp <<EOT
#include<stdio.h>
#include<stdlib.h>
#include<tqstring.h>
#include<tqdict.h>
#include<tqptrlist.h>
#include<tqfileinfo.h>
#include<tqfile.h>
#include<tqdir.h>
#include<tqstringlist.h>

class Conf;

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

	virtual TQString name() const=0;
	virtual TQString shortname() const=0;
	virtual bool exec()=0;

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

typedef TQPtrList<ConfObj> ConfObjList;
typedef TQPtrListIterator<ConfObj> ConfObjListIt;

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

		vars.insert("QMAKE_INCDIR_X11", new TQString(X11_INC));
		vars.insert("QMAKE_LIBDIR_X11", new TQString(X11_LIBDIR));
		vars.insert("QMAKE_LIBS_X11",   new TQString(X11_LIB));
		vars.insert("QMAKE_CC",         new TQString(CC));
	}

	~Conf()
	{
	}

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

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

	bool exec()
	{
		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) {
				TQString v = TQString("QC_ENABLE_") + o->shortname();
				if(getenv(v) != "Y")
					continue;
			}
			// and the opposite?
			else {
				TQString v = TQString("QC_DISABLE_") + o->shortname();
				if(getenv(v) == "Y")
					continue;
			}

			printf("Checking for %s ...", o->name().latin1());
			fflush(stdout);
			bool ok = o->exec();
			if(ok)
				printf(" yes\n");
			else
				printf(" no\n");
			if(!ok && o->required) {
				printf("\nError: need %s!\n", o->name().latin1());
				return false;
			}
		}
		return true;
	}

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

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

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

	int doCommand(const TQString &s)
	{
		//printf("[%s]\n", s.latin1());
		int r = system((s + " 1>/dev/null 2>/dev/null").latin1());
		//printf("returned: %d\n", r);
		return r;
	}

	bool doCompileAndLink(const TQString &filedata, const TQString &flags, int *retcode=0)
	{
		TQDir dir(".");
		TQString fname = "atest.c";
		TQString out = "atest";
		TQFile f(fname);
		TQCString cs = filedata.latin1();
		if(!f.open(IO_WriteOnly | IO_Truncate))
			return false;
		f.writeBlock(cs.data(), cs.length());
		f.close();

		TQString str = qvar("QMAKE_CC") + ' ' + fname + " -o " + out + ' ' + flags;
		int r = doCommand(str);
		if(r == 0 && retcode)
			*retcode = doCommand(TQString("./") + out);
		dir.remove(fname);
		dir.remove(out);
		if(r != 0)
			return false;
		return true;
	}

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

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

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

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

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

	void addDefine(const TQString &str)
	{
		if(DEFINES.isEmpty())
			DEFINES = str;
		else
			DEFINES += TQString(" ") + str;
	}

	void addLib(const TQString &str)
	{
		if(LIBS.isEmpty())
			LIBS = str;
		else
			LIBS += TQString(" ") + str;
	}

	void addIncludePath(const TQString &str)
	{
		if(INCLUDEPATH.isEmpty())
			INCLUDEPATH = str;
		else
			INCLUDEPATH += TQString(" ") + str;
	}

	void addExtra(const TQString &str)
	{
		extra += str + '\n';
	}

	TQString DEFINES;
	TQString INCLUDEPATH;
	TQString LIBS;
	TQString extra;

private:
	ConfObjList list;
	TQDict<TQString> vars;
	TQString blank;
};

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

ConfObj::~ConfObj()
{
}

#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()) {
		TQFile f("conf.pri");
		if(!f.open(IO_WriteOnly | IO_Truncate)) {
			printf("Error writing %s\n", f.name().latin1());
			return 1;
		}

		TQString str;
		str += "# qconf\n";
		str += "QT_PATH_PLUGINS = " + TQString(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 += TQString("target.path = ") + p + '\n';
			str += "INSTALLS += target\n";
		}

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

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

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

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 QTDIR
export QC_WITH_OPENSSL_INC
export QC_WITH_OPENSSL_LIB
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 "TQt 3.x Multithreaded (MT) build environment set up."
	if [ ! -f "$QTDIR/lib/libtqt-mt.so.3" ]; then
		echo
		echo "One possible reason is that you don't have"
		echo "libtqt-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
if expr match "$DEB_BUILD_OPTIONS" ".*nostrip"; then
	$qm QMAKE_STRIP=true qca-tls.pro
else
	$qm qca-tls.pro
fi
if [ "$?" != "0" ]; then
	echo
	exit 1;
fi
cat >Makefile.tmp <<EOT
export QTDIR = $QTDIR
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