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