TLS plugin for 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 12KB

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