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