]> git.lyx.org Git - features.git/blob - SConstruct
Some fixes to the scons-based building sytem, from Bo Peng (ben.bob@gmail.com)
[features.git] / SConstruct
1 # vi:filetype=python:expandtab:tabstop=2:shiftwidth=2
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 #
12 # This is a scons based building system for lyx, you can use it as follows:
13 # (after of course installation of scons from www.scons.org)
14 #  
15 #    scons [frontend=qt3|gt4] [boost=included|auto] ...
16 #
17 # Where:
18 #   * use scons -h for details about parameters
19 #   * qt3 is used by default on linux, cygwin and mac
20 #   * qt4 is used by default on win32
21 #
22 # File layouts (Important):
23 #   * Unless you specify builddir=dir, building will happen
24 #     in $BUILDDIR = $mode/$platform-$frontend. E.g., something like
25 #       debug/linux-qt3/
26 #   * All shared libs will be put in $BUILDDIR/libs, e.g.
27 #       debug/linux-qt3/libs
28 #   * lyx executable will be in directories like debug/linux-qt3
29 #  
30 # Hints:
31 #   * scons --config=force
32 #     force re-configuration (use scons -H for details)
33 #   
34 #   * check config.log to see why config has failed
35 #
36 #   * use extra_inc_path, extra_lib_path, qt_dir, qt_inc_path
37 #     qt_lib_path to help locate qt and other libraries
38 #     (there are extra_inc_path1, extra_lib_path1 for now)
39 #
40 #   * (Important) use scons logfile=logfile.log to enable command line
41 #     logging. (default is no logging)
42 #
43 # Notes:
44 #   * Currently, all scons does is building lyx in
45 #       $LYXROOT/$mode/$build_dir/
46 #     where $mode is debug or release, $build_dir is the build_dir name 
47 #     listed above
48 #
49 #   * scons install etc may be added later. Interested contributors can follow
50 #       http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/AccumulateBuilder
51 #     or
52 #       http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/DistTarBuilder
53 #     Please also see the commented out code in scons_utils.py
54 #       
55 #   * NSIS support can be found here.
56 #     http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/NsisSconsTool
57 #
58 #   * rpm support?
59 #     http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/RpmHonchoTemp
60 #
61 #   However, I decide to wait since scons seems to be standardizing these
62 #   features.
63 #
64
65 import os, sys
66
67 # config/scons_utils.py defines a few utility function
68 sys.path.append('config')
69 import scons_utils as utils
70
71 #----------------------------------------------------------
72 # Required runtime environment
73 #----------------------------------------------------------
74
75 # FIXME: I remember lyx requires higher version of python?
76 EnsurePythonVersion(1, 5)
77 # Please use at least 0.96.91 (not 0.96.1)
78 EnsureSConsVersion(0, 96)
79
80 #----------------------------------------------------------
81 # Global definitions
82 #----------------------------------------------------------
83
84 # some global settings
85 PACKAGE_VERSION = '1.5.0svn'
86 DEVEL_VERSION = True
87 default_build_mode = 'debug'
88
89 PACKAGE = 'lyx'
90 PACKAGE_BUGREPORT = 'lyx-devel@lists.lyx.org'
91 PACKAGE_NAME = 'LyX'
92 PACKAGE_TARNAME = 'lyx'
93 PACKAGE_STRING = '%s %s' % (PACKAGE_NAME, PACKAGE_VERSION)
94 PROGRAM_SUFFIX = ''
95 config_h = os.path.join('src', 'config.h')
96 default_log_file = 'scons_lyx.log'
97
98 # FIXME: what is this? (They are used in src/support/package.C.in
99 LOCALEDIR = "../locale/"
100 LYX_DIR = "/usr/local/share/lyx"
101
102 # platform dependent default build_dir and other settings
103 #
104 # I know, somebody would say: 
105 #   This is TOTALLY wrong! Everything should be automatically
106 #   determined.
107 #
108 if os.name == 'nt':
109   platform_name = 'win32'
110   default_frontend = 'qt4'
111   # boost and gettext are unlikely to be installed already
112   default_boost_opt = 'included'
113   default_gettext_opt = 'included'
114   default_pch_opt = False
115   default_with_x = False
116   spell_checker = 'auto'
117   # FIXME: I need to know what exactly is boost_posix
118   boost_posix = False
119   packaging_method = 'windows'
120 elif os.name == 'posix' and sys.platform != 'cygwin':
121   platform_name = 'linux'
122   default_frontend = 'qt3'
123   # try to use system boost/gettext libraries
124   default_boost_opt = 'auto'
125   default_gettext_opt = 'auto'
126   default_pch_opt = False
127   default_with_x = True
128   boost_posix = False
129   packaging_method = 'posix'
130 elif os.name == 'posix' and sys.platform == 'cygwin':
131   platform_name = 'cygwin'
132   default_frontend = 'qt3'
133   # force the use of cygwin/boost/gettext
134   default_boost_opt = 'system'
135   default_gettext_opt = 'system'
136   default_pch_opt = False
137   default_with_x = True
138   boost_posix = True
139   packaging_method = 'posix'
140 elif os.name == 'darwin':
141   platform_name = 'mac'
142   default_frontend = 'qt3'
143   # to be safe
144   default_boost_opt = 'included'
145   default_gettext_opt = 'included'
146   default_pch_opt = False
147   default_with_x = False
148   boost_posix = False
149   packaging_method = 'msc'
150 else:  # unsupported system
151   platform_name = 'others'
152   default_frontend = 'qt3'
153   # to be safe
154   default_boost_opt = 'included'
155   default_gettext_opt = 'included'
156   default_pch_opt = False
157   default_with_x = True
158   boost_posix = False
159   packaging_method = 'posix'
160
161 #---------------------------------------------------------
162 # Handling options
163 #----------------------------------------------------------
164 # Note that if you set the options via the command line, 
165 # they will be remembered in the file 'options.cache'
166
167 # NOTE: the scons people are trying to fix scons so that
168 # options like --prefix will be accepted. Right now,
169 # we have to use the KEY=VALUE style of scons
170
171 opts = Options(['options.cache', 'config.py'])
172 opts.AddOptions(
173   # frontend, 
174   EnumOption('frontend', 'Main GUI', 
175     default_frontend,
176     allowed_values = ('xform', 'qt3', 'qt4', 'gtk') ),
177   # debug or release build
178   EnumOption('mode', 'Building method', default_build_mode,
179     allowed_values = ('debug', 'release') ),
180   # boost libraries
181   EnumOption('boost', 
182     'Use included, system boost library, or try sytem first.', 
183     default_boost_opt,
184     allowed_values = (
185       'auto',       # detect boost, if not found, use included
186       'included',   # always use included boost
187       'system',     # always use system boost, fail if can not find
188       ) ),
189   EnumOption('gettext', 
190     'Use included, system gettext library, or try sytem first', 
191     default_gettext_opt,
192     allowed_values = (
193       'auto',       # detect gettext, if not found, use included
194       'included',   # always use included gettext
195       'system',     # always use system gettext, fail if can not find
196       ) ),
197   # FIXME: I am not allowed to use '' as default, '.' is not good either.
198   PathOption('qt_dir', 'Path to qt directory', '.'),
199   PathOption('qt_include_path', 'Path to qt include directory', '.'),
200   PathOption('qt_lib_path', 'Path to qt library directory', '.'),
201   # FIXME: I do not know how pch is working. Ignore this option now.
202   BoolOption('pch', '(NA) Whether or not use pch', default_pch_opt),
203   # FIXME: Not implemented yet.
204   BoolOption('version_suffix', '(NA) Whether or not add version suffix', False),
205   # build directory, will replace build_dir if set
206   PathOption('build_dir', 'Build directory', '.'),
207   # extra include and libpath
208   PathOption('extra_inc_path', 'Extra include path', '.'),
209   PathOption('extra_lib_path', 'Extra library path', '.'),
210   PathOption('extra_inc_path1', 'Extra include path', '.'),
211   PathOption('extra_lib_path1', 'Extra library path', '.'),
212   # enable assertion, (config.h has  ENABLE_ASSERTIOS
213   BoolOption('assertions', 'Use assertions', True),
214   # enable warning, (config.h has  WITH_WARNINGS)
215   BoolOption('warnings', 'Use warnings', True),
216   # enable glib, (config.h has  _GLIBCXX_CONCEPT_CHECKS)
217   BoolOption('concept_checks', 'Enable concept checks', True),
218   # FIXME: I do not know what is nls
219   BoolOption('nls', '(NA) Whether or not use native language support', False),
220   # FIXME: not implemented
221   BoolOption('profile', '(NA) Whether or not enable profiling', False),
222   # FIXME: not implemented
223   PathOption('prefix', '(NA) install architecture-independent files in PREFIX', '.'),
224   # FIXME: not implemented
225   PathOption('exec_prefix', '(NA) install architecture-independent executable files in PREFIX', '.'),
226   # FIXME: not implemented
227   BoolOption('std_debug', '(NA) Whether or not turn on stdlib debug', False),
228   # using x11?
229   BoolOption('X11', 'Use x11 windows system', default_with_x),
230   # FIXME: not implemented
231   BoolOption('libintl', '(NA) Use libintl library', False),
232   # FIXME: not implemented
233   PathOption('intl_prefix', '(NA) Path to intl library', '.'),
234   # log file
235   ('logfile', 'save commands (not outputs) to logfile', default_log_file),
236   # What is aiksaurus?
237   BoolOption('aikasurus', 'Whether or not use aikasurus library', False),
238   #
239   EnumOption('spell', 'Choose spell checker to use.', 'auto',
240     allowed_values = ('aspell', 'pspell', 'ispell', 'auto') )
241 )  
242
243 # Determine the frontend to use
244 frontend = ARGUMENTS.get('frontend', default_frontend)
245 use_X11 = ARGUMENTS.get('X11', default_with_x)
246
247 #---------------------------------------------------------
248 # Setting up environment
249 #---------------------------------------------------------
250
251 env = Environment(
252   options = opts 
253 )
254
255 # set environment since I do not really like ENV = os.environ
256 env['ENV']['PATH'] = os.environ.get('PATH')
257 env['ENV']['HOME'] = os.environ.get('HOME')
258 env['ENV']['PKG_CONFIG_PATH'] = os.environ.get('PKG_CONFIG_PATH')
259 env['TOP_SRC_DIR'] = Dir('.').abspath
260
261 #
262 # frontend, mode, BUILDDIR and LOCALLIBPATH=BUILDDIR/libs
263
264 env['frontend'] = frontend
265 env['mode'] = ARGUMENTS.get('mode', default_build_mode)
266 # lyx will be built to $build/build_dir so it is possible
267 # to build multiple build_dirs using the same source 
268 # $mode can be debug or release
269 if ARGUMENTS.has_key('build_dir'):
270   build_dir = ARGUMENTS['build_dir']
271   env['BUILDDIR'] = build_dir
272 else:
273   # Determine the name of the build (platform+frontend
274   build_dir = '%s-%s' % (platform_name, frontend)
275   if use_X11 and platform_name == 'cygwin':
276     build_dir += '-X11'
277   env['BUILDDIR'] = os.path.join('$mode', build_dir)
278 # all built libraries will go to build_dir/libs
279 # (This is different from the make file approach)
280 env['LOCALLIBPATH'] = '#$BUILDDIR/libs'
281 env.Append(LIBPATH = ['$LOCALLIBPATH'])
282
283 #
284 # QTDIR, QT_LIB_PATH, QT_INC_PATH
285 #
286 if platform_name == 'win32':
287   env.Tool('mingw')
288
289 if ARGUMENTS.has_key('qt_dir'):
290   env['QTDIR'] = ARGUMENTS['qt_dir']
291   # add path to the qt tools
292   env.Append(LIBPATH = [os.path.join(ARGUMENTS['qt_dir'], 'lib')])
293   env.Append(CPPPATH = [os.path.join(ARGUMENTS['qt_dir'], 'include')])
294   # set environment so that moc etc can be found even if its path is not set properly
295   env['ENV']['PATH'] = os.path.join(ARGUMENTS['qt_dir'], 'bin') + os.pathsep + env['ENV']['PATH']
296 else:
297   env['QTDIR'] = os.environ.get('QTDIR', '/usr/lib/qt-3.3')
298
299 if ARGUMENTS.has_key('qt_lib_path'):
300   env['QT_LIB_PATH'] = ARGUMENTS['qt_lib_path']
301 else:
302   env['QT_LIB_PATH'] = '$QTDIR/lib'
303 env.Append(LIBPATH = ['$QT_LIB_PATH'])
304 # qt4 seems to be using pkg_config
305 env['ENV']['PKG_CONFIG_PATH'] = env.subst('$QT_LIB_PATH')
306
307 if ARGUMENTS.has_key('qt_inc_path'):
308   env['QT_INC_PATH'] = ARGUMENTS['qt_inc_path']
309 elif os.path.isdir(os.path.join(env.subst('$QTDIR'), 'include')):
310   env['QT_INC_PATH'] = '$QTDIR/include'
311 else: # have to guess
312   env['QT_INC_PATH'] = '/usr/include/$frontend/'
313 env.Append(CPPPATH = env['QT_INC_PATH'])  
314
315 #
316 # extra_inc_path and extra_lib_path
317 #
318 if ARGUMENTS.has_key('extra_inc_path'):
319   env.Append(CPPPATH = [ARGUMENTS['extra_inc_path']])
320 if ARGUMENTS.has_key('extra_lib_path'):
321   env.Append(LIBPATH = [ARGUMENTS['extra_lib_path']])
322 if ARGUMENTS.has_key('extra_inc_path1'):
323   env.Append(CPPPATH = [ARGUMENTS['extra_inc_path1']])
324 if ARGUMENTS.has_key('extra_lib_path1'):
325   env.Append(LIBPATH = [ARGUMENTS['extra_lib_path1']])
326
327 #
328 # this is a bit out of place (after auto-configration)
329 # but it is required to do the tests.
330 if platform_name == 'win32':
331   env.Append(CPPPATH = ['#c:/MinGW/include'])
332
333 #----------------------------------------------------------
334 # Autoconf business 
335 #----------------------------------------------------------
336
337 conf = Configure(env,
338   custom_tests = {
339     'CheckPkgConfig' : utils.checkPkgConfig,
340     'CheckPackage' : utils.checkPackage,
341     'CheckPutenv' : utils.checkPutenv,
342     'CheckIstreambufIterator' : utils.checkIstreambufIterator,
343     'CheckMkdirOneArg' : utils.checkMkdirOneArg,
344     'CheckStdCount' : utils.checkStdCount,
345     'CheckSelectArgType' : utils.checkSelectArgType,
346     'CheckBoostLibraries' : utils.checkBoostLibraries,
347   }
348 )
349
350 # pkg-config? (if not, we use hard-coded options)
351 if conf.CheckPkgConfig('0.15.0'):
352   env['HAS_PKG_CONFIG'] = True
353 else:
354   print 'pkg-config >= 0.1.50 is not found'
355   env['HAS_PKG_CONFIG'] = False
356
357 # zlib? This is required.
358 if not conf.CheckLibWithHeader('z', 'zlib.h', 'C'): 
359   print 'Did not find libz or zlib.h, exiting!'
360   Exit(1)
361
362 # qt libraries?
363 #
364 # qt3 does not use pkg_config
365 if env['frontend'] == 'qt3':
366   if not conf.CheckLibWithHeader('qt-mt', 'qapp.h', 'c++', 'QApplication qapp();'):
367     print 'Did not find qt libraries, exiting!'
368     Exit(1)
369 elif env['frontend'] == 'qt4':
370   succ = False
371   # first: try pkg_config
372   if env['HAS_PKG_CONFIG']:
373     succ = conf.CheckPackage('QtCore') or conf.CheckPackage('QtCore4')
374     env['QT4_PKG_CONFIG'] = succ
375   # second: try to link to it
376   if not succ:
377     # FIXME: under linux, I can test the following perfectly
378     # However, under windows, lib names need to passed as libXXX4.a ...
379     succ = conf.CheckLibWithHeader('QtCore', 'QtGui/QApplication', 'c++', 'QApplication qapp();') or \
380       conf.CheckLibWithHeader('QtCore4', 'QtGui/QApplication', 'c++', 'QApplication qapp();')
381   # third: try to look up the path
382   if not succ:
383     succ = True
384     for lib in ['QtCore', 'QtGui', 'Qt3Support']:
385       # windows version has something like QtGui4 ...
386       if not (os.path.isfile(os.path.join(env.subst('$QT_LIB_PATH'), 'lib%s.a' % lib)) or \
387         os.path.isfile(os.path.join(env.subst('$QT_LIB_PATH'), 'lib%s4.a' % lib))):
388         succ = False
389         break
390   # still can not find it
391   if succ:
392     print "Qt4 libraries are found."
393   else:
394     print 'Did not find qt libraries, exiting!'
395     Exit(1)
396
397 # check socket libs
398 env['socket_libs'] = []
399 if conf.CheckLib('socket'):
400   env.Append(socket_libs = ['socket'])
401
402 # FIXME: What is nsl, is it related to socket?
403 if conf.CheckLib('nsl'):
404   env.Append(socket_libs = ['nsl'])
405
406 # check boost libraries
407 boost_opt = ARGUMENTS.get('boost', default_boost_opt)
408 # check for system boost
409 succ = False
410 if boost_opt in ['auto', 'system']:
411   pathes = env['LIBPATH'] + ['/usr/lib', '/usr/local/lib']
412   sig = conf.CheckBoostLibraries('boost_signals', pathes)
413   reg = conf.CheckBoostLibraries('boost_regex', pathes)
414   fil = conf.CheckBoostLibraries('boost_filesystem', pathes)
415   ios = conf.CheckBoostLibraries('boost_iostreams', pathes)
416   # if any them is not found
417   if ('' in [sig[0], reg[0], fil[0], ios[0]]):
418     if boost_opt == 'system':
419       print "Can not find system boost libraries"
420       print "Please supply a path through extra_lib_path"
421       print "and try again."
422       Exit(2)
423   else:
424     env['BOOST_LIBRARIES'] = [sig[1], reg[1], fil[1], ios[1]]
425     # assume all boost libraries are in the same path...
426     env.Append(LIBPATH = sig[0])
427     env['INCLUDED_BOOST'] = False
428     succ = True
429 # now, auto and succ = false, or included
430 if not succ:
431   # we do not need to set LIBPATH now.
432   env['BOOST_LIBRARIES'] = ['boost_signals', 'boost_regex', 
433     'boost_filesystem', 'boost_iostreams']
434   env['INCLUDED_BOOST'] = True
435   
436 #
437 # Building config.h
438
439
440 print "Generating ", config_h, "..."
441
442 # I do not handle all macros in src/config.h.in, rather I am following a list
443 # of *used-by-lyx* macros compiled by Abdelrazak Younes <younes.a@free.fr> 
444
445 # Note: addToConfig etc are defined in scons_util
446 utils.startConfigH(config_h)
447
448 # HAVE_IO_H
449 # HAVE_LIMITS_H
450 # HAVE_LOCALE_H
451 # HAVE_LOCALE
452 # HAVE_PROCESS_H
453 # HAVE_STDLIB_H
454 # HAVE_SYS_STAT_H
455 # HAVE_SYS_TIME_H
456 # HAVE_SYS_TYPES_H
457 # HAVE_SYS_UTIME_H
458 # HAVE_UNISTD_H
459 # HAVE_UTIME_H
460 # HAVE_ISTREAM
461 # HAVE_OSTREAM
462 # HAVE_IOS
463
464 # Check header files
465 headers = [
466   ('io.h', 'HAVE_IO_H', 'c'),
467   ('limits.h', 'HAVE_LIMITS_H', 'c'),
468   ('locale.h', 'HAVE_LOCALE_H', 'c'),
469   ('locale', 'HAVE_LOCALE', 'cxx'),
470   ('process.h', 'HAVE_PROCESS_H', 'c'),
471   ('stdlib.h', 'HAVE_STDLIB_H', 'c'),
472   ('sys/stat.h', 'HAVE_SYS_STAT_H', 'c'),
473   ('sys/time.h', 'HAVE_SYS_TIME_H', 'c'),
474   ('sys/types.h', 'HAVE_SYS_TYPES_H', 'c'),
475   ('sys/utime.h', 'HAVE_SYS_UTIME_H', 'c'),
476   ('sys/socket.h', 'HAVE_SYS_SOCKET_H', 'c'),
477   ('unistd.h', 'HAVE_UNISTD_H', 'c'),
478   ('utime.h', 'HAVE_UTIME_H', 'c'),
479   ('istream', 'HAVE_ISTREAM', 'cxx'),
480   ('ostream', 'HAVE_OSTREAM', 'cxx'),
481   ('ios', 'HAVE_IOS', 'cxx')
482 ]
483
484 for header in headers:
485   if (header[2] == 'c' and conf.CheckCHeader(header[0])) or \
486     (header[2] == 'cxx' and conf.CheckCXXHeader(header[0])):
487     utils.addToConfig('#define %s 1' % header[1])
488   else:
489     utils.addToConfig('/* #undef %s */' % header[1])
490
491 # HAVE_OPEN
492 # HAVE_CLOSE
493 # HAVE_POPEN
494 # HAVE_PCLOSE
495 # HAVE__OPEN
496 # HAVE__CLOSE
497 # HAVE__POPEN
498 # HAVE__PCLOSE
499 # HAVE_GETPID
500 # HAVE__GETPID
501 # HAVE_MKDIR
502 # HAVE__MKDIR
503 # HAVE_MKTEMP
504 # HAVE_MKSTEMP
505 # HAVE_STRERROR
506
507 # Check functions
508 functions = [
509   ('open', 'HAVE_OPEN'),
510   ('close', 'HAVE_CLOSE'),
511   ('popen', 'HAVE_POPEN'),
512   ('pclose', 'HAVE_PCLOSE'),
513   ('_open', 'HAVE__OPEN'),
514   ('_close', 'HAVE__CLOSE'),
515   ('_popen', 'HAVE__POPEN'),
516   ('_pclose', 'HAVE__PCLOSE'),
517   ('getpid', 'HAVE_GETPID'),
518   ('_getpid', 'HAVE__GETPID'),
519   ('mkdir', 'HAVE_MKDIR'),
520   ('_mkdir', 'HAVE__MKDIR'),
521   ('mktemp', 'HAVE_MKTEMP'),
522   ('mkstemp', 'HAVE_MKSTEMP'),
523   ('strerror', 'HAVE_STRERROR')
524 ]
525
526 for func in functions:
527   if conf.CheckFunc(func[0]):
528     utils.addToConfig('#define %s 1' % func[1])
529   else:
530     utils.addToConfig('/* #undef %s */' % func[1])
531
532 # PACKAGE
533 # PACKAGE_VERSION
534 # DEVEL_VERSION
535 utils.addToConfig('#define PACKAGE "%s"' % PACKAGE)
536 utils.addToConfig('#define PACKAGE_VERSION "%s"' % PACKAGE_VERSION)
537 if DEVEL_VERSION:
538   utils.addToConfig('#define DEVEL_VERSION 1')
539
540 # ENABLE_ASSERTIONS
541 # ENABLE_NLS
542 # WITH_WARNINGS
543 # _GLIBCXX_CONCEPT_CHECKS
544
545 # items are (ENV, ARGUMENTS)
546 values = [
547   ('ENABLE_ASSERTIONS', 'assertions'),
548   ('ENABLE_NLS', 'nls'),
549   ('WITH_WARNINGS', 'warnings'),
550   ('_GLIBCXX_CONCEPT_CHECKS', 'concept_checks'),
551 ]
552
553 for val in values:
554   if (env.has_key(val[0]) and env[val[0]]) or \
555       ARGUMENTS.get(val[1]):
556     utils.addToConfig('#define %s 1' % val[0])
557   else:
558     utils.addToConfig('/* #undef %s */' % val[0])
559
560 # AIKSAURUS_H_LOCATION
561 if ARGUMENTS.get('aiksaurus'):
562   if conf.CheckLib('Aiksaurus'):
563     utils.addToConfig("#define AIKSAURUS_H_LOCATION")
564   else:
565     print 'Library Aiksaurus not found'
566     Exit(2)
567
568 # USE_ASPELL
569 # USE_PSPELL
570 # USE_ISPELL
571
572 # determine headers to use
573 spell_engine = ARGUMENTS.get('spell', 'auto')
574 spell_detected = False
575 if spell_engine in ['auto', 'aspell'] and \
576   conf.CheckLibWithHeader('aspell', 'aspell.h', 'C'):
577   utils.addToConfig('#define USE_ASPELL 1')
578   spell_detected = True
579 elif spell_engine in ['auto', 'pspell'] and \
580   conf.CheckLibWithHeader('pspell', 'pspell.h', 'C'):
581   utils.addToConfig('#define USE_PSPELL 1')
582   spell_detected = True
583 elif spell_engine in ['auto', 'ispell'] and \
584   conf.CheckLibWithHeader('ispell', 'ispell.h', 'C'):
585   utils.addToConfig('#define USE_ISPELL 1')
586   spell_detected = False
587
588 if not spell_detected:
589   # FIXME: can lyx work without an spell engine
590   if spell_engine == 'auto':
591     print "Warning: Can not locate any spell checker"
592   else:
593     print "Warning: Can not locate specified spell checker:", spell_engine
594
595 # USE_POSIX_PACKAGING
596 # USE_MACOSX_PACKAGING
597 # USE_WINDOWS_PACKAGING
598 if packaging_method == 'windows':
599   utils.addToConfig('#define USE_WINDOWS_PACKAGING 1')
600 elif packaging_method == 'posix':
601   utils.addToConfig('#define USE_POSIX_PACKAGING 1')
602 elif packaging_method == 'mac':
603   utils.addToConfig('#define USE_MACOSX_PACKAGING 1')
604
605 # BOOST_POSIX
606 if boost_posix:
607   utils.addToConfig('#define BOOST_POSIX 1')
608 else:
609   utils.addToConfig('/* #undef BOOST_POSIX */')
610
611 # HAVE_PUTENV
612 if conf.CheckPutenv():
613   utils.addToConfig('#define HAVE_PUTENV 1')
614 else:
615   utils.addToConfig('/* #undef HAVE_PUTENV */')
616   
617 # HAVE_DECL_ISTREAMBUF_ITERATOR
618 if conf.CheckIstreambufIterator():
619   utils.addToConfig('#define HAVE_DECL_ISTREAMBUF_ITERATOR 1')
620 else:
621   utils.addToConfig('/* #undef HAVE_DECL_ISTREAMBUF_ITERATOR */')
622
623 # MKDIR_TAKES_ONE_ARG
624 if conf.CheckMkdirOneArg():
625   utils.addToConfig('#define MKDIR_TAKES_ONE_ARG 1')
626 else:
627   utils.addToConfig('/* #undef MKDIR_TAKES_ONE_ARG */')
628
629 # HAVE_STD_COUNT
630 if conf.CheckStdCount():
631   utils.addToConfig('#define HAVE_STD_COUNT 1')
632 else:
633   utils.addToConfig('/* #undef HAVE_STD_COUNT */')
634
635 # SELECT_TYPE_ARG1
636 # SELECT_TYPE_ARG234
637 # SELECT_TYPE_ARG5
638 (arg1, arg234, arg5) = conf.CheckSelectArgType()
639 utils.addToConfig('#define SELECT_TYPE_ARG1 %s' % arg1)
640 utils.addToConfig('#define SELECT_TYPE_ARG234 %s' % arg234)
641 utils.addToConfig('#define SELECT_TYPE_ARG5 %s' % arg5)
642
643 # mkstemp
644 # USE_BOOST_FORMAT
645 # WANT_GETFILEATTRIBUTESEX_WRAPPER
646 utils.endConfigH(config_h)
647
648 #
649 # Finish auto-configuration
650 env = conf.Finish()
651
652 #----------------------------------------------------------
653 # Now set up our build process accordingly 
654 #----------------------------------------------------------
655
656 #
657 # QT_LIB etc (EXTRA_LIBS holds lib for each frontend)
658 #
659 # NOTE: Tool('qt') or Tool('qt4') will be loaded later
660 # in their respective directory and specialized env.
661 try:
662   if frontend == 'qt3':
663     # note: env.Tool('qt') my set QT_LIB to qt
664     env['QT_LIB'] = 'qt-mt'
665     env['EXTRA_LIBS'] = ['qt-mt']
666     if platform_name == 'cygwin' and use_X11:
667       env['EXTRA_LIBS'] += ['GL',  'Xmu', 'Xi', 'Xrender', 'Xrandr', 'Xcursor',
668         'Xft', 'freetype', 'fontconfig', 'Xext', 'X11', 'SM', 'ICE', 'resolv',
669         'pthread']
670       env.Append(LIBPATH = ['/usr/X11R6/lib'])
671   elif frontend == 'qt4':
672     # local qt4 toolset from 
673     # http://www.iua.upf.es/~dgarcia/Codders/sconstools.html
674     if platform_name == "win32":
675       env['QT_LIB'] = ['QtCore4', 'QtGui4', 'Qt3Support4']
676     else:
677       env['QT_LIB'] = ['QtCore', 'QtGui', 'Qt3Support']
678     env['EXTRA_LIBS'] = env['QT_LIB']
679 except:
680   print "Can not locate qt tools"
681   print "What I get is "
682   print "  QTDIR: ", env['QTDIR']
683
684 #
685 # Build parameters CPPPATH etc
686 #
687 # boost is always in
688 env.Append(CPPPATH = ['#boost', '#src'])
689
690 # TODO: add (more) appropriate compiling options (-DNDEBUG etc)
691 # for debug/release mode 
692 if ARGUMENTS.get('mode', default_build_mode) == 'debug':
693   env.Append(CCFLAGS = [])
694 else:
695   env.Append(CCFLAGS = [])
696
697 #
698 # Customized builders
699 #
700 # install customized builders
701 env['BUILDERS']['substFile'] = Builder(action = utils.env_subst)
702 # FIXME: there must be a better way.
703 env['BUILDERS']['fileCopy'] = Builder(action = utils.env_filecopy)
704
705 #
706 # A Link script for cygwin see
707 # http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
708 # http://www.cygwin.com/ml/cygwin-apps/2004-09/msg00309.html
709 # for details
710
711 if platform_name == 'cygwin' and env['frontend'] == 'qt3':
712   ld_script_path = '/usr/lib/qt3/mkspecs/cygwin-g++'
713   ld_script = utils.installCygwinLDScript(ld_script_path)
714   env.Append(LINKFLAGS = ['-Wl,--enable-runtime-pseudo-reloc', 
715     '-Wl,--script,%s' % ld_script, '-Wl,-s'])
716
717 #
718 # Report results
719 #
720 # src/support/package.C.in needs the following to replace
721 env['LYX_DIR'] = LYX_DIR
722 env['LOCALEDIR'] = LOCALEDIR
723 env['TOP_SRCDIR'] = str(Dir('#'))
724 env['PROGRAM_SUFFIX'] = PROGRAM_SUFFIX
725 # needed by src/version.C.in => src/version.C
726 env['PACKAGE_VERSION'] = PACKAGE_VERSION
727 # fill in the version info
728 env['VERSION_INFO'] = '''Configuration
729   Host type:                      %s
730   Special build flags:            %s
731   C   Compiler:                   %s
732   C   Compiler flags:             %s %s
733   C++ Compiler:                   %s
734   C++ Compiler LyX flags:         %s
735   C++ Compiler flags:             %s %s
736   Linker flags:                   %s
737   Linker user flags:              %s
738 Build info: 
739   Builing directory:              %s
740   Local library directory:        %s
741   Libraries pathes:               %s
742   Boost libraries:                %s
743 Frontend: 
744   Frontend:                       %s
745   Packaging:                      %s
746   LyX binary dir:                 FIXME
747   LyX files dir:                  FIXME
748 ''' % (platform_name, 
749   env.subst('$CCFLAGS'), env.subst('$CC'),
750   env.subst('$CPPFLAGS'), env.subst('$CFLAGS'),
751   env.subst('$CXX'), env.subst('$CXXFLAGS'),
752   env.subst('$CPPFLAGS'), env.subst('$CXXFLAGS'),
753   env.subst('$LINKFLAGS'), env.subst('$LINKFLAGS'),
754   env.subst('$BUILDDIR'), env.subst('$LOCALLIBPATH'),
755   str(env['LIBPATH']), str(env['BOOST_LIBRARIES']),
756   env['frontend'], packaging_method)
757
758 if env['frontend'] in ['qt3', 'qt4']:
759   env['VERSION_INFO'] += '''  include dir:                    %s
760   library dir:                    %s
761   X11:                            %s
762 ''' % (env.subst('$QT_INC_PATH'), env.subst('$QT_LIB_PATH'), use_X11)
763
764 print env['VERSION_INFO']
765
766 #
767 # Mingw command line may be too short for our link usage, 
768 # Here we use a trick from scons wiki
769 # http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/LongCmdLinesOnWin32
770 #
771 # I also would like to add logging (commands only) capacity to the
772 # spawn system. 
773 logfile = ARGUMENTS.get('logfile', default_log_file)
774 if logfile != '' or platform_name == 'win32':
775   import time
776   utils.setLoggedSpawn(env, logfile, longarg = (platform_name == 'win32'),
777     info = '''# This is a log of commands used by scons to build lyx
778 # Time: %s 
779 # Command: %s
780 # Info: %s
781 ''' % (time.asctime(), ' '.join(sys.argv), 
782   env['VERSION_INFO'].replace('\n','\n# ')) )
783
784
785 #
786 # Cleanup stuff
787 #
788 # save options
789 opts.Save('options.cache', env)
790 # -h will print out help info
791 Help(opts.GenerateHelpText(env))
792
793
794
795 #----------------------------------------------------------
796 # Start building
797 #----------------------------------------------------------
798 Export('env')
799 env.BuildDir('$BUILDDIR', 'src')
800 print "Building all targets recursively"
801
802 client = env.SConscript('#$BUILDDIR/client/SConscript')
803 lyx = env.SConscript('#$BUILDDIR/SConscript')
804 tex2lyx = env.SConscript('#$BUILDDIR/tex2lyx/SConscript')
805
806 # avoid using full path to build them
807 Alias('client', client)
808 Alias('tex2lyx', tex2lyx)
809 Alias('lyx', lyx)
810
811 Default('lyx', 'tex2lyx')
812
813 print "Buinging lyx done with targets", map(str, BUILD_TARGETS)
814