From 03b667871d2d9fd0afa173cda1dedcc22bc2668c Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Wed, 4 Oct 2017 19:57:27 -0400
Subject: [PATCH] Update SCons setup to match podd setup and other cleanup  
 Eliminate duplicated/redundant configuration code in SCons system   Let SCons
 also clean ROOT 6's *_rdict.pcm class layout cache files   Move helper python
 script to site_scons   Remove EVIO from scons as podd build will take care of
 it.   Remove define of HALLC_MODS in SConstruct     (There is no longer any
 Hall C conditional code in Podd)

---
 SConscript.py                         |   2 +
 SConstruct                            | 197 +++++---------------------
 configure.py                          |  59 --------
 podd                                  |   2 +-
 site_scons/configure.py               | 111 +++++++++++++++
 darwin64.py => site_scons/darwin64.py |   0
 linux32.py => site_scons/linux32.py   |   0
 linux64.py => site_scons/linux64.py   |   0
 site_scons/rootcint.py                |  18 +++
 9 files changed, 168 insertions(+), 221 deletions(-)
 delete mode 100644 configure.py
 create mode 100644 site_scons/configure.py
 rename darwin64.py => site_scons/darwin64.py (100%)
 rename linux32.py => site_scons/linux32.py (100%)
 rename linux64.py => site_scons/linux64.py (100%)
 create mode 100644 site_scons/rootcint.py

diff --git a/SConscript.py b/SConscript.py
index 6ecc2d2..0afd3d2 100644
--- a/SConscript.py
+++ b/SConscript.py
@@ -33,6 +33,7 @@ os.system(cmd)
 hcheaders = Glob('src/*.h',exclude=['src/HallC_LinkDef.h'])+Glob('src/HallC_LinkDef.h')
 
 pbaseenv.RootCint(roothcdict,hcheaders)
+pbaseenv.Clean(roothcdict,re.sub(r'\.C\Z','_rdict.pcm',roothcdict))
 pbaseenv.SharedObject(target = roothcobj, source = roothcdict)
 
 #######  Start of main SConscript ###########
@@ -42,3 +43,4 @@ print ('LIBS = %s\n' % pbaseenv.subst('$LIBS'))
 analyzer = pbaseenv.Program(target = 'hcana', source = 'src/main.o')
 pbaseenv.Install('./bin',analyzer)
 pbaseenv.Alias('install',['./bin'])
+#pbaseenv.Clean(analyzer,)
diff --git a/SConstruct b/SConstruct
index f772154..d2ae17d 100644
--- a/SConstruct
+++ b/SConstruct
@@ -3,10 +3,12 @@
 ###### Author:	Edward Brash (brash@jlab.org) June 2013
 
 import os
-import sys
-import platform
-import commands
+#import sys
+#import platform
+#import commands
 import SCons
+import configure
+from rootcint import rootcint
 import subprocess
 
 ####### Check SCons version ##################
@@ -14,12 +16,7 @@ print('!!! Building the Hall C analyzer and libraries with SCons requires')
 print('!!! SCons version 2.5.0 or newer.')
 EnsureSConsVersion(2,5,0)
 
-baseenv = Environment(ENV = os.environ)
-#dict = baseenv.Dictionary()
-#keys = dict.keys()
-#keys.sort()
-#for key in keys:
-#	print "Construction variable = '%s', value = '%s'" % (key, dict[key])
+baseenv = Environment(ENV = os.environ,tools=["default"],toolpath=['site_scons'])
 
 ####### Hall A Build Environment #############
 #
