Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.
Differences between revisions 21 and 22
Revision 21 as of 2005-04-24 19:47:03
Size: 3244
Editor: 85-250-77-172
Comment: got rid of word wrapping
Revision 22 as of 2008-03-12 02:47:13
Size: 3244
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

   1 # An SConscript file to untar a package, run configure and then make
   2 # using a build directory.
   3 #
   4 # Replacing this with SConscript files written to compile just the
   5 # parts of the package that we want would be quicker, but would take some time
   6 # to do.
   7 
   8 Import('env')
   9 
  10 import sys
  11 import os
  12 import SCons.Script
  13 
  14 def run(cmd):
  15     """Run a command and decipher the return code. Exit by default."""
  16     res = os.system(cmd)
  17     # Assumes that if a process doesn't call exit, it was successful
  18     if (os.WIFEXITED(res)):
  19         code = os.WEXITSTATUS(res)
  20         if code != 0:
  21             print "Error: return code: " + str(code)
  22             if SCons.Script.keep_going_on_error == 0:
  23                 sys.exit(code)
  24 
  25 import time
  26 def ConfigureMake(target, source, env):
  27     """Run configure as necessary and then run make"""
  28     pkg_name = 'net-snmp-5.1'  # the name of the current snmp package
  29     baseDir = Dir("#.").abspath
  30     # BUILD_DIR is the top build directory relative to SConstruct
  31     buildDir = baseDir + '/' + env['BUILD_DIR']
  32 
  33     startdir = os.getcwd()   # restore cwd at the end
  34     if not os.path.exists(buildDir):
  35         os.makedirs(buildDir)
  36     os.chdir(buildDir)
  37 
  38     # Untar the source tgz file
  39     if not os.path.exists(pkg_name):
  40         cmd = 'tar xfz ' + source[0].abspath
  41         print '... untarring source files'
  42         run(cmd)
  43 
  44     # Change to the top of the source tree for net-snmp
  45     here = buildDir + '/' + pkg_name
  46     os.chdir(here)
  47 
  48     # See if configure needs to be run. Doesn't check for failed configures
  49     if os.path.exists('config.status'):
  50         print '... configure is up-to-date'
  51     else:
  52         # Customize the stock package here with other files if necessary
  53         # If configure needs interactive responses, write them to a file
  54         # config_responses and pass it as input to configure with 
  55         # >config_responses
  56 
  57         # Now run configure
  58         print '... running configure: ' +
  59           time.asctime(time.localtime(time.time()))
  60         cmd = './configure'
  61         run(cmd)
  62         print '... configure done: ' +
  63           time.asctime(time.localtime(time.time()))
  64 
  65     # Always run make
  66     print '... running make: ' + time.asctime(time.localtime(time.time()))
  67     run('make')
  68     print '... make finished: ' + time.asctime(time.localtime(time.time()))
  69     os.chdir(startdir)    # restore the original cwd
  70 
  71     return 0
  72 
  73 def log_output_fn(target, source, env):
  74     """The message seen in build logs when this action is called"""
  75     return "Building '%s'\n from '%s'\n at: %s" % (target[0], source[0], 
  76       time.asctime(time.localtime(time.time())))
  77 
  78 my_prog = env.Command(
  79     target = 'snmpd', # There are other targets, but this
  80                       # is one major one for this package
  81     source = '#/foo/bar/net-snmp-5.1.tar.gz', # Location of
  82                                               # package in 
  83                                               # the source tree
  84     action = Action(ConfigureMake, strfunction = log_output_fn),
  85 )
  86 # So that "scons doit" will run all this
  87 Alias('doit', my_prog)

Comments and fixes to Matt Doar, mdoar@pobox.com

RunningConfigureAndMake (last edited 2008-03-12 02:47:13 by localhost)