|
| 1 | + |
| 2 | +# |
| 3 | +# Jan. 31, 2014 David Lawrence |
| 4 | +# |
| 5 | +# This SConstruct file can be copied into a directory containing |
| 6 | +# the source for a plugin and used to compile it. It will use and |
| 7 | +# install into the directory specified by the HALLD_MY environment |
| 8 | +# variable if defined. Otherwise, it will install in the HALLD_RECON_HOME |
| 9 | +# directory. |
| 10 | +# |
| 11 | +# This file should not need modification. It will be copied in by |
| 12 | +# the mkplugin or mkfactory_plugin scripts or you can just copy it |
| 13 | +# by hand. |
| 14 | +# |
| 15 | +# To use this, just type "scons install" to build and install. |
| 16 | +# Just type "scons" if you want to build, but not install it. |
| 17 | +# |
| 18 | +# > scons install |
| 19 | +# |
| 20 | +# Note that unlike the rest of the SBMS system, this does not |
| 21 | +# use a separate build directory and builds everything in the |
| 22 | +# source directory. This is due to technical details and will hopefully |
| 23 | +# be fixed in the future. For now it means, that you must be |
| 24 | +# diligent of building for multiple platforms using the same source. |
| 25 | +# |
| 26 | + |
| 27 | +from __future__ import division |
| 28 | +from __future__ import absolute_import |
| 29 | +from __future__ import print_function |
| 30 | +from __future__ import unicode_literals |
| 31 | + |
| 32 | +from builtins import map |
| 33 | +from builtins import str |
| 34 | +from builtins import open |
| 35 | +from builtins import int |
| 36 | +from future import standard_library |
| 37 | +standard_library.install_aliases() |
| 38 | + |
| 39 | +import os |
| 40 | +import sys |
| 41 | +import subprocess |
| 42 | +import glob |
| 43 | + |
| 44 | +# Get HALLD_RECON_HOME environment variable, verifying it is set |
| 45 | +halld_home = os.getenv('HALLD_RECON_HOME') |
| 46 | +if(halld_home == None): |
| 47 | + print('HALLD_RECON_HOME environment variable not set!') |
| 48 | + exit(-1) |
| 49 | + |
| 50 | +# Get HALLD_MY if it exists. Otherwise use HALLD_RECON_HOME |
| 51 | +halld_my = os.getenv('HALLD_MY', halld_home) |
| 52 | + |
| 53 | +# Add SBMS directory to PYTHONPATH |
| 54 | +sbmsdir = "%s/src/SBMS" % halld_home |
| 55 | +sys.path.append(sbmsdir) |
| 56 | + |
| 57 | +import sbms |
| 58 | + |
| 59 | +# Get command-line options |
| 60 | +SHOWBUILD = ARGUMENTS.get('SHOWBUILD', 0) |
| 61 | + |
| 62 | +# Get platform-specific name |
| 63 | +osname = os.getenv('BMS_OSNAME', 'build') |
| 64 | + |
| 65 | +# Get architecture name |
| 66 | +arch_out = ROOT_CFLAGS = subprocess.Popen(["uname"], stdout=subprocess.PIPE).communicate()[0].strip() |
| 67 | +arch = str(arch_out, 'utf-8') |
| 68 | + |
| 69 | +# Setup initial environment |
| 70 | +installdir = "%s/%s" %(halld_my, osname) |
| 71 | +include = "%s/include" % (installdir) |
| 72 | +bin = "%s/bin" % (installdir) |
| 73 | +lib = "%s/lib" % (installdir) |
| 74 | +plugins = "%s/plugins" % (installdir) |
| 75 | +env = Environment( ENV = os.environ, # Bring in full environment, including PATH |
| 76 | + CPPPATH = [include], |
| 77 | + LIBPATH = ["%s/%s/lib" %(halld_home, osname)], # n.b. add HALLD_RECON_HOME here and prepend HALLD_MY below |
| 78 | + variant_dir = ".%s" % (osname)) |
| 79 | + |
| 80 | +# Only add HALLD_MY library search path if it already exists |
| 81 | +# since we'll get a warning otherwise |
| 82 | +if (os.path.exists(lib)): env.PrependUnique(lib) |
| 83 | + |
| 84 | +# These are SBMS-specific variables (i.e. not default scons ones) |
| 85 | +env.Replace(INSTALLDIR = installdir, |
| 86 | + OSNAME = osname, |
| 87 | + INCDIR = include, |
| 88 | + BINDIR = bin, |
| 89 | + LIBDIR = lib, |
| 90 | + PLUGINSDIR = plugins, |
| 91 | + ALL_SOURCES = [], # used so we can add generated sources |
| 92 | + SHOWBUILD = SHOWBUILD, |
| 93 | + COMMAND_LINE_TARGETS = COMMAND_LINE_TARGETS) |
| 94 | + |
| 95 | +# Use terse output unless otherwise specified |
| 96 | +if SHOWBUILD==0: |
| 97 | + env.Replace( CCCOMSTR = "Compiling [$SOURCE]", |
| 98 | + CXXCOMSTR = "Compiling [$SOURCE]", |
| 99 | + FORTRANPPCOMSTR = "Compiling [$SOURCE]", |
| 100 | + FORTRANCOMSTR = "Compiling [$SOURCE]", |
| 101 | + SHCCCOMSTR = "Compiling [$SOURCE]", |
| 102 | + SHCXXCOMSTR = "Compiling [$SOURCE]", |
| 103 | + LINKCOMSTR = "Linking [$TARGET]", |
| 104 | + SHLINKCOMSTR = "Linking [$TARGET]", |
| 105 | + INSTALLSTR = "Installing [$TARGET]", |
| 106 | + ARCOMSTR = "Archiving [$TARGET]", |
| 107 | + RANLIBCOMSTR = "Ranlib [$TARGET]") |
| 108 | + |
| 109 | + |
| 110 | +# Get compiler from environment variables (if set) |
| 111 | +env.Replace( CXX = os.getenv('CXX', 'g++'), |
| 112 | + CC = os.getenv('CC' , 'gcc'), |
| 113 | + FC = os.getenv('FC' , 'gfortran') ) |
| 114 | + |
| 115 | +# Add local directory, directories from HALLD_MY and HALLD_RECON_HOME to include search path |
| 116 | +#env.PrependUnique(CPPPATH = ['#']) |
| 117 | +env.PrependUnique(CPPPATH = ['%s/src' % halld_my, '%s/src/libraries' % halld_my, '%s/src/libraries/include' % halld_my]) |
| 118 | +env.PrependUnique(CPPPATH = ['%s/src' % halld_home, '%s/src/libraries' % halld_home, '%s/src/libraries/include' % halld_home]) |
| 119 | + |
| 120 | +env.PrependUnique(CPPPATH = ['%s/%s/include' % (halld_my,osname)]) |
| 121 | +env.PrependUnique(CPPPATH = ['%s/%s/include' % (halld_home,osname)]) |
| 122 | + |
| 123 | +# Turn on debug symbols and warnings |
| 124 | +env.PrependUnique( CFLAGS = ['-g', '-fPIC', '-Wall']) |
| 125 | +env.PrependUnique( CXXFLAGS = ['-g', '-fPIC', '-Wall']) |
| 126 | +env.PrependUnique(FORTRANFLAGS = ['-g', '-fPIC', '-Wall']) |
| 127 | + |
| 128 | +env.PrependUnique( CXXFLAGS = ['-std=c++11']) |
| 129 | + |
| 130 | +# Apply any platform/architecture specific settings |
| 131 | +sbms.ApplyPlatformSpecificSettings(env, arch) |
| 132 | +sbms.ApplyPlatformSpecificSettings(env, osname) |
| 133 | + |
| 134 | +# Make plugin from source in this directory |
| 135 | +sbms.AddDANA(env) |
| 136 | +sbms.AddROOT(env) |
| 137 | +sbms.plugin(env) |
| 138 | + |
| 139 | +# Make install target |
| 140 | +env.Alias('install', installdir) |
| 141 | + |
| 142 | + |
0 commit comments