]> git.lyx.org Git - features.git/blob - development/scons/SConscript
use glob instead of lists
[features.git] / development / scons / SConscript
1 # vi:filetype=python:expandtab:tabstop=2:shiftwidth=2
2
3 # file SConscript
4 #
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7 #
8 # \author Bo Peng
9 # Full author contact details are available in file CREDITS.
10
11 import os, sys
12 sys.path.append('config')
13 from scons_utils import globSource
14
15 Import('env')
16
17 def libExists(libname):
18   ''' Check whether or not lib $LOCALLIBNAME/libname already exists'''
19   return os.path.isfile(File(env.subst('$LOCALLIBPATH/${LIBPREFIX}%s$LIBSUFFIX'%libname)).abspath)
20
21 targets = env['BUILD_TARGETS']
22 # msvc need to pass full target name, so I have to look for path/lyx etc
23 build_lyx = targets == [] or True in ['lyx' in x for x in targets] \
24   or 'install' in targets or 'all' in targets
25 build_boost = (env['INCLUDED_BOOST'] and not libExists('boost_regex')) or 'boost' in targets
26 build_intl = (env['INCLUDED_GETTEXT'] and not libExists('included_intl')) or 'intl' in targets
27 build_support = build_lyx or True in [x in targets for x in ['support', 'client', 'tex2lyx']]
28 build_mathed = build_lyx or 'mathed' in targets
29 build_insets = build_lyx or 'insets' in targets
30 build_frontends = build_lyx or 'frontends' in targets
31 build_graphics = build_lyx or 'graphics' in targets
32 build_controllers = build_lyx or 'controllers' in targets
33 build_client = True in ['client' in x for x in targets] \
34   or 'install' in targets or 'all' in targets
35 build_tex2lyx = True in ['tex2lyx' in x for x in targets] \
36   or 'install' in targets or 'all' in targets
37 build_lyxbase = build_lyx or 'lyxbase' in targets
38 build_po = 'po' in targets or 'install' in targets or 'all' in targets
39 build_qt2 = (build_lyx and env['frontend'] == 'qt2') or 'qt2' in targets
40 build_qt3 = (build_lyx and env['frontend'] == 'qt3') or 'qt3' in targets
41 build_qt4 = (build_lyx and env['frontend'] == 'qt4') or 'qt4' in targets
42 build_msvs_projects = env['USE_VC'] and 'msvs_projects' in targets
43
44
45 # now, if rebuild_targets is specified, do not rebuild some targets
46 rebuild_targets = env['REBUILD_TARGETS']
47 if rebuild_targets:
48   def ifBuildLib(name, libname, old_value):
49     # explicitly asked to rebuild
50     if name in rebuild_targets:
51       return True
52     # else if not rebuild, and if the library already exists
53     elif libExists(libname):
54       return False
55     # do not change the original value
56     else:
57       return old_value
58   build_boost = ifBuildLib('boost', 'included_boost_filesystem', build_boost)
59   build_intl = ifBuildLib('intl', 'included_intl', build_intl)
60   build_support = ifBuildLib('support', 'support', build_support)
61   build_mathed = ifBuildLib('mathed', 'mathed', build_mathed)
62   build_insets = ifBuildLib('insets', 'insets', build_insets)
63   build_frontends = ifBuildLib('frontends', 'frontends', build_frontends)
64   build_graphics = ifBuildLib('graphics', 'graphics', build_graphics)
65   build_controllers = ifBuildLib('controllers', 'controllers', build_controllers)
66   build_lyxbase = ifBuildLib('lyxbase', 'lyxbase_pre', build_lyxbase)
67   build_qt2 = ifBuildLib('qt2', 'qt2', build_qt2)
68   build_qt3 = ifBuildLib('qt3', 'qt3', build_qt3)
69   build_qt4 = ifBuildLib('qt4', 'qt4', build_qt4)
70
71 # sync frontend and env['frontend'] (maybe build qt4 with frontend=qt3)
72 if build_qt2:
73   frontend = 'qt2'
74   env['frontend'] = 'qt2'
75 elif build_qt3:
76   frontend = 'qt3'
77   env['frontend'] = 'qt3'
78 elif build_qt4:
79   frontend = 'qt4'
80   env['frontend'] = 'qt4'
81 else:
82   frontend = env['frontend']
83
84
85 if build_boost:
86   #
87   # boost libraries
88   #
89   # special builddir
90   env.BuildDir('$BUILDDIR/boost', '$TOP_SRC_DIR/boost/libs', duplicate = 0)
91
92   boostenv = env.Copy()
93   boostenv.AppendUnique(CCFLAGS = '-DBOOST_USER_CONFIG="<config.h>"')
94
95   for lib in ['filesystem', 'regex', 'signals', 'iostreams']:
96     # lyx 1.4 does not have iostreams
97     if not os.path.isdir(os.path.join(env.subst('$TOP_SRC_DIR'), 'boost', 'libs', lib)):
98       continue
99       
100     print 'Processing files in boost/libs/%s/src...' % lib
101
102     boostlib = boostenv.StaticLibrary(
103       target = '$LOCALLIBPATH/included_boost_%s' % lib,
104       source = globSource(dir = env.subst('$TOP_SRC_DIR/boost/libs/%s/src' % lib), 
105         pattern = '*.cpp', build_dir = '$BUILDDIR/boost/%s/src' % lib)
106     )
107     Alias('boost', boostlib)
108
109
110 if build_intl:
111   # 
112   # intl
113   # 
114   print "Processing files in intl..."
115
116   env.BuildDir('$BUILDDIR/intl', '$TOP_SRC_DIR/intl', duplicate = 0)
117
118   intlenv = env.Copy()
119   # we need the original C compiler for these files
120   intlenv['CC'] = intlenv['C_COMPILER']
121   intlenv['CCFLAGS'] = intlenv['C_CCFLAGS']
122   intlenv['CPPPATH'] += ['intl']
123   
124   intlenv.Append(CCFLAGS = [
125     r'-DLOCALEDIR=\"' + env['LOCALE_DIR'].replace('\\', '\\\\') + r'\"',
126     r'-DLOCALE_ALIAS_PATH=\"' + env['LOCALE_DIR'].replace('\\', '\\\\') + r'\"',
127     r'-DLIBDIR=\"' + env['TOP_SRC_DIR'].replace('\\', '\\\\') + r'/lib\"',
128     '-DIN_LIBINTL',
129     '-DENABLE_RELOCATABLE=1',
130     '-DIN_LIBRARY',
131     r'-DINSTALLDIR=\"' + env['PREFIX'].replace('\\', '\\\\') + r'/lib\"',
132     '-DNO_XMALLOC',
133     '-Dset_relocation_prefix=libintl_set_relocation_prefix',
134     '-Drelocate=libintl_relocate',
135     '-DDEPENDS_ON_LIBICONV=1',
136     '-DHAVE_CONFIG_H'
137     ]
138   )
139
140   # libgnuintl.h.in => libintl.h
141   env.substFile('$TOP_SRC_DIR/intl/libintl.h', '$TOP_SRC_DIR/intl/libgnuintl.h.in')
142   env.Command('$TOP_SRC_DIR/intl/libgnuintl.h', '$TOP_SRC_DIR/intl/libintl.h',
143       [Copy('$TARGET', '$SOURCE')])
144   
145   intl = intlenv.StaticLibrary(
146     target = '$LOCALLIBPATH/included_intl',
147     LIBS = ['c'],
148     source = globSource(dir = env.subst('$TOP_SRC_DIR/intl'), pattern = '*.c',
149       exclude = ['vasnprintf.c', 'printf-parse.c', 'printf-args.c', 'os2compat.c'],
150       build_dir = '$BUILDDIR/intl')
151   )
152   Alias('intl', intl)
153
154
155 #
156 # Now, src code under src/
157 #
158 env.BuildDir('$BUILDDIR/common', '$TOP_SRC_DIR/src', duplicate = 0)
159
160
161 if build_support:
162   #
163   # src/support
164   #
165   print "Processing files in src/support..."
166
167   env.substFile('$BUILDDIR/common/support/package.C', '$TOP_SRC_DIR/src/support/package.C.in')
168
169   support = env.StaticLibrary(
170     target = '$LOCALLIBPATH/support',
171     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/support'), pattern = env['LYX_EXT'], 
172       exclude = ['os_win32.C', 'os_unix.C', 'os_cygwin.C', 'os_os2.C', 'atexit.c'],
173       include = ['package.C'], build_dir = '$BUILDDIR/common/support')
174   )
175   Alias('support', support)
176
177
178 if build_mathed:
179   #
180   # src/mathed
181   #
182   print "Processing files in src/mathed..."
183
184   mathed = env.StaticLibrary(
185     target = '$LOCALLIBPATH/mathed',
186     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/mathed'), pattern = env['LYX_EXT'],
187       exclude = ['math_xyarrowinset.C', 'math_mboxinset.C', 'formulamacro.C'],
188       build_dir = '$BUILDDIR/common/mathed')
189   )
190   Alias('mathed', mathed)
191
192
193 if build_insets:
194   #
195   # src/insets
196   #
197   print "Processing files in src/insets..."
198
199   insets = env.StaticLibrary(
200     target = '$LOCALLIBPATH/insets',
201     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/insets'), pattern = env['LYX_EXT'],
202       exclude = ['insettheorem.C'], build_dir = '$BUILDDIR/common/insets')
203   )
204   Alias('insets', insets)
205
206
207 if build_frontends:
208   #
209   # src/frontends
210   #
211   print "Processing files in src/frontends..."
212
213   frontends = env.StaticLibrary(
214     target = '$LOCALLIBPATH/frontends',
215     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends'), pattern = env['LYX_EXT'],
216       build_dir = '$BUILDDIR/common/frontends')
217   )
218   Alias('frontends', frontends)
219
220
221 if build_graphics:
222   #
223   # src/graphics
224   #
225   print "Processing files in src/graphics..."
226
227   graphics = env.StaticLibrary(
228     target = '$LOCALLIBPATH/graphics',
229     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/graphics'), pattern = env['LYX_EXT'],
230       build_dir = '$BUILDDIR/common/graphics')
231   )
232   Alias('graphics', graphics)
233
234
235 if build_controllers:
236   #
237   # src/frontends/controllers
238   #
239   print "Processing files in src/frontends/controllers..."
240
241   controllers = env.StaticLibrary(
242     target = '$LOCALLIBPATH/controllers',
243     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends/controllers'), pattern = env['LYX_EXT'],
244       build_dir = '$BUILDDIR/common/frontends/controllers')
245   )
246   Alias('controllers', controllers)
247
248
249 #
250 # src/frontend/qt2/3/4
251 #
252 if build_qt2 or build_qt3 or build_qt4:
253   env.BuildDir('$BUILDDIR/$frontend', '$TOP_SRC_DIR/src/frontend/$frontend', duplicate = 0)
254
255
256 if build_qt2:
257   print "Processing files in src/frontends/qt2..."
258
259   qt2env = env.Copy()
260   # disable auto scan to speed up non build time
261   qt2env['QT_AUTOSCAN'] = 0
262   qt2env['QT_MOCHPREFIX'] = ''
263
264   # load qt2 tools
265   qt2env.Tool('qt')
266
267   qt2env.AppendUnique(CPPPATH = [
268     '$BUILDDIR/common',
269     '$BUILDDIR/common/images',
270     '$BUILDDIR/common/frontends',
271     '$BUILDDIR/common/frontends/qt2',
272     '$BUILDDIR/common/frontends/controllers',
273     '$QT_INC_PATH']
274   )
275
276   qt2_moc_files = ["$BUILDDIR/common/frontends/qt2/%s" % x for x in Split('''
277     BulletsModule.C
278     emptytable.C
279     FileDialog_private.C
280     floatplacement.C
281     iconpalette.C
282     lengthcombo.C
283     panelstack.C
284     QAboutDialog.C
285     QBibitemDialog.C
286     QBibtexDialog.C
287     QBoxDialog.C
288     QBranchDialog.C
289     QBrowseBox.C
290     QChangesDialog.C
291     QCharacterDialog.C
292     QCitationDialog.C
293     QCommandBuffer.C
294     QCommandEdit.C
295     QContentPane.C
296     QDelimiterDialog.C
297     QDocumentDialog.C
298     QErrorListDialog.C
299     QERTDialog.C
300     QExternalDialog.C
301     QFloatDialog.C
302     QGraphicsDialog.C
303     QIncludeDialog.C
304     QIndexDialog.C
305     QLogDialog.C
306     QLPopupMenu.C
307     QLPrintDialog.C
308     QMathDialog.C
309     QMathMatrixDialog.C
310     QNoteDialog.C
311     QParagraphDialog.C
312     QPrefsDialog.C
313     QRefDialog.C
314     QSearchDialog.C
315     QSendtoDialog.C
316     qsetborder.C
317     QShowFileDialog.C
318     QSpellcheckerDialog.C
319     QDialogView.C
320     QTabularCreateDialog.C
321     QTabularDialog.C
322     QTexinfoDialog.C
323     QThesaurusDialog.C
324     QTocDialog.C
325     qttableview.C
326     QtView.C
327     QURLDialog.C
328     QVSpaceDialog.C
329     QWrapDialog.C
330     QLToolbar.C
331     socket_callback.C
332     validators.C
333   ''')]
334
335   # manually moc and uic files for better performance 
336   qt2_moced_files = [qt2env.Moc(x.replace('.C', '_moc.cpp'), x.replace('.C', '.h')) for x in qt2_moc_files]
337
338   qt2_uiced_files = [qt2env.Uic('$BUILDDIR/common/frontends/qt2/ui/'+x) for x in \
339      globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends/qt2/ui'), pattern = '*.ui')]
340
341   qt2_uiced_cc_files = []
342   for x in qt2_uiced_files:
343     qt2_uiced_cc_files.extend(x[1:])
344
345   qt2 = qt2env.StaticLibrary(
346     target = '$LOCALLIBPATH/qt2',
347     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends/qt2/'), pattern = env['LYX_EXT'],
348       build_dir = '$BUILDDIR/common/frontends/qt2') + qt2_moced_files + qt2_uiced_cc_files
349   )
350   Alias('qt2', qt2)
351
352
353 if build_qt3:
354   print "Processing files in src/frontends/qt3..."
355
356   qt3env = env.Copy()
357   # disable auto scan to speed up non build time
358   qt3env['QT_AUTOSCAN'] = 0
359   qt3env['QT_MOCHPREFIX'] = ''
360
361   # load qt3 tools
362   qt3env.Tool('qt')
363
364   qt3env.AppendUnique(CPPPATH = [
365     '$BUILDDIR/common',
366     '$BUILDDIR/common/images',
367     '$BUILDDIR/common/frontends',
368     '$BUILDDIR/common/frontends/qt3',
369     '$BUILDDIR/common/frontends/controllers',
370     '$QT_INC_PATH']
371   )
372
373   qt3_moc_files = ["$BUILDDIR/common/frontends/qt3/%s" % x for x in Split('''
374     BulletsModule.C
375     emptytable.C
376     FileDialog_private.C
377     floatplacement.C
378     iconpalette.C
379     lengthcombo.C
380     panelstack.C
381     QAboutDialog.C
382     QBibitemDialog.C
383     QBibtexDialog.C
384     QBoxDialog.C
385     QBranchDialog.C
386     QBrowseBox.C
387     QChangesDialog.C
388     QCharacterDialog.C
389     QCitationDialog.C
390     QCommandBuffer.C
391     QCommandEdit.C
392     QContentPane.C
393     QDelimiterDialog.C
394     QDocumentDialog.C
395     QErrorListDialog.C
396     QERTDialog.C
397     QExternalDialog.C
398     QFloatDialog.C
399     QGraphicsDialog.C
400     QIncludeDialog.C
401     QIndexDialog.C
402     QLogDialog.C
403     QViewSourceDialog.C
404     QLPopupMenu.C
405     QLPrintDialog.C
406     QMathDialog.C
407     QMathMatrixDialog.C
408     QNoteDialog.C
409     QParagraphDialog.C
410     QPrefsDialog.C
411     QRefDialog.C
412     QSearchDialog.C
413     QSendtoDialog.C
414     qsetborder.C
415     QShowFileDialog.C
416     QSpellcheckerDialog.C
417     QDialogView.C
418     QTabularCreateDialog.C
419     QTabularDialog.C
420     QTexinfoDialog.C
421     QThesaurusDialog.C
422     QTocDialog.C
423     qttableview.C
424     QtView.C
425     QURLDialog.C
426     QVSpaceDialog.C
427     QWrapDialog.C
428     QLToolbar.C
429     socket_callback.C
430     validators.C
431   ''')]
432
433   # manually moc and uic files for better performance 
434   qt3_moced_files = [qt3env.Moc(x.replace('.C', '_moc.cpp'), x.replace('.C', '.h')) for x in qt3_moc_files]
435
436   qt3_uiced_files = [qt3env.Uic('$BUILDDIR/common/frontends/qt3/ui/'+x) for x in \
437      globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends/qt3/ui'), pattern = '*.ui')]
438
439   qt3_uiced_cc_files = []
440   for x in qt3_uiced_files:
441     qt3_uiced_cc_files.extend(x[1:])
442
443   qt3 = qt3env.StaticLibrary(
444     target = '$LOCALLIBPATH/qt3',
445     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends/qt3/'), pattern = env['LYX_EXT'],
446       build_dir = '$BUILDDIR/common/frontends/qt3') + qt3_moced_files + qt3_uiced_cc_files
447   )
448   Alias('qt3', qt3)
449
450
451 if build_qt4:
452   print "Processing files in src/frontends/qt4..."
453
454   qt4env = env.Copy()
455   qt4env['QT_AUTOSCAN'] = 0
456
457   # local qt4 toolset from
458   # http://www.iua.upf.es/~dgarcia/Codders/sconstools.html
459   #
460   # NOTE: I have to patch qt4.py since it does not automatically
461   # process .C file!!! (add to cxx_suffixes )
462   #
463   qt4env.Tool('qt4', [env['SCONS_DIR']])
464   qt4env.EnableQt4Modules(env['QT_LIB'], debug = False)
465
466   qt4env.AppendUnique(CPPPATH = [
467     '$BUILDDIR/common',
468     '$BUILDDIR/common/images',
469     '$BUILDDIR/common/frontends',
470     '$BUILDDIR/common/frontends/qt4',
471     '$BUILDDIR/common/frontends/controllers' 
472     ]
473   )
474
475   # FIXME: replace by something from pkg_config
476   qt4env.Append(CCFLAGS = [
477     '-DHAVE_CONFIG_H',
478     '-DQT_CLEAN_NAMESPACE',
479     '-DQT_GENUINE_STR',
480     '-DQT_NO_STL',
481     '-DQT3_SUPPORT',
482     ]
483   )
484
485
486   qt4_moc_files = ["$BUILDDIR/common/frontends/qt4/%s" % x for x in Split('''
487     BulletsModule.C
488     emptytable.C
489     FileDialog_private.C
490     floatplacement.C
491     iconpalette.C
492     lengthcombo.C
493     InsertTableWidget.C
494     panelstack.C
495     QAboutDialog.C
496     QBibitemDialog.C
497     QBibtexDialog.C
498     QBoxDialog.C
499     QBranchDialog.C
500     QBranches.C
501     QChangesDialog.C
502     QCharacterDialog.C
503     QCitationDialog.C
504     QCommandBuffer.C
505     QCommandEdit.C
506     QDelimiterDialog.C
507     QDocumentDialog.C
508     QErrorListDialog.C
509     QERTDialog.C
510     QExternalDialog.C
511     QFloatDialog.C
512     QGraphicsDialog.C
513     QIncludeDialog.C
514     QIndexDialog.C
515     QLAction.C
516     QLogDialog.C
517     QViewSourceDialog.C
518     QViewSource.C
519     QLMenubar.C
520     QLPopupMenu.C
521     QLPrintDialog.C
522     QMathDialog.C
523     QMathMatrixDialog.C
524     QNoteDialog.C
525     QParagraphDialog.C
526     QPrefsDialog.C
527     QRefDialog.C
528     QSearchDialog.C
529     QSendtoDialog.C
530     qsetborder.C
531     QShowFileDialog.C
532     QSpellcheckerDialog.C
533     QDialogView.C
534     QTabularCreateDialog.C
535     QTabularDialog.C
536     QTexinfoDialog.C
537     QThesaurusDialog.C
538     TocModel.C
539     QTocDialog.C
540     QtView.C
541     QURLDialog.C
542     QVSpaceDialog.C
543     QWorkArea.C
544     QWrapDialog.C
545     QLToolbar.C
546     socket_callback.C
547     validators.C
548   ''') ]
549
550   #
551   # Compile resources
552   #
553   resources = [qt4env.Uic4(x.split('.')[0]) for x in \
554     globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends/qt4/ui'), pattern = '*.ui',
555       build_dir = '$BUILDDIR/common/frontends/qt4/ui')]
556
557   # 
558   # moc qt4_moc_files, the moced files are included in the original files
559   #
560   qt4_moced_files = [qt4env.Moc4(x.replace('.C', '_moc.cpp'), x.replace('.C', '.h')) for x in qt4_moc_files]
561
562   qt4 = qt4env.StaticLibrary(
563     target = '$LOCALLIBPATH/qt4',
564     LIBS = qt4env['QT_LIB'],
565     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/frontends/qt4'), pattern = env['LYX_EXT'],
566       exclude = ['QBrowseBox.C'], build_dir = '$BUILDDIR/common/frontends/qt4')
567   )
568   Alias('qt4', qt4)
569
570
571 if build_client:
572   #
573   # src/client
574   #
575   env.BuildDir('$BUILDDIR/common', '$TOP_SRC_DIR/src', duplicate = 0)
576
577   print "Processing files in src/client..."
578
579   if env['HAVE_FCNTL']:
580     client = env.Program(
581       target = '$BUILDDIR/common/client/lyxclient',
582       LIBS = ['support'] + env['INTL_LIBS'] + env['SYSTEM_LIBS'] + 
583         env['SOCKET_LIBS'] + env['BOOST_LIBRARIES'],
584       source = globSource(dir = env.subst('$TOP_SRC_DIR/src/client'), pattern = env['LYX_EXT'],
585         build_dir = '$BUILDDIR/common/client')
586     )
587     Alias('client', env.Command(os.path.join('$BUILDDIR', os.path.split(str(client[0]))[1]),
588       client, [Copy('$TARGET', '$SOURCE')]))
589   else:
590     client = None
591   Alias('client', client)
592
593
594 if build_tex2lyx:
595   #
596   # tex2lyx
597   #
598   print "Processing files in src/tex2lyx..."
599
600   tex2lyx_env = env.Copy()
601   # the order is important here.
602   tex2lyx_env.Prepend(CPPPATH = ['$BUILDDIR/common/tex2lyx'])
603   tex2lyx_env.AppendUnique(LIBPATH = ['#$LOCALLIBPATH'])
604
605   for file in ['FloatList.C', 'Floating.C', 'counters.C', 'lyxlayout.h', 'lyxlayout.C', 
606     'lyxtextclass.h', 'lyxtextclass.C', 'lyxlex.C', 'lyxlex_pimpl.C']:
607     env.Command('$BUILDDIR/common/tex2lyx/'+file, '$TOP_SRC_DIR/src/'+file,
608       [Copy('$TARGET', '$SOURCE')])
609
610   tex2lyx = tex2lyx_env.Program(
611     target = '$BUILDDIR/common/tex2lyx/tex2lyx',
612     LIBS = ['support'] + env['BOOST_LIBRARIES'] + env['SYSTEM_LIBS'],
613     source = globSource(dir = env.subst('$TOP_SRC_DIR/src/tex2lyx'), pattern = env['LYX_EXT'], 
614       include = ['FloatList.C', 'Floating.C', 'counters.C', 'lyxlayout.C', 
615         'lyxtextclass.C', 'lyxlex.C', 'lyxlex_pimpl.C'],
616       build_dir = '$BUILDDIR/common/tex2lyx')
617   )
618   Alias('tex2lyx', env.Command(os.path.join('$BUILDDIR', os.path.split(str(tex2lyx[0]))[1]),
619     tex2lyx, [Copy('$TARGET', '$SOURCE')]))
620   Alias('tex2lyx', tex2lyx)
621
622
623 if build_lyxbase:
624   #
625   # src/
626   #
627   print "Processing files in src..."
628
629   env.substFile('$BUILDDIR/common/version.C', '$TOP_SRC_DIR/src/version.C.in')
630
631   lyx_post_source = Split('''
632     tabular.C
633     dimension.C
634     PrinterParams.C
635     box.C
636     Thesaurus.C
637     SpellBase.C
638   ''')
639
640   if env.has_key('USE_ASPELL') and env['USE_ASPELL']:
641     lyx_post_source.append('aspell.C')
642   elif env.has_key('USE_PSPELL') and env['USE_PSPELL']:
643     lyx_post_source.append('pspell.C')
644   elif env.has_key('USE_ISPELL') and env['USE_ISPELL']:
645     lyx_post_source.append('ispell.C')
646
647   # temporary fix for MSVC, will remove later.
648   if not env['USE_VC']:
649     main_source = ['main.C']
650   else:
651     main_source = []
652
653   lyxbase_pre = env.StaticLibrary(
654     target = '$LOCALLIBPATH/lyxbase_pre',
655     source = globSource(dir = env.subst('$TOP_SRC_DIR/src'), pattern = env['LYX_EXT'], 
656       exclude = lyx_post_source + ['main.C', 'aspell.C', 'pspell.C', 'ispell.C', 'Variables.C', 'Sectioning.C'],
657       include = ['version.C'] + main_source, build_dir = '$BUILDDIR/common')
658   )
659   lyxbase_post = env.StaticLibrary(
660     target = '$LOCALLIBPATH/lyxbase_post',
661     source = ["$BUILDDIR/common/%s" % x for x in lyx_post_source]
662   )
663   Alias('lyxbase', lyxbase_pre)
664   Alias('lyxbase', lyxbase_post)
665
666
667 if build_lyx:
668   #
669   # Build lyx with given frontend
670   #
671   # temporary fix for MSVC, will remove later.
672   if env['USE_VC']:
673     lyx_source = ['$BUILDDIR/common/main.C']
674   else:
675     lyx_source = []
676   lyx = env.Program(
677     target = '$BUILDDIR/$frontend/lyx',
678     source = lyx_source,
679     LIBS = [
680       'lyxbase_pre',
681       'mathed',
682       'insets',
683       'frontends',
684       env['frontend'],
685       'controllers',
686       'graphics',
687       'support',
688       'lyxbase_post',
689       ] +
690       env['BOOST_LIBRARIES'] +
691       env['FRONTEND_LIBS'] +
692       env['INTL_LIBS'] + 
693       env['SOCKET_LIBS'] +
694       env['SYSTEM_LIBS']
695   )
696   # [/path/to/lyx.ext] => lyx-qt3.ext
697   target_name = os.path.split(str(lyx[0]))[1].replace('lyx', 'lyx-%s' % frontend)
698   Alias('lyx', env.Command(os.path.join('$BUILDDIR', target_name), lyx,
699     [Copy('$TARGET', '$SOURCE')]))
700   Alias('lyx', lyx)
701
702
703 if build_msvs_projects:
704   def build_project(target, dir, full_target = None, 
705     src_pattern = env['LYX_EXT'], include=[], resource=None, rebuild=True):
706     ''' build mavs project files 
707       target:      alias (correspond to directory name)
708       dir:         source directory or directories (a list)
709       full_target: full path/filename of the target
710       src_pattern: glob pattern
711       include:     files to include into source
712       resource:    directory or directories with resource (.ui) files
713       rebuild:     whether or not only rebuild this target
714
715     For non-debug-able targets like static libraries, target (alias) is 
716     enough to build the target. For executable targets, msvs need to know
717     the full path to start debug them.
718     '''
719     if resource is not None:
720       res = globSource(dir = env.subst('$TOP_SRC_DIR/'+resource), pattern = '*.ui', 
721         build_dir = env.subst('$TOP_SRC_DIR/'+resource))
722     else:
723       res = []
724     if rebuild:
725       cmds = 'faststart=yes rebuild='+target
726     else:
727       cmds = 'faststart=yes'
728     if type(dir) == type([]):
729       src = []
730       inc = []
731       for d in dir:
732         src.extend(globSource(dir = env.subst('$TOP_SRC_DIR/' + d), 
733           pattern = src_pattern, include = include,
734           build_dir = env.subst('$TOP_SRC_DIR/' + d) ))
735         inc.extend(globSource(dir = env.subst('$TOP_SRC_DIR/' + d), 
736           pattern = '*.h', 
737           build_dir = env.subst('$TOP_SRC_DIR/' + d) ))
738     else:
739       src = globSource(dir = env.subst('$TOP_SRC_DIR/' + dir), 
740         pattern = src_pattern, include = include,
741         build_dir = env.subst('$TOP_SRC_DIR/' + dir) )
742       inc = globSource(dir = env.subst('$TOP_SRC_DIR/' + dir), 
743         pattern = '*.h', 
744         build_dir = env.subst('$TOP_SRC_DIR/' + dir) )
745     if full_target is None:
746       build_target = target
747     else:
748       build_target = full_target
749     # project
750     proj = env.MSVSProject(
751       target = '$MSVSPATH/' + target + env['MSVSPROJECTSUFFIX'],
752       srcs = src,
753       incs = [env.subst('$TOP_SRC_DIR/src/config.h')],
754       localincs = inc,
755       resources = res,
756       buildtarget = build_target,
757       cmdargs = cmds,
758       variant = 'Debug'
759     )
760     Alias('msvs_projects', proj)
761   #
762   build_project('boost', ['boost/libs/filesystem/src',
763     'boost/libs/regex/src', 'boost/libs/signals/src',
764     'boost/libs/iostreams/src'], src_pattern = '*.cpp')
765   #
766   build_project('intl', 'intl', src_pattern = '*.c')
767   #
768   build_project('support', 'src/support', include=['package.C.in'])
769   #
770   build_project('mathed', 'src/mathed')
771   #
772   build_project('insets', 'src/insets')
773   #
774   build_project('frontends', 'src/frontends')
775   #
776   build_project('graphics', 'src/graphics')
777   #
778   build_project('controllers', 'src/frontends/controllers')
779   #
780   build_project('qt3', 'src/frontends/qt3', resource = 'src/frontends/qt3/ui')
781   #
782   build_project('qt4', 'src/frontends/qt4', resource = 'src/frontends/qt4/ui')
783   #
784   build_project('client', 'src/client', rebuild=False, 
785     full_target = File(env.subst('$BUILDDIR/common/client/lyxclient$PROGSUFFIX')).abspath)
786   #
787   build_project('tex2lyx', 'src/tex2lyx', rebuild=False,
788     full_target = File(env.subst('$BUILDDIR/common/tex2lyx/tex2lyx$PROGSUFFIX')).abspath)
789   #
790   build_project('lyxbase', 'src')
791   #
792   if frontend == 'qt3':
793     build_project('lyx', ['src', 'src/support', 'src/mathed', 'src/insets',
794       'src/frontends', 'src/graphics', 'src/frontends/controllers', 
795       'src/frontends/qt3'], resource = 'src/frontends/qt3/ui',
796       full_target = File(env.subst('$BUILDDIR/$frontend/lyx$PROGSUFFIX')).abspath)
797   else:
798     build_project('lyx', ['src', 'src/support', 'src/mathed', 'src/insets',
799       'src/frontends', 'src/graphics', 'src/frontends/controllers', 
800       'src/frontends/qt4'], resource = 'src/frontends/qt4/ui',
801       full_target = File(env.subst('$BUILDDIR/$frontend/lyx$PROGSUFFIX')).abspath)
802
803
804 if build_po:
805   #
806   # po/
807   #
808   print 'Processing files in po...'
809
810   import glob
811   # handle po files
812   #
813   # files to translate
814   transfiles = glob.glob(os.path.join(env.subst('$TOP_SRC_DIR'), 'po', '*.po'))
815   # possibly *only* handle these languages
816   languages = None
817   if env.has_key('languages'):
818     languages = env.make_list(env['lanauges'])
819   # use defulat msgfmt
820   if not env['MSGFMT']:
821     print 'msgfmt does not exist. Can not process po files'
822   else:
823     # create a builder
824     env['BUILDERS']['Transfiles'] = Builder(action='$MSGFMT $SOURCE -o $TARGET',suffix='.gmo',src_suffix='.po')
825     #
826     gmo_files = []
827     for f in transfiles:
828       # get filename
829       fname = os.path.split(f)[1]
830       # country code
831       country = fname.split('.')[0]
832       #
833       if not languages or country in languages:
834         gmo_files.extend(env.Transfiles(f))
835
836
837 if 'install' in targets:
838   # create the directory if needed
839   if not os.path.isdir(env['DEST_DIR']):
840     try:
841       os.makedirs(env['DEST_DIR'])
842     except:
843       pass
844     if not os.path.isdir(env['DEST_DIR']):
845       print 'Can not create directory', env['DEST_DIR']
846       Exit(3)
847   #
848   import glob
849   #
850   # do not install these files
851   exclude_list = ['Makefile.am', 'Makefile.in', 'Makefile', 
852     'lyx2lyx_version.py', 'lyx2lyx_version.py.in']
853
854   def install(dest, src):
855     ''' recusive installation of src to dest '''
856     # separate file and directory
857     files = filter(lambda x: os.path.isfile(x) and not os.path.split(x)[1] in exclude_list, src)
858     dirs = filter(os.path.isdir, src)
859     # install file
860     env.Install(dest, files)
861     # install directory
862     ins_dir = [dest]
863     for dir in dirs:
864       ins_dir.extend(install(os.path.join(dest, os.path.basename(dir)),
865         glob.glob(os.path.join(dir, '*'))) )
866     return ins_dir
867   #
868   # executables (some of them may be none)
869   #
870   if env['ADD_SUFFIX']:
871     version_suffix = env['PROGRAM_SUFFIX']
872   else:
873     version_suffix = ''
874   #
875   # install lyx
876   target_name = os.path.split(str(lyx[0]))[1].replace('lyx', 'lyx%s' % version_suffix)
877   target = os.path.join(env['BIN_DEST_DIR'], target_name)
878   env.InstallAs(target, lyx)
879   Alias('install', target)
880   # install lyx as lyx-qt3
881   target_name = os.path.split(str(lyx[0]))[1].replace('lyx', 'lyx-%s%s' % (frontend, version_suffix))
882   target = os.path.join(env['BIN_DEST_DIR'], target_name)
883   env.InstallAs(target, lyx)
884   Alias('install', target)
885   #
886   # install tex2lyx
887   target_name = os.path.split(str(tex2lyx[0]))[1].replace('tex2lyx', 'tex2lyx%s' % version_suffix)
888   target = os.path.join(env['BIN_DEST_DIR'], target_name)
889   env.InstallAs(target, tex2lyx)
890   Alias('install', target)
891   #
892   # install lyxclient, may not exist
893   if client != None:
894     target_name = os.path.split(str(client[0]))[1].replace('client', 'client%s' % version_suffix)
895     target = os.path.join(env['BIN_DEST_DIR'], target_name)
896     env.InstallAs(target, client)
897     Alias('install', target)
898   #
899   # share/lyx
900   dirs = install(env['SHARE_DEST_DIR'],
901     [env.subst('$TOP_SRC_DIR/lib/') + file for file in ['configure.py', 'encodings',
902      'chkconfig.ltx', 'CREDITS', 'external_templates', 'symbols', 'languages',
903      'lyxrc.example', 'syntax.default', 'bind', 'images', 'layouts', 'scripts', 
904      'templates', 'examples', 'kbd', 'lyx2lyx', 'tex', 'clipart', 'doc',  'ui']]
905   )
906   env.substFile('$SHARE_DEST_DIR/lyx2lyx/lyx2lyx_version.py', 
907     '$TOP_SRC_DIR/lib/lyx2lyx/lyx2lyx_version.py.in')
908   Alias('install', dirs)
909   # man
910   env.InstallAs(os.path.join(env['MAN_DEST_DIR'], 'lyx' + version_suffix + '.1'),
911     env.subst('$TOP_SRC_DIR/lyx.man'))
912   env.InstallAs(os.path.join(env['MAN_DEST_DIR'], 'tex2lyx' + version_suffix + '.1'),
913     env.subst('$TOP_SRC_DIR/src/tex2lyx/tex2lyx.man'))
914   env.InstallAs(os.path.join(env['MAN_DEST_DIR'], 'lyxclient' + version_suffix + '.1'),
915     env.subst('$TOP_SRC_DIR/src/client/lyxclient.man'))
916   Alias('install', [os.path.join(env['MAN_DEST_DIR'], x + version_suffix + '.1') for
917     x in ['lyx', 'tex2lyx', 'lyxclient']])
918   # locale files?
919   # ru.gmo ==> ru/LC_MESSAGES/lyxSUFFIX.mo
920   for gmo in gmo_files:
921     lan = os.path.split(str(gmo))[1].split('.')[0]
922     dest_file = os.path.join(env['LOCALE_DEST_DIR'], lan, 'LC_MESSAGES', 'lyx' + version_suffix + '.mo')
923     env.InstallAs(dest_file, gmo)
924     Alias('install', dest_file)
925
926
927 Default('lyx')
928 Alias('all', ['lyx', 'client', 'tex2lyx'])