source: qca/trunk/configure@ 26

Last change on this file since 26 was 24, checked in by dmik, 19 years ago

QCA: Imported original QCA 1.0 sources from Affinix

File size: 9.0 KB
Line 
1#!/bin/sh
2
3show_usage() {
4cat <<EOT
5Usage: ./configure [OPTION]...
6
7This script creates necessary configuration files to build/install.
8
9Main options:
10 --prefix=[path] Base path for build/install. Default: /usr/local
11 --qtdir=[path] Directory where Qt is installed.
12 --help This help text.
13
14EOT
15}
16
17while [ $# -gt 0 ]; do
18 case "$1" in
19 --prefix=*)
20 PREFIX=`expr "${1}" : "--prefix=\(.*\)"`
21 shift
22 ;;
23
24 --qtdir=*)
25 QTDIR=`expr "${1}" : "--qtdir=\(.*\)"`
26 shift
27 ;;
28
29 --debug)
30 QC_DEBUG="Y"
31 shift
32 ;;
33 --help) show_usage; exit ;;
34 *) show_usage; exit ;;
35 esac
36done
37
38PREFIX=${PREFIX:-/usr/local}
39
40echo "Configuring Qt Cryptographic Architecture (QCA) ..."
41
42if [ "$QC_DEBUG" = "Y" ]; then
43echo
44echo PREFIX=$PREFIX
45echo QTDIR=$QTDIR
46echo
47fi
48
49printf "Verifying Qt 3.x Multithreaded (MT) build environment ... "
50
51if [ -z "$QTDIR" ]; then
52 if [ "$QC_DEBUG" = "Y" ]; then
53 echo \$QTDIR not set... trying to find Qt manually
54 fi
55 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
56 if [ -d "$p/mkspecs" ]; then
57 QTDIR=$p
58 break;
59 fi;
60 done
61 if [ -z "$QTDIR" ]; then
62 echo fail
63 echo
64 echo Unable to find Qt 'mkspecs'. Please set QTDIR
65 echo manually. Perhaps you need to install Qt 3
66 echo development utilities. You may download them either
67 echo from the vendor of your operating system or from
68 echo www.trolltech.com
69 echo
70 exit 1;
71 fi
72fi
73
74if [ ! -x "$QTDIR/bin/qmake" ]; then
75 if [ "$QC_DEBUG" = "Y" ]; then
76 echo Warning: qmake not in \$QTDIR/bin/qmake
77 echo trying to find it in \$PATH
78 fi
79 qm=`type -p qmake`
80 if [ -x "$qm" ]; then
81 if [ "$QC_DEBUG" = "Y" ]; then
82 echo qmake found in $qm
83 fi
84 else
85 echo fail
86 echo
87 echo Sorry, you seem to have a very unusual setup,
88 echo or I missdetected \$QTDIR=$QTDIR
89 echo
90 echo Please set \$QTDIR manually and make sure that
91 echo \$QTDIR/bin/qmake exists.
92 echo
93 exit 1;
94 fi
95else
96 qm=$QTDIR/bin/qmake
97fi
98
99gen_files() {
100cat >$1/modules.cpp <<EOT
101
102EOT
103cat >$1/modules_new.cpp <<EOT
104
105EOT
106cat >$1/conf.cpp <<EOT
107#include<stdio.h>
108#include<stdlib.h>
109#include<qstring.h>
110#include<qdict.h>
111#include<qptrlist.h>
112#include<qfileinfo.h>
113#include<qfile.h>
114#include<qdir.h>
115#include<qstringlist.h>
116
117class Conf;
118
119class ConfObj
120{
121public:
122 ConfObj(Conf *c);
123 virtual ~ConfObj();
124
125 virtual QString name() const=0;
126 virtual QString shortname() const=0;
127 virtual bool exec()=0;
128
129 Conf *conf;
130 bool required;
131 bool disabled;
132};
133
134typedef QPtrList<ConfObj> ConfObjList;
135typedef QPtrListIterator<ConfObj> ConfObjListIt;
136
137class Conf
138{
139public:
140 Conf() : vars(17)
141 {
142 list.setAutoDelete(true);
143 vars.setAutoDelete(true);
144
145 vars.insert("QMAKE_INCDIR_X11", new QString(X11_INC));
146 vars.insert("QMAKE_LIBDIR_X11", new QString(X11_LIBDIR));
147 vars.insert("QMAKE_LIBS_X11", new QString(X11_LIB));
148 vars.insert("QMAKE_CC", new QString(CC));
149 }
150
151 ~Conf()
152 {
153 }
154
155 void added(ConfObj *o)
156 {
157 list.append(o);
158 }
159
160 QString getenv(const QString &var)
161 {
162 char *p = ::getenv(var.latin1());
163 if(!p)
164 return QString::null;
165 return QString(p);
166 }
167
168 bool exec()
169 {
170 ConfObjListIt it(list);
171 for(ConfObj *o; (o = it.current()); ++it) {
172 // if this was a disabled-by-default option, check if it was enabled
173 if(o->disabled) {
174 QString v = QString("QC_ENABLE_") + o->shortname();
175 if(getenv(v) != "Y")
176 continue;
177 }
178 // and the opposite?
179 else {
180 QString v = QString("QC_DISABLE_") + o->shortname();
181 if(getenv(v) == "Y")
182 continue;
183 }
184
185 printf("Checking for %s ...", o->name().latin1());
186 fflush(stdout);
187 bool ok = o->exec();
188 if(ok)
189 printf(" yes\n");
190 else
191 printf(" no\n");
192 if(!ok && o->required) {
193 printf("\nError: need %s!\n", o->name().latin1());
194 return false;
195 }
196 }
197 return true;
198 }
199
200 const QString & qvar(const QString &s)
201 {
202 QString *p = vars.find(s);
203 if(p)
204 return *p;
205 else
206 return blank;
207 }
208
209 QString expandIncludes(const QString &inc)
210 {
211 return QString("-I") + inc;
212 }
213
214 QString expandLibs(const QString &lib)
215 {
216 return QString("-L") + lib;
217 }
218
219 int doCommand(const QString &s)
220 {
221 //printf("[%s]\n", s.latin1());
222 int r = system((s + " 1>/dev/null 2>/dev/null").latin1());
223 //printf("returned: %d\n", r);
224 return r;
225 }
226
227 bool doCompileAndLink(const QString &filedata, const QString &flags, int *retcode=0)
228 {
229 QDir dir(".");
230 QString fname = "atest.c";
231 QString out = "atest";
232 QFile f(fname);
233 QCString cs = filedata.latin1();
234 if(!f.open(IO_WriteOnly | IO_Truncate))
235 return false;
236 f.writeBlock(cs.data(), cs.length());
237 f.close();
238
239 QString str = qvar("QMAKE_CC") + ' ' + fname + " -o " + out + ' ' + flags;
240 int r = doCommand(str);
241 if(r == 0 && retcode)
242 *retcode = doCommand(QString("./") + out);
243 dir.remove(fname);
244 dir.remove(out);
245 if(r != 0)
246 return false;
247 return true;
248 }
249
250 bool checkHeader(const QString &path, const QString &h)
251 {
252 QFileInfo fi(path + '/' + h);
253 if(fi.exists())
254 return true;
255 return false;
256 }
257
258 bool findHeader(const QString &h, const QStringList &ext, QString *inc)
259 {
260 if(checkHeader("/usr/include", h)) {
261 *inc = "";
262 return true;
263 }
264 QStringList dirs;
265 dirs += "/usr/local/include";
266 dirs += ext;
267 for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) {
268 if(checkHeader(*it, h)) {
269 *inc = *it;
270 return true;
271 }
272 }
273 return false;
274 }
275
276 bool checkLibrary(const QString &path, const QString &name)
277 {
278 QString str =
279 "int main()\n"
280 "{\n"
281 " return 0;\n"
282 "}\n";
283
284 QString extra;
285 if(!path.isEmpty())
286 extra += QString("-L") + path + ' ';
287 extra += QString("-l") + name;
288 if(!doCompileAndLink(str, extra))
289 return false;
290 return true;
291 }
292
293 bool findLibrary(const QString &name, QString *lib)
294 {
295 if(checkLibrary("", name)) {
296 *lib = "";
297 return true;
298 }
299 if(checkLibrary("/usr/local/lib", name)) {
300 *lib = "/usr/local/lib";
301 return true;
302 }
303 return false;
304 }
305
306 void addDefine(const QString &str)
307 {
308 if(DEFINES.isEmpty())
309 DEFINES = str;
310 else
311 DEFINES += QString(" ") + str;
312 }
313
314 void addLib(const QString &str)
315 {
316 if(LIBS.isEmpty())
317 LIBS = str;
318 else
319 LIBS += QString(" ") + str;
320 }
321
322 void addIncludePath(const QString &str)
323 {
324 if(INCLUDEPATH.isEmpty())
325 INCLUDEPATH = str;
326 else
327 INCLUDEPATH += QString(" ") + str;
328 }
329
330 void addExtra(const QString &str)
331 {
332 extra += str + '\n';
333 }
334
335 QString DEFINES;
336 QString INCLUDEPATH;
337 QString LIBS;
338 QString extra;
339
340private:
341 ConfObjList list;
342 QDict<QString> vars;
343 QString blank;
344};
345
346ConfObj::ConfObj(Conf *c)
347{
348 conf = c;
349 conf->added(this);
350 required = false;
351 disabled = false;
352}
353
354ConfObj::~ConfObj()
355{
356}
357
358#include"modules.cpp"
359
360//----------------------------------------------------------------------------
361// main
362//----------------------------------------------------------------------------
363int main()
364{
365 Conf *conf = new Conf;
366 ConfObj *o;
367 o = 0;
368#include"modules_new.cpp"
369
370 printf("ok\n");
371 bool success = false;
372 if(conf->exec()) {
373 QFile f("conf.pri");
374 if(!f.open(IO_WriteOnly | IO_Truncate)) {
375 printf("Error writing %s\n", f.name().latin1());
376 return 1;
377 }
378
379 QString str;
380 str += "# qconf\n";
381 if(!conf->DEFINES.isEmpty())
382 str += "DEFINES += " + conf->DEFINES + '\n';
383 if(!conf->INCLUDEPATH.isEmpty())
384 str += "INCLUDEPATH += " + conf->INCLUDEPATH + '\n';
385 if(!conf->LIBS.isEmpty())
386 str += "LIBS += " + conf->LIBS + '\n';
387 if(!conf->extra.isEmpty())
388 str += conf->extra;
389 str += '\n';
390
391 char *p = getenv("BINDIR");
392 if(p) {
393 str += QString("target.path = ") + p + '\n';
394 str += "INSTALLS += target\n";
395 }
396
397 QCString cs = str.latin1();
398 f.writeBlock(cs.data(), cs.length());
399 f.close();
400 success = true;
401 }
402 delete conf;
403
404 if(success)
405 return 0;
406 else
407 return 1;
408}
409
410EOT
411cat >$1/conf.pro <<EOT
412TEMPLATE = app
413CONFIG += qt x11 thread console
414TARGET = conf
415
416DEFINES += X11_INC='"\$\$QMAKE_INCDIR_X11"'
417DEFINES += X11_LIBDIR='"\$\$QMAKE_LIBDIR_X11"'
418DEFINES += X11_LIB='"\$\$QMAKE_LIBS_X11"'
419DEFINES += CC='"\$\$QMAKE_CC"'
420
421SOURCES += conf.cpp
422
423EOT
424}
425
426export PREFIX
427export QTDIR
428rm -rf .qconftemp
429(
430 mkdir .qconftemp
431 gen_files .qconftemp
432 cd .qconftemp
433 $qm conf.pro >/dev/null
434 QTDIR=$QTDIR make clean >/dev/null 2>&1
435 QTDIR=$QTDIR make >../conf.log 2>&1
436)
437
438if [ "$?" != "0" ]; then
439 rm -rf .qconftemp
440 echo fail
441 echo
442 echo "There was an error compiling 'conf'. Be sure you have a proper"
443 echo "Qt 3.x Multithreaded (MT) build environment set up."
444 if [ ! -f "$QTDIR/lib/libqt-mt.so.3" ]; then
445 echo
446 echo "One possible reason is that you don't have"
447 echo "libqt-mt.so.3 installed in $QTDIR/lib/."
448 fi
449 echo
450 exit 1;
451fi
452
453.qconftemp/conf
454ret="$?"
455if [ "$ret" = "1" ]; then
456 rm -rf .qconftemp
457 echo
458 exit 1;
459else
460 if [ "$ret" != "0" ]; then
461 rm -rf .qconftemp
462 echo fail
463 echo
464 echo Unexpected error launching 'conf'
465 echo
466 exit 1;
467 fi
468fi
469rm -rf .qconftemp
470
471if [ -x "./qcextra" ]; then
472 ./qcextra
473fi
474# run qmake
475$qm qca.pro
476if [ "$?" != "0" ]; then
477 echo
478 exit 1;
479fi
480cat >Makefile.tmp <<EOT
481export QTDIR = $QTDIR
482EOT
483cat Makefile >> Makefile.tmp
484rm -f Makefile
485cp -f Makefile.tmp Makefile
486rm -f Makefile.tmp
487
488echo
489echo Good, your configure finished. Now run \'make\'.
490echo
Note: See TracBrowser for help on using the repository browser.