From 2991595bd58c79ea894e3cce25b3e67ad02bb99b Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Tue, 30 Jul 2019 05:02:41 -0400
Subject: [PATCH] fixing scons build scripts

---
 .gitignore      |  2 ++
 SConscript      | 23 ++++++++++++-----------
 include/ehp.hpp |  6 +++++-
 src/SConscript  | 12 +-----------
 src/ehp.cpp     | 10 +++++++---
 5 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/.gitignore b/.gitignore
index 160f5ab..34c990b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,6 @@ src/libehp.a
 src/.*.swp
 src/*.o
 include/.*.swp
+*.os
+*.so
 
diff --git a/SConscript b/SConscript
index 932057a..0e75488 100644
--- a/SConscript
+++ b/SConscript
@@ -17,23 +17,24 @@
 import os
 
 Import('env')
+myenv=env.Clone();
 
-env.Replace(debug=ARGUMENTS.get("debug",0))
-env.Append(CFLAGS=" -DUSE_ELFIO ")
-env.Append(CXXFLAGS=" -DUSE_ELFIO ")
-if int(env['debug']) == 1:
+myenv.Replace(debug=ARGUMENTS.get("debug",0))
+myenv.Append(CFLAGS=" -DUSE_ELFIO=1 ")
+myenv.Append(CXXFLAGS=" -DUSE_ELFIO=1 ")
+if int(myenv['debug']) == 1:
         print "Setting debug mode"
-        env.Append(CFLAGS=" -g ")
-        env.Append(CXXFLAGS=" -g ")
-        env.Append(LINKFLAGS=" -g ")
+        myenv.Append(CFLAGS=" -g ")
+        myenv.Append(CXXFLAGS=" -g ")
+        myenv.Append(LINKFLAGS=" -g ")
 else:
         print "Setting release mode"
-        env.Append(CFLAGS=" -O3 ")
-        env.Append(CXXFLAGS=" -O3 ")
-        env.Append(LINKFLAGS=" -O3 ")
+        myenv.Append(CFLAGS=" -O3 ")
+        myenv.Append(CXXFLAGS=" -O3 ")
+        myenv.Append(LINKFLAGS=" -O3 ")
 
 
-lib=SConscript("src/SConscript")
+lib=myenv.SConscript("src/SConscript")
 
 Return('lib')
 
diff --git a/include/ehp.hpp b/include/ehp.hpp
index a67d653..d8d8d38 100644
--- a/include/ehp.hpp
+++ b/include/ehp.hpp
@@ -25,6 +25,10 @@
 #include <vector>
 
 
+#ifndef USE_ELFIO 
+#define USE_ELFIO 1
+#endif
+
 namespace EHP
 {
 
@@ -196,7 +200,7 @@ class EHFrameParser_t
 	virtual const CIEVector_t* getCIEs() const =0;
 	virtual const FDEContents_t* findFDE(uint64_t addr) const =0; 
 
-#ifdef USE_ELFIO
+#if USE_ELFIO 
 	static unique_ptr<const EHFrameParser_t> factory(const string filename);
 #endif
 	static unique_ptr<const EHFrameParser_t> factory(
diff --git a/src/SConscript b/src/SConscript
index 6acef90..189ce76 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -26,20 +26,10 @@ cpppath='''
 	'''
 cpppath=cpppath+Dir('.').srcnode().abspath+'/../third-party/elfio-code'
 
-AddOption('--no_elfio',
-          dest='no_elfio',
-          action='store_true',
-          default=False,
-          help='Do not use Elfio library to parse elf files')
-
-cpp_defines={}
-if( not GetOption('no_elfio')):
-    cpp_defines['USE_ELFIO']=1
-
 LIBPATH="$SECURITY_TRANSFORMS_HOME/lib"
 LIBS=Split("")
 
-myenv=myenv.Clone(CPPPATH=Split(cpppath),CPPDEFINES=cpp_defines)
+myenv=myenv.Clone(CPPPATH=Split(cpppath))
 myenv.Append(CXXFLAGS = " -std=c++11 -Wall -Werror -fmax-errors=2 -fPIC ")
 
 lib1=myenv.Library("ehp",  Split(files), LIBPATH=LIBPATH, LIBS=LIBS)
diff --git a/src/ehp.cpp b/src/ehp.cpp
index 02b6305..3e8fe15 100644
--- a/src/ehp.cpp
+++ b/src/ehp.cpp
@@ -29,7 +29,11 @@
 #include "ehp_priv.hpp"
 #include "scoop_replacement.hpp"
 
-#ifdef USE_ELFIO
+#ifndef USE_ELFIO
+#define USE_ELFIO 1
+#endif
+
+#if USE_ELFIO 
 #include <elfio/elfio.hpp>
 #endif
 #include <elf.h>
@@ -37,7 +41,7 @@
 using namespace std;
 using namespace EHP;
 
-#ifdef USE_ELFIO
+#if USE_ELFIO
 using namespace ELFIO;
 #endif
 
@@ -1949,7 +1953,7 @@ const FDEContents_t* split_eh_frame_impl_t<ptrsize>::findFDE(uint64_t addr) cons
 	return raw_ret_ptr;
 }
 
-#ifdef USE_ELFIO
+#if USE_ELFIO
 unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory(const string filename)
 {
 	auto elfiop=unique_ptr<elfio>(new elfio);
-- 
GitLab