@@ -43,163 +40,16 @@ print ("Hall A 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)
+baseenv.Append(CPPPATH = ['$HC_SRC','$HA_SRC','$HA_DC'])
 
-######## ROOT Dictionaries #########
-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.Append(ROOTCONFIG = 'root-config')
-try:
-        baseenv.PrependENVPath('PATH',baseenv['ENV']['ROOTSYS'] + '/bin')
-except KeyError:
-        pass    # ROOTSYS not defined
-
-try:
-        baseenv.ParseConfig('$ROOTCONFIG --cflags --glibs')
-        if sys.version_info >= (2, 7):
-                cmd = baseenv['ROOTCONFIG'] + " --cxx"
-                baseenv.Replace(CXX = subprocess.check_output(cmd, shell=True).rstrip())
-                cmd = baseenv['ROOTCONFIG'] + " --version"
-                baseenv.Replace(ROOTVERS = subprocess.check_output(cmd, shell=True).rstrip())
-        else:
-                baseenv.Replace(CXX = subprocess.Popen([baseenv['ROOTCONFIG'], '--cxx'],\
-                                        stdout=subprocess.PIPE).communicate()[0].rstrip())
-                baseenv.Replace(ROOTVERS = subprocess.Popen([baseenv['ROOTCONFIG'],\
-                        '--version'],stdout=subprocess.PIPE).communicate()[0].rstrip())
-        if platform.system() == 'Darwin':
-                try:
-                        baseenv.Replace(LINKFLAGS = baseenv['LINKFLAGS'].remove('-pthread'))
-                except:
-                        pass #  '-pthread' was not present in LINKFLAGS
-except OSError:
-        print('!!! Cannot find ROOT.  Check if root-config is in your PATH.')
-        Exit(1)
+configure.FindROOT(baseenv)
 
 bld = Builder(action=rootcint)
 baseenv.Append(BUILDERS = {'RootCint': bld})
-#
-# 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_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.tar.gz" % (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 https://github.com/JeffersonLab/hallac_evio/archive/evio-%s.tar.gz; tar xvfz evio-%s.tar.gz; mv hallac_evio-evio-%s evio-%s; cd evio-%s/ ; scons install -c --prefix=." % (evio_local,evio_version,evio_version,evio_version,evio_version,evio_version)
-			else:
-				evio_command_scons = "rm libevio*.*; cd %s; tar xvfz evio-%s.tar.gz; mv hallac_evio-evio-%s evio-%s; cd evio-%s/ ; scons install -c --prefix=." % (evio_local,evio_version,evio_version,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 %s" % (evio_local_lib_files,baseenv.subst('$HA_DIR'))
-		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 = ['$HC_SRC','$HA_SRC','$HA_DC'])
-
-proceed = "1" or "y" or "yes" or "Yes" or "Y"
-######## Configure Section #######
-
-import configure
-configure.config(baseenv,ARGUMENTS)
-
-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'):
-       	print('!! Your compiler and/or environment is not correctly configured.')
-       	Exit(0)
-
-if baseenv.subst('$CHECKHEADERS')==proceed:
-	system_header_list = ['arpa/inet.h','errno.h','assert.h','netdb.h','netinet/in.h','pthread.h','signal.h','stddef.h','stdio.h','stdlib.h','string.h','strings.h','sys/ioctl.h','sys/socket.h','sys/time.h','sys/types.h','time.h','unistd.h','memory.h','math.h','limits.h']
-
-	for header_file in system_header_list:
-		if not conf.CheckHeader(header_file):
-			print('!! Header file %s not found.' % header_file)
-			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)
@@ -211,6 +61,30 @@ if baseenv.subst('$CPPCHECK')==proceed:
 		cppcheck_command = baseenv.Command('cppcheck_report.txt',[],"cppcheck --quiet --enable=all src/ 2> $TARGET")
 		baseenv.AlwaysBuild(cppcheck_command)
 
+######## Configure Section #######
+
+if not (baseenv.GetOption('clean') or baseenv.GetOption('help')):
+
+        configure.config(baseenv,ARGUMENTS)
+
+        conf = Configure(baseenv)
+        if not conf.CheckCXX():
+                print('!!! Your compiler and/or environment is not correctly configured.')
+                Exit(1)
+        # if not conf.CheckFunc('printf'):
+        #         print('!!! Your compiler and/or environment is not correctly configured.')
+        #         Exit(1)
+        if conf.CheckCXXHeader('sstream'):
+                conf.env.Append(CPPDEFINES = 'HAS_SSTREAM')
+        baseenv = conf.Finish()
+
+Export('baseenv')
+
+#print (baseenv.Dump())
+#print ('CXXFLAGS = ', baseenv['CXXFLAGS'])
+#print ('LINKFLAGS = ', baseenv['LINKFLAGS'])
+#print ('SHLINKFLAGS = ', baseenv['SHLINKFLAGS'])
+
 ####### Start of main SConstruct ############
 
 hallclib = 'HallC'
@@ -220,9 +94,10 @@ eviolib = 'evio'
 
 baseenv.Append(LIBPATH=['$HC_DIR','$EVIO_LIB','$HA_DIR','$HC_SRC','$HA_SRC','$HA_DC'])
 baseenv.Replace(SHLIBSUFFIX = '.so')
