SConstruct (6168:ba6fe02228db) SConstruct (6654:4c84e771cca7)
1# -*- mode:python -*-
2
3# Copyright (c) 2009 The Hewlett-Packard Development Company
4# Copyright (c) 2004-2005 The Regents of The University of Michigan
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are

--- 82 unchanged lines hidden (view full) ---

91'python' first or (2) explicitly invoking an alternative interpreter
92on the scons script.
93
94For more details, see:
95 http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
96"""
97 raise
98
1# -*- mode:python -*-
2
3# Copyright (c) 2009 The Hewlett-Packard Development Company
4# Copyright (c) 2004-2005 The Regents of The University of Michigan
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are

--- 82 unchanged lines hidden (view full) ---

91'python' first or (2) explicitly invoking an alternative interpreter
92on the scons script.
93
94For more details, see:
95 http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
96"""
97 raise
98
99# Global Python includes
99import os
100import re
101import subprocess
102import sys
103
104from os import mkdir, environ
105from os.path import abspath, basename, dirname, expanduser, normpath
106from os.path import exists, isdir, isfile
107from os.path import join as joinpath, split as splitpath
108
100import os
101import re
102import subprocess
103import sys
104
105from os import mkdir, environ
106from os.path import abspath, basename, dirname, expanduser, normpath
107from os.path import exists, isdir, isfile
108from os.path import join as joinpath, split as splitpath
109
110# SCons includes
109import SCons
110import SCons.Node
111
111import SCons
112import SCons.Node
113
112def read_command(cmd, **kwargs):
113 """run the command cmd, read the results and return them
114 this is sorta like `cmd` in shell"""
115 from subprocess import Popen, PIPE, STDOUT
114# M5 includes
115sys.path[1:1] = [ Dir('src/python').srcnode().abspath ]
116
116
117 if isinstance(cmd, str):
118 cmd = cmd.split()
117from m5.util import compareVersions, readCommand
119
118
120 no_exception = 'exception' in kwargs
121 exception = kwargs.pop('exception', None)
122
123 kwargs.setdefault('shell', False)
124 kwargs.setdefault('stdout', PIPE)
125 kwargs.setdefault('stderr', STDOUT)
126 kwargs.setdefault('close_fds', True)
127 try:
128 subp = Popen(cmd, **kwargs)
129 except Exception, e:
130 if no_exception:
131 return exception
132 raise
133
134 return subp.communicate()[0]
135
136# helper function: compare arrays or strings of version numbers.
137# E.g., compare_version((1,3,25), (1,4,1)')
138# returns -1, 0, 1 if v1 is <, ==, > v2
139def compare_versions(v1, v2):
140 def make_version_list(v):
141 if isinstance(v, (list,tuple)):
142 return v
143 elif isinstance(v, str):
144 return map(lambda x: int(re.match('\d+', x).group()), v.split('.'))
145 else:
146 raise TypeError
147
148 v1 = make_version_list(v1)
149 v2 = make_version_list(v2)
150 # Compare corresponding elements of lists
151 for n1,n2 in zip(v1, v2):
152 if n1 < n2: return -1
153 if n1 > n2: return 1
154 # all corresponding values are equal... see if one has extra values
155 if len(v1) < len(v2): return -1
156 if len(v1) > len(v2): return 1
157 return 0
158
159########################################################################
160#
161# Set up the main build environment.
162#
163########################################################################
164use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
165 'RANLIB' ])
166

--- 45 unchanged lines hidden (view full) ---

212run the style hook. It is important.
213"""
214
215hg_info = "Unknown"
216if hgdir.exists():
217 # 1) Grab repository revision if we know it.
218 cmd = "hg id -n -i -t -b"
219 try:
119########################################################################
120#
121# Set up the main build environment.
122#
123########################################################################
124use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
125 'RANLIB' ])
126

--- 45 unchanged lines hidden (view full) ---

172run the style hook. It is important.
173"""
174
175hg_info = "Unknown"
176if hgdir.exists():
177 # 1) Grab repository revision if we know it.
178 cmd = "hg id -n -i -t -b"
179 try:
220 hg_info = read_command(cmd, cwd=main.root.abspath).strip()
180 hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
221 except OSError:
222 print mercurial_bin_not_found
223
224 # 2) Ensure that the style hook is in place.
225 try:
226 ui = None
227 if ARGUMENTS.get('IGNORE_STYLE') != 'True':
228 from mercurial import ui

--- 147 unchanged lines hidden (view full) ---

376Export('extras_dir_list')
377
378# the ext directory should be on the #includes path
379main.Append(CPPPATH=[Dir('ext')])
380
381# M5_PLY is used by isa_parser.py to find the PLY package.
382main.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath })
383
181 except OSError:
182 print mercurial_bin_not_found
183
184 # 2) Ensure that the style hook is in place.
185 try:
186 ui = None
187 if ARGUMENTS.get('IGNORE_STYLE') != 'True':
188 from mercurial import ui

--- 147 unchanged lines hidden (view full) ---

336Export('extras_dir_list')
337
338# the ext directory should be on the #includes path
339main.Append(CPPPATH=[Dir('ext')])
340
341# M5_PLY is used by isa_parser.py to find the PLY package.
342main.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath })
343
384CXX_version = read_command([main['CXX'],'--version'], exception=False)
385CXX_V = read_command([main['CXX'],'-V'], exception=False)
344CXX_version = readCommand([main['CXX'],'--version'], exception=False)
345CXX_V = readCommand([main['CXX'],'-V'], exception=False)
386
387main['GCC'] = CXX_version and CXX_version.find('g++') >= 0
388main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
389main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
390if main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
391 print 'Error: How can we have two at the same time?'
392 Exit(1)
393

