]> git.lyx.org Git - lyx.git/blob - development/scons/SConstruct
Scons: clear separation of env and frontend_env (a major reshuffling)
[lyx.git] / development / scons / SConstruct
1 # vi:filetype=python:expandtab:tabstop=4:shiftwidth=4
2 #
3 # file SConstruct
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 # This is a scons based building system for lyx, please refer
12 # to INSTALL.scons for detailed instructions.
13 #
14
15 import os, sys, copy, cPickle, glob, time
16
17 # scons_utils.py defines a few utility function
18 sys.path.append('config')
19 import scons_utils as utils
20 # import all file lists
21 from scons_manifest import *
22
23 #----------------------------------------------------------
24 # Required runtime environment
25 #----------------------------------------------------------
26
27 # scons asks for 1.5.2, lyx requires 2.3
28 EnsurePythonVersion(2, 3)
29 # Please use at least 0.96.92 (not 0.96.1)
30 EnsureSConsVersion(0, 96)
31 # also check for minor version number for scons 0.96
32 from SCons import __version__
33 version = map(int, __version__.split('.'))
34 if version[0] == 0 and version[1] == 96 and version[2] < 92:
35     print "Scons >= 0.96.92 is required."
36     Exit(1)
37
38 # determine where I am ...
39 #
40 from SCons.Node.FS import default_fs
41 # default_fs.SConstruct_dir is where SConstruct file is located.
42 scons_dir = default_fs.SConstruct_dir.path
43 # get the ../.. of scons_dir
44 top_src_dir = os.path.split(os.path.split(default_fs.SConstruct_dir.abspath)[0])[0]
45
46
47 #----------------------------------------------------------
48 # Global definitions
49 #----------------------------------------------------------
50
51 # some global settings
52 #
53 # get version number from configure.ac so that JMarc does
54 # not have to change SConstruct during lyx release
55 package_version = utils.getVerFromConfigure(top_src_dir)
56 package_cygwin_version = '%s-1' % package_version
57 boost_version = ['1_34']
58
59 if 'svn' in package_version:
60     devel_version = True
61     default_build_mode = 'debug'
62 else:
63     devel_version = False
64     default_build_mode = 'release'
65
66 package = 'lyx'
67 package_bugreport = 'lyx-devel@lists.lyx.org'
68 package_name = 'LyX'
69 package_tarname = 'lyx'
70 package_string = '%s %s' % (package_name, package_version)
71
72 # various cache/log files
73 default_log_file = 'scons_lyx.log'
74 opt_cache_file = 'opt.cache'
75
76
77 #----------------------------------------------------------
78 # platform dependent settings
79 #----------------------------------------------------------
80
81 if os.name == 'nt':
82     platform_name = 'win32'
83     default_prefix = 'c:/program files/lyx'
84     default_with_x = False
85     default_packaging_method = 'windows'
86 elif os.name == 'posix' and sys.platform != 'cygwin':
87     platform_name = sys.platform
88     default_prefix = '/usr/local'
89     default_with_x = True
90     default_packaging_method = 'posix'
91 elif os.name == 'posix' and sys.platform == 'cygwin':
92     platform_name = 'cygwin'
93     default_prefix = '/usr'
94     default_with_x = True
95     default_packaging_method = 'posix'
96 elif os.name == 'darwin':
97     platform_name = 'macosx'
98     # FIXME: macOSX default prefix?
99     default_prefix = '.'
100     default_with_x = False
101     default_packaging_method = 'macosx'
102 else:  # unsupported system, assume posix behavior
103     platform_name = 'others'
104     default_prefix = '.'
105     default_with_x = True
106     default_packaging_method = 'posix'
107
108 #---------------------------------------------------------
109 # Handling options
110 #----------------------------------------------------------
111 #
112 # You can set perminant default values in config.py
113 if os.path.isfile('config.py'):
114     print "Getting options from config.py..."
115     print open('config.py').read()
116
117 opts = Options(['config.py'])
118 opts.AddOptions(
119     # frontend
120     EnumOption('frontend', 'Main GUI', 'qt4',
121         allowed_values = ('qt4',) ),
122     # debug or release build
123     EnumOption('mode', 'Building method', default_build_mode,
124         allowed_values = ('debug', 'release') ),
125     # boost libraries
126     EnumOption('boost',
127         'Use included, system boost library, or try sytem boost first.',
128         'auto', allowed_values = (
129             'auto',       # detect boost, if not found, use included
130             'included',   # always use included boost
131             'system',     # always use system boost, fail if can not find
132             ) ),
133     #
134     EnumOption('gettext',
135         'Use included, system gettext library, or try sytem gettext first',
136         'auto', allowed_values = (
137             'auto',       # detect gettext, if not found, use included
138             'included',   # always use included gettext
139             'system',     # always use system gettext, fail if can not find
140             ) ),
141     #
142     EnumOption('spell', 'Choose spell checker to use.', 'auto',
143         allowed_values = ('aspell', 'pspell', 'ispell', 'auto', 'no') ),
144     # packaging method
145     EnumOption('packaging', 'Packaging method to use.', default_packaging_method,
146         allowed_values = ('windows', 'posix', 'macosx')),
147     #
148     BoolOption('fast_start', 'This option is obsolete.', False),
149     # No precompiled header support (too troublesome to make it work for msvc)
150     # BoolOption('pch', 'Whether or not use pch', False),
151     # enable assertion, (config.h has ENABLE_ASSERTIOS
152     BoolOption('assertions', 'Use assertions', True),
153     # enable warning, (config.h has WITH_WARNINGS)
154     # default to False since MSVC does not have #warning
155     BoolOption('warnings', 'Use warnings', False),
156     # config.h define _GLIBCXX_CONCEPT_CHECKS
157     # Note: for earlier version of gcc (3.3) define _GLIBCPP_CONCEPT_CHECKS
158     BoolOption('concept_checks', 'Enable concept checks', True),
159     #
160     BoolOption('nls', 'Whether or not use native language support', True),
161     #
162     BoolOption('profiling', 'Whether or not enable profiling', False),
163     # config.h define _GLIBCXX_DEBUG and _GLIBCXX_DEBUG_PEDANTIC
164     BoolOption('stdlib_debug', 'Whether or not turn on stdlib debug', False),
165     # using x11?
166     BoolOption('X11', 'Use x11 windows system', default_with_x),
167     # use MS VC++ to build lyx
168     BoolOption('use_vc', 'Use MS VC++ to build lyx (cl.exe will be probed)', None),
169     #
170     PathOption('qt_dir', 'Path to qt directory', None),
171     #
172     PathOption('qt_inc_path', 'Path to qt include directory', None),
173     #
174     PathOption('qt_lib_path', 'Path to qt library directory', None),
175     # extra include and libpath
176     PathOption('extra_inc_path', 'Extra include path', None),
177     #
178     PathOption('extra_lib_path', 'Extra library path', None),
179     #
180     PathOption('extra_bin_path', 'A convenient way to add a path to $PATH', None),
181     #
182     PathOption('extra_inc_path1', 'Extra include path', None),
183     #
184     PathOption('extra_lib_path1', 'Extra library path', None),
185     # rebuild only specifed, comma separated targets
186     ('rebuild', '''rebuild only specifed, comma separated targets.
187         yes or all (default): rebuild everything
188         no or none: rebuild nothing (usually used for installation)
189         comp1,comp2,...: rebuild specified targets''', None),
190     # can be set to a non-existing directory
191     ('prefix', 'install architecture-independent files in PREFIX', default_prefix),
192     # build directory, will use $mode if not set
193     ('build_dir', 'Build directory', None),
194     # version suffix
195     ('version_suffix', 'install lyx as lyx-suffix', None),
196     # how to load options
197     ('load_option', '''load option from previous scons run. option can be
198         yes (default): load all options
199         no: do not load any option
200         opt1,opt2: load specified options
201         -opt1,opt2: load all options other than specified ones''', 'yes'),
202     #
203     ('optimization', 'optimization CCFLAGS option.', None),
204     #
205     PathOption('exec_prefix', 'install architecture-independent executable files in PREFIX', None),
206     # log file
207     ('logfile', 'save commands (not outputs) to logfile', default_log_file),
208     # provided for backward compatibility
209     ('dest_dir', 'install to DESTDIR. (Provided for backward compatibility only)', None),
210     # environment variable can be set as options.
211     ('DESTDIR', 'install to DESTDIR', None),
212     ('CC', 'replace default $CC', None),
213     ('LINK', 'replace default $LINK', None),
214     ('CPP', 'replace default $CPP', None),
215     ('CXX', 'replace default $CXX', None),
216     ('CXXCPP', 'replace default $CXXCPP', None),
217     ('CCFLAGS', 'replace default $CCFLAGS', None),
218     ('CPPFLAGS', 'replace default $CPPFLAGS', None),
219     ('LINKFLAGS', 'replace default $LINKFLAGS', None),
220 )
221
222 # allowed options
223 all_options = [x.key for x in opts.options]
224
225 # copied from SCons/Options/BoolOption.py
226 # We need to use them before a boolean ARGUMENTS option is available
227 # in env as bool.
228 true_strings  = ('y', 'yes', 'true', 't', '1', 'on' , 'all' )
229 false_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none')
230
231 if ARGUMENTS.has_key('fast_start'):
232     print 'fast_start option is obsolete'
233
234 # if load_option=yes (default), load saved comand line options
235 #
236 # This option can take value yes/no/opt1,opt2/-opt1,opt2
237 # and tries to be clever in choosing options to load
238 if (not ARGUMENTS.has_key('load_option') or \
239     ARGUMENTS['load_option'] not in false_strings) \
240     and os.path.isfile(opt_cache_file):
241     cache_file = open(opt_cache_file)
242     opt_cache = cPickle.load(cache_file)
243     cache_file.close()
244     # import cached options, but we should ignore qt_dir when frontend changes
245     if ARGUMENTS.has_key('frontend') and opt_cache.has_key('frontend') \
246         and ARGUMENTS['frontend'] != opt_cache['frontend'] \
247         and opt_cache.has_key('qt_dir'):
248         opt_cache.pop('qt_dir')
249     # and we do not cache some options (dest_dir is obsolete)
250     for arg in ['load_option', 'dest_dir']:
251         if opt_cache.has_key(arg):
252             opt_cache.pop(arg)
253     # remove obsolete cached keys (well, SConstruct is evolving. :-)
254     for arg in opt_cache.keys():
255         if arg not in all_options:
256             print 'Option %s is obsolete, do not load it' % arg
257             opt_cache.pop(arg)
258     # now, if load_option=opt1,opt2 or -opt1,opt2
259     if ARGUMENTS.has_key('load_option') and \
260         ARGUMENTS['load_option'] not in true_strings + false_strings:
261         # if -opt1,opt2 is specified, do not load these options
262         if ARGUMENTS['load_option'][0] == '-':
263             for arg in ARGUMENTS['load_option'][1:].split(','):
264                 if opt_cache.has_key(arg):
265                     opt_cache.pop(arg)
266         # if opt1,opt2 is specified, only load specified options
267         else:
268             args = ARGUMENTS['load_option'].split(',')
269             for arg in opt_cache.keys():
270                 if arg not in args:
271                     opt_cache.pop(arg)
272     # now restore options as if entered from command line
273     for key in opt_cache.keys():
274         if not ARGUMENTS.has_key(key):
275             ARGUMENTS[key] = opt_cache[key]
276             print "Restoring cached option  %s=%s" % (key, ARGUMENTS[key])
277     print
278
279 # check if there is unused (or misspelled) argument
280 for arg in ARGUMENTS.keys():
281     if arg not in all_options:
282         import textwrap
283         print "Unknown option '%s'... exiting." % arg
284         print
285         print "Available options are (check 'scons -help' for details):"
286         print '    ' + '\n    '.join(textwrap.wrap(',  '.join(all_options)))
287         Exit(1)
288
289 # save options used
290 cache_file = open(opt_cache_file, 'w')
291 cPickle.dump(ARGUMENTS, cache_file)
292 cache_file.close()
293
294 #---------------------------------------------------------
295 # Setting up environment
296 #---------------------------------------------------------
297
298 # I do not really like ENV=os.environ, but you may add it
299 # here if you experience some environment related problem
300 env = Environment(options = opts)
301
302 # set individual variables since I do not really like ENV = os.environ
303 env['ENV']['PATH'] = os.environ.get('PATH')
304 env['ENV']['HOME'] = os.environ.get('HOME')
305 # these are defined for MSVC
306 env['ENV']['LIB'] = os.environ.get('LIB')
307 env['ENV']['INCLUDE'] = os.environ.get('INCLUDE')
308
309 # for simplicity, use var instead of env[var]
310 frontend = env['frontend']
311 prefix = env['prefix']
312 mode = env['mode']
313
314 if platform_name == 'win32':
315     if env.has_key('use_vc'):
316         use_vc = env['use_vc']
317         if WhereIs('cl.exe') is None:
318             print "cl.exe is not found. Are you using the MSVC environment?"
319             Exit(2)
320     elif WhereIs('cl.exe') is not None:
321         use_vc = True
322     else:
323         use_vc = False
324 else:
325     use_vc = False
326
327 # lyx will be built to $build/build_dir so it is possible
328 # to build multiple build_dirs using the same source
329 # $mode can be debug or release
330 if env.has_key('build_dir') and env['build_dir'] is not None:
331     # create the directory if needed
332     if not os.path.isdir(env['build_dir']):
333         try:
334             os.makedirs(env['build_dir'])
335         except:
336             pass
337         if not os.path.isdir(env['build_dir']):
338             print 'Can not create directory', env['build_dir']
339             Exit(3)
340     env['BUILDDIR'] = env['build_dir']
341 else:
342     # Determine the name of the build $mode
343     env['BUILDDIR'] = '#' + mode
344
345 # all built libraries will go to build_dir/libs
346 # (This is different from the make file approach)
347 env['LOCALLIBPATH'] = '$BUILDDIR/libs'
348 env.AppendUnique(LIBPATH = ['$LOCALLIBPATH'])
349
350
351 # Here is a summary of variables defined in env
352 # 1. defined options
353 # 2. undefined options with a non-None default value
354 # 3. compiler commands and flags like CCFLAGS.
355 #     MSGFMT used to process po files
356 # 4. Variables that will be used to replace variables in some_file.in
357 #     src/support/package.C.in:
358 #       TOP_SRCDIR, LOCALEDIR, LYX_DIR, PROGRAM_SUFFIX
359 #     lib/lyx2lyx/lyx2lyx_version.py.in
360 #       PACKAGE_VERSION
361 #     src/version.C.in
362 #       PACKAGE_VERSION, LYX_DATE, VERSION_INFO
363
364 # full path name is used to build msvs project files
365 # and to replace TOP_SRCDIR in package.C
366 env['TOP_SRCDIR'] = Dir(top_src_dir).abspath
367 # needed by src/version.C.in => src/version.C
368 env['PACKAGE_VERSION'] = package_version
369 env['LYX_DATE'] = time.asctime()
370
371 # determine share_dir etc
372 packaging_method = env.get('packaging')
373 if packaging_method == 'windows':
374     share_dir = 'Resources'
375     man_dir = 'Resources/man/man1'
376     locale_dir = 'Resources/locale'
377 else:
378     share_dir = 'share/lyx'
379     locale_dir = 'share/locale'
380     if platform_name == 'cygwin':
381         man_dir = 'share/man/man1'
382     else:
383         man_dir = 'man/man1'
384
385 # program suffix: can be yes, or a string
386 if env.has_key('version_suffix'):
387     if env['version_suffix'] in true_strings:
388         program_suffix = package_version
389     elif env['version_suffix'] in false_strings:
390         program_suffix = ''
391     else:
392         program_suffix = env['version_suffix']
393 else:
394     program_suffix = ''
395 # used by package.C.in
396 env['PROGRAM_SUFFIX'] = program_suffix
397
398 # whether or not add suffix to file and directory names
399 add_suffix = packaging_method != 'windows'
400 # LYX_DIR are different (used in package.C.in)
401 if add_suffix:
402     env['LYX_DIR'] = Dir(os.path.join(prefix, share_dir + program_suffix)).abspath
403 else:
404     env['LYX_DIR'] = Dir(os.path.join(prefix, share_dir)).abspath
405 # we need absolute path for package.C
406 env['LOCALEDIR'] = Dir(os.path.join(prefix, locale_dir)).abspath
407
408
409 #---------------------------------------------------------
410 # Setting building environment (Tools, compiler flags etc)
411 #---------------------------------------------------------
412
413 # Since Tool('mingw') will reset CCFLAGS etc, this should be
414 # done before getEnvVariable
415 if platform_name == 'win32':
416     if use_vc:
417         env.Tool('msvc')
418         env.Tool('mslink')
419     else:
420         env.Tool('mingw')
421         env.AppendUnique(CPPPATH = ['#c:/MinGW/include'])
422
423 # we differentiate between hard-coded options and default options
424 # hard-coded options are required and will always be there
425 # default options can be replaced by enviromental variables or command line options
426 CCFLAGS_required = []
427 LINKFLAGS_required = []
428 CCFLAGS_default = []
429
430 # under windows, scons is confused by .C/.c and uses gcc instead of
431 # g++. I am forcing the use of g++ here. This is expected to change
432 # after lyx renames all .C files to .cpp
433 #
434 # save the old c compiler and CCFLAGS (used by libintl)
435 C_COMPILER = env.subst('$CC')
436 C_CCFLAGS = env.subst('$CCFLAGS').split()
437 # if we use ms vc, the commands are fine (cl.exe and link.exe)
438 if use_vc:
439     # /TP treat all source code as C++
440     # C4819: The file contains a character that cannot be represented
441     #   in the current code page (number)
442     # C4996: foo was decleared deprecated
443     CCFLAGS_required.extend(['/TP', '/EHsc'])
444     if mode == 'debug':
445         CCFLAGS_default.extend(['/wd4819', '/wd4996', '/nologo', '/MDd'])
446         # the flags are also needed in C mode (for intl lib)
447         C_CCFLAGS.extend(['/wd4819', '/wd4996', '/nologo', '/MDd'])
448     else:
449         CCFLAGS_default.extend(['/wd4819', '/wd4996', '/nologo', '/MD'])
450         C_CCFLAGS.extend(['/wd4819', '/wd4996', '/nologo', '/MD'])
451 else:
452     if env.has_key('CXX') and env['CXX']:
453         env['CC'] = env.subst('$CXX')
454         env['LINK'] = env.subst('$CXX')
455     else:
456         env['CC'] = 'g++'
457         env['LINK'] = 'g++'
458
459 # for debug/release mode
460 if env.has_key('optimization') and env['optimization'] is not None:
461     # if user supplies optimization flags, use it anyway
462     CCFLAGS_required.extend(env['optimization'].split())
463     # and do not use default
464     set_default_optimization_flags = False
465 else:
466     set_default_optimization_flags = True
467
468 if mode == 'debug':
469     if use_vc:
470         CCFLAGS_required.append('/Zi')
471         LINKFLAGS_required.extend(['/debug', '/map'])
472     else:
473         CCFLAGS_required.append('-g')
474         CCFLAGS_default.append('-O')
475 elif mode == 'release' and set_default_optimization_flags:
476     if use_vc:
477         CCFLAGS_default.append('/O2')
478     else:
479         CCFLAGS_default.append('-O2')
480
481 # msvc uses separate tools for profiling
482 if env.has_key('profiling') and env['profiling']:
483     if use_vc:
484         print 'Visual C++ does not use profiling options'
485     else:
486         CCFLAGS_required.append('-pg')
487         LINKFLAGS_required.append('-pg')
488
489 if env.has_key('warnings') and env['warnings']:
490     if use_vc:
491         CCFLAGS_default.append('/W2')
492     else:
493         # Note: autotools detect gxx version and pass -W for 3.x
494         # and -Wextra for other versions of gcc
495         CCFLAGS_default.append('-Wall')
496
497 # Now, set the variables as follows:
498 # 1. if command line option exists: replace default
499 # 2. then if s envronment variable exists: replace default
500 # 3. set variable to required + default
501 def setEnvVariable(env, name, required = None, default = None, split = True):
502     ''' env: environment to set variable
503             name: variable
504             required: hardcoded options
505             default: default options that can be replaced by command line or
506                 environment variables
507             split: whether or not split obtained variable like '-02 -g'
508     '''
509     # 1. ARGUMENTS is already set to env[name], override default.
510     if ARGUMENTS.has_key(name):
511         # env[name] may be rewritten when building tools are reloaded
512         # if that is the case, commandline option will override it.
513         env[name] = ARGUMENTS[name]
514         default = None
515     # then use environment default
516     elif os.environ.has_key(name):
517         print "Acquiring variable %s from system environment: %s" % (name, os.environ[name])
518         default = os.environ[name]
519         if split:
520             default = default.split()
521     # the real value should be env[name] + default + required
522     if split:
523         value = []
524         if env.has_key(name):
525             value = str(env[name]).split()
526         if required is not None:
527             value += required
528         if default is not None:
529             value += default
530     else:
531         value = ""
532         if env.has_key(name):
533             value = str(env[name])
534         if required is not None:
535             value += " " + required
536         if default is not None:
537             value += " " + default
538     env[name] = value
539     # print name, env[name]
540
541 setEnvVariable(env, 'DESTDIR', split=False)
542 setEnvVariable(env, 'CC')
543 setEnvVariable(env, 'LINK')
544 setEnvVariable(env, 'CPP')
545 setEnvVariable(env, 'CXX')
546 setEnvVariable(env, 'CXXCPP')
547 setEnvVariable(env, 'CCFLAGS', CCFLAGS_required, CCFLAGS_default)
548 setEnvVariable(env, 'CXXFLAGS')
549 setEnvVariable(env, 'CPPFLAGS')
550 setEnvVariable(env, 'LINKFLAGS', LINKFLAGS_required)
551
552 # if DESTDIR is not set...
553 if env.has_key('dest_dir'):
554     print "This option is obsolete. Please use DESTDIR instead."
555     env['DESTDIR'] = env['dest_dir']
556
557 #
558 # extra_inc_path and extra_lib_path
559 #
560 extra_inc_paths = []
561 if env.has_key('extra_inc_path') and env['extra_inc_path']:
562     extra_inc_paths.append(env['extra_inc_path'])
563 if env.has_key('extra_lib_path') and env['extra_lib_path']:
564     env.AppendUnique(LIBPATH = [env['extra_lib_path']])
565 if env.has_key('extra_inc_path1') and env['extra_inc_path1']:
566     extra_inc_paths.append(env['extra_inc_path1'])
567 if env.has_key('extra_lib_path1') and env['extra_lib_path1']:
568     env.AppendUnique(LIBPATH = [env['extra_lib_path1']])
569 if env.has_key('extra_bin_path') and env['extra_bin_path']:
570     # only the first one is needed (a scons bug?)
571     os.environ['PATH'] += os.pathsep + env['extra_bin_path']
572     env.PrependENVPath('PATH', env['extra_bin_path'])
573 # extra_inc_paths will be used later by intlenv etc
574 env.AppendUnique(CPPPATH = extra_inc_paths)
575
576
577 #----------------------------------------------------------
578 # Autoconf business
579 #----------------------------------------------------------
580
581 conf = Configure(env,
582     custom_tests = {
583         'CheckPkgConfig' : utils.checkPkgConfig,
584         'CheckPackage' : utils.checkPackage,
585         'CheckMkdirOneArg' : utils.checkMkdirOneArg,
586         'CheckSelectArgType' : utils.checkSelectArgType,
587         'CheckBoostLibraries' : utils.checkBoostLibraries,
588         'CheckCommand' : utils.checkCommand,
589         'CheckCXXGlobalCstd' : utils.checkCXXGlobalCstd,
590         'CheckLC_MESSAGES' : utils.checkLC_MESSAGES,
591         'CheckIconvConst' : utils.checkIconvConst,
592         'CheckSizeOfWChar' : utils.checkSizeOfWChar,
593     }
594 )
595
596 # pkg-config? (if not, we use hard-coded options)
597 if conf.CheckPkgConfig('0.15.0'):
598     env['HAS_PKG_CONFIG'] = True
599 else:
600     print 'pkg-config >= 0.1.50 is not found'
601     env['HAS_PKG_CONFIG'] = False
602
603 # zlib? This is required.
604 if (not use_vc and not conf.CheckLibWithHeader('z', 'zlib.h', 'C')) \
605     or (use_vc and not conf.CheckLibWithHeader('zdll', 'zlib.h', 'C')):
606     print 'Did not find zdll.lib or zlib.h, exiting!'
607     Exit(1)
608 if conf.CheckLib('iconv'):
609     env['ICONV_LIB'] = 'iconv'
610 elif conf.CheckLib('libiconv'):
611     env['ICONV_LIB'] = 'libiconv'
612 elif conf.CheckFunc('iconv_open'):
613     env['ICONV_LIB'] = None
614 else:
615     print 'Did not find iconv or libiconv, exiting!'
616     Exit(1)
617
618 # check socket libs
619 socket_libs = []
620 if conf.CheckLib('socket'):
621     socket_libs.append('socket')
622 # nsl is the network services library and provides a
623 # transport-level interface to networking services.
624 if conf.CheckLib('nsl'):
625     socket_libs.append('nsl')
626
627 # check available boost libs (since lyx1.4 does not use iostream)
628 boost_libs = []
629 for lib in ['signals', 'regex', 'filesystem', 'iostreams']:
630     if os.path.isdir(os.path.join(top_src_dir, 'boost', 'libs', lib)):
631         boost_libs.append(lib)
632
633 # check boost libraries
634 boost_opt = ARGUMENTS.get('boost', 'auto')
635 # check for system boost
636 lib_paths = env['LIBPATH'] + ['/usr/lib', '/usr/local/lib']
637 inc_paths = env['CPPPATH'] + ['/usr/include', '/usr/local/include']
638 # default to $BUILDDIR/libs (use None since this path will be added anyway)
639 boost_libpath = None
640 # here I assume that all libraries are in the same directory
641 if boost_opt == 'included':
642     boost_libraries = ['included_boost_%s' % x for x in boost_libs]
643     included_boost = True
644     env['BOOST_INC_PATH'] = '$TOP_SRCDIR/boost'
645 elif boost_opt == 'auto':
646     res = conf.CheckBoostLibraries(boost_libs, lib_paths, inc_paths, boost_version, mode == 'debug')
647     # if not found, use local boost
648     if res[0] is None:
649         boost_libraries = ['included_boost_%s' % x for x in boost_libs]
650         included_boost = True
651         env['BOOST_INC_PATH'] = '$TOP_SRCDIR/boost'
652     else:
653         included_boost = False
654         (boost_libraries, boost_libpath, env['BOOST_INC_PATH']) = res
655 elif boost_opt == 'system':
656     res = conf.CheckBoostLibraries(boost_libs, lib_paths, inc_paths, boost_version, mode == 'debug')
657     if res[0] is None:
658         print "Can not find system boost libraries with version %s " % boost_version
659         print "Please supply a path through extra_lib_path and try again."
660         print "Or use boost=included to use included boost libraries."
661         Exit(2)
662     else:
663         included_boost = False
664         (boost_libraries, boost_libpath, env['BOOST_INC_PATH']) = res
665
666
667 if boost_libpath is not None:
668     env.AppendUnique(LIBPATH = [boost_libpath])
669
670
671 env['ENABLE_NLS'] = env['nls']
672
673 if not env['ENABLE_NLS']:
674     intl_libs = []
675     included_gettext = False
676 else:
677     # check gettext libraries
678     gettext_opt = ARGUMENTS.get('gettext', 'auto')
679     # check for system gettext
680     succ = False
681     if gettext_opt in ['auto', 'system']:
682         if conf.CheckFunc('gettext'):
683             included_gettext = False
684             intl_libs = []
685             succ = True
686         elif conf.CheckLib('intl'):
687             included_gettext = False
688             intl_libs = ['intl']
689             succ = True
690         else: # no found
691             if gettext_opt == 'system':
692                 print "Can not find system gettext library"
693                 print "Please supply a path through extra_lib_path and try again."
694                 print "Or use gettext=included to use included gettext libraries."
695                 Exit(2)
696     # now, auto and succ = false, or gettext=included
697     if not succ:
698         # we do not need to set LIBPATH now.
699         included_gettext = True
700         intl_libs = ['included_intl']
701
702
703 #
704 # check for msgfmt command
705 env['MSGFMT'] = conf.CheckCommand('msgfmt')
706
707 # cygwin packaging requires the binaries to be stripped
708 if platform_name == 'cygwin':
709     env['STRIP'] = conf.CheckCommand('strip')
710
711 #
712 # Customized builders
713 #
714 # install customized builders
715 env['BUILDERS']['substFile'] = Builder(action = utils.env_subst)
716
717
718 #----------------------------------------------------------
719 # Generating config.h
720 #----------------------------------------------------------
721 aspell_lib = 'aspell'
722 # assume that we use aspell, aspelld compiled for msvc
723 if platform_name == 'win32' and mode == 'debug' and use_vc:
724     aspell_lib = 'aspelld'
725
726 # check the existence of config.h
727 config_h = os.path.join(env.Dir('$BUILDDIR/common').path, 'config.h')
728 boost_config_h = os.path.join(env.Dir('$BUILDDIR/boost').path, 'config.h')
729 #
730 print "Creating %s..." % boost_config_h
731 #
732 utils.createConfigFile(conf,
733     config_file = boost_config_h,
734     config_pre = '''/* boost/config.h.  Generated by SCons.  */
735
736 /* -*- C++ -*- */
737 /*
738 * \file config.h
739 * This file is part of LyX, the document processor.
740 * Licence details can be found in the file COPYING.
741 *
742 * This is the compilation configuration file for LyX.
743 * It was generated by scon.
744 * You might want to change some of the defaults if something goes wrong
745 * during the compilation.
746 */
747
748 #ifndef _BOOST_CONFIG_H
749 #define _BOOST_CONFIG_H
750 ''',
751     headers = [
752         ('ostream', 'HAVE_OSTREAM', 'cxx'),
753         ('locale', 'HAVE_LOCALE', 'cxx'),
754         ('sstream', 'HAVE_SSTREAM', 'cxx'),
755         #('newapis.h', 'HAVE_NEWAPIS_H', 'c'),
756     ],
757     custom_tests = [
758         (env.has_key('assertions') and env['assertions'],
759             'ENABLE_ASSERTIONS',
760             'Define if you want assertions to be enabled in the code'
761         ),
762     ],
763     types = [
764         ('wchar_t', 'HAVE_WCHAR_T', None),
765     ],
766     config_post = '''
767
768 #if defined(HAVE_OSTREAM) && defined(HAVE_LOCALE) && defined(HAVE_SSTREAM)
769 #  define USE_BOOST_FORMAT 1
770 #else
771 #  define USE_BOOST_FORMAT 0
772 #endif
773
774 #if !defined(ENABLE_ASSERTIONS)
775 #  define BOOST_DISABLE_ASSERTS 1
776 #endif
777 #define BOOST_ENABLE_ASSERT_HANDLER 1
778
779 #define BOOST_DISABLE_THREADS 1
780 #define BOOST_NO_WSTRING 1
781
782 #ifdef __CYGWIN__
783 #  define BOOST_POSIX 1
784 #  define BOOST_POSIX_API 1
785 #  define BOOST_POSIX_PATH 1
786 #endif
787
788 #define BOOST_ALL_NO_LIB 1
789
790 #if defined(HAVE_NEWAPIS_H)
791 #  define WANT_GETFILEATTRIBUTESEX_WRAPPER 1
792 #endif
793
794 #if defined(HAVE_WCHAR_T) && SIZEOF_WCHAR_T == 4
795 #  define LIBC_WCTYPE_USES_UCS4
796 #endif
797
798 #endif
799 '''
800 )
801 #
802 print "\nGenerating %s..." % config_h
803
804 # AIKSAURUS_H_LOCATION
805 if (conf.CheckCXXHeader("Aiksaurus.h")):
806     aik_location = '<Aiksaurus.h>'
807 elif (conf.CheckCXXHeader("Aiksaurus/Aiksaurus.h")):
808     aik_location = '<Aiksaurus/Aiksaurus.h>'
809 else:
810     aik_location = ''
811
812 # determine headers to use
813 spell_opt = ARGUMENTS.get('spell', 'auto')
814 env['USE_ASPELL'] = False
815 env['USE_PSPELL'] = False
816 env['USE_ISPELL'] = False
817 if spell_opt in ['auto', 'aspell'] and conf.CheckLib(aspell_lib):
818     spell_engine = 'USE_ASPELL'
819 elif spell_opt in ['auto', 'pspell'] and conf.CheckLib('pspell'):
820     spell_engine = 'USE_PSPELL'
821 elif spell_opt in ['auto', 'ispell'] and conf.CheckLib('ispell'):
822     spell_engine = 'USE_ISPELL'
823 else:
824     spell_engine = None
825
826 if spell_engine is not None:
827     env[spell_engine] = True
828 else:
829     if spell_opt == 'auto':
830         print "Warning: Can not locate any spell checker"
831     elif spell_opt != 'no':
832         print "Warning: Can not locate specified spell checker:", spell_opt
833         Exit(1)
834
835 # check arg types of select function
836 (select_arg1, select_arg234, select_arg5) = conf.CheckSelectArgType()
837
838 # check the size of wchar_t
839 sizeof_wchar_t = conf.CheckSizeOfWChar()
840 # something wrong
841 if sizeof_wchar_t == 0:
842     print 'Error: Can not determine the size of wchar_t.'
843     Exit(1)
844
845 #
846 # create config.h
847 result = utils.createConfigFile(conf,
848     config_file = config_h,
849     config_pre = '''/* config.h.  Generated by SCons.  */
850
851 /* -*- C++ -*- */
852 /*
853 * \file config.h
854 * This file is part of LyX, the document processor.
855 * Licence details can be found in the file COPYING.
856 *
857 * This is the compilation configuration file for LyX.
858 * It was generated by scon.
859 * You might want to change some of the defaults if something goes wrong
860 * during the compilation.
861 */
862
863 #ifndef _CONFIG_H
864 #define _CONFIG_H
865 ''',
866     headers = [
867         ('io.h', 'HAVE_IO_H', 'c'),
868         ('limits.h', 'HAVE_LIMITS_H', 'c'),
869         ('locale.h', 'HAVE_LOCALE_H', 'c'),
870         ('process.h', 'HAVE_PROCESS_H', 'c'),
871         ('stdlib.h', 'HAVE_STDLIB_H', 'c'),
872         ('sys/stat.h', 'HAVE_SYS_STAT_H', 'c'),
873         ('sys/time.h', 'HAVE_SYS_TIME_H', 'c'),
874         ('sys/types.h', 'HAVE_SYS_TYPES_H', 'c'),
875         ('sys/utime.h', 'HAVE_SYS_UTIME_H', 'c'),
876         ('sys/socket.h', 'HAVE_SYS_SOCKET_H', 'c'),
877         ('unistd.h', 'HAVE_UNISTD_H', 'c'),
878         ('utime.h', 'HAVE_UTIME_H', 'c'),
879         ('direct.h', 'HAVE_DIRECT_H', 'c'),
880         ('istream', 'HAVE_ISTREAM', 'cxx'),
881         ('ios', 'HAVE_IOS', 'cxx'),
882     ],
883     functions = [
884         ('open', 'HAVE_OPEN', None),
885         ('chmod', 'HAVE_CHMOD', None),
886         ('close', 'HAVE_CLOSE', None),
887         ('popen', 'HAVE_POPEN', None),
888         ('pclose', 'HAVE_PCLOSE', None),
889         ('_open', 'HAVE__OPEN', None),
890         ('_close', 'HAVE__CLOSE', None),
891         ('_popen', 'HAVE__POPEN', None),
892         ('_pclose', 'HAVE__PCLOSE', None),
893         ('getpid', 'HAVE_GETPID', None),
894         ('_getpid', 'HAVE__GETPID', None),
895         ('mkdir', 'HAVE_MKDIR', None),
896         ('_mkdir', 'HAVE__MKDIR', None),
897         ('mktemp', 'HAVE_MKTEMP', None),
898         ('mkstemp', 'HAVE_MKSTEMP', None),
899         ('strerror', 'HAVE_STRERROR', None),
900         ('count', 'HAVE_STD_COUNT', '''
901 #include <algorithm>
902 int count()
903 {
904 char a[] = "hello";
905 return std::count(a, a+5, 'l');
906 }
907 '''),
908         ('getcwd', 'HAVE_GETCWD', None),
909         ('setenv', 'HAVE_SETENV', None),
910         ('putenv', 'HAVE_PUTENV', None),
911         ('fcntl', 'HAVE_FCNTL', None),
912     ],
913     types = [
914         ('std::istreambuf_iterator<std::istream>', 'HAVE_DECL_ISTREAMBUF_ITERATOR',
915             '#include <streambuf>\n#include <istream>'),
916         ('wchar_t', 'HAVE_WCHAR_T', None),
917         ('mode_t', 'HAVE_MODE_T', "#include <sys/types.h>"),
918     ],
919     libs = [
920         ('gdi32', 'HAVE_LIBGDI32'),
921         (('Aiksaurus', 'libAiksaurus'), 'HAVE_LIBAIKSAURUS', 'AIKSAURUS_LIB'),
922     ],
923     custom_tests = [
924         (conf.CheckType('pid_t', includes='#include <sys/types.h>'),
925             'HAVE_PID_T',
926             'Define is sys/types.h does not have pid_t',
927             '',
928             '#define pid_t int',
929         ),
930         (conf.CheckCXXGlobalCstd(),
931             'CXX_GLOBAL_CSTD',
932             'Define if your C++ compiler puts C library functions in the global namespace'
933         ),
934         (conf.CheckMkdirOneArg(),
935             'MKDIR_TAKES_ONE_ARG',
936             'Define if mkdir takes only one argument.'
937         ),
938         (conf.CheckIconvConst(),
939             'ICONV_CONST',
940             'Define as const if the declaration of iconv() needs const.',
941             '#define ICONV_CONST const',
942             '#define ICONV_CONST',
943         ),
944         (conf.CheckLC_MESSAGES(),
945             'HAVE_LC_MESSAGES',
946             'Define if your <locale.h> file defines LC_MESSAGES.'
947         ),
948         (devel_version, 'DEVEL_VERSION', 'Whether or not a development version'),
949         (env['nls'],
950             'ENABLE_NLS',
951             "Define to 1 if translation of program messages to the user's native anguage is requested.",
952         ),
953         (env['nls'] and not included_gettext,
954             'HAVE_GETTEXT',
955             'Define to 1 if using system gettext library'
956         ),
957         (env.has_key('warnings') and env['warnings'],
958             'WITH_WARNINGS',
959             'Define this if you want to see the warning directives put here and there by the developpers to get attention'
960         ),
961         (env.has_key('concept_checks') and env['concept_checks'],
962             '_GLIBCXX_CONCEPT_CHECKS',
963             'libstdc++ concept checking'
964         ),
965         (env.has_key('stdlib_debug') and env['stdlib_debug'],
966             '_GLIBCXX_DEBUG',
967             'libstdc++ debug mode'
968         ),
969         (env.has_key('stdlib_debug') and env['stdlib_debug'],
970             '_GLIBCXX_DEBUG_PEDANTIC',
971             'libstdc++ pedantic debug mode'
972         ),
973         (os.name != 'nt', 'BOOST_POSIX',
974             'Indicates to boost < 1.34 which API to use (posix or windows).'
975         ),
976         (os.name != 'nt', 'BOOST_POSIX_API',
977             'Indicates to boost 1.34 which API to use (posix or windows).'
978         ),
979         (os.name != 'nt', 'BOOST_POSIX_PATH',
980             'Indicates to boost 1.34 which path style to use (posix or windows).'
981         ),
982         (spell_engine is not None, spell_engine,
983             'Spell engine to use'
984         ),
985         # we need to know the byte order for unicode conversions
986         (sys.byteorder == 'big', 'WORDS_BIGENDIAN',
987             'Define to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX).'
988         ),
989     ],
990     extra_items = [
991         ('#define PACKAGE "%s%s"' % (package, program_suffix),
992             'Name of package'),
993         ('#define PACKAGE_BUGREPORT "%s"' % package_bugreport,
994             'Define to the address where bug reports for this package should be sent.'),
995         ('#define PACKAGE_NAME "%s"' % package_name,
996             'Define to the full name of this package.'),
997         ('#define PACKAGE_STRING "%s"' % package_string,
998             'Define to the full name and version of this package.'),
999         ('#define PACKAGE_TARNAME "%s"' % package_tarname,
1000             'Define to the one symbol short name of this package.'),
1001         ('#define PACKAGE_VERSION "%s"' % package_version,
1002             'Define to the version of this package.'),
1003         ('#define BOOST_ALL_NO_LIB 1',
1004             'disable automatic linking of boost libraries.'),
1005         ('#define USE_%s_PACKAGING 1' % packaging_method.upper(),
1006             'Packaging method'),
1007         ('#define AIKSAURUS_H_LOCATION ' + aik_location,
1008             'Aiksaurus include file'),
1009         ('#define SELECT_TYPE_ARG1 %s' % select_arg1,
1010             "Define to the type of arg 1 for `select'."),
1011         ('#define SELECT_TYPE_ARG234 %s' % select_arg234,
1012             "Define to the type of arg 2, 3, 4 for `select'."),
1013         ('#define SELECT_TYPE_ARG5 %s' % select_arg5,
1014             "Define to the type of arg 5 for `select'."),
1015         ('#define SIZEOF_WCHAR_T %d' % sizeof_wchar_t,
1016             'Define to be the size of type wchar_t'),
1017     ],
1018     config_post = '''/************************************************************
1019 ** You should not need to change anything beyond this point */
1020
1021 #ifndef HAVE_STRERROR
1022 #if defined(__cplusplus)
1023 extern "C"
1024 #endif
1025 char * strerror(int n);
1026 #endif
1027
1028 #ifdef HAVE_MKSTEMP
1029 #ifndef HAVE_DECL_MKSTEMP
1030 #if defined(__cplusplus)
1031 extern "C"
1032 #endif
1033 int mkstemp(char*);
1034 #endif
1035 #endif
1036
1037 #include <../boost/config.h>
1038
1039 #endif
1040 '''
1041 )
1042
1043 # these keys are needed in env
1044 for key in ['USE_ASPELL', 'USE_PSPELL', 'USE_ISPELL', 'HAVE_FCNTL',\
1045     'HAVE_LIBGDI32', 'HAVE_LIBAIKSAURUS', 'AIKSAURUS_LIB']:
1046     # USE_ASPELL etc does not go through result
1047     if result.has_key(key):
1048         env[key] = result[key]
1049
1050 #
1051 # if nls=yes and gettext=included, create intl/config.h
1052 # intl/libintl.h etc
1053 #
1054 intl_config_h = os.path.join(env.Dir('$BUILDDIR/intl').path, 'config.h')
1055 if env['nls'] and included_gettext:
1056     #
1057     print "Creating %s..." % intl_config_h
1058     #
1059     # create intl/config.h
1060     result = utils.createConfigFile(conf,
1061         config_file = intl_config_h,
1062         config_pre = '''/* intl/config.h.  Generated by SCons.  */
1063
1064 /* -*- C++ -*- */
1065 /*
1066 * \file config.h
1067 * This file is part of LyX, the document processor.
1068 * Licence details can be found in the file COPYING.
1069 *
1070 * This is the compilation configuration file for LyX.
1071 * It was generated by scon.
1072 * You might want to change some of the defaults if something goes wrong
1073 * during the compilation.
1074 */
1075
1076 #ifndef _CONFIG_H
1077 #define _CONFIG_H
1078 ''',
1079         headers = [
1080             ('unistd.h', 'HAVE_UNISTD_H', 'c'),
1081             ('inttypes.h', 'HAVE_INTTYPES_H', 'c'),
1082             ('string.h', 'HAVE_STRING_H', 'c'),
1083             ('strings.h', 'HAVE_STRINGS_H', 'c'),
1084             ('argz.h', 'HAVE_ARGZ_H', 'c'),
1085             ('limits.h', 'HAVE_LIMITS_H', 'c'),
1086             ('alloca.h', 'HAVE_ALLOCA_H', 'c'),
1087             ('stddef.h', 'HAVE_STDDEF_H', 'c'),
1088             ('stdint.h', 'HAVE_STDINT_H', 'c'),
1089             ('sys/param.h', 'HAVE_SYS_PARAM_H', 'c'),
1090         ],
1091         functions = [
1092             ('getcwd', 'HAVE_GETCWD', None),
1093             ('stpcpy', 'HAVE_STPCPY', None),
1094             ('strcasecmp', 'HAVE_STRCASECMP', None),
1095             ('strdup', 'HAVE_STRDUP', None),
1096             ('strtoul', 'HAVE_STRTOUL', None),
1097             ('alloca', 'HAVE_ALLOCA', None),
1098             ('__fsetlocking', 'HAVE___FSETLOCKING', None),
1099             ('mempcpy', 'HAVE_MEMPCPY', None),
1100             ('__argz_count', 'HAVE___ARGZ_COUNT', None),
1101             ('__argz_next', 'HAVE___ARGZ_NEXT', None),
1102             ('__argz_stringify', 'HAVE___ARGZ_STRINGIFY', None),
1103             ('setlocale', 'HAVE_SETLOCALE', None),
1104             ('tsearch', 'HAVE_TSEARCH', None),
1105             ('getegid', 'HAVE_GETEGID', None),
1106             ('getgid', 'HAVE_GETGID', None),
1107             ('getuid', 'HAVE_GETUID', None),
1108             ('wcslen', 'HAVE_WCSLEN', None),
1109             ('asprintf', 'HAVE_ASPRINTF', None),
1110             ('wprintf', 'HAVE_WPRINTF', None),
1111             ('snprintf', 'HAVE_SNPRINTF', None),
1112             ('printf', 'HAVE_POSIX_PRINTF', None),
1113             ('fcntl', 'HAVE_FCNTL', None),
1114         ],
1115         types = [
1116             ('intmax_t', 'HAVE_INTMAX_T', None),
1117             ('long double', 'HAVE_LONG_DOUBLE', None),
1118             ('long long', 'HAVE_LONG_LONG', None),
1119             ('wchar_t', 'HAVE_WCHAR_T', None),
1120             ('wint_t', 'HAVE_WINT_T', None),
1121             ('uintmax_t', 'HAVE_INTTYPES_H_WITH_UINTMAX', '#include <inttypes.h>'),
1122             ('uintmax_t', 'HAVE_STDINT_H_WITH_UINTMAX', '#include <stdint.h>'),
1123         ],
1124         libs = [
1125             ('c', 'HAVE_LIBC'),
1126         ],
1127         custom_tests = [
1128             (conf.CheckLC_MESSAGES(),
1129                 'HAVE_LC_MESSAGES',
1130                 'Define if your <locale.h> file defines LC_MESSAGES.'
1131             ),
1132             (conf.CheckIconvConst(),
1133                 'ICONV_CONST',
1134                 'Define as const if the declaration of iconv() needs const.',
1135                 '#define ICONV_CONST const',
1136                 '#define ICONV_CONST',
1137             ),
1138             (conf.CheckType('intmax_t', includes='#include <stdint.h>') or \
1139             conf.CheckType('intmax_t', includes='#include <inttypes.h>'),
1140                 'HAVE_INTMAX_T',
1141                 "Define to 1 if you have the `intmax_t' type."
1142             ),
1143             (env.has_key('nls') and env['nls'],
1144                 'ENABLE_NLS',
1145                 "Define to 1 if translation of program messages to the user's native anguage is requested.",
1146             ),
1147         ],
1148         extra_items = [
1149             ('#define HAVE_ICONV 1', 'Define if iconv or libiconv is found'),
1150             ('#define SIZEOF_WCHAR_T %d' % sizeof_wchar_t,
1151                 'Define to be the size of type wchar_t'),
1152         ],
1153         config_post = '#endif'
1154     )
1155
1156     # these keys are needed in env
1157     for key in ['HAVE_ASPRINTF', 'HAVE_WPRINTF', 'HAVE_SNPRINTF', \
1158         'HAVE_POSIX_PRINTF', 'HAVE_LIBC']:
1159         # USE_ASPELL etc does not go through result
1160         if result.has_key(key):
1161             env[key] = result[key]
1162
1163
1164 # this looks misplaced, but intl/libintl.h is needed by src/message.C
1165 if env['nls'] and included_gettext:
1166     # libgnuintl.h.in => libintl.h
1167     env.Depends('$TOP_SRCDIR/intl/libintl.h', '$BUILDDIR/intl/config.h')
1168     env.substFile('$BUILDDIR/intl/libintl.h', '$TOP_SRCDIR/intl/libgnuintl.h.in')
1169     env.Command('$BUILDDIR/intl/libgnuintl.h', '$BUILDDIR/intl/libintl.h',
1170         [Copy('$TARGET', '$SOURCE')])
1171
1172 #
1173 # Finish auto-configuration
1174 env = conf.Finish()
1175
1176 #----------------------------------------------------------
1177 # Now set up our build process accordingly
1178 #----------------------------------------------------------
1179
1180 if env['ICONV_LIB'] is None:
1181     system_libs = []
1182 else:
1183     system_libs = [env['ICONV_LIB']]
1184 if platform_name in ['win32', 'cygwin']:
1185     # the final link step needs stdc++ to succeed under mingw
1186     # FIXME: shouldn't g++ automatically link to stdc++?
1187     if use_vc:
1188         system_libs += ['ole32', 'shlwapi', 'shell32', 'advapi32', 'zdll']
1189     else:
1190         system_libs += ['shlwapi', 'stdc++', 'z']
1191 elif platform_name == 'cygwin' and env['X11']:
1192     system_libs += ['GL',  'Xmu', 'Xi', 'Xrender', 'Xrandr',
1193         'Xcursor', 'Xft', 'freetype', 'fontconfig', 'Xext', 'X11', 'SM', 'ICE', 
1194         'resolv', 'pthread', 'z']
1195 else:
1196     system_libs += ['z']
1197
1198 libs = [
1199     ('HAVE_LIBGDI32', 'gdi32'),
1200     ('HAVE_LIBAIKSAURUS', env['AIKSAURUS_LIB']),
1201     ('USE_ASPELL', aspell_lib),
1202     ('USE_ISPELL', 'ispell'),
1203     ('USE_PSPELL', 'pspell'),
1204 ]
1205
1206 for lib in libs:
1207     if env[lib[0]]:
1208         system_libs.append(lib[1])
1209
1210 #
1211 # Build parameters CPPPATH etc
1212 #
1213 if env['X11']:
1214     env.AppendUnique(LIBPATH = ['/usr/X11R6/lib'])
1215
1216 #
1217 # boost: for boost header files
1218 # BUILDDIR/common: for config.h
1219 # TOP_SRCDIR/src: for support/* etc
1220 #
1221 env['CPPPATH'] += ['$BUILDDIR/common', '$TOP_SRCDIR/src']
1222 #
1223 # Separating boost directories from CPPPATH stops scons from building
1224 # the dependency tree for boost header files, and effectively reduce
1225 # the null build time of lyx from 29s to 16s. Since lyx may tweak local
1226 # boost headers, this is only done for system boost headers.
1227 if included_boost:
1228     env.AppendUnique(CPPPATH = ['$BOOST_INC_PATH'])
1229 else:
1230     if use_vc:
1231         env.PrependUnique(CCFLAGS = ['/I$BOOST_INC_PATH'])
1232     else:
1233         env.PrependUnique(CCFLAGS = ['-I$BOOST_INC_PATH'])
1234
1235 # for intl/config.h, intl/libintl.h and intl/libgnuintl.h
1236 if env['nls'] and included_gettext:
1237     env['CPPPATH'].append('$BUILDDIR/intl')
1238 #
1239
1240 #
1241 # A Link script for cygwin see
1242 # http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
1243 # http://www.cygwin.com/ml/cygwin-apps/2004-09/msg00309.html
1244 # for details
1245 #
1246 if platform_name == 'cygwin':
1247     ld_script_path = '/tmp'
1248     ld_script = utils.installCygwinLDScript(ld_script_path)
1249     env.AppendUnique(LINKFLAGS = ['-Wl,--enable-runtime-pseudo-reloc',
1250         '-Wl,--script,%s' % ld_script, '-Wl,-s'])
1251
1252
1253 #---------------------------------------------------------
1254 # Frontend related variables (QTDIR etc)
1255 #---------------------------------------------------------
1256
1257 #
1258 # create a separate environment so that other files do not have
1259 # to be built with all the include directories etc
1260 #
1261 if frontend == 'qt4':
1262     frontend_env = env.Copy()
1263
1264     # handle qt related user specified paths
1265     # set environment so that moc etc can be found even if its path is not set properly
1266     if frontend_env.has_key('qt_dir') and frontend_env['qt_dir']:
1267         frontend_env['QTDIR'] = frontend_env['qt_dir']
1268         if os.path.isdir(os.path.join(frontend_env['qt_dir'], 'bin')):
1269             os.environ['PATH'] += os.pathsep + os.path.join(frontend_env['qt_dir'], 'bin')
1270             frontend_env.PrependENVPath('PATH', os.path.join(frontend_env['qt_dir'], 'bin'))
1271
1272     # if separate qt_lib_path is given
1273     if frontend_env.has_key('qt_lib_path') and frontend_env['qt_lib_path']:
1274         qt_lib_path = frontend_env.subst('$qt_lib_path')
1275         frontend_env.AppendUnique(LIBPATH = [qt_lib_path])
1276         frontend_env.PrependENVPath('PKG_CONFIG_PATH', qt_lib_path)
1277     else:
1278         qt_lib_path = None
1279
1280     # if separate qt_inc_path is given
1281     if frontend_env.has_key('qt_inc_path') and frontend_env['qt_inc_path']:
1282         qt_inc_path = frontend_env['qt_inc_path']
1283     else:
1284         qt_inc_path = None
1285
1286     # local qt4 toolset from
1287     # http://www.iua.upf.es/~dgarcia/Codders/sconstools.html
1288     #
1289     # NOTE: I have to patch qt4.py since it does not automatically
1290     # process .C file!!! (add to cxx_suffixes )
1291     #
1292     frontend_env.Tool('qt4', [scons_dir])
1293     frontend_env['QT_AUTOSCAN'] = 0
1294     frontend_env['QT4_AUTOSCAN'] = 0
1295     frontend_env['QT4_UICDECLFLAGS'] = '-tr lyx::qt_'
1296
1297     if qt_lib_path is None:
1298         qt_lib_path = os.path.join(frontend_env.subst('$QTDIR'), 'lib')
1299     if qt_inc_path is None:
1300         qt_inc_path = os.path.join(frontend_env.subst('$QTDIR'), 'include')
1301
1302
1303     conf = Configure(frontend_env,
1304         custom_tests = { 
1305             'CheckPackage' : utils.checkPackage,
1306             'CheckCommand' : utils.checkCommand,
1307         }
1308     )
1309
1310     succ = False
1311     # first: try pkg_config
1312     if frontend_env['HAS_PKG_CONFIG']:
1313         succ = conf.CheckPackage('QtCore') or conf.CheckPackage('QtCore4')
1314         # FIXME: use pkg_config information?
1315         #frontend_env['QT4_PKG_CONFIG'] = succ
1316     # second: try to link to it
1317     if not succ:
1318         # Under linux, I can test the following perfectly
1319         # Under windows, lib names need to passed as libXXX4.a ...
1320         if platform_name == 'win32' and use_vc:
1321             succ = conf.CheckLibWithHeader('QtCore4', 'QtGui/QApplication', 'c++', 'QApplication qapp();')
1322         else:
1323             succ = conf.CheckLibWithHeader('QtCore', 'QtGui/QApplication', 'c++', 'QApplication qapp();')
1324     # still can not find it
1325     if not succ:
1326         print 'Did not find qt libraries, exiting!'
1327         Exit(1)
1328     #
1329     # Now, determine the correct suffix:
1330     qt_libs = ['QtCore', 'QtGui']
1331     if platform_name == 'win32':
1332         if mode == 'debug' and use_vc and \
1333             conf.CheckLibWithHeader('QtCored4', 'QtGui/QApplication', 'c++', 'QApplication qapp();'):
1334             qt_lib_suffix = 'd4'
1335             use_qt_debug_libs = True
1336         else:
1337             qt_lib_suffix = '4'
1338             use_qt_debug_libs = False
1339     else:
1340         if mode == 'debug' and conf.CheckLibWithHeader('QtCore_debug', 'QtGui/QApplication', 'c++', 'QApplication qapp();'):
1341             qt_lib_suffix = '_debug'
1342             use_qt_debug_libs = True
1343         else:
1344             qt_lib_suffix = ''
1345             use_qt_debug_libs = False
1346     frontend_env.EnableQt4Modules(qt_libs, debug = (mode == 'debug' and use_qt_debug_libs))
1347     frontend_libs = [x + qt_lib_suffix for x in qt_libs]
1348     qtcore_lib = ['QtCore' + qt_lib_suffix]
1349
1350     # check uic and moc commands for qt frontends
1351     if conf.CheckCommand('uic') == None or conf.CheckCommand('moc') == None:
1352         print 'uic or moc command is not found for frontend', frontend
1353         Exit(1)
1354     
1355     # now, if msvc2005 is used, we will need that QT_LIB_PATH/QT_LIB.manifest file
1356     if use_vc:
1357         if mode == 'debug':
1358             if qt_lib_path is not None:
1359                 manifest = os.path.join(qt_lib_path, 'QtGuid4.dll.manifest')
1360             else:
1361                 manifest = 'QtGuid4.dll.manifest'
1362         else:
1363             if qt_lib_path is not None:
1364                 manifest = os.path.join(qt_lib_path, 'QtGui4.dll.manifest')
1365             else:
1366                 manifest = 'QtGui4.dll.manifest'
1367         if os.path.isfile(manifest):
1368             env['LINKCOM'] = [env['LINKCOM'], 'mt.exe /MANIFEST %s /outputresource:$TARGET;1' % manifest]
1369
1370     frontend_env = conf.Finish()
1371
1372
1373 #
1374 # Report results
1375 #
1376 # fill in the version info
1377 env['VERSION_INFO'] = '''Configuration
1378   Host type:                      %s
1379   Special build flags:            %s
1380   C   Compiler:                   %s
1381   C   Compiler flags:             %s %s
1382   C++ Compiler:                   %s
1383   C++ Compiler LyX flags:         %s
1384   C++ Compiler flags:             %s %s
1385   Linker flags:                   %s
1386   Linker user flags:              %s
1387 Build info:
1388   Builing directory:              %s
1389   Local library directory:        %s
1390   Libraries paths:                %s
1391   Boost libraries:                %s
1392   Frontend libraries:             %s
1393   System libraries:               %s
1394   include search path:            %s
1395 Frontend:
1396   Frontend:                       %s
1397   Packaging:                      %s
1398   LyX dir:                        %s
1399   LyX files dir:                  %s
1400 ''' % (platform_name,
1401     env.subst('$CCFLAGS'), env.subst('$CC'),
1402     env.subst('$CPPFLAGS'), env.subst('$CFLAGS'),
1403     env.subst('$CXX'), env.subst('$CXXFLAGS'),
1404     env.subst('$CPPFLAGS'), env.subst('$CXXFLAGS'),
1405     env.subst('$LINKFLAGS'), env.subst('$LINKFLAGS'),
1406     env.subst('$BUILDDIR'), env.subst('$LOCALLIBPATH'),
1407     str(env['LIBPATH']), str(boost_libraries),
1408     str(frontend_libs), str(system_libs), str(env['CPPPATH']),
1409     frontend, packaging_method,
1410     prefix, env['LYX_DIR'])
1411
1412 if frontend in ['qt4']:
1413     env['VERSION_INFO'] += '''  include dir:                    %s
1414   library dir:                    %s
1415   X11:                            %s
1416 ''' % (qt_inc_path, qt_lib_path, env['X11'])
1417
1418 print env['VERSION_INFO']
1419
1420 #
1421 # Mingw command line may be too short for our link usage,
1422 # Here we use a trick from scons wiki
1423 # http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/LongCmdLinesOnWin32
1424 #
1425 # I also would like to add logging (commands only) capacity to the
1426 # spawn system.
1427 logfile = env.get('logfile', default_log_file)
1428 if logfile != '' or platform_name == 'win32':
1429     import time
1430     utils.setLoggedSpawn(env, logfile, longarg = (platform_name == 'win32'),
1431         info = '''# This is a log of commands used by scons to build lyx
1432 # Time: %s
1433 # Command: %s
1434 # Info: %s
1435 ''' % (time.asctime(), ' '.join(sys.argv),
1436     env['VERSION_INFO'].replace('\n','\n# ')) )
1437
1438
1439 # Cleanup stuff
1440 #
1441 # -h will print out help info
1442 Help(opts.GenerateHelpText(env))
1443
1444
1445
1446 #----------------------------------------------------------
1447 # Start building
1448 #----------------------------------------------------------
1449 # this has been the source of problems on some platforms...
1450 # I find that I need to supply it with full path name
1451 env.SConsignFile(os.path.join(Dir(env['BUILDDIR']).abspath, '.sconsign'))
1452 # this usage needs further investigation.
1453 #env.CacheDir('%s/Cache/%s' % (env['BUILDDIR'], frontend))
1454
1455 print "Building all targets recursively"
1456
1457 if env.has_key('rebuild'):
1458     rebuild_targets = env['rebuild'].split(',')
1459     if 'none' in rebuild_targets or 'no' in rebuild_targets:
1460         rebuild_targets = []
1461     elif 'all' in rebuild_targets or 'yes' in rebuild_targets:
1462         # None: let scons decide which components to build
1463         # Forcing all components to be rebuilt is in theory not necessary
1464         rebuild_targets = None    
1465 else:
1466     rebuild_targets = None
1467
1468 def libExists(libname):
1469     ''' Check whether or not lib $LOCALLIBNAME/libname already exists'''
1470     return os.path.isfile(File(env.subst('$LOCALLIBPATH/${LIBPREFIX}%s$LIBSUFFIX'%libname)).abspath)
1471
1472 def appExists(apppath, appname):
1473     ''' Check whether or not application already exists'''
1474     return os.path.isfile(File(env.subst('$BUILDDIR/common/%s/${PROGPREFIX}%s$PROGSUFFIX' % (apppath, appname))).abspath)
1475
1476 targets = BUILD_TARGETS
1477 # msvc need to pass full target name, so I have to look for path/lyx etc
1478 build_lyx = targets == [] or True in ['lyx' in x for x in targets] \
1479     or 'install' in targets or 'all' in targets
1480 build_boost = (included_boost and not libExists('boost_regex')) or 'boost' in targets
1481 build_intl = (included_gettext and not libExists('included_intl')) or 'intl' in targets
1482 build_support = build_lyx or True in [x in targets for x in ['support', 'client', 'tex2lyx']]
1483 build_mathed = build_lyx or 'mathed' in targets
1484 build_insets = build_lyx or 'insets' in targets
1485 build_frontends = build_lyx or 'frontends' in targets
1486 build_graphics = build_lyx or 'graphics' in targets
1487 build_controllers = build_lyx or 'controllers' in targets
1488 build_client = True in ['client' in x for x in targets] \
1489     or 'install' in targets or 'all' in targets
1490 build_tex2lyx = True in ['tex2lyx' in x for x in targets] \
1491     or 'install' in targets or 'all' in targets
1492 build_lyxbase = build_lyx or 'lyxbase' in targets
1493 build_po = 'po' in targets or 'install' in targets or 'all' in targets
1494 build_qt4 = (build_lyx and frontend == 'qt4') or 'qt4' in targets
1495 build_msvs_projects = use_vc and 'msvs_projects' in targets
1496
1497
1498 # now, if rebuild_targets is specified, do not rebuild some targets
1499 if rebuild_targets is not None:
1500     #
1501     def ifBuildLib(name, libname, old_value):
1502         # explicitly asked to rebuild
1503         if name in rebuild_targets:
1504             return True
1505         # else if not rebuild, and if the library already exists
1506         elif libExists(libname):
1507             return False
1508         # do not change the original value
1509         else:
1510             return old_value
1511     build_boost = ifBuildLib('boost', 'included_boost_filesystem', build_boost)
1512     build_intl = ifBuildLib('intl', 'included_intl', build_intl)
1513     build_support = ifBuildLib('support', 'support', build_support)
1514     build_mathed = ifBuildLib('mathed', 'mathed', build_mathed)
1515     build_insets = ifBuildLib('insets', 'insets', build_insets)
1516     build_frontends = ifBuildLib('frontends', 'frontends', build_frontends)
1517     build_graphics = ifBuildLib('graphics', 'graphics', build_graphics)
1518     build_controllers = ifBuildLib('controllers', 'controllers', build_controllers)
1519     build_lyxbase = ifBuildLib('lyxbase', 'lyxbase_pre', build_lyxbase)
1520     build_qt4 = ifBuildLib('qt4', 'qt4', build_qt4)
1521     #
1522     def ifBuildApp(name, appname, old_value):
1523         # explicitly asked to rebuild
1524         if name in rebuild_targets:
1525             return True
1526         # else if not rebuild, and if the library already exists
1527         elif appExists(name, appname):
1528             return False
1529         # do not change the original value
1530         else:
1531             return old_value
1532     build_tex2lyx = ifBuildApp('tex2lyx', 'tex2lyx', build_tex2lyx)
1533     build_client = ifBuildApp('client', 'lyxclient', build_client)
1534
1535 # sync frontend and frontend (?)
1536 if build_qt4:
1537     frontend = 'qt4'
1538
1539
1540 if build_boost:
1541     #
1542     # boost libraries
1543     #
1544     # special builddir
1545     env.BuildDir('$BUILDDIR/boost', '$TOP_SRCDIR/boost/libs', duplicate = 0)
1546
1547     boostenv = env.Copy()
1548     #
1549     # boost use its own config.h
1550     boostenv['CPPPATH'] = ['$TOP_SRCDIR/boost', '$BUILDDIR/boost'] + extra_inc_paths
1551     boostenv.AppendUnique(CCFLAGS = ['-DBOOST_USER_CONFIG="<config.h>"'])
1552
1553     for lib in boost_libs:
1554         print 'Processing files in boost/libs/%s/src...' % lib
1555         boostlib = boostenv.StaticLibrary(
1556             target = '$LOCALLIBPATH/included_boost_%s' % lib,
1557             source = ['$BUILDDIR/boost/%s/src/%s' % (lib, x) for x in eval('boost_libs_%s_src_files' % lib)]
1558         )
1559         Alias('boost', boostlib)
1560
1561
1562 if build_intl:
1563     #
1564     # intl
1565     #
1566     intlenv = env.Copy()
1567
1568     print "Processing files in intl..."
1569
1570     env.BuildDir('$BUILDDIR/intl', '$TOP_SRCDIR/intl', duplicate = 0)
1571
1572     # we need the original C compiler for these files
1573     intlenv['CC'] = C_COMPILER
1574     intlenv['CCFLAGS'] = C_CCFLAGS
1575     if use_vc:
1576         intlenv.Append(CCFLAGS=['/Dinline#', '/D__attribute__(x)#', '/Duintmax_t=UINT_MAX'])
1577     # intl does not use global config.h
1578     intlenv['CPPPATH'] = ['$BUILDDIR/intl'] + extra_inc_paths
1579
1580     intlenv.Append(CCFLAGS = [
1581         r'-DLOCALEDIR=\"' + env['LOCALEDIR'].replace('\\', '\\\\') + r'\"',
1582         r'-DLOCALE_ALIAS_PATH=\"' + env['LOCALEDIR'].replace('\\', '\\\\') + r'\"',
1583         r'-DLIBDIR=\"' + env['TOP_SRCDIR'].replace('\\', '\\\\') + r'/lib\"',
1584         '-DIN_LIBINTL',
1585         '-DENABLE_RELOCATABLE=1',
1586         '-DIN_LIBRARY',
1587         r'-DINSTALLDIR=\"' + prefix.replace('\\', '\\\\') + r'/lib\"',
1588         '-DNO_XMALLOC',
1589         '-Dset_relocation_prefix=libintl_set_relocation_prefix',
1590         '-Drelocate=libintl_relocate',
1591         '-DDEPENDS_ON_LIBICONV=1',
1592         '-DHAVE_CONFIG_H'
1593         ]
1594     )
1595
1596     intl = intlenv.StaticLibrary(
1597         target = '$LOCALLIBPATH/included_intl',
1598         LIBS = ['c'],
1599         source = ['$BUILDDIR/intl/%s' % x for x in intl_files]
1600     )
1601     Alias('intl', intl)
1602
1603
1604 #
1605 # Now, src code under src/
1606 #
1607 env.BuildDir('$BUILDDIR/common', '$TOP_SRCDIR/src', duplicate = 0)
1608
1609
1610 if build_support:
1611     #
1612     # src/support
1613     #
1614     print "Processing files in src/support..."
1615
1616     frontend_env.Depends('$BUILDDIR/common/support/package.C', '$BUILDDIR/common/config.h')
1617     env.substFile('$BUILDDIR/common/support/package.C', '$TOP_SRCDIR/src/support/package.C.in')
1618
1619     support = frontend_env.StaticLibrary(
1620         target = '$LOCALLIBPATH/support',
1621         source = ['$BUILDDIR/common/support/%s' % x for x in src_support_files],
1622     )
1623     Alias('support', support)
1624
1625
1626 if build_mathed:
1627     #
1628     # src/mathed
1629     #
1630     print "Processing files in src/mathed..."
1631     #
1632     mathed = env.StaticLibrary(
1633         target = '$LOCALLIBPATH/mathed',
1634         source = ['$BUILDDIR/common/mathed/%s' % x for x in src_mathed_files]
1635     )
1636     Alias('mathed', mathed)
1637
1638
1639 if build_insets:
1640     #
1641     # src/insets
1642     #
1643     print "Processing files in src/insets..."
1644     #
1645     insets = env.StaticLibrary(
1646         target = '$LOCALLIBPATH/insets',
1647         source = ['$BUILDDIR/common/insets/%s' % x for x in src_insets_files]
1648     )
1649     Alias('insets', insets)
1650
1651
1652 if build_frontends:
1653     #
1654     # src/frontends
1655     #
1656     print "Processing files in src/frontends..."
1657
1658     frontends = env.StaticLibrary(
1659         target = '$LOCALLIBPATH/frontends',
1660         source = ['$BUILDDIR/common/frontends/%s' % x for x in src_frontends_files]
1661     )
1662     Alias('frontends', frontends)
1663
1664
1665 if build_graphics:
1666     #
1667     # src/graphics
1668     #
1669     print "Processing files in src/graphics..."
1670
1671     graphics = env.StaticLibrary(
1672         target = '$LOCALLIBPATH/graphics',
1673         source = ['$BUILDDIR/common/graphics/%s' % x for x in src_graphics_files]
1674     )
1675     Alias('graphics', graphics)
1676
1677
1678 if build_controllers:
1679     #
1680     # src/frontends/controllers
1681     #
1682     print "Processing files in src/frontends/controllers..."
1683
1684     controllers = env.StaticLibrary(
1685         target = '$LOCALLIBPATH/controllers',
1686         source = ['$BUILDDIR/common/frontends/controllers/%s' % x for x in src_frontends_controllers_files]
1687     )
1688     Alias('controllers', controllers)
1689
1690
1691 #
1692 # src/frontend/qt4
1693 #
1694 if build_qt4:
1695     env.BuildDir('$BUILDDIR/$frontend', '$TOP_SRCDIR/src/frontend/$frontend', duplicate = 0)
1696
1697     print "Processing files in src/frontends/qt4..."
1698
1699     qt4_moc_files = ["$BUILDDIR/common/frontends/qt4/%s" % x for x in src_frontends_qt4_moc_files]
1700
1701     #
1702     # Compile resources
1703     #
1704     resources = [frontend_env.Uic4(x.split('.')[0]) for x in \
1705         ["$BUILDDIR/common/frontends/qt4/ui/%s" % x for x in src_frontends_qt4_ui_files]]
1706
1707     #
1708     # moc qt4_moc_files, the moced files are included in the original files
1709     #
1710     qt4_moced_files = [frontend_env.Moc4(x.replace('.C', '_moc.cpp'), x.replace('.C', '.h')) for x in qt4_moc_files]
1711
1712     qt4 = frontend_env.StaticLibrary(
1713         target = '$LOCALLIBPATH/qt4',
1714         source = ['$BUILDDIR/common/frontends/qt4/%s' % x for x in src_frontends_qt4_files],
1715         CPPPATH = [
1716             '$CPPPATH',
1717             '$BUILDDIR/common',
1718             '$BUILDDIR/common/images',
1719             '$BUILDDIR/common/frontends',
1720             '$BUILDDIR/common/frontends/qt4',
1721             '$BUILDDIR/common/frontends/controllers'
1722         ],
1723         CCFLAGS =  [
1724             '-DHAVE_CONFIG_H',
1725             '-DQT_CLEAN_NAMESPACE',
1726             '-DQT_GENUINE_STR',
1727             '-DQT_NO_STL',
1728             '-DQT_NO_KEYWORDS',
1729         ]
1730     )
1731     Alias('qt4', qt4)
1732
1733
1734 if build_client:
1735     #
1736     # src/client
1737     #
1738     frontend_env.BuildDir('$BUILDDIR/common', '$TOP_SRCDIR/src', duplicate = 0)
1739
1740     print "Processing files in src/client..."
1741
1742     if env['HAVE_FCNTL']:
1743         client = frontend_env.Program(
1744             target = '$BUILDDIR/common/client/lyxclient',
1745             LIBS = ['support'] + intl_libs + system_libs +
1746                 socket_libs + boost_libraries + qtcore_lib,
1747             source = ['$BUILDDIR/common/client/%s' % x for x in src_client_files]
1748         )
1749         Alias('client', frontend_env.Command(os.path.join('$BUILDDIR', os.path.split(str(client[0]))[1]),
1750             client, [Copy('$TARGET', '$SOURCE')]))
1751     else:
1752         client = None
1753     Alias('client', client)
1754 else:
1755     if env['HAVE_FCNTL']:
1756         # define client even if lyxclient is not built with rebuild=no
1757         client = [env.subst('$BUILDDIR/common/client/${PROGPREFIX}lyxclient$PROGSUFFIX')]
1758     else:
1759         client = None
1760
1761
1762 if build_tex2lyx:
1763     #
1764     # tex2lyx
1765     #
1766     print "Processing files in src/tex2lyx..."
1767
1768     #
1769     for file in ['FloatList.C', 'Floating.C', 'counters.C', 'lyxlayout.h', 'lyxlayout.C', 
1770         'lyxtextclass.h', 'lyxtextclass.C', 'lyxlex.C', 'lyxlex_pimpl.C']:
1771         frontend_env.Command('$BUILDDIR/common/tex2lyx/'+file, '$TOP_SRCDIR/src/'+file,
1772             [Copy('$TARGET', '$SOURCE')])
1773
1774     tex2lyx = frontend_env.Program(
1775         target = '$BUILDDIR/common/tex2lyx/tex2lyx',
1776         LIBS = ['support'] + boost_libraries + intl_libs + system_libs + qtcore_lib,
1777         source = ['$BUILDDIR/common/tex2lyx/%s' % x for x in src_tex2lyx_files],
1778         CPPPATH = ['$BUILDDIR/common/tex2lyx', '$CPPPATH'],
1779         LIBPATH = ['#$LOCALLIBPATH', '$LIBPATH'],
1780     )
1781     Alias('tex2lyx', frontend_env.Command(os.path.join('$BUILDDIR', os.path.split(str(tex2lyx[0]))[1]),
1782         tex2lyx, [Copy('$TARGET', '$SOURCE')]))
1783     Alias('tex2lyx', tex2lyx)
1784 else:
1785     # define tex2lyx even if tex2lyx is not built with rebuild=no
1786     tex2lyx = [frontend_env.subst('$BUILDDIR/common/tex2lyx/${PROGPREFIX}tex2lyx$PROGSUFFIX')]
1787
1788
1789 if build_lyxbase:
1790     #
1791     # src/
1792     #
1793     print "Processing files in src..."
1794
1795     env.Depends('$BUILDDIR/common/version.C', '$BUILDDIR/common/config.h')
1796     env.substFile('$BUILDDIR/common/version.C', '$TOP_SRCDIR/src/version.C.in')
1797
1798     if env.has_key('USE_ASPELL') and env['USE_ASPELL']:
1799         src_post_files.append('aspell.C')
1800     elif env.has_key('USE_PSPELL') and env['USE_PSPELL']:
1801         src_post_files.append('pspell.C')
1802     elif env.has_key('USE_ISPELL') and env['USE_ISPELL']:
1803         src_post_files.append('ispell.C')
1804
1805     # msvc requires at least one source file with main()
1806     # so I exclude main.C from lyxbase
1807     lyxbase_pre = env.StaticLibrary(
1808         target = '$LOCALLIBPATH/lyxbase_pre',
1809         source = ['$BUILDDIR/common/%s' % x for x in src_pre_files]
1810     )
1811     lyxbase_post = env.StaticLibrary(
1812         target = '$LOCALLIBPATH/lyxbase_post',
1813         source = ["$BUILDDIR/common/%s" % x for x in src_post_files]
1814     )
1815     Alias('lyxbase', lyxbase_pre)
1816     Alias('lyxbase', lyxbase_post)
1817
1818
1819 if build_lyx:
1820     #
1821     # Build lyx with given frontend
1822     #
1823     lyx = frontend_env.Program(
1824         target = '$BUILDDIR/lyx',
1825         source = ['$BUILDDIR/common/main.C'],
1826         LIBS = [
1827             'lyxbase_pre',
1828             'mathed',
1829             'insets',
1830             'frontends',
1831             frontend,
1832             'controllers',
1833             'graphics',
1834             'support',
1835             'lyxbase_post',
1836             ] +
1837             boost_libraries +
1838             frontend_libs +
1839             intl_libs +
1840             socket_libs +
1841             system_libs
1842     )
1843     Alias('lyx', lyx)
1844 else:
1845     # define lyx even if lyx is not built with rebuild=no
1846     lyx = [frontend_env.subst('$BUILDDIR/${PROGPREFIX}lyx$PROGSUFFIX')]
1847
1848
1849 if build_msvs_projects:
1850     def build_project(target, full_target = None,
1851         src = [], inc = [], res = [], rebuildTargetOnly = True):
1852         ''' build mavs project files
1853             target:      alias (correspond to directory name)
1854             full_target: full path/filename of the target
1855             src:         source files
1856             inc:         include files
1857             res:         resource files
1858             rebuildTargetOnly:     whether or not only rebuild this target
1859
1860         For non-debug-able targets like static libraries, target (alias) is
1861         enough to build the target. For executable targets, msvs need to know
1862         the full path to start debug them.
1863         '''
1864         if rebuildTargetOnly:
1865             cmds = 'rebuild='+target
1866         else:
1867             cmds = ''
1868         if full_target is None:
1869             build_target = target
1870         else:
1871             build_target = full_target
1872         # project
1873         proj = env.MSVSProject(
1874             target = target + env['MSVSPROJECTSUFFIX'],
1875             # this allows easy access to header files (along with source)
1876             srcs = [env.subst(x) for x in src + inc],
1877             incs = [env.subst('$TOP_SRCDIR/src/config.h')],
1878             localincs = [env.subst(x) for x in inc],
1879             resources = [env.subst(x) for x in res],
1880             buildtarget = build_target,
1881             cmdargs = cmds,
1882             variant = 'Debug'
1883         )
1884         Alias('msvs_projects', proj)
1885     #
1886     boost_src = []
1887     for lib in boost_libs:
1888         boost_src += ['$TOP_SRCDIR/boost/libs/%s/src/%s' % (lib, x) for x in eval('boost_libs_%s_src_files' % lib)]
1889     build_project('boost', src = boost_src)
1890     #
1891     build_project('intl', src = ['$TOP_SRCDIR/intl/%s' % x for x in intl_files], 
1892         inc = ['$TOP_SRCDIR/intl/%s' % x for x in intl_header_files])
1893     #
1894     build_project('support', src = ['$TOP_SRCDIR/src/support/%s' % x for x in src_support_files], 
1895         inc = ['$TOP_SRCDIR/src/support/%s' % x for x in src_support_header_files])
1896     #
1897     build_project('mathed', src = ['$TOP_SRCDIR/src/support/%s' % x for x in src_support_files], 
1898         inc = ['$TOP_SRCDIR/src/support/%s' % x for x in src_support_header_files])
1899     #
1900     build_project('insets', src = ['$TOP_SRCDIR/src/insets/%s' % x for x in src_insets_files], 
1901         inc = ['$TOP_SRCDIR/src/insets/%s' % x for x in src_insets_header_files])
1902     #
1903     build_project('frontends', src = ['$TOP_SRCDIR/src/frontends/%s' % x for x in src_frontends_files], 
1904         inc = ['$TOP_SRCDIR/src/frontends/%s' % x for x in src_frontends_header_files])
1905     #
1906     build_project('graphics', src = ['$TOP_SRCDIR/src/graphics/%s' % x for x in src_graphics_files], 
1907         inc = ['$TOP_SRCDIR/src/graphics/%s' % x for x in src_graphics_header_files])
1908     #
1909     build_project('controllers', src = ['$TOP_SRCDIR/src/frontends/controllers/%s' % x for x in src_frontends_controllers_files], 
1910         inc = ['$TOP_SRCDIR/src/frontends/controllers/%s' % x for x in src_frontends_controllers_header_files])
1911     #
1912     build_project('qt4', src = ['$TOP_SRCDIR/src/frontends/qt4/%s' % x for x in src_frontends_qt4_files + src_frontends_qt4_moc_files],
1913         inc = ['$TOP_SRCDIR/src/frontends/qt4/%s' % x for x in src_frontends_qt4_header_files],
1914         res = ['$TOP_SRCDIR/src/frontends/qt4/ui/%s' % x for x in src_frontends_qt4_ui_files])
1915     #
1916     build_project('client', src = ['$TOP_SRCDIR/src/client/%s' % x for x in src_client_files],
1917         inc = ['$TOP_SRCDIR/src/client/%s' % x for x in src_client_header_files],
1918         rebuildTargetOnly = False,
1919         full_target = File(env.subst('$BUILDDIR/common/client/lyxclient$PROGSUFFIX')).abspath)
1920     #
1921     build_project('tex2lyx', src = ['$TOP_SRCDIR/src/tex2lyx/%s' % x for x in src_tex2lyx_files],
1922         inc = ['$TOP_SRCDIR/src/tex2lyx/%s' % x for x in src_tex2lyx_header_files],
1923         rebuildTargetOnly = False,
1924         full_target = File(env.subst('$BUILDDIR/common/tex2lyx/tex2lyx$PROGSUFFIX')).abspath)
1925     #
1926     build_project('lyxbase', src = ['$TOP_SRCDIR/src/%s' % x for x in src_pre_files + src_post_files],
1927         inc = ['$TOP_SRCDIR/src/%s' % x for x in src_header_files])
1928     build_project('lyx', 
1929         src = ['$TOP_SRCDIR/src/%s' % x for x in src_pre_files + src_post_files] + \
1930             ['$TOP_SRCDIR/src/support/%s' % x for x in src_support_files] + \
1931             ['$TOP_SRCDIR/src/mathed/%s' % x for x in src_mathed_files] + \
1932             ['$TOP_SRCDIR/src/insets/%s' % x for x in src_insets_files] + \
1933             ['$TOP_SRCDIR/src/frontends/%s' % x for x in src_frontends_files] + \
1934             ['$TOP_SRCDIR/src/graphics/%s' % x for x in src_graphics_files] + \
1935             ['$TOP_SRCDIR/src/frontends/controllers/%s' % x for x in src_frontends_controllers_files] + \
1936             ['$TOP_SRCDIR/src/frontends/qt4/%s' % x for x in src_frontends_qt4_files + src_frontends_qt4_moc_files],
1937         inc = ['$TOP_SRCDIR/src/%s' % x for x in src_header_files] + \
1938             ['$TOP_SRCDIR/src/support/%s' % x for x in src_support_header_files] + \
1939             ['$TOP_SRCDIR/src/mathed/%s' % x for x in src_mathed_header_files] + \
1940             ['$TOP_SRCDIR/src/insets/%s' % x for x in src_insets_header_files] + \
1941             ['$TOP_SRCDIR/src/frontends/%s' % x for x in src_frontends_header_files] + \
1942             ['$TOP_SRCDIR/src/graphics/%s' % x for x in src_graphics_header_files] + \
1943             ['$TOP_SRCDIR/src/frontends/controllers/%s' % x for x in src_frontends_controllers_header_files] + \
1944             ['$TOP_SRCDIR/src/frontends/qt4/%s' % x for x in src_frontends_qt4_header_files],
1945         res = ['$TOP_SRCDIR/src/frontends/qt4/ui/%s' % x for x in src_frontends_qt4_ui_files],
1946         rebuildTargetOnly = False,
1947         full_target = File(env.subst('$BUILDDIR/lyx$PROGSUFFIX')).abspath)
1948
1949
1950 if build_po:
1951     #
1952     # po/
1953     #
1954     print 'Processing files in po...'
1955
1956     import glob
1957     # handle po files
1958     #
1959     # files to translate
1960     transfiles = glob.glob(os.path.join(env.subst('$TOP_SRCDIR'), 'po', '*.po'))
1961     # possibly *only* handle these languages
1962     languages = None
1963     if env.has_key('languages'):
1964         languages = env.make_list(env['lanauges'])
1965     # use defulat msgfmt
1966     gmo_files = []
1967     if not env['MSGFMT']:
1968         print 'msgfmt does not exist. Can not process po files'
1969     else:
1970         # create a builder
1971         env['BUILDERS']['Transfiles'] = Builder(action='$MSGFMT $SOURCE -o $TARGET',suffix='.gmo',src_suffix='.po')
1972         #
1973         for f in transfiles:
1974             # get filename
1975             fname = os.path.split(f)[1]
1976             # country code
1977             country = fname.split('.')[0]
1978             #
1979             if not languages or country in languages:
1980                 gmo_files.extend(env.Transfiles(f))
1981
1982
1983 if 'install' in targets:
1984     #
1985     # this part is a bit messy right now. Since scons will provide
1986     # --DESTDIR option soon, at least the dest_dir handling can be 
1987     # removed later.
1988     #
1989     # how to join dest_dir and prefix
1990     def joinPaths(path1, path2):
1991         ''' join path1 and path2, do not use os.path.join because
1992             under window, c:\destdir\d:\program is invalid '''
1993         if path1 == '':
1994             return os.path.normpath(path2)
1995         # separate drive letter
1996         (drive, path) = os.path.splitdrive(os.path.normpath(path2))
1997         # ignore drive letter, so c:\destdir + c:\program = c:\destdir\program
1998         return os.path.join(os.path.normpath(path1), path[1:])
1999     #
2000     # install to dest_dir/prefix
2001     dest_dir = env.get('DESTDIR', '')
2002     dest_prefix_dir = joinPaths(dest_dir, env.Dir(prefix).abspath)
2003     # create the directory if needed
2004     if not os.path.isdir(dest_prefix_dir):
2005         try:
2006             os.makedirs(dest_prefix_dir)
2007         except:
2008             pass
2009         if not os.path.isdir(dest_prefix_dir):
2010             print 'Can not create directory', dest_prefix_dir
2011             Exit(3)
2012     #
2013     if env.has_key('exec_prefix'):
2014         bin_dest_dir = joinPaths(dest_dir, Dir(env['exec_prefix']).abspath)
2015     else:
2016         bin_dest_dir = os.path.join(dest_prefix_dir, 'bin')
2017     if add_suffix:
2018         share_dest_dir = os.path.join(dest_prefix_dir, share_dir + program_suffix)
2019     else:
2020         share_dest_dir = os.path.join(dest_prefix_dir, share_dir)
2021     man_dest_dir = os.path.join(dest_prefix_dir, man_dir)
2022     locale_dest_dir = os.path.join(dest_prefix_dir, locale_dir)
2023     #
2024     import glob
2025     #
2026     # install executables (lyxclient may be None)
2027     #
2028     if add_suffix:
2029         version_suffix = program_suffix
2030     else:
2031         version_suffix = ''
2032     #
2033     # install lyx, if in release mode, try to strip the binary
2034     if env.has_key('STRIP') and env['STRIP'] is not None and mode != 'debug':
2035         # create a builder to strip and install
2036         env['BUILDERS']['StripInstallAs'] = Builder(action='$STRIP $SOURCE -o $TARGET')
2037
2038     # install executables
2039     for (name, obj) in (('lyx', lyx), ('tex2lyx', tex2lyx), ('client', client)):
2040         if obj is None:
2041             continue
2042         target_name = os.path.split(str(obj[0]))[1].replace(name, '%s%s' % (name, version_suffix))
2043         target = os.path.join(bin_dest_dir, target_name)
2044         if env['BUILDERS'].has_key('StripInstallAs'):
2045             env.StripInstallAs(target, obj)
2046         else:
2047             env.InstallAs(target, obj)
2048         Alias('install', target)
2049
2050     # share/lyx
2051     dirs = []
2052     for (dir,files) in [
2053             ('.', lib_files),  
2054             ('clipart', lib_clipart_files),
2055             ('examples', lib_examples_files),
2056             ('images', lib_images_files),
2057             ('images/math', lib_images_math_files),
2058             ('bind', lib_bind_files),
2059             ('kbd', lib_kbd_files),
2060             ('layouts', lib_layouts_files),
2061             ('scripts', lib_scripts_files),
2062             ('templates', lib_templates_files),
2063             ('tex', lib_tex_files),
2064             ('ui', lib_ui_files),
2065             ('doc', lib_doc_files),
2066             ('lyx2lyx', lib_lyx2lyx_files)]:
2067         dirs.append(env.Install(os.path.join(share_dest_dir, dir),
2068             [env.subst('$TOP_SRCDIR/lib/%s/%s' % (dir, file)) for file in files]))
2069     Alias('install', dirs)
2070     
2071     if platform_name == 'cygwin':
2072         # cygwin packaging requires a file /usr/share/doc/Cygwin/foot-vendor-suffix.README
2073         Cygwin_README = os.path.join(dest_prefix_dir, 'share', 'doc', 'Cygwin', 
2074             '%s-%s.README' % (package, package_cygwin_version))
2075         env.InstallAs(Cygwin_README,
2076             os.path.join(env.subst('$TOP_SRCDIR'), 'README.cygwin'))
2077         Alias('install', Cygwin_README)
2078         # also a directory /usr/share/doc/lyx for README etc
2079         Cygwin_Doc = os.path.join(dest_prefix_dir, 'share', 'doc', package)
2080         env.Install(Cygwin_Doc, [os.path.join(env.subst('$TOP_SRCDIR'), x) for x in \
2081             ['INSTALL', 'README', 'README.Cygwin', 'RELEASE-NOTES', 'COPYING', 'ANNOUNCE']])
2082         Alias('install', Cygwin_Doc)
2083         # cygwin fonts also need to be installed
2084         Cygwin_fonts = os.path.join(share_dest_dir, 'fonts')
2085         env.Install(Cygwin_fonts, 
2086             [env.subst('$TOP_SRCDIR/development/Win32/packaging/bakoma/%s' % file) \
2087                   for file in win32_bakoma_fonts])
2088         Alias('install', Cygwin_fonts)
2089         # we also need a post installation script
2090         tmp_script = utils.installCygwinPostinstallScript('/tmp')
2091         postinstall_path = os.path.join(dest_dir, 'etc', 'postinstall')
2092         env.Install(postinstall_path, tmp_script)
2093         Alias('install', postinstall_path)
2094
2095     # subst and install lyx2lyx_version.py which is not in scons_manifest.py
2096     env.Depends(share_dest_dir + '/lyx2lyx/lyx2lyx_version.py', '$BUILDDIR/common/config.h')
2097     env.substFile(share_dest_dir + '/lyx2lyx/lyx2lyx_version.py',
2098         '$TOP_SRCDIR/lib/lyx2lyx/lyx2lyx_version.py.in')
2099     Alias('install', share_dest_dir + '/lyx2lyx/lyx2lyx_version.py')
2100
2101     # man
2102     env.InstallAs(os.path.join(man_dest_dir, 'lyx' + version_suffix + '.1'),
2103         env.subst('$TOP_SRCDIR/lyx.man'))
2104     env.InstallAs(os.path.join(man_dest_dir, 'tex2lyx' + version_suffix + '.1'),
2105         env.subst('$TOP_SRCDIR/src/tex2lyx/tex2lyx.man'))
2106     env.InstallAs(os.path.join(man_dest_dir, 'lyxclient' + version_suffix + '.1'),
2107         env.subst('$TOP_SRCDIR/src/client/lyxclient.man'))
2108     Alias('install', [os.path.join(man_dest_dir, x + version_suffix + '.1') for
2109         x in ['lyx', 'tex2lyx', 'lyxclient']])
2110     # locale files?
2111     # ru.gmo ==> ru/LC_MESSAGES/lyxSUFFIX.mo
2112     for gmo in gmo_files:
2113         lan = os.path.split(str(gmo))[1].split('.')[0]
2114         dest_file = os.path.join(locale_dest_dir, lan, 'LC_MESSAGES', 'lyx' + program_suffix + '.mo')
2115         env.InstallAs(dest_file, gmo)
2116         Alias('install', dest_file)
2117
2118
2119 Default('lyx')
2120 Alias('all', ['lyx', 'client', 'tex2lyx'])