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