--- 36 unchanged lines hidden (view full) ---

430
431# Check for SWIG
432if not main.has_key('SWIG'):
433 print 'Error: SWIG utility not found.'
434 print ' Please install (see http://www.swig.org) and retry.'
435 Exit(1)
436
437# Check for appropriate SWIG version
346
347main['GCC'] = CXX_version and CXX_version.find('g++') >= 0
348main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
349main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
350if main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
351 print 'Error: How can we have two at the same time?'
352 Exit(1)
353

--- 36 unchanged lines hidden (view full) ---

390
391# Check for SWIG
392if not main.has_key('SWIG'):
393 print 'Error: SWIG utility not found.'
394 print ' Please install (see http://www.swig.org) and retry.'
395 Exit(1)
396
397# Check for appropriate SWIG version
438swig_version = read_command(('swig', '-version'), exception='').split()
398swig_version = readCommand(('swig', '-version'), exception='').split()
439# First 3 words should be "SWIG Version x.y.z"
440if len(swig_version) < 3 or \
441 swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
442 print 'Error determining SWIG version.'
443 Exit(1)
444
445min_swig_version = '1.3.28'
399# First 3 words should be "SWIG Version x.y.z"
400if len(swig_version) < 3 or \
401 swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
402 print 'Error determining SWIG version.'
403 Exit(1)
404
405min_swig_version = '1.3.28'
446if compare_versions(swig_version[2], min_swig_version) < 0:
406if compareVersions(swig_version[2], min_swig_version) < 0:
447 print 'Error: SWIG version', min_swig_version, 'or newer required.'
448 print ' Installed version:', swig_version[2]
449 Exit(1)
450
451# Set up SWIG flags & scanner
452swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
453main.Append(SWIGFLAGS=swig_flags)
454

--- 54 unchanged lines hidden (view full) ---

509# Check for leading underscores. Don't really need to worry either
510# way so don't need to check the return code.
511conf.CheckLeading()
512
513# Check if we should compile a 64 bit binary on Mac OS X/Darwin
514try:
515 import platform
516 uname = platform.uname()
407 print 'Error: SWIG version', min_swig_version, 'or newer required.'
408 print ' Installed version:', swig_version[2]
409 Exit(1)
410
411# Set up SWIG flags & scanner
412swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
413main.Append(SWIGFLAGS=swig_flags)
414

--- 54 unchanged lines hidden (view full) ---

469# Check for leading underscores. Don't really need to worry either
470# way so don't need to check the return code.
471conf.CheckLeading()
472
473# Check if we should compile a 64 bit binary on Mac OS X/Darwin
474try:
475 import platform
476 uname = platform.uname()
517 if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
518 if int(read_command('sysctl -n hw.cpu64bit_capable')[0]):
477 if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
478 if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
519 main.Append(CCFLAGS='-arch x86_64')
520 main.Append(CFLAGS='-arch x86_64')
521 main.Append(LINKFLAGS='-arch x86_64')
522 main.Append(ASFLAGS='-arch x86_64')
523except:
524 pass
525
526# Recent versions of scons substitute a "Null" object for Configure()

--- 83 unchanged lines hidden (view full) ---

610#
611# Check for mysql.
612#
613mysql_config = WhereIs('mysql_config')
614have_mysql = bool(mysql_config)
615
616# Check MySQL version.
617if have_mysql:
479 main.Append(CCFLAGS='-arch x86_64')
480 main.Append(CFLAGS='-arch x86_64')
481 main.Append(LINKFLAGS='-arch x86_64')
482 main.Append(ASFLAGS='-arch x86_64')
483except:
484 pass
485
486# Recent versions of scons substitute a "Null" object for Configure()

--- 83 unchanged lines hidden (view full) ---

570#
571# Check for mysql.
572#
573mysql_config = WhereIs('mysql_config')
574have_mysql = bool(mysql_config)
575
576# Check MySQL version.
577if have_mysql:
618 mysql_version = read_command(mysql_config + ' --version')
578 mysql_version = readCommand(mysql_config + ' --version')
619 min_mysql_version = '4.1'
579 min_mysql_version = '4.1'
620 if compare_versions(mysql_version, min_mysql_version) < 0:
580 if compareVersions(mysql_version, min_mysql_version) < 0:
621 print 'Warning: MySQL', min_mysql_version, 'or newer required.'
622 print ' Version', mysql_version, 'detected.'
623 have_mysql = False
624
625# Set up mysql_config commands.
626if have_mysql:
627 mysql_config_include = mysql_config + ' --include'
628 if os.system(mysql_config_include + ' > /dev/null') != 0:

--- 278 unchanged lines hidden ---
581 print 'Warning: MySQL', min_mysql_version, 'or newer required.'
582 print ' Version', mysql_version, 'detected.'
583 have_mysql = False
584
585# Set up mysql_config commands.
586if have_mysql:
587 mysql_config_include = mysql_config + ' --include'
588 if os.system(mysql_config_include + ' > /dev/null') != 0:

--- 278 unchanged lines hidden ---