TDE frontend for streamripper
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.

kde.py 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. # Made from scons qt.py and (heavily) modified into kde.py
  2. # Thomas Nagy, 2004, 2005 <tnagy2^8@yahoo.fr>
  3. """
  4. Run scons -h to display the associated help, or look below ..
  5. """
  6. BOLD ="\033[1m"
  7. RED ="\033[91m"
  8. GREEN ="\033[92m"
  9. YELLOW ="\033[1m" #"\033[93m" # unreadable on white backgrounds
  10. CYAN ="\033[96m"
  11. NORMAL ="\033[0m"
  12. import os, re
  13. # Returns the name of the shared object (i.e. libtdeui.so.4)
  14. # referenced by a libtool archive (like libtdeui.la)
  15. def getSOfromLA(lafile):
  16. contents = open(lafile, 'r').read()
  17. match = re.search("^dlname='([^']*)'$", contents, re.M)
  18. if match:
  19. return match.group(1)
  20. return None
  21. def exists(env):
  22. return True
  23. def detect_kde(env):
  24. """ Detect the qt and kde environment using tde-config mostly """
  25. prefix = env['ARGS'].get('prefix', None)
  26. execprefix = env['ARGS'].get('execprefix', None)
  27. datadir = env['ARGS'].get('datadir', None)
  28. libdir = env['ARGS'].get('libdir', None)
  29. libsuffix = env['ARGS'].get('libsuffix', '')
  30. kdeincludes = env['ARGS'].get('kdeincludes', None)
  31. tdelibs = env['ARGS'].get('tdelibs', None)
  32. qtincludes = env['ARGS'].get('qtincludes', None)
  33. tqtincludes = env['ARGS'].get('tqtincludes', None)
  34. tqtlibs = env['ARGS'].get('tqtlibs', None)
  35. tdedir = env['ARGS'].get('tdedir', None)
  36. if libdir:
  37. libdir = libdir+libsuffix
  38. ## Detect the tde libraries
  39. print "Checking for tde-config : ",
  40. str="which tde-config 2>/dev/null"
  41. if tdedir: str="which %s 2>/dev/null" % (tdedir+'/bin/tde-config')
  42. kde_config = os.popen(str).read().strip()
  43. if len(kde_config):
  44. print GREEN + 'tde-config was found as ' + kde_config + NORMAL
  45. else:
  46. if tdedir: print RED + 'tde-config was NOT found in the folder given ' + tdedir + NORMAL
  47. else: print RED + 'tde-config was NOT found in your PATH' + NORMAL
  48. print "Make sure kde is installed properly"
  49. print "(missing package tdebase-devel?)"
  50. env.Exit(1)
  51. if tdedir: env['TDEDIR']=tdedir
  52. else: env['TDEDIR'] = os.popen(kde_config+' -prefix').read().strip()
  53. print "Checking for tde version : ",
  54. tde_version = os.popen(kde_config + " --version|grep TDE").read().strip().split()[1]
  55. tde_major = tde_version.split('.')[0].lstrip('R')
  56. tde_minor = tde_version.split('.')[1]
  57. tde_patch = tde_version.split('.')[2]
  58. try:
  59. env['KDEm1']=int(tde_major)
  60. except:
  61. pass
  62. try:
  63. env['KDEm2']=int(tde_minor)
  64. except:
  65. pass
  66. try:
  67. env['KDEm3']=int(tde_patch)
  68. except:
  69. pass
  70. if int(tde_major) != 14:
  71. print RED + tde_version
  72. print RED + "Your tde version might be too old" + NORMAL
  73. print RED + "Please make sure TDE is at least R14.0" + NORMAL
  74. else:
  75. print GREEN + tde_version + NORMAL
  76. ## Detect the qt library
  77. print "Checking for the qt library : ",
  78. qtdir = os.getenv("TQTDIR")
  79. if qtdir:
  80. print GREEN+"qt is in "+qtdir+NORMAL
  81. else:
  82. libdir = os.popen(kde_config + ' --expandvars --install lib').read().strip()
  83. libtdeuiSO = libdir+'/'+getSOfromLA(libdir+'/libtdeui.la')
  84. try:
  85. m = re.search('(.*)/lib/libtqt.*', os.popen('ldd ' + libtdeuiSO + ' | grep libtqt').read().strip().split()[2])
  86. except:
  87. m = re.search('(.*)/lib/libtqt.*', os.popen('ldd ' + libtdeuiSO + ' | grep libtqt').read().strip().split()[2])
  88. pass
  89. if m:
  90. qtdir = m.group(1)
  91. print YELLOW+"qt was found as "+m.group(1)+NORMAL
  92. else:
  93. print RED+"qt was not found"+NORMAL
  94. print RED+"Please set TQTDIR first (/usr/lib/qt3?)"+NORMAL
  95. env.Exit(1)
  96. env['TQTDIR'] = qtdir.strip()
  97. ## Find the necessary programs uic-tqt and moc
  98. print "Checking for uic-tqt : ",
  99. uic = qtdir + "/bin/uic-tqt"
  100. if os.path.isfile(uic):
  101. print GREEN+"uic-tqt was found as "+uic+NORMAL
  102. else:
  103. uic = os.popen("which uic-tqt 2>/dev/null").read().strip()
  104. if len(uic):
  105. print YELLOW+"uic-tqt was found as "+uic+NORMAL
  106. else:
  107. uic = os.popen("which uic-tqt 2>/dev/null").read().strip()
  108. if len(uic):
  109. print YELLOW+"uic-tqt was found as "+uic+NORMAL
  110. else:
  111. print RED+"uic-tqt was not found - set TQTDIR put it in your PATH ?"+NORMAL
  112. env.Exit(1)
  113. env['QT_UIC'] = uic
  114. print "Checking for moc : ",
  115. moc = qtdir + "/bin/tqmoc"
  116. if os.path.isfile(moc):
  117. print GREEN + "moc was found as " + moc + NORMAL
  118. else:
  119. moc = os.popen("which moc 2>/dev/null").read().strip()
  120. if len(moc):
  121. print YELLOW + "moc was found as " + moc + NORMAL
  122. elif os.path.isfile("/usr/share/tqt3/bin/tqmoc"):
  123. moc = "/usr/share/tqt3/bin/tqmoc"
  124. print YELLOW + "moc was found as " + moc + NORMAL
  125. elif os.path.isfile("/usr/share/qt3/bin/tqmoc"):
  126. moc = "/usr/share/qt3/bin/tqmoc"
  127. print YELLOW + "moc was found as " + moc + NORMAL
  128. else:
  129. print RED + "moc was not found - set TQTDIR or put it in your PATH ?" + NORMAL
  130. env.Exit(1)
  131. env['QT_MOC'] = moc
  132. ## check for the tqt includes
  133. print "Checking for the tqt includes : ",
  134. if tqtincludes and os.path.isfile(tqtincludes + "/tqlayout.h"):
  135. # The user told where to look for and it looks valid
  136. print GREEN + "ok " + tqtincludes + NORMAL
  137. else:
  138. if os.path.isfile(qtdir + "/include/qlayout.h"):
  139. # Automatic detection
  140. print GREEN + "ok " + qtdir + "/include/ " + NORMAL
  141. tqtincludes = qtdir + "/include/"
  142. elif os.path.isfile("/usr/include/tqt/tqlayout.h"):
  143. # Debian probably
  144. print YELLOW + "the qt headers were found in /usr/include/tqt/ " + NORMAL
  145. tqtincludes = "/usr/include/tqt"
  146. elif os.path.isfile("/usr/include/qt4/Qt/qglobal.h"):
  147. # Debian probably
  148. print YELLOW + "the qt headers were found in /usr/include/qt4/ " + NORMAL
  149. tqtincludes = "/usr/include/qt4"
  150. else:
  151. print RED + "the qt headers were not found" + NORMAL
  152. env.Exit(1)
  153. ## check for the qt includes
  154. print "Checking for the qt includes : ",
  155. if qtincludes and os.path.isfile(qtincludes + "/ntqglobal.h"):
  156. # The user told where to look for and it looks valid
  157. print GREEN + "ok " + qtincludes + NORMAL
  158. else:
  159. if os.path.isfile(qtdir + "/include/ntqglobal.h"):
  160. # Automatic detection
  161. print GREEN + "ok " + qtdir + "/include/ " + NORMAL
  162. qtincludes = qtdir + "/include/"
  163. elif os.path.isfile("/usr/include/tqt3/ntqglobal.h"):
  164. # Debian probably
  165. print YELLOW + "the qt headers were found in /usr/include/tqt3/ " + NORMAL
  166. qtincludes = "/usr/include/tqt3"
  167. else:
  168. print RED + "the qt headers were not found" + NORMAL
  169. env.Exit(1)
  170. print "Checking for the tde includes : ",
  171. kdeprefix = os.popen(kde_config + " --prefix").read().strip()
  172. if not kdeincludes:
  173. kdeincludes = kdeprefix+"/include/"
  174. if os.path.isfile(kdeincludes + "/klineedit.h"):
  175. print GREEN + "ok " + kdeincludes + NORMAL
  176. else:
  177. if os.path.isfile(kdeprefix+"/include/tde/klineedit.h"):
  178. # Debian, Fedora probably
  179. print YELLOW + "the kde headers were found in " + kdeprefix + "/include/tde/" + NORMAL
  180. kdeincludes = kdeprefix + "/include/tde/"
  181. else:
  182. print RED + "The kde includes were NOT found" + NORMAL
  183. env.Exit(1)
  184. if prefix:
  185. ## use the user-specified prefix
  186. if not execprefix:
  187. execprefix = prefix
  188. if not datadir:
  189. datadir=prefix+"/share"
  190. if not libdir:
  191. libdir=execprefix+"/lib"+libsuffix
  192. subst_vars = lambda x: x.replace('${exec_prefix}', execprefix).replace('${datadir}',datadir).replace('${libdir}', libdir)
  193. debian_fix = lambda x: x.replace('/usr/share', '${datadir}')
  194. env['KDEBIN'] = subst_vars(os.popen(kde_config + ' --install exe').read().strip())
  195. env['KDEAPPS'] = subst_vars(os.popen(kde_config + ' --install apps').read().strip())
  196. env['KDEDATA'] = subst_vars(os.popen(kde_config + ' --install data').read().strip())
  197. env['KDEMODULE']= subst_vars(os.popen(kde_config + ' --install module').read().strip())
  198. env['KDELOCALE']= subst_vars(os.popen(kde_config + ' --install locale').read().strip())
  199. env['KDEDOC'] = subst_vars( debian_fix(os.popen(kde_config + ' --install html').read().strip()) )
  200. env['KDEKCFG'] = subst_vars(os.popen(kde_config + ' --install kcfg').read().strip())
  201. env['KDEXDG'] = subst_vars(os.popen(kde_config + ' --install xdgdata-apps').read().strip())
  202. env['KDEXDGDIR']= subst_vars(os.popen(kde_config + ' --install xdgdata-dirs').read().strip())
  203. env['KDEMENU'] = subst_vars(os.popen(kde_config + ' --install apps').read().strip())
  204. env['KDEMIME'] = subst_vars(os.popen(kde_config + ' --install mime').read().strip())
  205. env['KDEICONS'] = subst_vars(os.popen(kde_config + ' --install icon').read().strip())
  206. env['KDESERV'] = subst_vars(os.popen(kde_config + ' --install services').read().strip())
  207. else:
  208. # the user has given no prefix, install as a normal kde app
  209. env['PREFIX'] = os.popen(kde_config + ' --prefix').read().strip()
  210. env['KDEBIN'] = os.popen(kde_config + ' --expandvars --install exe').read().strip()
  211. env['KDEAPPS'] = os.popen(kde_config + ' --expandvars --install apps').read().strip()
  212. env['KDEDATA'] = os.popen(kde_config + ' --expandvars --install data').read().strip()
  213. env['KDEMODULE']= os.popen(kde_config + ' --expandvars --install module').read().strip()
  214. env['KDELOCALE']= os.popen(kde_config + ' --expandvars --install locale').read().strip()
  215. env['KDEDOC'] = os.popen(kde_config + ' --expandvars --install html').read().strip()
  216. env['KDEKCFG'] = os.popen(kde_config + ' --expandvars --install kcfg').read().strip()
  217. env['KDEXDG'] = os.popen(kde_config + ' --expandvars --install xdgdata-apps').read().strip()
  218. env['KDEXDGDIR']= os.popen(kde_config + ' --expandvars --install xdgdata-dirs').read().strip()
  219. env['KDEMENU'] = os.popen(kde_config + ' --expandvars --install apps').read().strip()
  220. env['KDEMIME'] = os.popen(kde_config + ' --expandvars --install mime').read().strip()
  221. env['KDEICONS'] = os.popen(kde_config + ' --expandvars --install icon').read().strip()
  222. env['KDESERV'] = os.popen(kde_config + ' --expandvars --install services').read().strip()
  223. env['QTPLUGINS']=os.popen(kde_config + ' --expandvars --install qtplugins').read().strip()
  224. ## kde libs and includes
  225. env['KDEINCLUDEPATH']=kdeincludes
  226. if not tdelibs:
  227. tdelibs=os.popen(kde_config + ' --expandvars --install lib').read().strip()
  228. env['KDELIBPATH']=tdelibs
  229. ## qt libs and includes
  230. env['QTINCLUDEPATH']=qtincludes
  231. env['TQTINCLUDEPATH']=tqtincludes
  232. if not tqtlibs:
  233. tqtlibs=qtdir+"/lib"
  234. env['TQTLIBPATH']=tqtlibs
  235. def generate(env):
  236. """"Set up the qt and kde environment and builders - the moc part is difficult to understand """
  237. env.Help("""
  238. """+BOLD+
  239. """*** KDE options ***
  240. -------------------"""
  241. +NORMAL+"""
  242. """+BOLD+"""* prefix """+NORMAL+""": base install path, ie: /usr/local
  243. """+BOLD+"""* execprefix """+NORMAL+""": install path for binaries, ie: /usr/bin
  244. """+BOLD+"""* datadir """+NORMAL+""": install path for the data, ie: /usr/local/share
  245. """+BOLD+"""* libdir """+NORMAL+""": install path for the libs, ie: /usr/lib
  246. """+BOLD+"""* tdedir """+NORMAL+""": path to TDE directory, ie: /opt/trinity
  247. """+BOLD+"""* libsuffix """+NORMAL+""": suffix of libraries on amd64, ie: 64, 32
  248. """+BOLD+"""* kdeincludes"""+NORMAL+""": path to the kde includes (/usr/include/tde on debian, ...)
  249. """+BOLD+"""* qtincludes """+NORMAL+""": same punishment, for qt includes (/usr/include/qt on debian, ...)
  250. """+BOLD+"""* tdelibs """+NORMAL+""": path to the kde libs, for linking the programs
  251. """+BOLD+"""* tqtlibs """+NORMAL+""": same punishment, for qt libraries
  252. ie: """+BOLD+"""scons configure libdir=/usr/local/lib qtincludes=/usr/include/qt
  253. """+NORMAL)
  254. import SCons.Defaults
  255. import SCons.Tool
  256. import SCons.Util
  257. ui_extensions = [".ui"]
  258. header_extensions = [".h", ".hxx", ".hpp", ".hh"]
  259. source_extensions = [".cpp", ".cxx", ".cc"]
  260. def find_file(filename, paths, node_factory):
  261. retval = None
  262. for dir in paths:
  263. node = node_factory(filename, dir)
  264. if node.rexists():
  265. return node
  266. return None
  267. class _Metasources:
  268. """ Callable class, which works as an emitter for Programs, SharedLibraries
  269. and StaticLibraries."""
  270. def __init__(self, objBuilderName):
  271. self.objBuilderName = objBuilderName
  272. def __call__(self, target, source, env):
  273. """ Smart autoscan function. Gets the list of objects for the Program
  274. or Lib. Adds objects and builders for the special qt files. """
  275. try:
  276. if int(env.subst('$QT_AUTOSCAN')) == 0:
  277. return target, source
  278. except ValueError:
  279. pass
  280. try:
  281. qtdebug = int(env.subst('$QT_DEBUG'))
  282. except ValueError:
  283. qtdebug = 0
  284. # some shortcuts used in the scanner
  285. FS = SCons.Node.FS.default_fs
  286. splitext = SCons.Util.splitext
  287. objBuilder = getattr(env, self.objBuilderName)
  288. # some regular expressions:
  289. # Q_OBJECT detection
  290. q_object_search = re.compile(r'[^A-Za-z0-9]Q_OBJECT[^A-Za-z0-9]')
  291. # The following is kind of hacky to get builders working properly (FIXME) ??
  292. objBuilderEnv = objBuilder.env
  293. objBuilder.env = env
  294. mocBuilderEnv = env.Moc.env
  295. env.Moc.env = env
  296. # make a deep copy for the result; MocH objects will be appended
  297. out_sources = source[:]
  298. for obj in source:
  299. if not obj.has_builder():
  300. # binary obj file provided
  301. if qtdebug:
  302. print "scons: qt: '%s' seems to be a binary. Discarded." % str(obj)
  303. continue
  304. cpp = obj.sources[0]
  305. if not splitext(str(cpp))[1] in source_extensions:
  306. if qtdebug:
  307. print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp)
  308. # c or fortran source
  309. continue
  310. #cpp_contents = comment.sub('', cpp.get_contents())
  311. cpp_contents = cpp.get_contents()
  312. h = None
  313. ui = None
  314. for ui_ext in ui_extensions:
  315. # try to find the ui file in the corresponding source directory
  316. uiname = splitext(cpp.name)[0] + ui_ext
  317. ui = find_file(uiname, (cpp.get_dir(),), FS.File)
  318. if ui:
  319. if qtdebug:
  320. print "scons: qt: found .ui file of header" #% (str(h), str(cpp))
  321. #h_contents = comment.sub('', h.get_contents())
  322. break
  323. # if we have a .ui file, do not continue, it is automatically handled by Uic
  324. if ui:
  325. continue
  326. for h_ext in header_extensions:
  327. # try to find the header file in the corresponding source
  328. # directory
  329. hname = splitext(cpp.name)[0] + h_ext
  330. h = find_file(hname, (cpp.get_dir(),), FS.File)
  331. if h:
  332. if qtdebug:
  333. print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))
  334. #h_contents = comment.sub('', h.get_contents())
  335. h_contents = h.get_contents()
  336. break
  337. if not h and qtdebug:
  338. print "scons: qt: no header for '%s'." % (str(cpp))
  339. if h and q_object_search.search(h_contents):
  340. # h file with the Q_OBJECT macro found -> add .moc or _moc.cpp file
  341. moc_cpp = None
  342. if env.has_key('NOMOCSCAN'):
  343. moc_cpp = env.Moc(h)
  344. else:
  345. reg = '\n\s*#include\s*("|<)'+splitext(cpp.name)[0]+'.moc("|>)'
  346. meta_object_search = re.compile(reg)
  347. if meta_object_search.search(cpp_contents):
  348. moc_cpp = env.Moc(h)
  349. else:
  350. moc_cpp = env.Moccpp(h)
  351. moc_o = objBuilder(moc_cpp)
  352. out_sources.append(moc_o)
  353. if qtdebug:
  354. print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp[0]))
  355. if cpp and q_object_search.search(cpp_contents):
  356. print "error, bksys cannot handle cpp files with Q_OBJECT classes"
  357. print "if you are sure this is a feature worth the effort, "
  358. print "report this to the authors tnagyemail-mail yahoo.fr"
  359. # restore the original env attributes (FIXME)
  360. objBuilder.env = objBuilderEnv
  361. env.Moc.env = mocBuilderEnv
  362. return (target, out_sources)
  363. MetasourcesShared = _Metasources('SharedObject')
  364. MetasourcesStatic = _Metasources('StaticObject')
  365. CLVar = SCons.Util.CLVar
  366. splitext = SCons.Util.splitext
  367. Builder = SCons.Builder.Builder
  368. # Detect the environment - replaces ./configure implicitely and store the options into a cache
  369. from SCons.Options import Options
  370. cachefile=env['CACHEDIR']+'kde.cache.py'
  371. opts = Options(cachefile)
  372. opts.AddOptions(
  373. ('PREFIX', 'root of the program installation'),
  374. ('TQTDIR', 'root of qt directory'),
  375. ('TQTLIBPATH', 'path to the qt libraries'),
  376. ('QTINCLUDEPATH', 'path to the qt includes'),
  377. ('TQTINCLUDEPATH', 'path to the tqt includes'),
  378. ('QT_UIC', 'moc directory'),
  379. ('QT_MOC', 'moc executable command'),
  380. ('QTPLUGINS', 'uic executable command'),
  381. ('TDEDIR', 'root of kde directory'),
  382. ('KDELIBPATH', 'path to the kde libs'),
  383. ('KDEINCLUDEPATH', 'path to the kde includes'),
  384. ('KDEBIN', 'installation path of the kde binaries'),
  385. ('KDEMODULE', 'installation path of the parts and libs'),
  386. ('KDEAPPS', ''),
  387. ('KDEDATA', 'installation path of the application data'),
  388. ('KDELOCALE', ''),
  389. ('KDEDOC', 'installation path of the application documentation'),
  390. ('KDEKCFG', 'installation path of the .kcfg files'),
  391. ('KDEXDG', 'installation path of the service types'),
  392. ('KDEXDGDIR', 'installation path of the xdg service directories'),
  393. ('KDEMENU', ''),
  394. ('KDEMIME', 'installation path of to the mimetypes'),
  395. ('KDEICONS', ''),
  396. ('KDEm1', ''),
  397. ('KDEm2', ''),
  398. ('KDEm3', ''),
  399. ('KDESERV', ''),
  400. )
  401. opts.Update(env)
  402. # reconfigure when things are missing
  403. if 'configure' in env['TARGS'] or not env.has_key('TQTDIR') or not env.has_key('TDEDIR'):
  404. detect_kde(env)
  405. # finally save the configuration to the cache file
  406. opts.Save(cachefile, env)
  407. ## set default variables, one can override them in sconscript files
  408. env.Append(CXXFLAGS = ['-I'+env['KDEINCLUDEPATH'], '-I'+env['QTINCLUDEPATH'], '-I'+env['TQTINCLUDEPATH'], '-include', 'tqt.h' ])
  409. env.Append(LIBPATH = [env['KDELIBPATH'], env['TQTLIBPATH'] ])
  410. env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
  411. env['QT_AUTOSCAN'] = 1
  412. env['QT_DEBUG'] = 0
  413. env['QT_UIC_HFLAGS'] = '-L $QTPLUGINS -nounload'
  414. env['QT_UIC_CFLAGS'] = '$QT_UIC_HFLAGS -tr tr2i18n'
  415. env['TQT_LIBS'] = 'tqt'
  416. env['QT_UICIMPLPREFIX'] = ''
  417. env['QT_UICIMPLSUFFIX'] = '.cpp'
  418. env['QT_MOCHPREFIX'] = ''
  419. env['QT_MOCHSUFFIX'] = '.moc'
  420. env['KDE_KCFG_IMPLPREFIX'] = ''
  421. env['KDE_KCFG_IMPL_HSUFFIX'] = '.h'
  422. env['KDE_KCFG_IMPL_CSUFFIX'] = '.cpp'
  423. env['KDE_SKEL_IMPL_SUFFIX'] = '.skel'
  424. env['MEINPROC'] = 'meinproc'
  425. env['MSGFMT'] = 'msgfmt'
  426. ## ui file processing
  427. def uicGenerator(target, source, env, for_signature):
  428. act=[]
  429. act.append('$QT_UIC $QT_UIC_HFLAGS -o '+target[0].path+' '+source[0].path)
  430. act.append('rm -f ' +target[1].path)
  431. act.append('echo \'#include <tdelocale.h>\' >> '+target[1].path)
  432. act.append('echo \'#include <kdialog.h>\' >> '+target[1].path)
  433. act.append('$QT_UIC $QT_UIC_CFLAGS -impl '+target[0].path+' -o '+target[1].path+'.tmp '+source[0].path)
  434. act.append('cat '+target[1].path+'.tmp >> '+target[1].path)
  435. act.append('rm -f '+target[1].path+'.tmp')
  436. act.append('echo \'#include "' + target[2].name + '"\' >> '+target[1].path)
  437. act.append('moc-tqt $QT_MOC '+target[0].path+' '+target[2].path)
  438. return act
  439. def uicEmitter(target, source, env):
  440. adjustixes = SCons.Util.adjustixes
  441. bs = SCons.Util.splitext(str(source[0].name))[0]
  442. bs = os.path.join(str(target[0].get_dir()),bs)
  443. # first target is automatically added by builder (.h file)
  444. if len(target) < 2:
  445. # second target is .cpp file
  446. target.append(adjustixes(bs,
  447. env.subst('$QT_UICIMPLPREFIX'),
  448. env.subst('$QT_UICIMPLSUFFIX')))
  449. if len(target) < 3:
  450. # third target is .moc file
  451. target.append(adjustixes(bs,
  452. env.subst('$QT_MOCHPREFIX'),
  453. env.subst('$QT_MOCHSUFFIX')))
  454. return target, source
  455. UIC_BUILDER = Builder(
  456. generator = uicGenerator,
  457. emitter = uicEmitter,
  458. suffix = '.h',
  459. src_suffix = '.ui')
  460. ## moc file processing
  461. env['QT_MOCCOM'] = ('moc-tqt $QT_MOC $SOURCE ${TARGETS[0]}')
  462. MOC_BUILDER = Builder(
  463. action = '$QT_MOCCOM',
  464. suffix = '.moc',
  465. src_suffix = '.h')
  466. MOCCPP_BUILDER = Builder(
  467. action = '$QT_MOCCOM',
  468. suffix = '_moc.cpp',
  469. src_suffix = '.h')
  470. ## kcfg file processing
  471. def kcfgGenerator(target, source, env, for_signature):
  472. act=[]
  473. act.append('tdeconfig_compiler -d'+str(source[0].get_dir())+' '+source[1].path+' '+source[0].path)
  474. return act
  475. def kcfgEmitter(target, source, env):
  476. adjustixes = SCons.Util.adjustixes
  477. bs = SCons.Util.splitext(str(source[0].name))[0]
  478. bs = os.path.join(str(target[0].get_dir()),bs)
  479. # .h file is automatically added
  480. if len(target) < 2:
  481. # add .cpp file
  482. target.append(adjustixes(bs, env.subst('$KDE_KCFG_IMPLPREFIX'), env.subst('$KDE_KCFG_IMPL_CSUFFIX')))
  483. if len(source) <2:
  484. if not os.path.isfile(str(source[0])):
  485. print RED+'kcfg file given'+str(source[0])+' does not exist !'+NORMAL
  486. return target, source
  487. kfcgfilename=""
  488. kcfgFileDeclRx = re.compile("^[fF]ile\s*=\s*(.+)\s*$")
  489. for line in file(str(source[0]), "r").readlines():
  490. match = kcfgFileDeclRx.match(line.strip())
  491. if match:
  492. kcfgfilename = match.group(1)
  493. break
  494. source.append(str(source[0].get_dir())+'/'+kcfgfilename)
  495. return target, source
  496. KCFG_BUILDER = Builder(
  497. generator = kcfgGenerator,
  498. emitter = kcfgEmitter,
  499. suffix = '.h',
  500. src_suffix = '.kcfgc')
  501. ## dcop processing
  502. def dcopGenerator(target, source, env, for_signature):
  503. act=[]
  504. act.append('dcopidl '+source[0].path+' > '+target[1].path+'|| ( rm -f '+target[1].path+' ; false)')
  505. act.append('dcopidl2cpp --c++-suffix cpp --no-signals --no-stub '+target[1].path)
  506. return act
  507. def dcopEmitter(target, source, env):
  508. bs = SCons.Util.splitext(str(source[0].name))[0]
  509. bs = os.path.join(str(target[0].get_dir()),bs)
  510. target.append(bs+'.kidl')
  511. #target.append(bs+'_skel.cpp')
  512. return target, source
  513. DCOP_BUILDER = Builder(
  514. generator = dcopGenerator,
  515. emitter = dcopEmitter,
  516. suffix = '_skel.cpp',
  517. src_suffix = '.h')
  518. ## documentation processing
  519. MEINPROC_BUILDER = Builder(
  520. action = '$MEINPROC --check --cache $TARGET $SOURCE',
  521. suffix = '.cache.bz2')
  522. ## translation files builder
  523. TRANSFILES_BUILDER = Builder(
  524. action = '$MSGFMT $SOURCE -o $TARGET',
  525. suffix = '.gmo',
  526. src_suffix = '.po')
  527. ## libtool file builder
  528. def laGenerator(target, source, env, for_signature):
  529. act=[]
  530. act.append('echo "dlname=\''+source[0].name+'\'" > '+target[0].path)
  531. act.append('echo "library_names=\''+source[0].name+' '+source[0].name+' '+source[0].name+'\'" >> '+target[0].path)
  532. act.append('echo "old_library=\'\'">> '+target[0].path)
  533. act.append('echo "dependency_libs=\'\'">> '+target[0].path)
  534. act.append('echo "current=0">> '+target[0].path)
  535. act.append('echo "age=0">> '+target[0].path)
  536. act.append('echo "revision=0">> '+target[0].path)
  537. act.append('echo "installed=yes">> '+target[0].path)
  538. act.append('echo "shouldnotlink=no">> '+target[0].path)
  539. act.append('echo "dlopen=\'\'">> '+target[0].path)
  540. act.append('echo "dlpreopen=\'\'">> '+target[0].path)
  541. act.append('echo "libdir=\''+env['KDEMODULE']+'\'" >> '+target[0].path)
  542. env.Depends(target, source)
  543. return act
  544. LA_BUILDER = Builder(
  545. generator = laGenerator,
  546. suffix = '.la',
  547. src_suffix = env['SHLIBSUFFIX'])
  548. ## register the builders
  549. env['BUILDERS']['Uic'] = UIC_BUILDER
  550. env['BUILDERS']['Moc'] = MOC_BUILDER
  551. env['BUILDERS']['Moccpp'] = MOCCPP_BUILDER
  552. env['BUILDERS']['Dcop'] = DCOP_BUILDER
  553. env['BUILDERS']['Kcfg'] = KCFG_BUILDER
  554. env['BUILDERS']['LaFile'] = LA_BUILDER
  555. env['BUILDERS']['Meinproc'] = MEINPROC_BUILDER
  556. env['BUILDERS']['Transfiles']= TRANSFILES_BUILDER
  557. static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
  558. static_obj.src_builder.append('Uic')
  559. shared_obj.src_builder.append('Uic')
  560. static_obj.src_builder.append('Kcfg')
  561. shared_obj.src_builder.append('Kcfg')
  562. static_obj.src_builder.append('LaFile')
  563. shared_obj.src_builder.append('LaFile')
  564. static_obj.src_builder.append('Meinproc')
  565. shared_obj.src_builder.append('Meinproc')
  566. static_obj.src_builder.append('Transfiles')
  567. shared_obj.src_builder.append('Transfiles')
  568. ## Find the files to moc, dcop, and link against kde and qt
  569. env.AppendUnique(PROGEMITTER = [MetasourcesStatic], SHLIBEMITTER=[MetasourcesShared], LIBEMITTER =[MetasourcesStatic])
  570. ## Handy helpers for building kde programs
  571. ## You should not have to modify them ..
  572. #import SCons.Util
  573. skel_ext = [".skel", ".SKEL"]
  574. def KDEfiles(lenv, target, source):
  575. """ Returns a list of files for scons (handles kde tricks like .skel)
  576. It also makes custom checks against double includes like : ['file.ui', 'file.cpp']
  577. (file.cpp is already included because of file.ui) """
  578. src=[]
  579. ui_files=[]
  580. kcfg_files=[]
  581. skel_files=[]
  582. other_files=[]
  583. # For each file, check wether it is a dcop file or not, and create the complete list of sources
  584. for file in source:
  585. bs = SCons.Util.splitext(file)[0]
  586. ext = SCons.Util.splitext(file)[1]
  587. if ext in skel_ext:
  588. lenv.Dcop(bs+'.h')
  589. src.append(bs+'_skel.cpp')
  590. elif ext == ".moch":
  591. lenv.Moccpp(bs+'.h')
  592. src.append(bs+'_moc.cpp')
  593. else:
  594. src.append(file)
  595. if ext == '.ui':
  596. ui_files.append(bs)
  597. elif ext == '.kcfgc':
  598. kcfg_files.append(bs)
  599. elif ext == '.skel':
  600. skel_files.append(bs)
  601. else:
  602. other_files.append(bs)
  603. # Now check against typical newbie errors
  604. for file in ui_files:
  605. for ofile in other_files:
  606. if ofile == file:
  607. print RED+"WARNING: You have included "+file+".ui and another file of the same prefix"+NORMAL
  608. print "Files generated by uic (file.h, file.cpp must not be included"
  609. for file in kcfg_files:
  610. for ofile in other_files:
  611. if ofile == file:
  612. print RED+"WARNING: You have included "+file+".kcfg and another file of the same prefix"+NORMAL
  613. print "Files generated by tdeconfig_compiler (settings.h, settings.cpp) must not be included"
  614. return src
  615. """
  616. In the future, these functions will contain the code that will dump the
  617. configuration for re-use from an IDE
  618. """
  619. import glob
  620. def KDEinstall(lenv, restype, subdir, files):
  621. if not 'install' in env['TARGS']:
  622. return
  623. basedir=env['DESTDIR']
  624. if len(restype)>0:
  625. if not lenv.has_key(restype):
  626. print RED+"unknown resource type "+restype+NORMAL
  627. else:
  628. basedir += lenv[restype]+'/'
  629. #print file # <- useful to trace stuff :)
  630. install_list = env.Install(basedir+subdir+'/', files)
  631. env.Alias('install', install_list)
  632. return install_list
  633. def KDEinstallas(lenv, restype, destfile, file):
  634. if not 'install' in env['TARGS']:
  635. return
  636. basedir=env['DESTDIR']
  637. if len(restype)>0:
  638. if not lenv.has_key(restype):
  639. print RED+"unknown resource type "+restype+NORMAL
  640. else:
  641. basedir += lenv[restype]+'/'
  642. install_list = env.InstallAs(basedir+destfile, file)
  643. env.Alias('install', install_list)
  644. return install_list
  645. def KDEprogram(lenv, target, source):
  646. """ Makes a kde program
  647. The program is installed except if one sets env['NOAUTOINSTALL'] """
  648. src = KDEfiles(lenv, target, source)
  649. program_list = lenv.Program(target, src)
  650. if not lenv.has_key('NOAUTOINSTALL'):
  651. KDEinstall(lenv, 'KDEBIN', '', target)
  652. return program_list
  653. def KDEshlib(lenv, target, source, kdelib=0, libprefix='lib'):
  654. """ Makes a shared library for kde (.la file for klibloader)
  655. The library is installed except if one sets env['NOAUTOINSTALL'] """
  656. src = KDEfiles(lenv, target, source)
  657. lenv['LIBPREFIX']=libprefix
  658. library_list = lenv.SharedLibrary(target, src)
  659. lafile_list = lenv.LaFile(target, library_list)
  660. if not lenv.has_key('NOAUTOINSTALL'):
  661. install_dir = 'KDEMODULE'
  662. if kdelib==1:
  663. install_dir = 'KDELIBPATH'
  664. KDEinstall(lenv, install_dir, '', library_list)
  665. KDEinstall(lenv, install_dir, '', lafile_list)
  666. return library_list
  667. def KDEstaticlib(lenv, target, source):
  668. """ Makes a static library for kde - in practice you should not use static libraries
  669. 1. they take more memory than shared ones
  670. 2. makefile.am needed it because of limitations
  671. (cannot handle sources in separate folders - takes extra processing) """
  672. src = KDEfiles(lenv, target, source)
  673. return lenv.StaticLibrary(target, src)
  674. # do not install static libraries by default
  675. def KDEaddflags_cxx(lenv, fl):
  676. """ Compilation flags for C++ programs """
  677. lenv.AppendUnique(CXXFLAGS = fl)
  678. def KDEaddflags_c(lenv, fl):
  679. """ Compilation flags for C programs """
  680. lenv.AppendUnique(CFLAGS = fl)
  681. def KDEaddflags_link(lenv, fl):
  682. """ Add link flags - Use this if KDEaddlibs below is not enough """
  683. lenv.AppendUnique(LINKFLAGS = fl)
  684. def KDEaddlibs(lenv, libs):
  685. """ Helper function """
  686. lenv.AppendUnique(LIBS = libs)
  687. def KDEaddpaths_includes(lenv, paths):
  688. """ Add new include paths """
  689. lenv.AppendUnique(CPPPATH = paths)
  690. def KDEaddpaths_libs(lenv, paths):
  691. """ Add paths to libraries """
  692. lenv.AppendUnique(LIBPATH = paths)
  693. def KDElang(lenv, folder, appname):
  694. """ Process translations (.po files) in a po/ dir """
  695. transfiles = glob.glob(folder+'/*.po')
  696. for lang in transfiles:
  697. result = lenv.Transfiles(lang)
  698. country = SCons.Util.splitext(result[0].name)[0]
  699. KDEinstallas(lenv, 'KDELOCALE', country+'/LC_MESSAGES/'+appname+'.mo', result)
  700. def KDEicon(lenv, icname):
  701. """ Emulates the behaviour of Makefile.am to install icons
  702. Contributed by: "Andrey Golovizin" <grooz@gorodok@net> """
  703. type_dic = { 'action' : 'actions', 'app' : 'apps', 'device' :
  704. 'devices', 'filesys' : 'filesystems', 'mime' : 'mimetypes' }
  705. dir_dic = {
  706. 'los' :'locolor/16x16',
  707. 'lom' :'locolor/32x32',
  708. 'him' :'hicolor/32x32',
  709. 'hil' :'hicolor/48x48',
  710. 'lo16' :'locolor/16x16',
  711. 'lo22' :'locolor/22x22',
  712. 'lo32' :'locolor/32x32',
  713. 'hi16' :'hicolor/16x16',
  714. 'hi22' :'hicolor/22x22',
  715. 'hi32' :'hicolor/32x32',
  716. 'hi48' :'hicolor/48x48',
  717. 'hi64' :'hicolor/64x64',
  718. 'hi128':'hicolor/128x128',
  719. 'hisc' :'hicolor/scalable',
  720. 'cr16' :'crystalsvg/16x16',
  721. 'cr22' :'crystalsvg/22x22',
  722. 'cr32' :'crystalsvg/32x32',
  723. 'cr48' :'crystalsvg/48x48',
  724. 'cr64' :'crystalsvg/64x64',
  725. 'cr128':'crystalsvg/128x128',
  726. 'crsc' :'crystalsvg/scalable'
  727. }
  728. iconfiles = []
  729. for ext in ['png', 'xpm', 'mng', 'svg', 'svgz']:
  730. files = glob.glob('*-*-%s.%s' % (icname, ext))
  731. iconfiles += files
  732. for iconfile in iconfiles:
  733. tmp = iconfile.split('-')
  734. if len(tmp)!=3:
  735. print RED+'WARNING: icon filename has unknown format: '+iconfile+NORMAL
  736. continue
  737. [icon_dir, icon_type, icon_filename]=tmp
  738. try:
  739. destfile = '%s/%s/%s/%s' % (lenv['KDEICONS'], dir_dic[icon_dir], type_dic[icon_type], icon_filename)
  740. except KeyError:
  741. print RED+'WARNING: unknown icon type: '+iconfile+NORMAL
  742. continue
  743. ## Do not use KDEinstallas here, as parsing from an ide will be necessary
  744. if 'install' in env['TARGS']:
  745. env.Alias('install', env.InstallAs( env['DESTDIR']+'/'+destfile, iconfile ) )
  746. # Attach the functions to the environment so that sconscripts can use them
  747. from SCons.Script.SConscript import SConsEnvironment
  748. SConsEnvironment.KDEprogram = KDEprogram
  749. SConsEnvironment.KDEshlib = KDEshlib
  750. SConsEnvironment.KDEstaticlib = KDEstaticlib
  751. SConsEnvironment.KDEinstall = KDEinstall
  752. SConsEnvironment.KDEinstallas = KDEinstallas
  753. SConsEnvironment.KDElang = KDElang
  754. SConsEnvironment.KDEicon = KDEicon
  755. SConsEnvironment.KDEaddflags_cxx = KDEaddflags_cxx
  756. SConsEnvironment.KDEaddflags_c = KDEaddflags_c
  757. SConsEnvironment.KDEaddflags_link = KDEaddflags_link
  758. SConsEnvironment.KDEaddlibs = KDEaddlibs
  759. SConsEnvironment.KDEaddpaths_includes = KDEaddpaths_includes
  760. SConsEnvironment.KDEaddpaths_libs = KDEaddpaths_libs