-baseenv.Append(CPPDEFINES = '-DHALLC_MODS')
+baseenv.Replace(SOSUFFIX = baseenv.subst('$SHLIBSUFFIX'))
+#baseenv.Replace(SHLIBSUFFIX = '.so')
+baseenv.Append(SHLIBSUFFIX = '.'+baseenv.subst('$VERSION'))
 
-baseenv.Append(SHLIBSUFFIX ='.'+baseenv.subst('$VERSION'))
 pbaseenv=baseenv.Clone()
 pbaseenv.Prepend(LIBS=[hallclib,hallalib,dclib,eviolib])
 baseenv.Prepend(LIBS=[hallalib,dclib,eviolib])
diff --git a/configure.py b/configure.py
deleted file mode 100644
index b88a0ed..0000000
--- a/configure.py
+++ /dev/null
@@ -1,59 +0,0 @@
-import platform
-import os
-
-def config(env,args):
-
-	if env['PLATFORM'] == 'posix':
-      		if (platform.machine() == 'x86_64'):
-        		print "Got a 64-bit processor, I can do a 64-bit build in theory..."
-			for element in platform.architecture():
-         			if (element == '32bit'):
-             				print '32-bit Linux build'
-             				env['MEMORYMODEL'] = '32bit'
-             				import linux32
-             				linux32.config(env, args)
-					break
-         			elif (element == '64bit'):
-             				print '64-bit Linux build'
-             				env['MEMORYMODEL'] = '64bit'
-             				import linux64
-             				linux64.config(env, args)
-					break
-         			else:
-             				print 'Memory model not specified, so I\'m building 32-bit...'
-             				env['MEMORYMODEL'] = '32bit'
-             				import linux32
-             				linux32.config(env, args)
-      		else:
-          		print '32-bit Linux Build.'
-          		env['MEMORYMODEL'] = '32bit'
-          		import linux32
-          		linux32.config(env, args)
-#	elif env['PLATFORM'] == 'win32':
-#      		if (os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64' or (os.environ.has_key('PROCESSOR_ARCHITEW6432') and os.environ['PROCESSOR_ARCHITEW6432'] == 'AMD64')):
-#         		print "Got a 64-bit processor, I can do a 64-bit build in theory..."
-#         		if args.get('32bit', 0):
-#            			print '32-bit Windows build.'
-#            			#import win6432
-#            			#win6432.config(env, args)
-#         		elif args.get('64bit', 0):
-#            			print '64-bit Windows build.'
-#            			#import win64
-#            			#win64.config(env, args)
-#         		else:
-#            			print 'Memory model not specified, so I\'m building 32-bit.'
-#            			#import win6432
-#            			#win6432.config(env, args)
-#      		else:
-#			print '32-bit Windows build.'
-#         		#import win32
-#         		#win32.config(env, args)
-	elif env['PLATFORM'] == 'darwin':
-      		print 'OS X Darwin is a 64-bit build.'
-      		env['MEMORYMODEL'] = '64bit'
-      		import darwin64
-      		darwin64.config(env, args)
-	else:
-      		print 'ERROR! unrecognized platform.  Twonk.'
-
-#end configure.py
diff --git a/podd b/podd
index bcaa7a4..f91a6ea 160000
--- a/podd
+++ b/podd
@@ -1 +1 @@
-Subproject commit bcaa7a496ce8508a81731a2e4c0ee3cf38641d3a
+Subproject commit f91a6ea6e929b10969f7ce405ac2e409afd8a39a
diff --git a/site_scons/configure.py b/site_scons/configure.py
new file mode 100644
index 0000000..0225457
--- /dev/null
+++ b/site_scons/configure.py
@@ -0,0 +1,111 @@
+import sys
+import platform
+import os
+import subprocess
+
+def config(env,args):
+
+	if env['PLATFORM'] == 'posix':
+      		if (platform.machine() == 'x86_64'):
+        		print "Got a 64-bit processor, I can do a 64-bit build in theory..."
+			for element in platform.architecture():
+         			if (element == '32bit'):
+             				print '32-bit Linux build'
+             				env['MEMORYMODEL'] = '32bit'
+             				import linux32
+             				linux32.config(env, args)
+					break
+         			elif (element == '64bit'):
+             				print '64-bit Linux build'
+             				env['MEMORYMODEL'] = '64bit'
+             				import linux64
+             				linux64.config(env, args)
+					break
+         			else:
+             				print 'Memory model not specified, so I\'m building 32-bit...'
+             				env['MEMORYMODEL'] = '32bit'
+             				import linux32
+             				linux32.config(env, args)
+      		else:
+          		print '32-bit Linux Build.'
+          		env['MEMORYMODEL'] = '32bit'
+          		import linux32
+          		linux32.config(env, args)
+#	elif env['PLATFORM'] == 'win32':
+#      		if (os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64' or (os.environ.has_key('PROCESSOR_ARCHITEW6432') and os.environ['PROCESSOR_ARCHITEW6432'] == 'AMD64')):
+#         		print "Got a 64-bit processor, I can do a 64-bit build in theory..."
+#         		if args.get('32bit', 0):
+#            			print '32-bit Windows build.'
+#            			#import win6432
+#            			#win6432.config(env, args)
+#         		elif args.get('64bit', 0):
+#            			print '64-bit Windows build.'
+#            			#import win64
+#            			#win64.config(env, args)
+#         		else:
+#            			print 'Memory model not specified, so I\'m building 32-bit.'
+#            			#import win6432
+#            			#win6432.config(env, args)
+#      		else:
+#			print '32-bit Windows build.'
+#         		#import win32
+#         		#win32.config(env, args)
+	elif env['PLATFORM'] == 'darwin':
+      		print 'OS X Darwin is a 64-bit build.'
+      		env['MEMORYMODEL'] = '64bit'
+      		import darwin64
+      		darwin64.config(env, args)
+	else:
+      		print 'ERROR! unrecognized platform.  Twonk.'
+
+# which() utility
+def which(program):
+        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
+
+####### ROOT Definitions ####################
+def FindROOT(env, need_glibs = True):
+        root_config = 'root-config'
+        try:
+                env.PrependENVPath('PATH',env['ENV']['ROOTSYS'] + '/bin')
+        except KeyError:
+                pass    # ROOTSYS not defined
+
+        try:
+                if need_glibs:
+                        env.ParseConfig(root_config + ' --cflags --glibs')
+                else:
+                        env.ParseConfig(root_config + ' --cflags --libs')
+                if sys.version_info >= (2, 7):
+                        cmd = root_config + ' --cxx'
+                        env.Replace(CXX = subprocess.check_output(cmd, shell=True).rstrip())
+                        cmd = root_config + ' --version'
+                        env.Replace(ROOTVERS = subprocess.check_output(cmd, shell=True).rstrip())
+                else:
+                        env.Replace(CXX = subprocess.Popen([root_config, '--cxx'],\
+                                stdout=subprocess.PIPE).communicate()[0].rstrip())
+                        env.Replace(ROOTVERS = subprocess.Popen([root_config,\
+                                '--version'],stdout=subprocess.PIPE).communicate()[0].rstrip())
+                if platform.system() == 'Darwin':
+                        try:
+                                env.Replace(LINKFLAGS = env['LINKFLAGS'].remove('-pthread'))
+                        except:
+                                pass #  '-pthread' was not present in LINKFLAGS
+
+        except OSError:
+                print('!!! Cannot find ROOT.  Check if root-config is in your PATH.')
+                env.Exit(1)
+
+#end configure.py
diff --git a/darwin64.py b/site_scons/darwin64.py
similarity index 100%
rename from darwin64.py
rename to site_scons/darwin64.py
diff --git a/linux32.py b/site_scons/linux32.py
similarity index 100%
rename from linux32.py
rename to site_scons/linux32.py
diff --git a/linux64.py b/site_scons/linux64.py
similarity index 100%
rename from linux64.py
rename to site_scons/linux64.py
diff --git a/site_scons/rootcint.py b/site_scons/rootcint.py
new file mode 100644
index 0000000..958ad17
--- /dev/null
+++ b/site_scons/rootcint.py
@@ -0,0 +1,18 @@
+# rootcint.py
+
+import os
+
+def rootcint(target,source,env):
+        """Executes the ROOT dictionary generator over a list of headers."""
+        dictname = target[0]
+        cpppath = env.subst('$_CCCOMCOM')
+#        ccflags = env.subst('$CCFLAGS')
+#        print ("Doing rootcint call now ...")
+        headers = ""
+        for f in source:
+                headers += str(f) + " "
+        command = "rootcint -f %s -c %s %s" % (dictname,cpppath,headers)
+#	print ('RootCint Command = %s\n' % command)
+        ok = os.system(command)
+        return ok
+
-- 
GitLab