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