forked from JeffersonLab/analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
239 lines (207 loc) · 9.58 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env python
###### Hall A Software Main SConstruct Build File #####
###### Author: Edward Brash ([email protected]) June 2013
import os
import sys
import platform
import commands
import SCons
import time
import subprocess
import configure
def rootcint(target,source,env):
"""Executes the ROOT dictionary generator over a list of headers."""
dictname = target[0]
headers = ""
cpppath = env.subst('$_CCCOMCOM')
ccflags = env.subst('$CCFLAGS')
rootcint = env.subst('$ROOTCINT')
print "Doing rootcint call now ..."
for f in source:
headers += str(f) + " "
command = rootcint + " -f %s -c -pthread -fPIC %s %s" % (dictname,cpppath,headers)
print ('RootCint Command = %s\n' % command)
ok = os.system(command)
return ok
baseenv = Environment(ENV = os.environ,tools=["default","disttar"],toolpath='.')
#dict = baseenv.Dictionary()
#keys = dict.keys()
#keys.sort()
#for key in keys:
# print "Construction variable = '%s', value = '%s'" % (key, dict[key])
####### Check SCons version ##################
#print('!!! You should be using the local version of SCons, invoked with:')
#print('!!! ./scons/scons.py')
print('!!! Building the Hall A analyzer and libraries with SCons requires')
print('!!! SCons version 2.1.0 or newer.')
EnsureSConsVersion(2,1,0)
configure.config(baseenv,ARGUMENTS)
####### Hall A Build Environment #############
#
baseenv.Append(MAIN_DIR = Dir('.').abspath)
baseenv.Append(HA_DIR = baseenv.subst('$MAIN_DIR'))
baseenv.Append(HA_SRC = baseenv.subst('$HA_DIR')+'/src ')
baseenv.Append(HA_DC = baseenv.subst('$HA_DIR')+'/hana_decode ')
baseenv.Append(MAJORVERSION = '1')
baseenv.Append(MINORVERSION = '6')
baseenv.Append(PATCH = '0')
baseenv.Append(SOVERSION = baseenv.subst('$MAJORVERSION')+'.'+baseenv.subst('$MINORVERSION'))
baseenv.Append(VERSION = baseenv.subst('$SOVERSION')+'.'+baseenv.subst('$PATCH'))
baseenv.Append(NAME = 'analyzer-'+baseenv.subst('$VERSION'))
baseenv.Append(EXTVERS = '-beta3')
baseenv.Append(HA_VERSION = baseenv.subst('$VERSION')+baseenv.subst('$EXTVERS'))
print "Main Directory = %s" % baseenv.subst('$HA_DIR')
print "Software Version = %s" % baseenv.subst('$VERSION')
ivercode = 65536*int(float(baseenv.subst('$SOVERSION')))+ 256*int(10*(float(baseenv.subst('$SOVERSION'))-int(float(baseenv.subst('$SOVERSION')))))+ int(float(baseenv.subst('$PATCH')))
baseenv.Append(VERCODE = ivercode)
#
# evio environment
#
evio_libdir = os.getenv('EVIO_LIBDIR')
evio_incdir = os.getenv('EVIO_INCDIR')
if evio_libdir is None or evio_incdir is None:
print "No external EVIO environment configured !!!"
print "EVIO_LIBDIR = %s" % evio_libdir
print "EVIO_INCDIR = %s" % evio_incdir
print "Using local installation ... "
evio_local = baseenv.subst('$HA_DIR')+'/evio'
evio_command_dircreate = "mkdir -p %s" % (evio_local)
os.system(evio_command_dircreate)
evio_version = '4.4.6'
uname = os.uname();
platform = uname[0];
machine = uname[4];
evio_name = platform + '-' + machine
print "evio_name = %s" % evio_name
evio_local_lib = "%s/evio-%s/%s/lib" % (evio_local,evio_version,evio_name)
evio_local_inc = "%s/evio-%s/%s/include" % (evio_local,evio_version,evio_name)
evio_tarfile = "%s/evio-%s.tgz" % (evio_local,evio_version)
####### Check to see if scons -c has been called #########
if baseenv.GetOption('clean'):
subprocess.call(['echo', '!!!!!!!!!!!!!! EVIO Cleaning Process !!!!!!!!!!!! '])
if not os.path.isdir(evio_local_lib):
if not os.path.exists(evio_tarfile):
evio_command_scons = "rm libevio*.*; cd %s; wget --no-check-certificate https://coda.jlab.org/drupal/system/files/evio-%s.tgz; tar xvfz evio-%s.tgz; cd evio-%s/ ; scons install -c --prefix=." % (evio_local,evio_version,evio_version,evio_version)
else:
evio_command_scons = "rm libevio*.*; cd %s; tar xvfz evio-%s.tgz; cd evio-%s/ ; scons install -c --prefix=." % (evio_local,evio_version,evio_version)
else:
evio_command_scons = "rm libevio*.*; cd %s; cd evio-%s/ ; scons install -c --prefix=." % (evio_local,evio_version)
print "evio_command_scons = %s" % evio_command_scons
os.system(evio_command_scons)
else:
if not os.path.isdir(evio_local_lib):
if not os.path.exists(evio_tarfile):
evio_command_scons = "cd %s; wget --no-check-certificate https://coda.jlab.org/drupal/system/files/evio-%s.tgz; tar xvfz evio-%s.tgz; cd evio-%s/ ; scons install --prefix=." % (evio_local,evio_version,evio_version,evio_version)
else:
evio_command_scons = "cd %s; tar xvfz evio-%s.tgz; cd evio-%s/ ; scons install --prefix=." % (evio_local,evio_version,evio_version)
else:
evio_command_scons = "cd %s; cd evio-%s/ ; scons install --prefix=." % (evio_local,evio_version)
print "evio_command_scons = %s" % evio_command_scons
os.system(evio_command_scons)
evio_local_lib_files = "%s/*.*" % (evio_local_lib)
evio_command_libcopy = "cp %s ." % (evio_local_lib_files)
print "evio_command_libcopy = %s" % evio_command_libcopy
os.system(evio_command_libcopy)
baseenv.Append(EVIO_LIB = evio_local_lib)
baseenv.Append(EVIO_INC = evio_local_inc)
else:
# evio_command_scons = "cd %s; scons install --prefix=." % evio_instdir
# os.system(evio_command_scons)
baseenv.Append(EVIO_LIB = os.getenv('EVIO_LIBDIR'))
baseenv.Append(EVIO_INC = os.getenv('EVIO_INCDIR'))
print "EVIO lib Directory = %s" % baseenv.subst('$EVIO_LIB')
print "EVIO include Directory = %s" % baseenv.subst('$EVIO_INC')
baseenv.Append(CPPPATH = ['$EVIO_INC'])
#
# end evio environment
#
baseenv.Append(CPPPATH = ['$HA_SRC','$HA_DC'])
####### ROOT Definitions ####################
baseenv.Append(ROOTCONFIG = 'root-config')
baseenv.Append(ROOTCINT = 'rootcint')
try:
baseenv.ParseConfig('$ROOTCONFIG --cflags')
baseenv.ParseConfig('$ROOTCONFIG --libs')
if sys.version_info >= (2, 7):
cmd = baseenv['ROOTCONFIG'] + " --cxx"
baseenv.Replace(CXX = subprocess.check_output(cmd, shell=True).rstrip())
else:
baseenv.Replace(CXX = subprocess.Popen([baseenv['ROOTCONFIG'], '--cxx'], stdout=subprocess.PIPE).communicate()[0].rstrip())
except OSError:
try:
baseenv.Replace(ROOTCONFIG = baseenv['ENV']['ROOTSYS'] + '/bin/root-config')
baseenv.Replace(ROOTCINT = baseenv['ENV']['ROOTSYS'] + '/bin/rootcint')
baseenv.ParseConfig('$ROOTCONFIG --cflags')
baseenv.ParseConfig('$ROOTCONFIG --libs')
if sys.version_info >= (2, 7):
cmd = baseenv['ROOTCONFIG'] + " --cxx"
baseenv.Replace(CXX = subprocess.check_output(cmd, shell=True).rstrip())
else:
baseenv.Replace(CXX = subprocess.Popen([baseenv['ROOTCONFIG'], '--cxx'], stdout=subprocess.PIPE).communicate()[0].rstrip())
except KeyError:
print('!!! Cannot find ROOT. Check if root-config is in your PATH.')
Exit(1)
bld = Builder(action=rootcint)
baseenv.Append(BUILDERS = {'RootCint': bld})
######## Configure Section #######
Export('baseenv')
conf = Configure(baseenv)
if not conf.CheckCXX():
print('!!! Your compiler and/or environment is not correctly configured.')
Exit(0)
#if not conf.CheckFunc('printf'):
if not conf.CheckCC():
print('!!! Your compiler and/or environment is not correctly configured.')
Exit(0)
baseenv = conf.Finish()
######## cppcheck ###########################
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
proceed = "1" or "y" or "yes" or "Yes" or "Y"
if baseenv.subst('$CPPCHECK')==proceed:
is_cppcheck = which('cppcheck')
print "Path to cppcheck is %s\n" % is_cppcheck
if(is_cppcheck == None):
print('!!! cppcheck not found on this system. Check if cppcheck is installed and in your PATH.')
Exit(1)
else:
cppcheck_command = baseenv.Command('cppcheck_report.txt',[],"cppcheck --quiet --enable=all src/ hana_decode/ 2> $TARGET")
print "cppcheck_command = %s" % cppcheck_command
baseenv.AlwaysBuild(cppcheck_command)
####### build source distribution tarball #############
if baseenv.subst('$SRCDIST')==proceed:
baseenv['DISTTAR_FORMAT']='gz'
baseenv.Append(
DISTTAR_EXCLUDEEXTS=['.o','.os','.so','.a','.dll','.cache','.pyc','.cvsignore','.dblite','.log', '.gz', '.bz2', '.zip','.pcm','.supp','.patch','.txt']
, DISTTAR_EXCLUDEDIRS=['.git','VDCsim','bin','scripts','.sconf_temp','tests','work','hana_scaler']
, DISTTAR_EXCLUDERES=[r'Dict\.C$', r'Dict\.h$',r'analyzer',r'\~$',r'\.so\.',r'\.#']
)
tar = baseenv.DistTar("dist/analyzer-"+baseenv.subst('$VERSION'),[baseenv.Dir('#')])
print "tarball target = %s" % tar
### tar_command = 'tar cvz -C .. -f ../' + baseenv.subst('$NAME') + '.tar.gz -X .exclude -V "JLab/Hall A C++ Analysis Software '+baseenv.subst('$VERSION') + ' `date -I`" ' + '../' + baseenv.subst('$NAME') + '/.exclude ' + '../' + baseenv.subst('$NAME') + '/Changelog ' + '../' + baseenv.subst('$NAME') + '/src ' + '../' + baseenv.subst('$NAME') + '/hana_decode ' + '../' + baseenv.subst('$NAME') + '/Makefile ' + '../' + baseenv.subst('$NAME') + '/*.py' + '../' + baseenv.subst('$NAME') + '/SConstruct'
####### Start of main SConstruct ############
hallalib = 'HallA'
dclib = 'dc'
eviolib = 'evio'
baseenv.Append(LIBPATH=['$HA_DIR','$EVIO_LIB','$HA_SRC','$HA_DC'])
baseenv.Prepend(LIBS=[hallalib,dclib,eviolib])
baseenv.Replace(SHLIBSUFFIX = '.so')
baseenv.Append(SHLIBSUFFIX = '.'+baseenv.subst('$VERSION'))
SConscript(dirs = ['./','src/','hana_decode/'],name='SConscript.py',exports='baseenv')
####### End of SConstruct #########
# Local Variables:
# mode: python
# End: