/[ascend]/trunk/SConstruct
ViewVC logotype

Contents of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log


Revision 647 - (show annotations) (download)
Mon May 29 14:14:10 2006 UTC (14 years, 3 months ago) by johnpye
File size: 29535 byte(s)
Turning off MSVC extensions when compiling
1 import os, commands, platform, distutils.sysconfig, os.path
2
3 version = "0.9.5.92"
4
5 #------------------------------------------------------
6 # OPTIONS
7 #
8 # Note that if you set the options via the command line, they will be
9 # remembered in the file 'options.cache'. It's a feature ;-)
10
11 opts = Options(['options.cache', 'config.py'])
12 #print "PLATFORM = ",platform.system()
13
14 if platform.system()=="Windows":
15 default_tcl_lib = "tcl84"
16 default_tk_lib = "tk84"
17 default_tktable_lib = "Tktable28"
18 default_install_assets = "glade/"
19 icon_extension = '.png'
20 default_tcl = "c:\\Tcl"
21 if os.environ.get('MSYSTEM')=="MINGW32":
22 default_tcl_libpath="$TCL\\bin"
23 else:
24 default_tcl_libpath="$TCL\\lib"
25 default_rel_distdir = '.'
26 default_absolute_paths = False
27 else:
28 default_tcl_lib = "tcl8.3"
29 default_tk_lib = "tk8.3"
30 default_tktable_lib = "Tktable2.8"
31 default_install_assets = "$INSTALL_ASCDATA/glade/"
32 icon_extension = '.svg'
33 default_tcl = os.path.expanduser("~/activetcl")
34 default_tcl_libpath = "$TCL/lib"
35 default_rel_distdir = '../share/ascend'
36 default_absolute_paths = True
37
38 if not os.path.isdir(default_tcl):
39 default_tcl = '/usr'
40
41 opts.Add(
42 'CC'
43 ,'C Compiler command'
44 ,None
45 )
46
47 opts.Add(
48 'CXX'
49 ,'C++ Compiler command'
50 ,None
51 )
52
53 opts.Add(BoolOption(
54 'GCOV'
55 , 'Whether to enable coverage testing in object code'
56 , False
57 ))
58
59 # Package linking option
60 opts.Add(EnumOption(
61 'PACKAGE_LINKING'
62 , 'Style of linking for external libraries'
63 , 'DYNAMIC_PACKAGES'
64 , ['DYNAMIC_PACKAGES', 'STATIC_PACKAGES', 'NO_PACKAGES']
65 ))
66
67 opts.Add(BoolOption(
68 'WITH_GCCVISIBILITY'
69 ,"Whether to use GCC Visibility features (only applicable if available)"
70 ,True
71 ))
72
73 # You can turn off building of Tcl/Tk interface
74 opts.Add(BoolOption(
75 'WITH_TCLTK'
76 ,"Set to True if you don't want to build the original Tcl/Tk GUI."
77 , True
78 ))
79
80 # You can turn off the building of the Python interface
81 opts.Add(BoolOption(
82 'WITH_PYTHON'
83 ,"Set to True if you don't want to build Python wrappers."
84 , True
85 ))
86
87 # Which solvers will we allow?
88 opts.Add(ListOption(
89 'WITH_SOLVERS'
90 ,"List of the solvers you want to build. The default is the minimum that"
91 +" works."
92 ,["QRSLV","CMSLV"]
93 ,['QRSLV','MPS','SLV','OPTSQP'
94 ,'NGSLV','CMSLV','LRSLV','MINOS','CONOPT'
95 ,'LSOD','OPTSQP'
96 ]
97 ))
98
99 # Where will the local copy of the help files be kept?
100 opts.Add(PackageOption(
101 'WITH_LOCAL_HELP'
102 , "Directory containing the local copy of the help files (optional)"
103 , "no"
104 ))
105
106 # Will bintoken support be enabled?
107 opts.Add(BoolOption(
108 'WITH_BINTOKEN'
109 ,"Enable bintoken support? This means compiling models as C-code before"
110 +" running them, to increase solving speed for large models."
111 ,False
112 ))
113
114 # What should the default ASCENDLIBRARY path be?
115 # Note: users can change it by editing their ~/.ascend.ini
116 opts.Add(
117 'DEFAULT_ASCENDLIBRARY'
118 ,"Set the default value of the ASCENDLIBRARY -- the location where"
119 +" ASCEND will look for models when running ASCEND"
120 ,"$INSTALL_ASCDATA/models"
121 )
122
123 # Where is SWIG?
124 opts.Add(
125 'SWIG'
126 ,"SWIG location, probably only required for MinGW and MSVC users."
127 +" Enter the location as a Windows-style path, for example"
128 +" 'c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe'."
129 )
130
131 # Build the test suite?
132 opts.Add(BoolOption(
133 'WITH_CUNIT'
134 ,"Whether to build the CUnit tests. Default is off. If set to on,"
135 +" you must have CUnit installed somewhere that SCons can"
136 +" find it, or else use the CUNIT_* options to specify."
137 ,False
138 ))
139
140 # Where are the CUnit includes?
141 opts.Add(PackageOption(
142 'CUNIT_CPPPATH'
143 ,"Where are your CUnit include files?"
144 ,'off'
145 ))
146
147 # Where are the CUnit libraries?
148 opts.Add(PackageOption(
149 'CUNIT_LIBPATH'
150 ,"Where are your CUnit libraries?"
151 ,'off'
152 ))
153
154
155 opts.Add(
156 'TCL'
157 ,'Base of Tcl distribution'
158 ,default_tcl
159 )
160
161 # Where are the Tcl includes?
162 opts.Add(
163 'TCL_CPPPATH'
164 ,"Where are your Tcl include files?"
165 ,"$TCL/include"
166 )
167
168 # Where are the Tcl libs?
169 opts.Add(
170 'TCL_LIBPATH'
171 ,"Where are your Tcl libraries?"
172 ,default_tcl_libpath
173 )
174
175 # What is the name of the Tcl lib?
176 opts.Add(
177 'TCL_LIB'
178 ,"Name of Tcl lib (eg 'tcl' or 'tcl83'), for full path to static library (if STATIC_TCLTK is set)"
179 ,default_tcl_lib
180 )
181
182 # Where are the Tk includes?
183 opts.Add(
184 'TK_CPPPATH'
185 ,"Where are your Tk include files?"
186 ,'$TCL_CPPPATH'
187 )
188
189 # Where are the Tk libs?
190 opts.Add(
191 'TK_LIBPATH'
192 ,"Where are your Tk libraries?"
193 ,'$TCL_LIBPATH'
194 )
195
196 # What is the name of the Tk lib?
197 opts.Add(
198 'TK_LIB'
199 ,"Name of Tk lib (eg 'tk' or 'tk83'), or full path to static library"
200 ,default_tk_lib
201 )
202
203 # Static linking to TkTable
204
205 opts.Add(BoolOption(
206 'STATIC_TCLTK'
207 ,'Set true for static linking for Tcl/Tk and TkTable. EXPERIMENTAL'
208 ,False
209 ))
210
211 opts.Add(
212 'TKTABLE_LIBPATH'
213 ,'Location of TkTable static library'
214 ,'$TCL_LIBPATH/Tktable2.8'
215 )
216
217 opts.Add(
218 'TKTABLE_LIB'
219 ,'Stem name of TkTable (eg tktable2.8, no ".so" or "lib") shared library, or full path of static tktable (/usr/lib/...)'
220 ,default_tktable_lib
221 )
222
223 opts.Add(
224 'TKTABLE_CPPPATH'
225 ,'Location of TkTable header file'
226 ,'$TCL_CPPPATH'
227 )
228
229 opts.Add(
230 'X11'
231 ,'Base X11 directory. Only used when STATIC_TCLTK is turned on. EXPERIMENTAL'
232 ,'/usr/X11R6'
233 )
234
235 opts.Add(
236 'X11_LIBPATH'
237 ,'Location of X11 lib. EXPERIMENTAL'
238 ,'$X11/lib'
239 )
240
241 opts.Add(
242 'X11_CPPPATH'
243 ,'Location of X11 includes. EXPERIMENTAL'
244 ,'$X11/include'
245 )
246
247 opts.Add(
248 'X11_LIB'
249 ,'Name of X11 lib. EXPERIMENTAL'
250 ,'X11'
251 )
252
253 opts.Add(
254 'INSTALL_PREFIX'
255 ,'Root location for installed files'
256 ,'/usr/local'
257 )
258
259 opts.Add(
260 'INSTALL_BIN'
261 ,'Location to put binaries during installation'
262 ,"$INSTALL_PREFIX/bin"
263 )
264
265 opts.Add(
266 'INSTALL_LIB'
267 ,'Location to put binaries during installation'
268 ,"$INSTALL_PREFIX/lib"
269 )
270
271 opts.Add(
272 'INSTALL_SHARE'
273 ,'Common shared-file location on this system'
274 ,"$INSTALL_PREFIX/share"
275 )
276
277
278 opts.Add(
279 'INSTALL_ASCDATA'
280 ,"Location of ASCEND shared data (TK, python, models etc)"
281 ,"$INSTALL_SHARE/ascend"
282 )
283
284 opts.Add(
285 'INSTALL_INCLUDE'
286 ,'Location to put header files during installation'
287 ,"$INSTALL_PREFIX/include"
288 )
289
290 opts.Add(
291 'PYGTK_ASSETS'
292 ,'Default location for Glade assets (placed in pygtk/config.py)'
293 ,default_install_assets
294 )
295
296 opts.Add(BoolOption(
297 'DEBUG'
298 ,"Compile source with debugger symbols, eg for use with 'gdb'"
299 ,False
300 ))
301
302 opts.Add(BoolOption(
303 'MALLOC_DEBUG'
304 ,"Compile with debugging version of MALLOC. Required for full CUnit testing"
305 ,False
306 ))
307
308 opts.Add(
309 'INSTALL_ROOT'
310 ,'For use by RPM only: location of %{buildroot} during rpmbuild'
311 ,""
312 )
313
314 opts.Add(
315 'DISTTAR_NAME'
316 ,"Stem name of the tarball created by 'scons dist'. So for 'ascend-aaa.tar.bz2', set this to 'ascend-aaa'."
317 ,"ascend-"+version
318 )
319
320 opts.Add(BoolOption(
321 'ABSOLUTE_PATHS'
322 ,"Whether to use absolute or relative paths in the installed Tcl/Tk interface. If you want to build an RPM, set this to false."
323 ,default_absolute_paths
324 ))
325
326 opts.Add(
327 'WIN_INSTALLER_NAME'
328 ,"Name of the installer .exe to create under Windows (minus the '.exe')"
329 ,"ascend-"+version
330 )
331
332 opts.Add(BoolOption(
333 'WITH_XTERM_COLORS'
334 ,"Set to 0 if you don't want xterm colour codes in the console output"
335 ,True
336 ))
337
338 if platform.system()!="Windows":
339 opts.Add(BoolOption(
340 'WITH_GCCVISIBILITY'
341 , 'Whether to use GCC Visibility extensions when building with GCC 4.0'
342 , True
343 ))
344
345 # TODO: OTHER OPTIONS?
346 # TODO: flags for optimisation
347 # TODO: turning on/off bintoken functionality
348 # TODO: Where will the 'Makefile.bt' file be installed?
349
350 # Import the outside environment
351
352 if os.environ.get('OSTYPE')=='msys':
353 env = Environment(
354 ENV=os.environ
355 , tools=['mingw','lex','yacc','fortran','swig','disttar','nsis']
356 , toolpath=['scons']
357 )
358 env['IS_MINGW']=True
359 else:
360 env = Environment(
361 ENV=os.environ
362 ,tools=['default','lex','yacc','fortran','swig','disttar','nsis']
363 , toolpath=['scons']
364 )
365
366 if platform.system()=='Windows' and env.has_key('MSVS'):
367 print "INCLUDE =",env['ENV']['INCLUDE']
368 print "LIB =",env['ENV']['LIB']
369 print "PATH =",env['ENV']['PATH']
370 env.Append(CPPPATH=env['ENV']['INCLUDE'])
371 env.Append(LIBPATH=env['ENV']['LIB'])
372 env.Append(CPPDEFINES=['_CRT_SECURE_NO_DEPRECATE'])
373 env.Append(CCFLAGS=['/Za'])
374
375 opts.Update(env)
376 opts.Save('options.cache',env)
377
378 Help(opts.GenerateHelpText(env))
379
380 with_tcltk = env.get('WITH_TCLTK')
381 without_tcltk_reason = "disabled by options/config.py"
382
383 with_python = env.get('WITH_PYTHON')
384 without_python_reason = "disabled by options/config.py"
385
386 with_cunit = env.get('WITH_CUNIT')
387 without_cunit_reason = "not requested"
388
389 if platform.system()=="Windows":
390 with_installer=1
391 else:
392 with_installer=0
393 without_installer_reason = "only possible under Windows"
394
395 #print "SOLVERS:",env['WITH_SOLVERS']
396 #print "WITH_BINTOKEN:",env['WITH_BINTOKEN']
397 #print "DEFAULT_ASCENDLIBRARY:",env['DEFAULT_ASCENDLIBRARY']
398
399 can_install = True
400 if platform.system()=='Windows':
401 can_install = False
402
403 env['CAN_INSTALL']=can_install
404
405 print "TCL_CPPPATH =",env['TCL_CPPPATH']
406 print "TCL_LIBPATH =",env['TCL_LIBPATH']
407 print "TCL_LIB =",env['TCL_LIB']
408 print "CC =",env['CC']
409 print "CXX =",env['CXX']
410
411 print "ABSOLUTE PATHS =",env['ABSOLUTE_PATHS']
412 #------------------------------------------------------
413 # SPECIAL CONFIGURATION TESTS
414
415 need_fortran = False
416
417 #----------------
418 # SWIG
419
420 import os,re
421
422 def get_swig_version(env):
423 cmd = env['SWIG']+' -version'
424 (cin,coutcerr) = os.popen4(cmd)
425 output = coutcerr.read()
426
427 restr = "SWIG\\s+Version\\s+(?P<maj>[0-9]+)\\.(?P<min>[0-9]+)\\.(?P<pat>[0-9]+)\\s*$"
428 expr = re.compile(restr,re.M);
429 m = expr.search(output);
430 if not m:
431 return None
432 maj = int(m.group('maj'))
433 min = int(m.group('min'))
434 pat = int(m.group('pat'))
435
436 return (maj,min,pat)
437
438
439 def CheckSwigVersion(context):
440
441 try:
442 context.Message("Checking version of SWIG... ")
443 maj,min,pat = get_swig_version(context.env)
444 except:
445 context.Result("Failed to detect version, or failed to run SWIG")
446 return 0;
447
448 context.env['SWIGVERSION']=tuple([maj,min,pat])
449
450 if maj == 1 and (
451 min > 3
452 or (min == 3 and pat >= 24)
453 ):
454 context.Result("ok, %d.%d.%d" % (maj,min,pat))
455 return 1;
456 else:
457 context.Result("too old, %d.%d.%d" % (maj,min,pat))
458 return 0;
459
460 #----------------
461 # General purpose library-and-header test
462
463 class KeepContext:
464 def __init__(self,context,varprefix,static=False):
465 self.keep = {}
466 for k in ['LIBS','LIBPATH','CPPPATH','LINKFLAGS']:
467 if context.env.has_key(k):
468 self.keep[k] = context.env[k]
469 else:
470 self.keep[k] = None
471
472 if context.env.has_key(varprefix+'_CPPPATH'):
473 context.env.Append(CPPPATH=[env[varprefix+'_CPPPATH']])
474 #print "Adding '"+str(cpppath_add)+"' to cpp path"
475
476 if static:
477 staticlib=env[varprefix+'_LIB']
478 #print "STATIC LIB = ",staticlib
479 context.env.Append(
480 LINKFLAGS=[staticlib]
481 )
482 else:
483 if context.env.has_key(varprefix+'_LIBPATH'):
484 context.env.Append(LIBPATH=[env[varprefix+'_LIBPATH']])
485 #print "Adding '"+str(libpath_add)+"' to lib path"
486
487 if context.env.has_key(varprefix+'_LIB'):
488 context.env.Append(LIBS=[env[varprefix+'_LIB']])
489 #print "Adding '"+str(libs_add)+"' to libs"
490
491 def restore(self,context):
492 #print "RESTORING CONTEXT"
493 #print self.keep
494 #print "..."
495 for k in self.keep:
496 if self.keep[k]==None:
497 if context.env.has_key(k):
498 #print "Clearing "+str(k)
499 del context.env[k];
500 else:
501 #print "Restoring "+str(k)+" to '"+self.keep[k]+"'"
502 context.env[k]=self.keep[k];
503
504 def CheckExtLib(context,libname,text,ext='.c',varprefix=None,static=False):
505 """This method will check for variables LIBNAME_LIBPATH
506 and LIBNAME_CPPPATH and try to compile and link the
507 file with the provided text, linking with the
508 library libname."""
509
510 if static:
511 context.Message( 'Checking for static '+libname+'... ' )
512 else:
513 context.Message( 'Checking for '+libname+'... ' )
514
515 if varprefix==None:
516 varprefix = libname.upper()
517
518 keep = KeepContext(context,varprefix,static)
519
520 if not context.env.has_key(varprefix+'_LIB'):
521 # if varprefix_LIB were in env, KeepContext would
522 # have appended it already
523 context.env.Append(LIBS=libname)
524
525 is_ok = context.TryLink(text,ext)
526
527 #print "Link success? ",(is_ok != 0)
528
529 keep.restore(context)
530
531 # print "Restored CPPPATH="+str(context.env['CPPPATH'])
532 # print "Restored LIBS="+libname
533 # print "Restored LIBPATH="+str(context.env['LIBPATH'])
534
535 context.Result(is_ok)
536 return is_ok
537
538 #----------------
539 # GCC
540
541 gcc_test_text = """
542 #ifndef __GNUC__
543 # error "Not using GCC"
544 #endif
545
546 int main(void){
547 return __GNUC__;
548 }
549 """
550
551 def CheckGcc(context):
552 context.Message("Checking for GCC... ")
553 is_ok = context.TryCompile(gcc_test_text,".c")
554 context.Result(is_ok)
555 return is_ok
556
557 #----------------
558 # GCC VISIBILITY feature
559
560 gccvisibility_test_text = """
561 #if __GNUC__ < 4
562 # error "Require GCC version 4 or newer"
563 #endif
564
565 __attribute__ ((visibility("default"))) int x;
566
567 int main(void){
568 extern int x;
569 x = 4;
570 }
571 """
572
573 def CheckGccVisibility(context):
574 context.Message("Checking for GCC 'visibility' capability... ")
575 if not context.env.has_key('WITH_GCCVISIBILITY') or not env['WITH_GCCVISIBILITY']:
576 context.Result("disabled")
577 return 0
578 is_ok = context.TryCompile(gccvisibility_test_text,".c")
579 context.Result(is_ok)
580 return is_ok
581
582 #----------------
583 # YACC
584
585 yacc_test_text = """
586 %{
587 #include <stdio.h>
588 %}
589 %token MSG
590 %start ROOT
591 %%
592 ROOT:
593 MSG { printf("HELLO"); }
594 ;
595 %%
596 """
597
598 def CheckYacc(context):
599 context.Message("Checking for Yacc ('%s')... " % context.env.get('YACC'))
600 is_ok = context.TryCompile(yacc_test_text,".y")
601 context.Result(is_ok)
602 return is_ok
603
604 #----------------
605 # CUnit test
606
607 cunit_test_text = """
608 #include <CUnit/CUnit.h>
609 int maxi(int i1, int i2){
610 return (i1 > i2) ? i1 : i2;
611 }
612
613 void test_maxi(void){
614 CU_ASSERT(maxi(0,2) == 2);
615 CU_ASSERT(maxi(0,-2) == 0);
616 CU_ASSERT(maxi(2,2) == 2);
617
618 }
619 int main(void){
620 /* CU_initialize_registry() */
621 return 0;
622 }
623 """
624
625 def CheckCUnit(context):
626 return CheckExtLib(context,'cunit',cunit_test_text)
627
628 #----------------
629 # Tcl test
630
631 # TCL and TK required version 8.1, 8.2, 8.3, or 8.4:
632 tcltk_minor_newest_acceptable = 4
633 tcltk_major_required = 8
634
635 tcl_check_text = r"""
636 #include <tcl.h>
637 #include <stdio.h>
638 int main(void){
639 printf("%s",TCL_PATCH_LEVEL);
640 return 0;
641 }
642 """
643
644 def CheckTcl(context):
645 return CheckExtLib(context,'tcl',tcl_check_text,static=env['STATIC_TCLTK'])
646
647 def CheckTclVersion(context):
648 keep = KeepContext(context,'TCL',static=env['STATIC_TCLTK'])
649 context.Message("Checking Tcl version... ")
650 (is_ok,output) = context.TryRun(tcl_check_text,'.c')
651 keep.restore(context)
652 if not is_ok:
653 context.Result("failed to run check")
654 return 0
655
656 major,minor,patch = tuple([int(i) for i in output.split(".")])
657 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
658 context.Result(output+" (bad version)")
659 # bad version
660 return 0
661
662 # good version
663 context.Result(output+", good")
664 return 1
665
666 #----------------
667 # Tk test
668
669 tk_check_text = r"""
670 #include <tk.h>
671 #include <stdio.h>
672 int main(void){
673 printf("%s",TK_PATCH_LEVEL);
674 return 0;
675 }
676 """
677 def CheckTk(context):
678 return CheckExtLib(context,'tk',tcl_check_text,static=env['STATIC_TCLTK'])
679
680
681 def CheckTkVersion(context):
682 keep = KeepContext(context,'TK',static=context.env['STATIC_TCLTK'])
683 context.Message("Checking Tk version... ")
684 #print "LINKFLAGS =",context.env['LINKFLAGS']
685 (is_ok,output) = context.TryRun(tk_check_text,'.c')
686 keep.restore(context)
687 if not is_ok:
688 context.Result("failed to run check")
689 return 0
690
691 major,minor,patch = tuple([int(i) for i in output.split(".")])
692 if major != tcltk_major_required or minor > tcltk_minor_newest_acceptable:
693 # bad version
694 context.Result(output+" (bad version)")
695 return 0
696
697 # good version
698 context.Result(output+" (good)")
699 return 1
700
701 #----------------
702 # Tktable test
703
704 tktable_check_text = r"""
705 #include <tkTable.h>
706 #include <stdio.h>
707 int main(void){
708 Table mytable;
709 return 0;
710 }
711 """
712
713 def CheckTkTable(context):
714 return CheckExtLib(context,'tktable',tktable_check_text,static=env['STATIC_TCLTK'])
715
716 #---------------
717 # X11 test
718
719 x11_check_text = r"""
720 #include <X11/Xlib.h>
721 #include <X11/IntrinsicP.h>
722 #include <X11/Intrinsic.h>
723 #include <X11/ObjectP.h>
724 #include <X11/Object.h>
725 int main(void){
726 Object mything;
727 return 0;
728 }
729 """
730
731 def CheckX11(context):
732 return CheckExtLib(context,'X11',x11_check_text)
733
734 #----------------
735 # GCC Version sniffing
736
737 # TODO FIXME
738
739 gcc_version4 = False
740
741 #------------------------------------------------------
742 # CONFIGURATION
743
744 conf = Configure(env
745 , custom_tests = {
746 'CheckSwigVersion' : CheckSwigVersion
747 , 'CheckCUnit' : CheckCUnit
748 , 'CheckTcl' : CheckTcl
749 , 'CheckTclVersion' : CheckTclVersion
750 , 'CheckTk' : CheckTk
751 , 'CheckTkVersion' : CheckTkVersion
752 , 'CheckGcc' : CheckGcc
753 , 'CheckGccVisibility' : CheckGccVisibility
754 , 'CheckYacc' : CheckYacc
755 , 'CheckTkTable' : CheckTkTable
756 , 'CheckX11' : CheckX11
757 # , 'CheckIsNan' : CheckIsNan
758 # , 'CheckCppUnitConfig' : CheckCppUnitConfig
759 }
760 # , config_h = "config.h"
761 )
762
763
764 # Math library
765
766 #if not conf.CheckFunc('sinh') and not conf.CheckLibWithHeader(['m','c','libc'], 'math.h', 'C'):
767 # print 'Did not find math library, exiting!'
768 # Exit(1)
769
770 # Where is 'isnan'?
771
772 if not conf.CheckFunc('isnan'):
773 print "Didn't find isnan"
774 # Exit(1)
775
776 # GCC visibility
777
778 if conf.CheckGcc():
779 conf.env['HAVE_GCC']=True;
780 if env['WITH_GCCVISIBILITY'] and conf.CheckGccVisibility():
781 conf.env['HAVE_GCCVISIBILITY']=True;
782 conf.env.Append(CCFLAGS=['-fvisibility=hidden'])
783 conf.env.Append(CPPDEFINES=['HAVE_GCCVISIBILITY'])
784
785 # YACC
786
787 if not conf.CheckYacc():
788 print "YACC NOT FOUND OR NOT WORKING"
789 else:
790 conf.env['HAVE_YACC']=True
791
792 conf.env['HAVE_LEX']=True
793
794 # Tcl/Tk
795
796 if with_tcltk:
797 if conf.CheckTcl():
798 if conf.CheckTclVersion():
799 if conf.CheckTk():
800 if with_tcltk and conf.CheckTkVersion():
801 if env['STATIC_TCLTK']:
802 if conf.CheckTkTable():
803 pass
804 else:
805 without_tcltk_reason = "TkTable not found"
806 with_tcltk = False
807 else:
808 without_tcltk_reason = "Require Tk version <= 8.4. See 'scons -h'"
809 with_tcltk = False
810 else:
811 without_tcltk_reason = "Tk not found."
812 with_tcltk = False
813 else:
814 without_tcltk_reason = "Require Tcl <= 8.4 Tcl."
815 with_tcltk = False
816
817 else:
818 without_tcltk_reason = "Tcl not found."
819 with_tcltk = False
820
821 if env['STATIC_TCLTK']:
822 conf.CheckX11()
823
824 # Python... obviously we're already running python, so we just need to
825 # check that we can link to the python library OK:
826
827 if platform.system()=="Windows":
828 python_lib='python24'
829 else:
830 python_lib='python2.4'
831
832 # SWIG version
833
834 if not conf.CheckSwigVersion():
835 without_python_reason = 'SWIG >= 1.3.24 is required'
836 with_python = False
837
838 # CUnit
839
840 if with_cunit:
841 if not conf.CheckCUnit():
842 without_cunit_reason = 'CUnit not found'
843
844 # BLAS
845
846 need_blas=False
847 if with_tcltk:
848 need_blas=True
849 if need_blas:
850 if conf.CheckLib('blas'):
851 with_local_blas = False
852 without_local_blas_reason = "Found BLAS installed on system"
853 else:
854 with_local_blas = True
855 need_fortran = True
856
857 # FORTRAN
858
859 if need_fortran:
860 conf.env.Tool('fortran')
861 detect_fortran = conf.env.Detect(['g77','f77','gfortran'])
862 if detect_fortran:
863 # For some reason, g77 doesn't get detected properly on MinGW
864 if not env.has_key('F77'):
865 conf.env.Replace(F77=detect_fortran)
866 conf.env.Replace(F77COM='$F77 $F77FLAGS -c -o $TARGET $SOURCE')
867 conf.env.Replace(F77FLAGS='')
868 #print "F77:",conf.env['F77']
869 #print "F77COM:",conf.env['F77COM']
870 #print "F77FLAGS:",conf.env['F77FLAGS']
871 fortran_builder = Builder(
872 action='$F77COM'
873 , suffix='.o'
874 , src_suffix='.f'
875 )
876 conf.env.Append(BUILDERS={'Fortran':fortran_builder})
877 else:
878 with_tcltk=False;
879 without_tcltk_reason="FORTRAN-77 required but not found"
880
881 #else:
882 # print "FORTRAN not required"
883
884 # TODO: -D_HPUX_SOURCE is needed
885
886 # TODO: check size of void*
887
888 # TODO: detect if dynamic libraries are possible or not
889
890 if platform.system()=="Windows" and env.has_key('MSVS'):
891 if not conf.CheckHeader('windows.h') and env['PACKAGE_LINKING']=='DYNAMIC_PACKAGES':
892 print "Reverting to STATIC_PACKAGES since windows.h is not available. Probably you "\
893 +"need to install the Microsoft Windows Server 2003 Platform SDK, or similar."
894 env['PACKAGE_LINKING']='STATIC_PACKAGES'
895
896 if with_python and not conf.CheckHeader(['basetsd.h','BaseTsd.h']):
897 with_python = 0;
898 without_python_reason = "Header file 'basetsd.h' not found. Install the MS Platform SDK."
899
900 conf.env.Append(CPPDEFINES=env['PACKAGE_LINKING'])
901
902 conf.Finish()
903
904 env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
905 env.Append(PYTHON_LIB=[python_lib])
906 env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
907
908 #---------------------------------------
909 # SUBSTITUTION DICTIONARY for .in files
910
911 subst_dict = {
912 '@DEFAULT_ASCENDLIBRARY@':env['DEFAULT_ASCENDLIBRARY']
913 , '@GLADE_FILE@':'ascend.glade'
914 , '@HELP_ROOT@':''
915 , '@ICON_EXTENSION@':icon_extension
916 , '@INSTALL_ASCDATA@':env['INSTALL_ASCDATA']
917 , '@INSTALL_BIN@':env['INSTALL_BIN']
918 , '@INSTALL_INCLUDE@':env['INSTALL_INCLUDE']
919 , '@PYGTK_ASSETS@':env['PYGTK_ASSETS']
920 , '@VERSION@':version
921 , '@DISTTAR_NAME@':env['DISTTAR_NAME']
922 , '@WEBHELPROOT@':'http://pye.dyndns.org/ascend/manual/'
923 , '@ASC_SHLIBSUFFIX@':env['SHLIBSUFFIX']
924 , '@ASC_SHLIBPREFIX@':env['SHLIBPREFIX']
925 , '@ASC_ENV_TK_DEFAULT@' : '$$ASCENDDIST/tcltk'
926 , '@ASC_DISTDIR_REL_BIN@' : default_rel_distdir
927 }
928
929 if env.get('WITH_LOCAL_HELP'):
930 print "WITH_LOCAL_HELP:",env['WITH_LOCAL_HELP']
931 subst_dict['@HELP_ROOT@']=env['WITH_LOCAL_HELP']
932
933 # bool options...
934 for k,v in { \
935 'ABSOLUTE_PATHS' : 'ASC_ABSOLUTE_PATHS', \
936 'WITH_XTERM_COLORS' : 'ASC_XTERM_COLORS', \
937 'MALLOC_DEBUG' : 'MALLOC_DEBUG' \
938 }.iteritems():
939 if env.get(k):
940 subst_dict['ifdef '+v]="if 1"
941
942 if with_python:
943 subst_dict['@ASCXX_USE_PYTHON@']="1"
944
945 if env.has_key('HAVE_GCCVISIBILITY'):
946 subst_dict['@HAVE_GCCVISIBILITY@'] = "1"
947
948 env.Append(SUBST_DICT=subst_dict)
949
950 #------------------------------------------------------
951 # RECIPE: SWIG scanner
952
953 import SCons.Script
954
955 SWIGScanner = SCons.Scanner.ClassicCPP(
956 "SWIGScan"
957 , ".i"
958 , "CPPPATH"
959 , '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
960 )
961
962 env.Append(SCANNERS=[SWIGScanner])
963
964 #------------------------------------------------------
965 # RECIPE: 'SubstInFile', used in pygtk SConscript
966
967 import re
968 from SCons.Script import * # the usual scons stuff you get in a SConscript
969
970 def TOOL_SUBST(env):
971 """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
972 from the source to the target.
973 The values of SUBST_DICT first have any construction variables expanded
974 (its keys are not expanded).
975 If a value of SUBST_DICT is a python callable function, it is called and
976 the result is expanded as the value.
977 If there's more than one source and more than one target, each target gets
978 substituted from the corresponding source.
979 """
980 env.Append(TOOLS = 'SUBST')
981 def do_subst_in_file(targetfile, sourcefile, dict):
982 """Replace all instances of the keys of dict with their values.
983 For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
984 then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
985 """
986 try:
987 f = open(sourcefile, 'rb')
988 contents = f.read()
989 f.close()
990 except:
991 raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
992 for (k,v) in dict.items():
993 contents = re.sub(k, v, contents)
994 try:
995 f = open(targetfile, 'wb')
996 f.write(contents)
997 f.close()
998 except:
999 raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
1000 return 0 # success
1001
1002 def subst_in_file(target, source, env):
1003 if not env.has_key('SUBST_DICT'):
1004 raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
1005 d = dict(env['SUBST_DICT']) # copy it
1006 for (k,v) in d.items():
1007 if callable(v):
1008 d[k] = env.subst(v())
1009 elif SCons.Util.is_String(v):
1010 d[k]=env.subst(v)
1011 else:
1012 raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
1013 for (t,s) in zip(target, source):
1014 return do_subst_in_file(str(t), str(s), d)
1015
1016 def subst_in_file_string(target, source, env):
1017 """This is what gets printed on the console."""
1018 return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
1019 for (t,s) in zip(target, source)])
1020
1021 def subst_emitter(target, source, env):
1022 """Add dependency from substituted SUBST_DICT to target.
1023 Returns original target, source tuple unchanged.
1024 """
1025 d = env['SUBST_DICT'].copy() # copy it
1026 for (k,v) in d.items():
1027 if callable(v):
1028 d[k] = env.subst(v())
1029 elif SCons.Util.is_String(v):
1030 d[k]=env.subst(v)
1031 Depends(target, SCons.Node.Python.Value(d))
1032 return target, source
1033
1034 subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
1035 env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
1036
1037 TOOL_SUBST(env)
1038
1039 #------------------------------------------------------
1040 # Recipe for 'CHMOD' ACTION
1041
1042 import SCons
1043 from SCons.Script.SConscript import SConsEnvironment
1044 SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod,
1045 lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode))
1046
1047 def InstallPerm(env, dest, files, perm):
1048 obj = env.Install(dest, files)
1049 for i in obj:
1050 env.AddPostAction(i, env.Chmod(str(i), perm))
1051
1052 SConsEnvironment.InstallPerm = InstallPerm
1053
1054 # define wrappers
1055 SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
1056 SConsEnvironment.InstallHeader = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1057 SConsEnvironment.InstallShared = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
1058
1059 #------------------------------------------------------
1060 # BUILD...
1061
1062 # so that #include <modulename/headername.h> works across all modules...
1063 env.Append(CPPPATH=['#base/generic'])
1064
1065 if gcc_version4:
1066 env.Append(CCFLAGS=['-fvisibility=hidden'])
1067
1068 if env['DEBUG']:
1069 env.Append(CCFLAGS=['-g'])
1070
1071 if env['GCOV']:
1072 env.Append(
1073 CPPFLAGS=['-g','-fprofile-arcs','-ftest-coverage']
1074 , LIBS=['gcov']
1075 , LINKFLAGS=['-fprofile-arcs','-ftest-coverage']
1076 )
1077
1078 #-------------
1079 # TCL/TK GUI
1080
1081 if with_tcltk:
1082 if with_local_blas:
1083 env.SConscript(['blas/SConscript'],'env')
1084 else:
1085 print "Skipping... BLAS won't be build:", without_local_blas_reason
1086
1087 env.SConscript(['lsod/SConscript'],'env')
1088
1089 env.SConscript(['linpack/SConscript'],'env')
1090 env.SConscript(['tcltk/generic/interface/SConscript'],'env')
1091 else:
1092 print "Skipping... Tcl/Tk GUI isn't being built:",without_tcltk_reason
1093
1094 #-------------
1095 # PYTHON INTERFACE
1096
1097 if with_python:
1098 env.SConscript(['pygtk/SConscript'],'env')
1099 else:
1100 print "Skipping... Python GUI isn't being built:",without_python_reason
1101
1102 #------------
1103 # BASE/GENERIC SUBDIRECTORIES
1104
1105 dirs = ['general','utilities','compiler','solver','packages']
1106
1107 srcs = []
1108 for d in dirs:
1109 heresrcs = env.SConscript('base/generic/'+d+'/SConscript','env')
1110 srcs += heresrcs
1111
1112 #-------------
1113 # LIBASCEND -- all base/generic functionality
1114
1115 libascend = env.SharedLibrary('ascend',srcs)
1116
1117 #-------------
1118 # UNIT TESTS
1119
1120 if with_cunit:
1121 testdirs = ['general','solver','utilities']
1122 testsrcs = []
1123 for testdir in testdirs:
1124 path = 'base/generic/'+testdir+'/test/'
1125 env.SConscript([path+'SConscript'],'env')
1126 testsrcs += [i.path for i in env['TESTSRCS_'+testdir.upper()]]
1127
1128 #print "TESTSRCS =",testsrcs
1129
1130 env.SConscript(['test/SConscript'],'env')
1131 env.SConscript(['base/generic/test/SConscript'],'env')
1132
1133 env.Alias('test',[env.Dir('test'),env.Dir('base/generic/test')])
1134
1135 else:
1136 print "Skipping... CUnit tests aren't being built:",without_cunit_reason
1137
1138 #------------------------------------------------------
1139 # INSTALLATION
1140
1141 if env.get('CAN_INSTALL'):
1142 # the models directory only needs to be processed for installation, no other processing required.
1143 env.SConscript(['models/SConscript'],'env')
1144
1145 dirs = ['INSTALL_BIN','INSTALL_ASCDATA','INSTALL_LIB']
1146 install_dirs = [env['INSTALL_ROOT']+env[d] for d in dirs]
1147
1148 # TODO: add install options
1149 env.Alias('install',install_dirs)
1150
1151 env.InstallShared(env['INSTALL_ROOT']+env['INSTALL_LIB'],libascend)
1152
1153 #------------------------------------------------------
1154 # WINDOWS INSTALLER
1155 # For the windows installer, please see pygtk/SConscript
1156
1157 if with_installer:
1158 pass
1159 else:
1160 print "Skipping... Windows installer isn't being built:",without_installer_reason
1161
1162 #------------------------------------------------------
1163 # CREATE the SPEC file for generation of RPM packages
1164
1165 if platform.system()=="Linux":
1166 env.SubstInFile('ascend.spec.in')
1167
1168 #------------------------------------------------------
1169 # DISTRIBUTION TAR FILE
1170
1171 env['DISTTAR_FORMAT']='bz2'
1172 env.Append(
1173 DISTTAR_EXCLUDEEXTS=['.o','.os','.so','.a','.dll','.cc','.cache','.pyc','.cvsignore','.dblite','.log','.pl']
1174 , DISTTAR_EXCLUDEDIRS=['CVS','.svn','.sconf_temp', 'dist']
1175 )
1176
1177 tar = env.DistTar("dist/"+env['DISTTAR_NAME']
1178 , [env.Dir('#')]
1179 )
1180
1181 #------------------------------------------------------
1182 # RPM BUILD
1183
1184 #if platform.system()=="Linux":
1185 # pass
1186
1187 #------------------------------------------------------
1188 # DEFAULT TARGETS
1189
1190 default_targets =[]
1191 if with_tcltk:
1192 default_targets.append('tcltk')
1193 if with_python:
1194 default_targets.append('pygtk')
1195 if with_installer:
1196 default_targets.append('installer')
1197
1198 env.Default(default_targets)
1199
1200 print "Building targets:"," ".join([str(i) for i in BUILD_TARGETS])
1201

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22