The TQt Cryptographic Architecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

configure 9.7KB

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