From a2f1db27db7b77ab6c5d1cce0f6329ba45c09ea7 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Thu, 13 Apr 2017 14:28:14 +0200 Subject: [PATCH 1/3] Search for *both* libfd binutil specific and generic one. --- bootstrap/cmake_modules/FindLibbfd.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/cmake_modules/FindLibbfd.cmake b/bootstrap/cmake_modules/FindLibbfd.cmake index 7b7b5e89..782af707 100644 --- a/bootstrap/cmake_modules/FindLibbfd.cmake +++ b/bootstrap/cmake_modules/FindLibbfd.cmake @@ -35,7 +35,7 @@ ENV CPATH) # Ugly, yes ugly... - find_library(LIBBFD_BFD_LIBRARY NAMES bfd-${BINUTILS_VERSION} + find_library(LIBBFD_BFD_LIBRARY NAMES bfd-${BINUTILS_VERSION} bfd PATHS /usr/lib /usr/lib64 /usr/local/lib From 4126a5340602937fc54707d03f2e694dfdfe032c Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Thu, 13 Apr 2017 17:04:35 +0200 Subject: [PATCH 2/3] More reliable detection of libbfd. --- bootstrap/cmake_modules/FindLibbfd.cmake | 104 ++++++++++++----------- hurricane/src/hurricane/Backtrace.cpp | 2 + 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/bootstrap/cmake_modules/FindLibbfd.cmake b/bootstrap/cmake_modules/FindLibbfd.cmake index 782af707..edb6ab30 100644 --- a/bootstrap/cmake_modules/FindLibbfd.cmake +++ b/bootstrap/cmake_modules/FindLibbfd.cmake @@ -23,59 +23,61 @@ OUTPUT_VARIABLE LD_MESSAGE OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX REPLACE "GNU ld version ([^ ]+) .*" "\\1" BINUTILS_VERSION ${LD_MESSAGE} ) - message("-- Using system specific BFD library: " ${BINUTILS_VERSION}) + if(RETURN_CODE EQUAL 0) + string(REGEX REPLACE "GNU ld version ([^ ]+) .*" "\\1" BINUTILS_VERSION ${LD_MESSAGE} ) + message("-- Using system specific BFD library: " ${BINUTILS_VERSION}) - find_path(LIBBFD_INCLUDE_DIRS NAMES bfd.h - dis-asm.h - PATHS /usr/include - /usr/local/include - /opt/local/include - /opt/include - ENV CPATH) + find_path(LIBBFD_INCLUDE_DIRS NAMES bfd.h + dis-asm.h + PATHS /usr/include + /usr/local/include + /opt/local/include + /opt/include + ENV CPATH) -# Ugly, yes ugly... - find_library(LIBBFD_BFD_LIBRARY NAMES bfd-${BINUTILS_VERSION} bfd - PATHS /usr/lib - /usr/lib64 - /usr/local/lib - /usr/local/lib64 - /usr/include - /opt/local/lib - /opt/usr/lib64 - ENV LIBRARY_PATH - ENV LD_LIBRARY_PATH) - -#find_library (LIBBFD_IBERTY_LIBRARY NAMES iberty -# PATHS /usr/lib -# /usr/lib64 -# /usr/local/lib -# /usr/local/lib64 -# /usr/include -# /opt/local/lib -# /opt/usr/lib64 -# ENV LIBRARY_PATH -# ENV LD_LIBRARY_PATH) - -#find_library (LIBBFD_OPCODES_LIBRARY NAMES opcodes -# PATHS /usr/lib -# /usr/lib64 -# /usr/local/lib -# /usr/local/lib64 -# /usr/include -# /opt/local/lib -# /opt/usr/lib64 -# ENV LIBRARY_PATH -# ENV LD_LIBRARY_PATH) - - include(FindPackageHandleStandardArgs) - - find_package_handle_standard_args(LIBBFD DEFAULT_MSG - LIBBFD_BFD_LIBRARY -# LIBBFD_IBERTY_LIBRARY -# LIBBFD_OPCODES_LIBRARY - LIBBFD_INCLUDE_DIRS) - + # Ugly, yes ugly... + find_library(LIBBFD_BFD_LIBRARY NAMES bfd-${BINUTILS_VERSION} bfd + PATHS /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /usr/include + /opt/local/lib + /opt/usr/lib64 + ENV LIBRARY_PATH + ENV LD_LIBRARY_PATH) + + #find_library (LIBBFD_IBERTY_LIBRARY NAMES iberty + # PATHS /usr/lib + # /usr/lib64 + # /usr/local/lib + # /usr/local/lib64 + # /usr/include + # /opt/local/lib + # /opt/usr/lib64 + # ENV LIBRARY_PATH + # ENV LD_LIBRARY_PATH) + + #find_library (LIBBFD_OPCODES_LIBRARY NAMES opcodes + # PATHS /usr/lib + # /usr/lib64 + # /usr/local/lib + # /usr/local/lib64 + # /usr/include + # /opt/local/lib + # /opt/usr/lib64 + # ENV LIBRARY_PATH + # ENV LD_LIBRARY_PATH) + + include(FindPackageHandleStandardArgs) + + find_package_handle_standard_args(LIBBFD DEFAULT_MSG + LIBBFD_BFD_LIBRARY + # LIBBFD_IBERTY_LIBRARY + # LIBBFD_OPCODES_LIBRARY + LIBBFD_INCLUDE_DIRS) + endif() + if(LIBBFD_FOUND) add_definitions(-DHAVE_LIBBFD) endif() diff --git a/hurricane/src/hurricane/Backtrace.cpp b/hurricane/src/hurricane/Backtrace.cpp index 873898ab..aad56166 100644 --- a/hurricane/src/hurricane/Backtrace.cpp +++ b/hurricane/src/hurricane/Backtrace.cpp @@ -82,6 +82,8 @@ #if (defined __linux__ || defined __FreeBSD__ || defined __APPLE__) #include #ifdef HAVE_LIBBFD +#define PACKAGE "Hurricane" +#define PACKAGE_VERSION "no_version" #include #endif #endif From 2396ff7120dff773be5d500639d49d69af010a8a Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Fri, 14 Apr 2017 12:09:48 +0200 Subject: [PATCH 3/3] Fully automatic shell detection. Automatic switch to Debug. --- bootstrap/coriolisEnv.py | 98 ++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 38 deletions(-) diff --git a/bootstrap/coriolisEnv.py b/bootstrap/coriolisEnv.py index 8bfc0f9c..34940328 100755 --- a/bootstrap/coriolisEnv.py +++ b/bootstrap/coriolisEnv.py @@ -9,26 +9,35 @@ import subprocess import optparse -coriolisPattern = re.compile ( r".*coriolis.*" ) +reCoriolisPattern = re.compile( r".*coriolis.*" ) +reReleaseSharedPattern = re.compile( r".*Release\.Shared.*" ) +reReleaseStaticPattern = re.compile( r".*Release\.Static.*" ) +reDebugSharedPattern = re.compile( r".*Debug\.Shared.*" ) +reDebugStaticPattern = re.compile( r".*Debug\.Static.*" ) -def stripPath ( pathName ): - pathEnv = os.getenv ( pathName ) +def scrubPath ( pathName ): + pathEnv = os.getenv( pathName ) if not pathEnv: return "" - pathList = string.split ( pathEnv, ':' ) - strippedList = [] + pathList = string.split( pathEnv, ':' ) + scrubbedList = [] for pathElement in pathList: - if not coriolisPattern.match(pathElement): - strippedList += [ pathElement ] + if reCoriolisPattern .match(pathElement) \ + or reReleaseSharedPattern.match(pathElement) \ + or reReleaseStaticPattern.match(pathElement) \ + or reDebugSharedPattern .match(pathElement) \ + or reDebugStaticPattern .match(pathElement): + continue + scrubbedList += [ pathElement ] - if len(strippedList) == 0: return "" + if len(scrubbedList) == 0: return "" - strippedEnv = strippedList[0] - for pathElement in strippedList[1:]: - strippedEnv += ":" + pathElement + scrubbedEnv = scrubbedList[0] + for pathElement in scrubbedList[1:]: + scrubbedEnv += ":" + pathElement - return strippedEnv + return scrubbedEnv def guessOs (): @@ -131,25 +140,31 @@ def guessOs (): return (osType,libDir,useDevtoolset2) -def guessCsh (): - cshBins = [ '/usr/bin/tcsh' - , '/bin/tcsh' - , '/usr/pkg/bin/tcsh' - , '/usr/bin/csh' - , '/bin/csh' - , '/usr/pkg/bin/csh' - ] - for cshBin in cshBins: - if os.path.isfile(cshBin): return cshBin - return None - - def guessShell (): - if os.environ.has_key('SHELL'): return os.environ['SHELL'] + # This environement variable cannot be trusted as it is set once when + # the user logs in. If aftewards it changes it that variable is *not* + # affected :-(. + #if os.environ.has_key('SHELL'): return os.environ['SHELL'] - # If SHELL is not set, it is likely we are under C-Shell variant. - # Look for standard places where the binaries are expecteds. - return guessCsh() + psCommand = subprocess.Popen ( ['ps', '-p', str(os.getppid()) ], stdout=subprocess.PIPE ) + shell = psCommand.stdout.readlines()[1][:-1].split()[-1] + whichCommand = subprocess.Popen ( ['which', shell ], stdout=subprocess.PIPE ) + shellPath = whichCommand.stdout.readlines()[0][:-1] + + isBourneShell = True + cshBins = [ '/usr/bin/tcsh' + , '/bin/tcsh' + , '/usr/pkg/bin/tcsh' + , '/usr/local/bin/tcsh' + , '/usr/bin/csh' + , '/bin/csh' + , '/usr/pkg/bin/csh' + , '/usr/local/bin/csh' + ] + if shellPath in cshBins: isBourneShell = False + #print 'GUESSED SHELL: "%s"' % shellPath + + return shellPath, isBourneShell @@ -159,13 +174,12 @@ if __name__ == "__main__": buildType = "Release" linkType = "Shared" rootDir = None - shellBin = guessShell() + shellBin, isBourneShell = guessShell() parser = optparse.OptionParser () # Build relateds. parser.add_option ( "--query-inst-root", action="store_true" , dest="queryInstRoot" ) parser.add_option ( "--query-isys-root", action="store_true" , dest="queryISysRoot" ) - parser.add_option ( "--csh" , action="store_true" , dest="csh" ) parser.add_option ( "--release" , action="store_true" , dest="release" ) parser.add_option ( "--debug" , action="store_true" , dest="debug" ) parser.add_option ( "--devel" , action="store_true" , dest="devel" ) @@ -176,7 +190,6 @@ if __name__ == "__main__": parser.add_option ( "--root" , action="store" , type="string", dest="rootDir" ) ( options, args ) = parser.parse_args () - if options.csh: shellBin = guessCsh() if options.release: buildType = "Release" if options.debug: buildType = "Debug" if options.devel: buildType = "Debug" @@ -184,13 +197,16 @@ if __name__ == "__main__": if options.shared: linkType = "Shared" if options.rootDir: rootDir = options.rootDir + scriptPath = os.path.abspath(os.path.dirname(sys.argv[0])) + if 'Debug.' in scriptPath: buildType = 'Debug' + if not shellBin: print 'echo "[ERROR] coriolisEnv.py was not able to guess/find the current shell interpeter."' sys.exit( 1 ) - strippedPath = stripPath ( "PATH" ) - strippedLibraryPath = stripPath ( "LD_LIBRARY_PATH" ) - strippedPythonPath = stripPath ( "PYTHONPATH" ) + strippedPath = scrubPath( "PATH" ) + strippedLibraryPath = scrubPath( "LD_LIBRARY_PATH" ) + strippedPythonPath = scrubPath( "PYTHONPATH" ) shellScriptSh = \ 'echo "%(MESSAGE)s";' \ @@ -246,6 +262,10 @@ if __name__ == "__main__": strippedPath = "%s/bin:%s" % ( coriolisTop, strippedPath ) strippedLibraryPath = "%s:%s" % ( absLibDir , strippedLibraryPath ) + if not os.path.exists(coriolisTop): + print 'echo "[ERROR] coriolisEnv.py, top directory <%s> do not exists."' % coriolisTop + sys.exit( 1 ) + if not options.nopython: pyVersion = sys.version_info version = "%d.%d" % (pyVersion[0],pyVersion[1]) @@ -281,11 +301,13 @@ if __name__ == "__main__": shellScriptSh += "hash -r;" shellScriptCsh += "rehash;" - if options.csh: shellScript = shellScriptCsh - else: shellScript = shellScriptSh + if isBourneShell: shellScript = shellScriptSh + else: shellScript = shellScriptCsh if useDevtoolset2: - shellScript += ' scl enable devtoolset-2 %(SHELL)s' + shellScript += \ + ' echo "Launching a devtoolset-2 subshell though scl (CTRL+D to exit).";' \ + ' scl enable devtoolset-2 %(SHELL)s' evalScript = shellScript % { "PATH" : strippedPath , "LD_LIBRARY_PATH" : strippedLibraryPath