29 Options: |
29 Options: |
30 """) |
30 """) |
31 |
31 |
32 import os, sys |
32 import os, sys |
33 env = Environment(ENV = {'PATH' : os.environ['PATH']}) |
33 env = Environment(ENV = {'PATH' : os.environ['PATH']}) |
34 #Decider('MD5-timestamp') |
34 Decider('MD5-timestamp') |
35 |
35 |
36 opt = Options(['.optioncache']) |
36 opt = Options(['.optioncache']) |
37 opt.AddOptions( |
37 opt.AddOptions( |
38 BoolOption('intelc', 'use Intel C++ Compiler, if available', True), |
38 BoolOption('intelc', 'use Intel C++ Compiler, if available', True), |
39 ('precision', 'floating point number precision (single/double)', "single"), |
39 ('precision', 'floating point number precision (single/double)', "single"), |
59 elif env['PLATFORM'] == 'win32': |
59 elif env['PLATFORM'] == 'win32': |
60 platform = 'win32' |
60 platform = 'win32' |
61 context.Result(platform) |
61 context.Result(platform) |
62 return True |
62 return True |
63 |
63 |
64 cpu = 'unknown' |
|
65 def CheckCPU(context): |
|
66 global cpu, platform |
|
67 context.Message('Checking CPU model... ') |
|
68 if (platform == 'linux'): |
|
69 if (os.system("cat /proc/cpuinfo | grep 'Core(TM)2 CPU' >/dev/null") == 0): |
|
70 cpu = 'core2' |
|
71 context.Result(cpu) |
|
72 return True |
|
73 |
|
74 intelc = Tool("intelc").exists(env) == True |
|
75 def CheckIntelC(context): |
64 def CheckIntelC(context): |
76 global intelc |
65 global intelc, intelcversion |
77 context.Message('Checking for Intel C++ Compiler... ') |
66 context.Message('Checking for Intel C++ Compiler... ') |
|
67 intelc = Tool("intelc").exists(env) == True |
78 if intelc: |
68 if intelc: |
79 testenv = Environment() |
69 testenv = Environment() |
80 Tool("intelc").generate(testenv) |
70 Tool("intelc").generate(testenv) |
81 context.Result(str(testenv['INTEL_C_COMPILER_VERSION']/10.)) |
71 intelcversion = str(testenv['INTEL_C_COMPILER_VERSION']/10.) |
|
72 context.Result(intelcversion) |
82 else: |
73 else: |
83 context.Result(intelc) |
74 context.Result(intelc) |
84 return intelc |
75 return intelc |
85 |
76 |
86 def CheckGCC(context): |
77 def CheckGCC(context): |
87 global gcc, gccversion |
78 global gcc, gccversion |
88 context.Message('Checking for GCC... ') |
79 context.Message('Checking for GCC... ') |
89 gcc = "g++" in env['TOOLS'] |
80 gcc = "g++" in env['TOOLS'] |
90 if gcc: |
81 if gcc: |
91 gccversion = os.popen("g++ --version").read().split()[2] |
82 gccversion = env['CCVERSION'] |
92 context.Result(gccversion) |
83 context.Result(gccversion) |
93 else: |
84 else: |
94 context.Result(False) |
85 context.Result(False) |
95 return gcc |
86 return gcc |
96 |
87 |
|
88 def CheckCPUFlags(context): |
|
89 global cpu, cpuflags_gcc, cpuflags_intelc |
|
90 context.Message('Checking CPU arch and flags... ') |
|
91 env.Execute('@$CC tools/cpuflags.c -o tools/cpuflags') |
|
92 (cpu, cpuflags_gcc, cpuflags_intelc) = os.popen('tools/cpuflags %s %s' |
|
93 % (''.join(gccversion.rsplit('.',1)), intelcversion) ).read().split('\n')[:3] |
|
94 context.Result(cpu) |
|
95 return True |
|
96 |
97 conf = Configure(env, |
97 conf = Configure(env, |
98 custom_tests = { |
98 custom_tests = { |
99 'CheckPlatform' : CheckPlatform, 'CheckCPU' : CheckCPU, |
99 'CheckPlatform' : CheckPlatform, 'CheckCPUFlags' : CheckCPUFlags, |
100 'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC}) |
100 'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC}) |
101 conf.CheckPlatform() |
101 conf.CheckPlatform() |
102 conf.CheckCPU() |
|
103 conf.CheckGCC() |
102 conf.CheckGCC() |
104 conf.CheckIntelC() |
103 conf.CheckIntelC() |
|
104 conf.CheckCPUFlags() |
105 env = conf.Finish() |
105 env = conf.Finish() |
106 |
106 |
107 |
107 |
108 if intelc and env['intelc']: |
108 if intelc and env['intelc']: |
109 Tool("intelc").generate(env) |
109 Tool("intelc").generate(env) |
111 elif gcc: |
111 elif gcc: |
112 cc = 'gcc' |
112 cc = 'gcc' |
113 |
113 |
114 add_flags = '' |
114 add_flags = '' |
115 if cc == 'gcc': |
115 if cc == 'gcc': |
116 add_flags += '-ffast-math ' |
116 add_flags += cpuflags_gcc + ' -ffast-math ' |
117 if cpu == 'core2': |
117 if cc == 'intelc': |
118 if (cc == 'intelc' or gccversion[:3] == '4.3'): |
118 add_flags += cpuflags_intelc + ' ' |
119 add_flags += '-march=core2 -mtune=core2 ' |
|
120 if cc == 'intelc': |
|
121 add_flags += '-xT ' |
|
122 if cc == 'gcc': |
|
123 add_flags += '-msse3 -mfpmath=sse ' |
|
124 |
119 |
125 if env['precision'] == 'double': |
120 if env['precision'] == 'double': |
126 add_flags += '-DPYRIT_DOUBLE ' |
121 add_flags += '-DPYRIT_DOUBLE ' |
127 elif cc == 'gcc': |
122 elif cc == 'gcc': |
128 add_flags += '-fsingle-precision-constant ' |
123 add_flags += '-fsingle-precision-constant ' |