SIP4 python bindings for TQt
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.py 48KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. # This script generates the PyTQt configuration and generates the Makefiles.
  2. #
  3. # Copyright (c) 2007
  4. # Riverbank Computing Limited <info@riverbankcomputing.co.uk>
  5. #
  6. # This file is part of PyTQt.
  7. #
  8. # This copy of PyTQt is free software; you can redistribute it and/or modify it
  9. # under the terms of the GNU General Public License as published by the Free
  10. # Software Foundation; either version 2, or (at your option) any later
  11. # version.
  12. #
  13. # PyTQt is supplied in the hope that it will be useful, but WITHOUT ANY
  14. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16. # details.
  17. #
  18. # You should have received a copy of the GNU General Public License along with
  19. # PyTQt; see the file LICENSE. If not, write to the Free Software Foundation,
  20. # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. import sys
  22. import os
  23. import string
  24. import glob
  25. import getopt
  26. import shutil
  27. import py_compile
  28. from sip4_tqt import sipconfig
  29. src_dir = os.path.dirname(os.path.abspath(__file__))
  30. # Initialise the globals.
  31. pyqt_version = 0x031201
  32. pyqt_version_str = "3.18.1"
  33. sip_min_version = 0x040800
  34. # Try and find a TQt installation to use as the default.
  35. try:
  36. qt_dir = os.environ["TQTDIR"]
  37. except KeyError:
  38. qt_dir = ""
  39. qt_version = 0
  40. qt_edition = ""
  41. qt_incdir = None
  42. qt_libdir = None
  43. qt_threaded = 0
  44. qt_winconfig = ""
  45. pyqt = None
  46. pyqt_modules = []
  47. qt_sip_flags = []
  48. qtext_sip_flags = []
  49. qtpe_sip_flags = []
  50. qsci_version = 0
  51. disabled_classes = []
  52. if sys.platform == "win32":
  53. qsci_define = "TQEXTSCINTILLA_DLL"
  54. else:
  55. qsci_define = ""
  56. # Get the SIP configuration.
  57. sipcfg = sipconfig.Configuration()
  58. # Command line options.
  59. opt_tqtlib = None
  60. opt_qconfigdir = None
  61. opt_pyqtbindir = sipcfg.default_bin_dir
  62. opt_pyqtmoddir = os.path.join(sipcfg.default_mod_dir, "python_tqt")
  63. opt_pyqtsipdir = sipcfg.default_sip_dir
  64. opt_qtpetag = None
  65. opt_qsciincdir = None
  66. opt_qscilibdir = None
  67. opt_static = 0
  68. opt_debug = 0
  69. opt_concat = 0
  70. opt_split = 1
  71. opt_tracing = 0
  72. opt_verbose = 0
  73. opt_keepfeatures = 0
  74. opt_vendorcheck = 0
  75. opt_vendincdir = sipcfg.py_inc_dir
  76. opt_vendlibdir = sipcfg.py_lib_dir
  77. def usage(rcode = 2):
  78. """Display a usage message and exit.
  79. rcode is the return code passed back to the calling process.
  80. """
  81. if qt_dir:
  82. def_qt_dir = qt_dir
  83. else:
  84. def_qt_dir = "none"
  85. sys.stdout.write("Usage:\n")
  86. sys.stdout.write(" python configure.py [-h] [-a tag] [-b dir] [-c] [-d dir] [-e lib] [-f] [-g dir] [-i] [-j #] [-k] [-l dir] [-m dir] [-n dir] [-o dir] [-q dir] [-r] [-s] [-u] [-v dir] [-w] [-y lib] option=value option+=value ...\n")
  87. sys.stdout.write("where:\n")
  88. sys.stdout.write(" -h display this help message\n")
  89. sys.stdout.write(" -a tag explicitly enable the qtpe module\n")
  90. sys.stdout.write(" -b dir where pyuic and pylupdate will be installed [default %s]\n" % opt_pyqtbindir)
  91. sys.stdout.write(" -c concatenate each module's C/C++ source files\n")
  92. sys.stdout.write(" -d dir where the PyTQt modules will be installed [default %s]\n" % opt_pyqtmoddir)
  93. sys.stdout.write(" -e lib explicitly specify the python library\n")
  94. sys.stdout.write(" -f keep any existing features file (when cross-compiling) [default remove]\n")
  95. sys.stdout.write(" -g dir where the TQt qconfig.h file can be found [default TQt include directory]\n")
  96. sys.stdout.write(" -i enable checking of signed interpreters using the VendorID package [default disabled]\n")
  97. sys.stdout.write(" -j # split the concatenated C++ source files into # pieces [default 1]\n")
  98. sys.stdout.write(" -k build the PyTQt modules as static libraries\n")
  99. sys.stdout.write(" -l dir the directory containing the VendorID header file [default %s]\n" % opt_vendincdir)
  100. sys.stdout.write(" -m dir the directory containing the VendorID library [default %s]\n" % opt_vendlibdir)
  101. sys.stdout.write(" -n dir the directory containing the TQScintilla header files [default TQt include directory]\n")
  102. sys.stdout.write(" -o dir the directory containing the TQScintilla library [default TQt lib directory]\n")
  103. sys.stdout.write(" -q dir the root directory of the TQt installation [default %s]\n" % def_qt_dir)
  104. sys.stdout.write(" -r generate code with tracing enabled [default disabled]\n")
  105. sys.stdout.write(" -s TQScintilla is a static library and not a DLL (Windows only)\n")
  106. sys.stdout.write(" -u build with debugging symbols (requires a debug build of Python on Windows\n")
  107. sys.stdout.write(" -v dir where the PyTQt .sip files will be installed [default %s]\n" % opt_pyqtsipdir)
  108. sys.stdout.write(" -w don't suppress compiler output during configuration\n")
  109. sys.stdout.write(" -y lib explicitly specify the type of TQt library, either qt, qt-mt, qte, qte-mt, qtmt, tqt, tqt-mt, tqte, tqte-mt or tqtmt\n")
  110. sys.exit(rcode)
  111. class ConfigureBase:
  112. """This is the base class for all PyTQt version specific configurer classes.
  113. Anything here is common to all configurers.
  114. """
  115. def check_modules(self):
  116. """Check which modules should be built and add them to the global list.
  117. Returns the name of any additional library that needs to be linked with
  118. the main module.
  119. """
  120. return None
  121. def sip_flags(self):
  122. """Get the configuration specific SIP flags.
  123. Returns a list of flags.
  124. """
  125. return []
  126. def qt_version_tags(self):
  127. """Get the versions tags for the configuration.
  128. Returns a dictionary of versions and corresponding tags.
  129. """
  130. return {}
  131. def code(self, extra_include_dirs, extra_lib_dir, extra_libs):
  132. """Generate the code for a configuration.
  133. extra_include_dirs is a list of directories to add to those supplied by
  134. the SIP configuration.
  135. extra_lib_dir is an optional directory to add to those supplied by the
  136. SIP configuration.
  137. extra_lib_dirs is an optional list of directories to add to those
  138. supplied by the SIP configuration.
  139. """
  140. pass
  141. def tools(self):
  142. """Create the Makefiles for any other sub-directories and return a list
  143. of those directories.
  144. Returns a list of sub-directories with Makefile.
  145. """
  146. return []
  147. def module_dir(self):
  148. """Return the configuration's module directory.
  149. """
  150. return opt_pyqtmoddir
  151. def module_installs(self):
  152. """Return a list of files to install in the module directory other than
  153. the modules themselves.
  154. """
  155. return ["__init__.py", "pyqtconfig.py"]
  156. def sip_dir(self):
  157. """Return the configuration's .sip files directory.
  158. """
  159. return opt_pyqtsipdir
  160. class ConfigurePyTQt3(ConfigureBase):
  161. """This class defines the methods to configure PyTQt v3.
  162. """
  163. def check_modules(self):
  164. pyqt_modules.append("qt")
  165. check_module("qtcanvas", "qcanvas.h", "TQCanvas()")
  166. check_module("qtnetwork", "qsocket.h", "TQSocket()")
  167. check_module("qttable", "qtable.h", "TQTable()")
  168. check_module("qtxml", "qdom.h", "TQDomImplementation()")
  169. check_module("qtgl", "qgl.h", "TQGLWidget()", opengl=1)
  170. if qt_version >= 0x030000:
  171. check_module("qtui", "qwidgetfactory.h", "TQWidgetFactory()", lib="tqui")
  172. if qt_edition in ("enterprise", "free"):
  173. check_module("qtsql", "qsql.h", "TQSql()")
  174. if sys.platform == "win32" and sipcfg.sip_version >= 0x040200:
  175. check_module("qtaxcontainer", "qaxobject.h", "TQAxObject()", lib="qaxcontainer")
  176. if qsci_version:
  177. check_module("qtext", "qextscintillabase.h", "QextScintillaBase()", define=qsci_define, include_dir=opt_qsciincdir, lib_dir=opt_qscilibdir, lib="qscintilla")
  178. if opt_qtpetag:
  179. pyqt_modules.append("qtpe")
  180. qtmod_lib = None
  181. if qt_version >= 0x030100:
  182. sipconfig.inform("Checking to see if the TQAssistantClient class is available...")
  183. if check_class("qassistantclient.h", "TQAssistantClient(\"foo\")", lib="qassistantclient"):
  184. qtmod_lib = "qassistantclient"
  185. else:
  186. if check_class("ntqassistantclient.h", "TQAssistantClient(\"foo\")", lib="qassistantclient"):
  187. qtmod_lib = "qassistantclient"
  188. else:
  189. disabled_classes.append("TQAssistantClient")
  190. return qtmod_lib
  191. def sip_flags(self):
  192. return get_feature_flags()
  193. def qt_version_tags(self):
  194. return {
  195. 0x010403: None,
  196. 0x020000: "TQt_1_43",
  197. 0x020100: "TQt_2_00",
  198. 0x020200: "TQt_2_1_0",
  199. 0x020300: "TQt_2_2_0",
  200. 0x020301: "TQt_2_3_0",
  201. 0x030000: "TQt_2_3_1",
  202. 0x030001: "TQt_3_0_0",
  203. 0x030002: "TQt_3_0_1",
  204. 0x030004: "TQt_3_0_2",
  205. 0x030005: "TQt_3_0_4",
  206. 0x030006: "TQt_3_0_5",
  207. 0x030100: "TQt_3_0_6",
  208. 0x030101: "TQt_3_1_0",
  209. 0x030102: "TQt_3_1_1",
  210. 0x030200: "TQt_3_1_2",
  211. 0x030300: "TQt_3_2_0",
  212. 0x030305: "TQt_3_3_0",
  213. 0x030306: "TQt_3_3_5",
  214. 0x040000: "TQt_3_3_6"
  215. }
  216. def code(self, extra_include_dirs, extra_lib_dir, extra_libs):
  217. generate_code("qt", extra_include_dirs=extra_include_dirs, extra_lib_dir=extra_lib_dir, extra_libs=extra_libs)
  218. if "qtext" in pyqt_modules:
  219. generate_code("qtext", extra_define=qsci_define, extra_include_dirs=[opt_qsciincdir], extra_lib_dir=opt_qscilibdir, extra_libs=["qscintilla"]+extra_libs, sip_flags=qtext_sip_flags)
  220. if "qtgl" in pyqt_modules:
  221. generate_code("qtgl", opengl=1, extra_include_dirs=extra_include_dirs, extra_lib_dir=extra_lib_dir, extra_libs=extra_libs)
  222. if "qtpe" in pyqt_modules:
  223. generate_code("qtpe", extra_include_dirs=extra_include_dirs, extra_lib_dir=extra_lib_dir, extra_libs=["qpe"]+extra_libs, sip_flags=qtpe_sip_flags)
  224. if "qtui" in pyqt_modules:
  225. generate_code("qtui", extra_include_dirs=extra_include_dirs, extra_lib_dir=extra_lib_dir, extra_libs=["tqui"]+extra_libs)
  226. if "qtaxcontainer" in pyqt_modules:
  227. generate_code("qtaxcontainer", extra_include_dirs=extra_include_dirs, extra_lib_dir=extra_lib_dir, extra_libs=["qaxcontainer"]+extra_libs)
  228. # The rest don't need special handling.
  229. for m in ("qtcanvas", "qtnetwork", "qtsql", "qttable", "qtxml"):
  230. if m in pyqt_modules:
  231. generate_code(m, extra_include_dirs=extra_include_dirs, extra_lib_dir=extra_lib_dir, extra_libs=extra_libs)
  232. def tools(self):
  233. tool_dirs = []
  234. if qt_version >= 0x030000:
  235. # The Professional Edition needs special handling.
  236. prof = (qt_edition == "professional")
  237. sipconfig.inform("Creating pyuic Makefile...")
  238. if prof or "qtxml" not in pyqt_modules:
  239. buildfile= "pyuic-prof.sbf"
  240. for xml in ("qdom.cpp", "qxml.cpp"):
  241. shutil.copyfile(qt_dir + "/src/xml/" + xml, "pyuic3/" + xml)
  242. else:
  243. buildfile= "pyuic.sbf"
  244. makefile = sipconfig.ProgramMakefile(
  245. configuration=sipcfg,
  246. build_file=os.path.join(src_dir, "pyuic3", buildfile),
  247. dir="pyuic3",
  248. install_dir=opt_pyqtbindir,
  249. console=1,
  250. qt=1,
  251. warnings=1
  252. )
  253. makefile.extra_defines.append("UIC")
  254. makefile.extra_defines.append("QT_INTERNAL_XML")
  255. if prof or "qtxml" not in pyqt_modules:
  256. makefile.extra_defines.append("TQT_MODULE_XML")
  257. if qt_version < 0x030100:
  258. makefile.extra_include_dirs.append(qt_dir + "/src/3rdparty/zlib")
  259. makefile.extra_include_dirs.append(os.path.join(src_dir, "pyuic3"))
  260. if not os.access("pyuic3", os.F_OK):
  261. os.mkdir("pyuic3")
  262. makefile.generate()
  263. tool_dirs.append("pyuic3")
  264. sipconfig.inform("Creating pylupdate Makefile...")
  265. if prof or "qtxml" not in pyqt_modules:
  266. buildfile= "pylupdate-prof.sbf"
  267. shutil.copyfile(qt_dir + "/src/xml/qxml.cpp", "pylupdate3/qxml.cpp")
  268. else:
  269. buildfile= "pylupdate.sbf"
  270. makefile = sipconfig.ProgramMakefile(
  271. configuration=sipcfg,
  272. build_file=os.path.join(src_dir, "pylupdate3", buildfile),
  273. dir="pylupdate3",
  274. install_dir=opt_pyqtbindir,
  275. console=1,
  276. qt=1,
  277. warnings=1
  278. )
  279. makefile.extra_defines.append("QT_INTERNAL_XML")
  280. if prof or "qtxml" not in pyqt_modules:
  281. makefile.extra_defines.append("TQT_MODULE_XML")
  282. makefile.extra_include_dirs.append(os.path.join(src_dir, "pylupdate3"))
  283. if not os.access("pylupdate3", os.F_OK):
  284. os.mkdir("pylupdate3")
  285. makefile.generate()
  286. tool_dirs.append("pylupdate3")
  287. elif qt_version >= 0x020000:
  288. sipconfig.inform("Creating pyuic Makefile...")
  289. makefile = sipconfig.ProgramMakefile(
  290. configuration=sipcfg,
  291. build_file="pyuic.sbf",
  292. dir="pyuic2",
  293. install_dir=opt_pyqtbindir,
  294. console=1,
  295. qt=1,
  296. warnings=1
  297. )
  298. makefile.extra_defines.append("UIC")
  299. makefile.extra_include_dirs.append(qt_dir + "/src/3rdparty/zlib")
  300. makefile.generate()
  301. tool_dirs.append("pyuic2")
  302. return tool_dirs
  303. def inform_user():
  304. """Tell the user the option values that are going to be used.
  305. """
  306. if qt_edition:
  307. edstr = qt_edition + " edition "
  308. else:
  309. edstr = ""
  310. sipconfig.inform("TQt v%s %sis being used." % (sipconfig.version_to_string(qt_version), edstr))
  311. sipconfig.inform("SIP %s is being used." % sipcfg.sip_version_str)
  312. sipconfig.inform("These PyTQt modules will be built: %s." % string.join(pyqt_modules))
  313. if disabled_classes:
  314. sipconfig.inform("Support for these TQt classes has been disabled: %s." % string.join(disabled_classes))
  315. sipconfig.inform("The PyTQt modules will be installed in %s." % opt_pyqtmoddir)
  316. sipconfig.inform("The PyTQt .sip files will be installed in %s." % opt_pyqtsipdir)
  317. sipconfig.inform("The TQt header files are in %s." % qt_incdir)
  318. sipconfig.inform("The %s TQt library is in %s." % (opt_tqtlib, qt_libdir))
  319. if qt_version >= 0x020000:
  320. sipconfig.inform("pyuic will be installed in %s." % opt_pyqtbindir)
  321. if qt_version >= 0x030000:
  322. sipconfig.inform("pylupdate will be installed in %s." % opt_pyqtbindir)
  323. if opt_vendorcheck:
  324. sipconfig.inform("PyTQt will only be usable with signed interpreters.")
  325. def create_config(module, template, macros):
  326. """Create the PyTQt configuration module so that it can be imported by build
  327. scripts.
  328. module is the module file name.
  329. template is the template file name.
  330. macros is the dictionary of platform specific build macros.
  331. """
  332. sipconfig.inform("Creating %s..." % module)
  333. content = {
  334. "pyqt_config_args": sys.argv[1:],
  335. "pyqt_version": pyqt_version,
  336. "pyqt_version_str": pyqt_version_str,
  337. "pyqt_bin_dir": opt_pyqtbindir,
  338. "pyqt_mod_dir": opt_pyqtmoddir,
  339. "pyqt_sip_dir": opt_pyqtsipdir,
  340. "pyqt_modules": pyqt_modules,
  341. "pyqt_qt_sip_flags": qt_sip_flags,
  342. "qt_version": qt_version,
  343. "qt_edition": qt_edition,
  344. "qt_winconfig": qt_winconfig,
  345. "qt_framework": 0,
  346. "qt_threaded": qt_threaded,
  347. "qt_dir": qt_dir,
  348. "qt_inc_dir": qt_incdir,
  349. "qt_lib": opt_tqtlib,
  350. "qt_lib_dir": qt_libdir
  351. }
  352. if "qtaxcontainer" in pyqt_modules:
  353. content["pyqt_qtaxcontainer_sip_flags"] = qt_sip_flags
  354. if "qtcanvas" in pyqt_modules:
  355. content["pyqt_qtcanvas_sip_flags"] = qt_sip_flags
  356. if "qtext" in pyqt_modules:
  357. content["pyqt_qtext_sip_flags"] = qtext_sip_flags
  358. # These are internal.
  359. content["_pyqt_qscintilla_defines"] = qsci_define
  360. content["_pyqt_qscintilla_inc_dir"] = opt_qsciincdir
  361. content["_pyqt_qscintilla_lib_dir"] = opt_qscilibdir
  362. if "qtgl" in pyqt_modules:
  363. content["pyqt_qtgl_sip_flags"] = qt_sip_flags
  364. if "qtnetwork" in pyqt_modules:
  365. content["pyqt_qtnetwork_sip_flags"] = qt_sip_flags
  366. if "qtpe" in pyqt_modules:
  367. content["pyqt_qtpe_sip_flags"] = qtpe_sip_flags
  368. if "qtsql" in pyqt_modules:
  369. content["pyqt_qtsql_sip_flags"] = qt_sip_flags
  370. if "qttable" in pyqt_modules:
  371. content["pyqt_qttable_sip_flags"] = qt_sip_flags
  372. if "qtui" in pyqt_modules:
  373. content["pyqt_qtui_sip_flags"] = qt_sip_flags
  374. if "qtxml" in pyqt_modules:
  375. content["pyqt_qtxml_sip_flags"] = qt_sip_flags
  376. sipconfig.create_config_module(module, template, content, macros)
  377. def compile_qt_program(name, define=None, include_dir=None, lib_dir=None, lib=None, opengl=0, python=0, debug=0):
  378. """Compile a simple TQt application.
  379. name is the name of the single source file.
  380. define is a name to add to the list of preprocessor defines.
  381. include_dir is the name of a directory to add to the list of include
  382. directories.
  383. lib_dir is the name of a directory to add to the list of library
  384. directories.
  385. lib is the name of a library to add to the list of libraries.
  386. opengl is set if the application uses OpenGL.
  387. python is set if the application #includes Python.h.
  388. debug is set if this is a debug build.
  389. Returns the name of the executable suitable for running or None if it
  390. wasn't created.
  391. """
  392. makefile = sipconfig.ProgramMakefile(sipcfg, console=1, qt=1, warnings=0, opengl=opengl, python=python, debug=debug)
  393. if define:
  394. makefile.extra_defines.append(define)
  395. if include_dir:
  396. makefile.extra_include_dirs.append(include_dir)
  397. if lib_dir:
  398. makefile.extra_lib_dirs.append(lib_dir)
  399. if lib:
  400. makefile.extra_libs.append(lib)
  401. exe, build = makefile.build_command(name)
  402. # Make sure the executable file doesn't exist.
  403. try:
  404. os.remove(exe)
  405. except OSError:
  406. pass
  407. if not opt_verbose:
  408. try:
  409. import subprocess
  410. p = subprocess.Popen(build, shell=True, stdin=subprocess.PIPE,
  411. stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  412. fout = p.stdout
  413. except ImportError:
  414. _, fout = os.popen4(build)
  415. # Read stdout and stderr until there is no more output.
  416. lout = fout.readline()
  417. while lout:
  418. lout = fout.readline()
  419. fout.close()
  420. try:
  421. os.wait()
  422. except:
  423. pass
  424. else:
  425. os.system(build)
  426. if not os.access(exe, os.X_OK):
  427. return None
  428. if sys.platform != "win32":
  429. exe = "./" + exe
  430. return exe
  431. def check_qscintilla():
  432. """See if TQScintilla can be found and what its version is.
  433. """
  434. # Set the defaults if they haven't been explicitly specified.
  435. global opt_qsciincdir, opt_qscilibdir
  436. if opt_qsciincdir is None:
  437. opt_qsciincdir = qt_incdir
  438. if opt_qscilibdir is None:
  439. opt_qscilibdir = qt_libdir
  440. # Find the TQScintilla header files.
  441. sciglobal = os.path.join(opt_qsciincdir, "qextscintillaglobal.h")
  442. if os.access(sciglobal, os.F_OK):
  443. # Get the TQScintilla version number.
  444. global qsci_version
  445. qsci_version, sciversstr = sipconfig.read_version(sciglobal, "TQScintilla", "TQSCINTILLA_VERSION", "TQSCINTILLA_VERSION_STR")
  446. if glob.glob(os.path.join(opt_qscilibdir, "*qscintilla*")):
  447. sipconfig.inform("TQScintilla %s is being used." % sciversstr)
  448. # If we find a snapshot then set a negative version number as a
  449. # special case.
  450. if string.find(sciversstr, "snapshot") >= 0:
  451. qsci_version = -1
  452. else:
  453. sipconfig.inform("The TQScintilla library could not be found in %s and so the qtext module will not be built. If TQScintilla is installed then use the -o argument to explicitly specify the correct directory." % opt_qscilibdir)
  454. else:
  455. sipconfig.inform("qextscintillaglobal.h could not be found in %s and so the qtext module will not be built. If TQScintilla is installed then use the -n argument to explicitly specify the correct directory." % opt_qsciincdir)
  456. def check_vendorid():
  457. """See if the VendorID library and include file can be found.
  458. """
  459. global opt_vendorcheck
  460. if opt_vendorcheck:
  461. if os.access(os.path.join(opt_vendincdir, "vendorid.h"), os.F_OK):
  462. if glob.glob(os.path.join(opt_vendlibdir, "*vendorid*")):
  463. sipconfig.inform("The VendorID package was found.")
  464. else:
  465. opt_vendorcheck = 0
  466. sipconfig.inform("The VendorID library could not be found in %s and so signed interpreter checking will be disabled. If the VendorID library is installed then use the -m argument to explicitly specify the correct directory." % opt_vendlibdir)
  467. else:
  468. opt_vendorcheck = 0
  469. sipconfig.inform("vendorid.h could not be found in %s and so signed interpreter checking will be disabled. If the VendorID package is installed then use the -l argument to explicitly specify the correct directory." % opt_vendincdir)
  470. def check_module(mname, incfile, ctor, define=None, include_dir=None, lib_dir=None, lib=None, opengl=0):
  471. """See if a module can be built and, if so, add it to the global list of
  472. modules.
  473. mname is the name of the module.
  474. incfile is the name of the include file needed for the test.
  475. ctor is the C++ constructor of the class being used for the test.
  476. define is a name to add to the list of preprocessor defines.
  477. include_dir is the name of a directory to add to the list of include
  478. directories.
  479. lib_dir is the name of a directory to add to the list of library
  480. directories.
  481. lib is the name of a library to add to the list of libraries.
  482. opengl is set if the application uses OpenGL.
  483. """
  484. # Check the module's main .sip file exists.
  485. if os.access(os.path.join(src_dir, "sip", mname, mname + "mod.sip"), os.F_OK):
  486. sipconfig.inform("Checking to see if the %s module should be built..." % mname)
  487. if check_class(incfile, ctor, define, include_dir, lib_dir, lib, opengl):
  488. pyqt_modules.append(mname)
  489. else:
  490. if check_class("nt" + incfile, ctor, define, include_dir, lib_dir, lib, opengl):
  491. pyqt_modules.append(mname)
  492. def check_class(incfile, ctor, define=None, include_dir=None, lib_dir=None, lib=None, opengl=0):
  493. """Return non-zero if a class is available.
  494. incfile is the name of the include file needed for the test.
  495. ctor is the C++ constructor of the class.
  496. define is a name to add to the list of preprocessor defines.
  497. include_dir is the name of a directory to add to the list of include
  498. directories.
  499. lib_dir is the name of a directory to add to the list of library
  500. directories.
  501. lib is the name of a library to add to the list of libraries.
  502. opengl is set if the application uses OpenGL.
  503. """
  504. cfgtest = "cfgtest.cpp"
  505. f = open(cfgtest, "w")
  506. f.write("""#include <%s>
  507. int main(int argc, char **argv)
  508. {
  509. new %s;
  510. }
  511. """ % (incfile, ctor))
  512. f.close()
  513. return compile_qt_program(cfgtest, define, include_dir, lib_dir, lib, opengl)
  514. def check_plugin(cname, incfile):
  515. """Return non-zero if a class that might be a plugin is in the main TQt
  516. library.
  517. cname is the name of the class.
  518. incfile is the name of the include file needed for the test.
  519. """
  520. sipconfig.inform("Checking to see if the %s class is built in..." % cname)
  521. return check_class(incfile, cname + "()")
  522. def create_features_file(name):
  523. """Create the features file.
  524. name is the name of the features file in the current directory.
  525. """
  526. # The features that a given TQt configuration may or may not support. Note
  527. # that STYLE_WINDOWSXP and ASSISTANTCLIENT require special handling.
  528. flist = ["ACTION", "CLIPBOARD", "CODECS", "COLORDIALOG", "DATASTREAM",
  529. "DIAL", "DNS", "DOM", "DRAGANDDROP", "ICONVIEW", "IMAGE_TEXT",
  530. "INPUTDIALOG", "FILEDIALOG", "FONTDATABASE", "FONTDIALOG",
  531. "MESSAGEBOX", "MIMECLIPBOARD",
  532. "NETWORKPROTOCOL", "NETWORKPROTOCOL_FTP", "NETWORKPROTOCOL_HTTP",
  533. "PICTURE", "PRINTDIALOG", "PRINTER", "PROGRESSDIALOG",
  534. "PROPERTIES",
  535. "SEMIMODAL", "SIZEGRIP", "SOUND", "SPLITTER", "STYLE_CDE",
  536. "STYLE_INTERLACE", "STYLE_MOTIF", "STYLE_MOTIFPLUS",
  537. "STYLE_PLATINUM", "STYLE_SGI", "STYLE_WINDOWS",
  538. "TABDIALOG", "TABLE", "TABLEVIEW", "TRANSFORMATIONS",
  539. "TRANSLATION", "WIZARD", "WORKSPACE"]
  540. # Generate the program which will generate the features file.
  541. f = open("mkfeatures.cpp", "w")
  542. f.write(
  543. """#include <Python.h>
  544. #include <stdio.h>
  545. #include <tqglobal.h>
  546. #include <tqapplication.h>
  547. int main(int argc,char **argv)
  548. {
  549. FILE *fp;
  550. TQApplication app(argc,argv,0);
  551. if ((fp = fopen("%s","w")) == NULL)
  552. {
  553. printf("Unable to create '%s'\\n");
  554. return 1;
  555. }
  556. #if !defined(WITH_THREAD) || !defined(TQT_THREAD_SUPPORT)
  557. fprintf(fp,"-x TQt_THREAD_SUPPORT\\n");
  558. #endif
  559. #if !defined(Q_WS_WIN) || TQT_VERSION < 0x030000 || defined(TQT_NO_STYLE_WINDOWSXP)
  560. fprintf(fp,"-x TQt_STYLE_WINDOWSXP\\n");
  561. #endif
  562. #if defined(Q_OS_WIN64)
  563. fprintf(fp,"-x TQt_TQ_LONG_IS_long\\n");
  564. #endif
  565. """ % (name, name))
  566. for feat in flist:
  567. f.write(
  568. """
  569. #if defined(TQT_NO_%s)
  570. fprintf(fp,"-x TQt_%s\\n");
  571. #endif
  572. """ % (feat, feat))
  573. # Disable TQAssistantClient for the Professional Edition.
  574. if "TQAssistantClient" in disabled_classes:
  575. f.write(
  576. """
  577. fprintf(fp,"-x TQt_ASSISTANTCLIENT\\n");
  578. """)
  579. f.write(
  580. """
  581. fclose(fp);
  582. return 0;
  583. }
  584. """)
  585. f.close()
  586. # Build the program.
  587. exe = compile_qt_program("mkfeatures.cpp", include_dir=sipcfg.py_inc_dir, python=1)
  588. if not exe:
  589. sipconfig.error("Unable to build mkfeatures utility.")
  590. os.system(exe)
  591. # Check the file was created.
  592. if not os.access(name, os.F_OK):
  593. sipconfig.error("There was an error creating the features file.")
  594. # Check what features have been implemented as plugins and disable them.
  595. plugins = [("STYLE_CDE", "qcdestyle.h", "TQCDEStyle"),
  596. ("STYLE_INTERLACE", "qinterlacestyle.h", "TQInterlaceStyle"),
  597. ("STYLE_MOTIF", "qmotifstyle.h", "TQMotifStyle"),
  598. ("STYLE_MOTIFPLUS", "qmotifplusstyle.h", "TQMotifPlusStyle"),
  599. ("STYLE_PLATINUM", "qplatinumstyle.h", "TQPlatinumStyle"),
  600. ("STYLE_SGI", "qsgistyle.h", "TQSGIStyle"),
  601. ("STYLE_WINDOWSXP", "qwindowsxpstyle.h", "TQWindowsXPStyle"),
  602. ("STYLE_WINDOWS", "qwindowsstyle.h", "TQWindowsStyle")]
  603. f = open(name, "a")
  604. for (feat, incfile, cname) in plugins:
  605. if not check_plugin(cname, incfile):
  606. if not check_plugin(cname, "nt" + incfile):
  607. f.write("-x TQt_%s\n" % feat)
  608. disabled_classes.append(cname)
  609. f.close()
  610. def get_feature_flags():
  611. """Return the list of SIP flags that exclude unsupported TQt features.
  612. """
  613. featfile = "features"
  614. # Create the features file if it doesn't exist and we are not keeping it.
  615. if opt_keepfeatures and os.access(featfile,os.F_OK):
  616. sipconfig.inform("Using existing features file.")
  617. else:
  618. sipconfig.inform("Creating features file...")
  619. create_features_file(featfile)
  620. # Parse the features file.
  621. ff = open(featfile, "r")
  622. flags = []
  623. line = ff.readline()
  624. while line:
  625. flags.extend(string.split(line))
  626. line = ff.readline()
  627. if sipcfg.sip_version >= 0x040702:
  628. flags.extend(['-x', 'TQt_SIP_PRE_4_7_2'])
  629. return flags
  630. def set_sip_flags():
  631. """Set the SIP platform, version and feature flags.
  632. """
  633. qt_sip_flags.extend(pyqt.sip_flags())
  634. # If we don't check for signed interpreters, we exclude the 'VendorID'
  635. # feature
  636. if not opt_vendorcheck:
  637. qt_sip_flags.append("-x")
  638. qt_sip_flags.append("VendorID")
  639. # Handle the platform tag.
  640. if opt_qtpetag:
  641. plattag = "WS_QWS"
  642. elif sys.platform == "win32":
  643. plattag = "WS_WIN"
  644. elif sys.platform == "darwin":
  645. if "__DARWIN_X11__" in sipcfg.build_macros()["DEFINES"]:
  646. plattag = "WS_X11"
  647. else:
  648. plattag = "WS_MACX"
  649. else:
  650. plattag = "WS_X11"
  651. qt_sip_flags.append("-t")
  652. qt_sip_flags.append(plattag)
  653. # Handle the TQt version tag.
  654. verstag = sipconfig.version_to_sip_tag(qt_version, pyqt.qt_version_tags(), "TQt")
  655. if verstag:
  656. qt_sip_flags.append("-t")
  657. qt_sip_flags.append(verstag)
  658. # The flags so far are common.
  659. for f in qt_sip_flags:
  660. qtext_sip_flags.append(f)
  661. qtpe_sip_flags.append(f)
  662. # Handle the TQScintilla version tag.
  663. if qsci_version:
  664. qscitags = {
  665. 0x010100: None,
  666. 0x010200: "TQScintilla_1_1",
  667. 0x010300: "TQScintilla_1_2",
  668. 0x010400: "TQScintilla_1_3",
  669. 0x010500: "TQScintilla_1_4",
  670. 0x010600: "TQScintilla_1_5",
  671. 0x010700: "TQScintilla_1_6",
  672. 0x020000: "TQScintilla_1_7"
  673. }
  674. verstag = sipconfig.version_to_sip_tag(qsci_version, qscitags, "TQScintilla")
  675. if verstag:
  676. qtext_sip_flags.append("-t")
  677. qtext_sip_flags.append(verstag)
  678. # Handle the TQtopia tag.
  679. if opt_qtpetag:
  680. qtpe_sip_flags.append("-t")
  681. qtpe_sip_flags.append(opt_qtpetag)
  682. def generate_code(mname, extra_cflags=None, extra_cxxflags=None, extra_define=None, extra_include_dirs=None, extra_lflags=None, extra_lib_dir=None, extra_libs=None, opengl=0, sip_flags=None):
  683. """Generate the code for a module.
  684. mname is the name of the module.
  685. extra_cflags is a string containing additional C compiler flags.
  686. extra_cxxflags is a string containing additional C++ compiler flags.
  687. extra_define is a name to add to the list of preprocessor defines.
  688. extra_include_dirs is a list of directories to add to the list of include
  689. directories.
  690. extra_lflags is a string containing additional linker flags.
  691. extra_lib_dir is the name of a directory to add to the list of library
  692. directories.
  693. extra_libs is a list of the names of extra libraries to add to the list of
  694. libraries.
  695. opengl is set if the module needs OpenGL support.
  696. sip_flags is the list of sip flags to use instead of the defaults.
  697. """
  698. sipconfig.inform("Generating the C++ source for the %s module..." % mname)
  699. try:
  700. shutil.rmtree(mname)
  701. except:
  702. pass
  703. try:
  704. os.mkdir(mname)
  705. except:
  706. sipconfig.error("Unable to create the %s directory." % mname)
  707. # Build the SIP command line.
  708. argv = ['"' + sipcfg.sip_bin + '"']
  709. if sip_flags is None:
  710. sip_flags = qt_sip_flags
  711. argv.extend(sip_flags)
  712. if opt_concat:
  713. argv.append("-j")
  714. argv.append(str(opt_split))
  715. if opt_tracing:
  716. argv.append("-r")
  717. argv.append("-c")
  718. argv.append(mname)
  719. buildfile = os.path.join(mname, mname + ".sbf")
  720. argv.append("-b")
  721. argv.append(buildfile)
  722. argv.append("-I")
  723. argv.append(os.path.join(src_dir, "sip"))
  724. # SIP assumes POSIX style path separators.
  725. argv.append(string.join([src_dir, "sip", mname, mname + "mod.sip"], "/"))
  726. os.system(string.join(argv))
  727. # Check the result.
  728. if not os.access(buildfile, os.F_OK):
  729. sipconfig.error("Unable to create the C++ code.")
  730. # Generate the Makefile.
  731. sipconfig.inform("Creating the Makefile for the %s module..." % mname)
  732. installs = []
  733. sipfiles = []
  734. for s in glob.glob("sip/" + mname + "/*.sip"):
  735. sipfiles.append(os.path.join(src_dir, "sip", mname, os.path.basename(s)))
  736. installs.append([sipfiles, os.path.join(pyqt.sip_dir(), mname)])
  737. makefile = sipconfig.SIPModuleMakefile(
  738. configuration=sipcfg,
  739. build_file=mname + ".sbf",
  740. dir=mname,
  741. install_dir=pyqt.module_dir(),
  742. installs=installs,
  743. qt=1,
  744. opengl=opengl,
  745. warnings=1,
  746. static=opt_static,
  747. debug=opt_debug
  748. )
  749. if extra_cflags:
  750. makefile.extra_cflags.append(extra_cflags)
  751. if extra_cxxflags:
  752. makefile.extra_cxxflags.append(extra_cxxflags)
  753. if extra_define:
  754. makefile.extra_defines.append(extra_define)
  755. if extra_include_dirs:
  756. makefile.extra_include_dirs.extend(extra_include_dirs)
  757. if extra_lflags:
  758. makefile.extra_lflags.append(extra_lflags)
  759. if extra_lib_dir:
  760. makefile.extra_lib_dirs.append(extra_lib_dir)
  761. if extra_libs:
  762. makefile.extra_libs.extend(extra_libs)
  763. makefile.generate()
  764. def check_license():
  765. """Handle the validation of the PyTQt license.
  766. """
  767. try:
  768. import license
  769. ltype = license.LicenseType
  770. lname = license.LicenseName
  771. try:
  772. lfile = license.LicenseFile
  773. except AttributeError:
  774. lfile = None
  775. except ImportError:
  776. ltype = None
  777. if ltype is None:
  778. ltype = "GPL"
  779. lname = "GNU General Public License"
  780. lfile = None
  781. sipconfig.inform("This is the %s version of PyTQt %s (licensed under the %s) for Python %s on %s." % (ltype, pyqt_version_str, lname, string.split(sys.version)[0], sys.platform))
  782. # Common checks.
  783. if ltype == "GPL" and sys.platform == "win32":
  784. error("You cannot use the GPL version of PyTQt under Windows.")
  785. try:
  786. qted = qt_edition
  787. except AttributeError:
  788. qted = None
  789. if qted and ltype != "internal":
  790. if (qted == "free" and ltype != "GPL") or (qted != "free" and ltype == "GPL"):
  791. sipconfig.error("This version of PyTQt and the %s edition of TQt have incompatible licenses." % qted)
  792. # Confirm the license.
  793. sys.stdout.write("""
  794. Type 'L' to view the license.
  795. Type 'yes' to accept the terms of the license.
  796. Type 'no' to decline the terms of the license.
  797. """)
  798. while 1:
  799. try:
  800. resp = raw_input("Do you accept the terms of the license? ")
  801. except:
  802. resp = ""
  803. resp = string.lower(string.strip(resp))
  804. if resp == "yes":
  805. break
  806. if resp == "no":
  807. sys.exit(0)
  808. if resp == "l":
  809. os.system("more LICENSE")
  810. # If there should be a license file then check it is where it should be.
  811. if lfile:
  812. if os.access(os.path.join("sip", lfile), os.F_OK):
  813. sipconfig.inform("Found the license file %s." % lfile)
  814. else:
  815. sipconfig.error("Please copy the license file %s to the sip directory." % lfile)
  816. def get_build_macros(overrides):
  817. """Return the dictionary of platform specific build macros from the TQt
  818. installation. Return None if any of the overrides was invalid.
  819. overrides is a list of macros overrides from the user.
  820. """
  821. # Get the name of the qmake configuration file to take the macros from.
  822. if "QMAKESPEC" in os.environ.keys():
  823. fname = os.path.join(qt_dir, "mkspecs", os.environ["QMAKESPEC"], "qmake.conf")
  824. else:
  825. fname = os.path.join(qt_dir, "mkspecs", "default", "qmake.conf")
  826. if not os.access(fname, os.F_OK):
  827. sipconfig.error("Unable to find the default configuration file %s. You can use the QMAKESPEC environment variable to specify the correct platform instead of \"default\"." % fname)
  828. # Add the TQt specific macros to the default.
  829. names = sipcfg.build_macros().keys()
  830. names.append("INCDIR_TQT")
  831. names.append("LIBDIR_TQT")
  832. names.append("MOC")
  833. # Make sure $TQTDIR reflects any directory passed on the command line.
  834. os.environ["TQTDIR"] = qt_dir
  835. properties = {
  836. "QT_INSTALL_BINS": os.path.join(qt_dir, "bin"),
  837. "QT_INSTALL_HEADERS": os.path.join(qt_dir, "include"),
  838. "QT_INSTALL_LIBS": os.path.join(qt_dir, "lib")
  839. }
  840. return sipconfig.parse_build_macros(fname, names, overrides, properties)
  841. def check_qt_installation(macros):
  842. """Check the TQt installation and get the version number and edition.
  843. macros is the dictionary of build macros.
  844. """
  845. # Get the Makefile generator.
  846. generator = macros["MAKEFILE_GENERATOR"]
  847. # Set the TQt include and lib directories.
  848. global qt_incdir, qt_libdir
  849. qt_incdir = macros["INCDIR_TQT"]
  850. if not qt_incdir:
  851. qt_incdir = os.path.join(qt_dir, "include")
  852. macros["INCDIR_TQT"] = qt_incdir
  853. qt_libdir = macros["LIBDIR_TQT"]
  854. if not qt_libdir:
  855. qt_libdir = os.path.join(qt_dir, "lib")
  856. macros["LIBDIR_TQT"] = qt_libdir
  857. # Check the TQt header files have been installed. Quietly check for TQt v4.
  858. qt4_d = os.path.join(qt_incdir, "TQtCore")
  859. qglobal = os.path.join(qt4_d, "qglobal.h")
  860. if not os.access(qglobal, os.F_OK):
  861. qglobal = os.path.join(qt_incdir, "qglobal.h")
  862. if not os.access(qglobal, os.F_OK):
  863. qglobal = os.path.join(qt_incdir, "ntqglobal.h")
  864. if not os.access(qglobal, os.F_OK):
  865. sipconfig.error("qglobal.h or ntqglobal.h could not be found in %s." % qt_incdir)
  866. # Get the TQt version number.
  867. global qt_version
  868. qt_version, ignore = sipconfig.read_version(qglobal, "TQt", "TQT_VERSION")
  869. # Early versions of TQt for the Mac didn't include everything. Rather than
  870. # maintain these in the future we just mandate a later version.
  871. if sys.platform == "darwin" and qt_version < 0x030100:
  872. sipconfig.error("PyTQt for MacOS/X requires TQt v3.1.0 or later.")
  873. # The way SIP v4.2 and later handle connections between signals and Python
  874. # slots only works with TQt v3 and later. Therefore TQt v2 and earlier needs
  875. # SIP v3.
  876. if qt_version < 0x030000:
  877. sipconfig.error("TQt v2.x and earlier require SIP v3.x.")
  878. if qt_version >= 0x040000:
  879. sipconfig.error("TQt v4.x requires PyTQt v4.x.")
  880. # Try and work out which edition it is.
  881. global qt_edition
  882. if qt_version >= 0x030000:
  883. if opt_qconfigdir:
  884. qconfigdir = opt_qconfigdir
  885. else:
  886. qconfigdir = qt_incdir
  887. qconfig = os.path.join(qconfigdir, "qconfig.h")
  888. if not os.access(qconfig,os.F_OK):
  889. qconfig = os.path.join(qconfigdir, "ntqconfig.h")
  890. if not os.access(qconfig,os.F_OK):
  891. sipconfig.error("qconfig.h or ntqconfig.h could not be found in %s." % qconfigdir)
  892. f = open(qconfig)
  893. l = f.readline()
  894. while l:
  895. wl = string.split(l)
  896. if len(wl) == 3 and wl[0] == "#define" and wl[1] == "QT_PRODUCT_LICENSE":
  897. qt_edition = wl[2][4:-1]
  898. break
  899. l = f.readline()
  900. f.close()
  901. if not qt_edition:
  902. sipconfig.error("The TQt edition could not be determined by parsing %s." % qconfig)
  903. elif qt_version == 0x020300 and sys.platform == "win32":
  904. # See if we have the TQt v2 non-commercial version.
  905. if os.access(os.path.join(qt_libdir, "qt-mt230nc.lib"), os.F_OK):
  906. qt_edition = "non-commercial"
  907. if sys.platform == "win32":
  908. # Work out how TQt was built on Windows.
  909. global qt_winconfig
  910. try:
  911. f = open(os.path.join(qt_dir, ".qtwinconfig"), "r")
  912. except IOError:
  913. f = None
  914. if f:
  915. cfg = f.readline()
  916. f.close()
  917. val = string.find(cfg, "=")
  918. if val >= 0:
  919. qt_winconfig = string.strip(cfg[val + 1:])
  920. else:
  921. # Assume it was built as a DLL.
  922. qt_winconfig = "shared"
  923. # Determine the TQt library to link against and if it has thread support.
  924. global qt_threaded
  925. resolve_qt3_library(generator)
  926. if opt_tqtlib in ("qt-mt", "qt-mtedu", "qt-mteval", "qte-mt", "qtmt", "qtmtedu", "qtmteval", "tqt-mt", "tqt-mtedu", "tqt-mteval", "tqte-mt", "tqtmt", "tqtmtedu", "tqtmteval"):
  927. qt_threaded = 1
  928. global pyqt
  929. pyqt = ConfigurePyTQt3()
  930. # We haven't yet factored out sipconfig's knowledge of how to build TQt
  931. # binaries and it is expecting to find these in the configuration when it
  932. # generates the Makefiles.
  933. sipcfg.qt_version = qt_version
  934. sipcfg.qt_edition = qt_edition
  935. sipcfg.qt_winconfig = qt_winconfig
  936. sipcfg.qt_framework = 0
  937. sipcfg.qt_threaded = qt_threaded
  938. sipcfg.qt_dir = qt_dir
  939. sipcfg.qt_lib = opt_tqtlib
  940. sipcfg.qt_lib_dir = qt_libdir
  941. def resolve_qt3_library(generator):
  942. """See which version of the TQt v3 library can be found. (We can't trust
  943. the configuration files.)
  944. generator is the name of the Makefile generator.
  945. """
  946. global opt_tqtlib
  947. if opt_tqtlib:
  948. if not is_qt_library(generator, opt_tqtlib):
  949. sipconfig.error("The %s TQt library could not be found in %s." % (opt_tqtlib, qt_libdir))
  950. else:
  951. stlib = is_qt_library(generator, "tqt")
  952. mtlib = is_qt_library(generator, "tqt-mt")
  953. edlib = is_qt_library(generator, "tqt-mtedu")
  954. evlib = is_qt_library(generator, "tqt-mteval")
  955. emlib = is_qt_library(generator, "tqte")
  956. etlib = is_qt_library(generator, "tqte-mt")
  957. # Borland likes to be a little different.
  958. bmtlib = is_qt_library(generator, "tqtmt")
  959. bedlib = is_qt_library(generator, "tqtmtedu")
  960. bevlib = is_qt_library(generator, "tqtmteval")
  961. names = []
  962. if stlib:
  963. opt_tqtlib = "tqt"
  964. names.append(opt_tqtlib)
  965. if mtlib:
  966. opt_tqtlib = "tqt-mt"
  967. names.append(opt_tqtlib)
  968. if edlib:
  969. opt_tqtlib = "tqt-mtedu"
  970. names.append(opt_tqtlib)
  971. if evlib:
  972. opt_tqtlib = "tqt-mteval"
  973. names.append(opt_tqtlib)
  974. if emlib:
  975. opt_tqtlib = "tqte"
  976. names.append(opt_tqtlib)
  977. if etlib:
  978. opt_tqtlib = "tqte-mt"
  979. names.append(opt_tqtlib)
  980. if bmtlib:
  981. opt_tqtlib = "tqtmt"
  982. names.append(opt_tqtlib)
  983. if bedlib:
  984. opt_tqtlib = "tqtmtedu"
  985. names.append(opt_tqtlib)
  986. if bevlib:
  987. opt_tqtlib = "tqtmteval"
  988. names.append(opt_tqtlib)
  989. if not names:
  990. sipconfig.error("No TQt libraries could be found in %s." % qt_libdir)
  991. if len(names) > 1:
  992. sipconfig.error("These TQt libraries were found: %s. Use the -y argument to explicitly specify which you want to use." % string.join(names))
  993. def is_qt_library(generator, lib):
  994. """See if a particular TQt library is installed.
  995. generator is the name of the Makefile generator.
  996. lib is the name of the library.
  997. """
  998. if generator in ("MSVC", "MSVC.NET", "BMAKE"):
  999. lpatts = [lib + "[0-9]*.lib", lib + ".lib"]
  1000. else:
  1001. lpatts = ["lib" + lib + ".*"]
  1002. for lpatt in lpatts:
  1003. lmatch = glob.glob(os.path.join(qt_libdir, lpatt))
  1004. if lmatch:
  1005. return lmatch
  1006. return []
  1007. def main(argv):
  1008. """Create the configuration module module.
  1009. argv is the list of command line arguments.
  1010. """
  1011. # Check Python isn't too new.
  1012. if sipcfg.py_version >= 0x030000:
  1013. sipconfig.error("PyTQt v3.x does not support Python v3.x")
  1014. # Check SIP is new enough.
  1015. if sipcfg.sip_version_str[:8] != "snapshot":
  1016. if sipcfg.sip_version < sip_min_version:
  1017. sipconfig.error("This version of PyTQt requires SIP v%s or later" % sipconfig.version_to_string(sip_min_version))
  1018. # Parse the command line.
  1019. try:
  1020. optlist, args = getopt.getopt(argv[1:], "ha:b:cd:e:fg:ij:kl:m:n:o:q:rsuv:wy:")
  1021. except getopt.GetoptError:
  1022. usage()
  1023. global qt_dir, opt_tqtlib, opt_qconfigdir
  1024. global opt_pyqtbindir, opt_pyqtmoddir, opt_pyqtsipdir
  1025. global opt_qtpetag, opt_static, opt_debug, opt_concat
  1026. global opt_split, opt_tracing, opt_verbose, opt_keepfeatures
  1027. global opt_qsciincdir, opt_qscilibdir, qsci_define
  1028. global opt_vendorcheck, opt_vendincdir, opt_vendlibdir
  1029. global opt_libpython
  1030. opt_libpython = None
  1031. for opt, arg in optlist:
  1032. if opt == "-h":
  1033. usage(0)
  1034. elif opt == "-a":
  1035. opt_qtpetag = arg
  1036. elif opt == "-b":
  1037. opt_pyqtbindir = os.path.abspath(arg)
  1038. elif opt == "-c":
  1039. opt_concat = 1
  1040. elif opt == "-d":
  1041. opt_pyqtmoddir = os.path.abspath(arg)
  1042. elif opt == "-e":
  1043. opt_libpython = arg
  1044. elif opt == "-f":
  1045. opt_keepfeatures = 1
  1046. elif opt == "-g":
  1047. opt_qconfigdir = os.path.abspath(arg)
  1048. elif opt == "-i":
  1049. opt_vendorcheck = 1
  1050. elif opt == "-j":
  1051. try:
  1052. opt_split = int(arg)
  1053. except:
  1054. usage()
  1055. elif opt == "-k":
  1056. opt_static = 1
  1057. elif opt == "-l":
  1058. opt_vendincdir = arg
  1059. elif opt == "-m":
  1060. opt_vendlibdir = arg
  1061. elif opt == "-n":
  1062. opt_qsciincdir = arg
  1063. elif opt == "-o":
  1064. opt_qscilibdir = arg
  1065. elif opt == "-q":
  1066. qt_dir = os.path.abspath(arg)
  1067. elif opt == "-r":
  1068. opt_tracing = 1
  1069. elif opt == "-s":
  1070. qsci_define = ""
  1071. elif opt == "-u":
  1072. opt_debug = 1
  1073. elif opt == "-v":
  1074. opt_pyqtsipdir = os.path.abspath(arg)
  1075. elif opt == "-w":
  1076. opt_verbose = 1
  1077. elif opt == "-y":
  1078. if arg in ("qt", "qt-mt", "qt-mtedu", "qt-mteval", "qte", "qte-mt", "qtmt", "qtmtedu", "tqt", "tqt-mt", "tqt-mtedu", "tqt-mteval", "tqte", "tqte-mt", "tqtmt", "tqtmtedu"):
  1079. opt_tqtlib = arg
  1080. else:
  1081. usage()
  1082. # Check that we know the name of the TQt root directory.
  1083. if not qt_dir:
  1084. sipconfig.error("A TQt installation could not be found. Use use the -q argument or the TQTDIR environment variable to explicitly specify the correct directory.")
  1085. # When building static libraries, signed interpreter checking makes no
  1086. # sense.
  1087. if opt_vendorcheck and opt_static:
  1088. sipconfig.error("Using the VendorID package when building static libraries makes no sense.")
  1089. # Replace the existing build macros with the ones from the TQt installation.
  1090. macros = get_build_macros(args)
  1091. if macros is None:
  1092. usage()
  1093. sipcfg.set_build_macros(macros)
  1094. # Check TQt is what we need.
  1095. check_qt_installation(macros)
  1096. # Check the licenses are compatible.
  1097. check_license()
  1098. # Check for TQScintilla.
  1099. check_qscintilla()
  1100. # Check which modules to build.
  1101. qtmod_lib = pyqt.check_modules()
  1102. # Check for the VendorID package.
  1103. check_vendorid()
  1104. # Set the SIP platform, version and feature flags.
  1105. set_sip_flags()
  1106. # Tell the user what's been found.
  1107. inform_user()
  1108. # Generate the code.
  1109. extra_include_dirs = []
  1110. extra_libs = []
  1111. if qtmod_lib:
  1112. extra_libs.append(qtmod_lib)
  1113. if opt_libpython:
  1114. extra_libs.append(opt_libpython)
  1115. if opt_vendorcheck:
  1116. extra_include_dirs.append(opt_vendincdir)
  1117. extra_lib_dir = opt_vendlibdir
  1118. extra_libs.append("vendorid")
  1119. else:
  1120. extra_lib_dir = None
  1121. pyqt.code(extra_include_dirs, extra_lib_dir, extra_libs)
  1122. # Create the additional Makefiles.
  1123. sipconfig.inform("Creating top level Makefile...")
  1124. sipconfig.ParentMakefile(
  1125. configuration=sipcfg,
  1126. subdirs=pyqt_modules + pyqt.tools(),
  1127. installs=(pyqt.module_installs(), pyqt.module_dir())
  1128. ).generate()
  1129. # Install module initialization script.
  1130. create_config("__init__.py", os.path.join(src_dir, "module-init.py"), macros)
  1131. # Install the configuration module.
  1132. create_config("pyqtconfig.py", os.path.join(src_dir, "pyqtconfig.py.in"), macros)
  1133. ###############################################################################
  1134. # The script starts here.
  1135. ###############################################################################
  1136. if __name__ == "__main__":
  1137. try:
  1138. main(sys.argv)
  1139. except SystemExit:
  1140. raise
  1141. except:
  1142. sys.stderr.write(
  1143. """An internal error occured. Please report all the output from the program,
  1144. including the following traceback, to support@riverbankcomputing.co.uk.
  1145. """)
  1146. raise