# Copyright (C) 2008, 2009 by Sirrix AG security technologies # Copyright (C) 2010 by Philipp Deppenwiese # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # scons_utils.py defines a few autoconf utility functions import scons_utils as utils import os Version = "1.5" ################################################################################## # Scons configuration ################################################################################## Decider( 'MD5-timestamp' ) # only calculate checksum if timestamp has changed SetOption( 'max_drift', 2 ) # calculate only if file is X seconds old SetOption( 'num_jobs', 2 ) # use two jobs in parallel ################################################################################## # Command line options ################################################################################## vars = Variables() vars.Add( BoolVariable('debug', 'Set to 0 to disable debugging', 1) ) vars.Add( BoolVariable('trousers', 'Set to 0 to use internal microtss', 1) ) ################################################################################## # Create the main environment ################################################################################## env = Environment( variables = vars, CPPPATH = ['#src/include', '#src/include/utils', '#src/include/crypto/cryptomanager', '#src/include/crypto', '#src/include/tpmcrypt', '.'] ) cflags = " -Wall" cxxflags = " -Weffc++" ################################################################################## # Check system configuration ################################################################################## if not env.GetOption('clean'): utils.startConfig( 'Config' ) conf = env.Configure( custom_tests = { 'checkEndian' : utils.checkEndian, 'checkTypeSize' : utils.checkTypeSize } ) ############################################################################## if env["trousers"]: ############################################################################## # Check for TSS library print 'Using TrouSerS for TPM access' if not conf.CheckLibWithHeader('tspi', 'trousers/tss.h', 'c'): print 'Did not find TrouSerS header files, exiting!' Exit(1) else: print 'Using MicroTSS of Sirrix AG for TPM access' ############################################################################## # Check for crypt library if not conf.CheckLibWithHeader('crypt', 'crypt.h', 'c'): print 'Did not find crypt library, exiting!' Exit(1) ############################################################################## # Check for pthread library if not conf.CheckLibWithHeader('pthread', 'pthread.h', 'c'): print 'Did not find pthread library, exiting!' Exit(1) ############################################################################## # Check for gmp library if not conf.CheckLibWithHeader('gmp', 'gmp.h', 'c'): print 'Did not find gmp library, exiting!' Exit(1) ############################################################################## # Check for tr library (function clock_gettime()) if not conf.CheckLibWithHeader( 'rt', 'time.h', 'c', 'clock_gettime( CLOCK_MONOTONIC, (struct timespec*)0 );'): print 'Did not find the rt library providing the function clock_gettime(), exiting!' Exit(1) ############################################################################## # Check for cryptlib library ############################################################################## # Check byteorder endian = conf.checkEndian() if endian == "big": utils.addToConfig( '#define WORDS_BIGENDIAN', comment='/* CPU uses big endian byte order */' ) else: if not endian == "little": print 'Could not determine CPU byte order, exiting!' Exit(1) else: utils.addToConfig( '/* #undef WORDS_BIGENDIAN */', comment='/* CPU uses little endian byte order */' ) ############################################################################## # Check type size utils.addToConfig( '#define SIZEOF_CHAR ' + str( conf.checkTypeSize( 'char' ) ), comment='/* Size of type char in bytes */' ) utils.addToConfig( '#define SIZEOF_SHORT ' + str( conf.checkTypeSize( 'short' ) ), comment='/* Size of type short in bytes */' ) utils.addToConfig( '#define SIZEOF_INT ' + str( conf.checkTypeSize( 'int' ) ), comment='/* Size of type int in bytes */' ) utils.addToConfig( '#define SIZEOF_INTP ' + str( conf.checkTypeSize( 'int*' ) ), comment='/* Size of type int* in bytes */' ) utils.addToConfig( '#define SIZEOF_LONG ' + str( conf.checkTypeSize( 'long' ) ), comment='/* Size of type long in bytes */' ) utils.addToConfig( '#define SIZEOF_LONG_LONG ' + str( conf.checkTypeSize( 'long long' ) ), comment='/* Size of type long long in bytes */' ) ################################################################################## # Set environment variables if env["debug"]: cflags += " -g" utils.addToConfig( '#define DEBUG', comment='/* Debugging enabled */' ) else: cflags += " -O2" utils.addToConfig( '/* #undef DEBUG */', comment='/* Debugging disabled */' ) conf.env.AppendUnique( CFLAGS = Split( cflags ), CXXFLAGS = Split( cflags + cxxflags ) ) env = conf.Finish() utils.endConfig( 'src/include' ) ################################################################################## # Set VERSION string utils.startConfig( 'VERSION' ) revision = os.popen( 'svnversion' ) utils.addToConfig( '#define VERSION "'+Version+'-r'+revision.read().strip()+'"', comment='/* Current TpmCrypt version */' ) utils.endConfig( 'src/include' ) ################################################################################## Export( "env" ) ################################################################################## # TpmCrypt SConscript( "src/SConscript" ) # Generate the help text Help(vars.GenerateHelpText(env))