diff --git a/Wrapping/Common/mitk_swig_common.i b/Wrapping/Common/mitk_swig_common.i index cdcbc58efa..42cf0b1f73 100644 --- a/Wrapping/Common/mitk_swig_common.i +++ b/Wrapping/Common/mitk_swig_common.i @@ -1,37 +1,37 @@ // Ignore common warnings: // 302 : Redefinition of Macro, usually not a problem // 362 : Operator= is ignored. Can't help it. // 503 : Can't wrap operator of type "*" unless renamed to a valid identifier, no problem as operator not needed. // 509 : Overloaded function ignored. Usually not a problem, as overloaded functions shouldn't give different results. // 511 : Can't use keyword arguments with overloaded functions #pragma SWIG nowarn=302,362,503,509,511 -// Splitted the information about the addition files into sub-files: +// Split the information about the additional files into sub-files: %naturalvar; // Includes of STD-Files goes in here %include // Include c++ code in this file. It is basically a c++-header wrapped in the commands so it is included in the std-file %include // SWIG-Macro definition goes in here, for example SWIG_ADD_MITK_CLASS %include // information about classes that are going to be wrapped are in here: %include // // How to wrap a new class: // ------------------------------------ // (1. Add the c++ include file to mitk_swig_cpp_include.i // If the class is in a new module, make sure that this module is added as dependency in cmake ) // This step should no longer be necessary as the corresponding header is now included by // the SWIG_ADD_MITK_CLASS macro. // 2. Add the class definition in mitk_swig_classes.i // If the definition of the class needs new macros, for example because it is not in the core // and has a new Export-Macro, be sure to define this macro first. // If the class inherit from mitk::BaseData use the SWIG_ADD_MITK_CLASS macro, as it defines // some redundante code. // std::vector mitk::GetImageSize(mitk::Image::Pointer image); \ No newline at end of file diff --git a/Wrapping/Common/mitk_swig_macros.i b/Wrapping/Common/mitk_swig_macros.i index f3f8c589a5..1d8c746414 100644 --- a/Wrapping/Common/mitk_swig_macros.i +++ b/Wrapping/Common/mitk_swig_macros.i @@ -1,232 +1,232 @@ // // This file contains macros for swig. // // // MITKSWIG_ADD_HEADERFILE includes a header-file into SWIG // %define MITKSWIG_ADD_HEADERFILE( classinclude ) // Include the given header, where the class definition is found %include < ## classinclude ## > // Include the include file in the generated cpp file %{ #include < ## classinclude ## > %} %enddef // // MITKSWIG_ADD_CLASS is a helper macro in order to do // all important stuff in order to wrap an existing // class // %define MITKSWIG_ADD_CLASS(classname, classinclude, nspace) MITKSWIG_ADD_HEADERFILE( classinclude ) // Using class name in order to remove ambigiouties %{ typedef nspace ## :: ## classname classname ## ; using nspace ## :: ## classname ; %} using nspace ##:: ## classname ; // Typedef is necessary to overcome ambigiouties resulting in the fact that SWIG // ignores namespaces. This can lead to some problems with templates. typedef nspace ## :: ## classname classname ## ; %enddef // // MITKSWIG_AUTOMATED_CASTING is a helper macro in order to -// provide a convinience interface for up/downcasting of +// provide a convenience interface for up/downcasting of // classes // %define MITKSWIG_AUTOMATED_CASTING(classname, classinclude, nspace) // Define a conversion method to convert from and to types %template(ConvertTo ## classname) ConvertTo< nspace ##:: ## classname ## >; // This extend is necessary to have the automatic cast methods available %extend itk::SmartPointer< nspace ## :: ## classname ## ::Self> { %pythoncode %{ def _GetListOfValidItems(self): return [str(k) for k in self.GetClassHierarchy() if str(k) in convertion_list.keys() ] %} %pythoncode %{ def __getattr__(self, item): if type(item)==str: if (len(item) > 9) and ('ConvertTo' in item): searchString=item[9:] if searchString in self._GetListOfValidItems(): def func_t(): return convertion_list[searchString](self) return func_t %} %pythoncode %{ def __dir__(self): return super().__dir__() + ['ConvertTo'+k for k in self._GetListOfValidItems()] %} } %extend std::vector< nspace ## :: ## classname *>::value_type { %pythoncode %{ def _GetListOfValidItems(self): return [str(k) for k in self.GetClassHierarchy() if str(k) in convertion_list.keys() ] %} %pythoncode %{ def __getattr__(self, item): if type(item)==str: if (len(item) > 9) and ('ConvertTo' in item): searchString=item[9:] if searchString in self._GetListOfValidItems(): def func_t(): return convertion_list[searchString](self) return func_t %} %pythoncode %{ def __dir__(self): return super().__dir__() + ['ConvertTo'+k for k in self._GetListOfValidItems()] %} } %pythoncode %{ convertion_list['classname'] = ConvertTo ## classname %} %enddef // // MITKSWIG_SMARTPOINTERVECTOR : Wrapper for Vectors of Smartpointer-Classes // %define MITKSWIG_SMARTPOINTERVECTOR(classname, classinclude, nspace) // Initianziation of std. vectors containing pointers to these classes. This allows to use // vectors of these types as target language arrays. %template(Vector ## classname ## Pointer) std::vector< nspace ## :: ## classname ## ::Pointer >; %template(Vector ## classname) std::vector< nspace ## :: ## classname ## ::Self *>; %enddef // // MITKSWIG_POINTERVECTOR : Wrapper for Vectors of Classes // %define MITKSWIG_POINTERVECTOR(classname, classinclude, nspace) // Initianziation of std. vectors containing pointers to these classes. This allows to use // vectors of these types as target language arrays. %template(Vector ## classname ## Pointer) std::vector< nspace ## :: ## classname * >; %template(Vector ## classname) std::vector< nspace ## :: ## classname >; %enddef // // MITKSWIG_MITKSMARTPOINTER_INITIALIZATION : Wrapper for Vectors of Smartpointer-Classes // %define MITKSWIG_MITKSMARTPOINTER_INITIALIZATION(classname, classinclude, nspace) // Declaring that this class is a smart-pointer class, in order to handle // online upcasting where necessary (for example python) %feature("smartptr", noblock=1) nspace ##:: ## classname { itk::SmartPointer } %enddef // // MITKSWIG_MITKSMARTPOINTER_TEMPLATE : Wrapper for Vectors of Smartpointer-Classes // %define MITKSWIG_MITKSMARTPOINTER_TEMPLATE(classname, classinclude, nspace) // Defining the Smartpointer, allows easy access in target language %template(classname ## Pointer) itk::SmartPointer; %enddef // // SWIG_ADD_MITK_CLASS is a helper macro in order to do // all important stuff before an mitk::Class is included. // Requires the name of the class as it is in c++ as classname // and the include file, in which the class is defined. // It is assumed that the class is somehow inherited from // mitk::BaseData, and supports smartpointers. // %define SWIG_ADD_MITK_CLASS_VECTORFREE(classname, classinclude, nspace) %include < ## classinclude ## > MITKSWIG_MITKSMARTPOINTER_INITIALIZATION(classname, classinclude, nspace) MITKSWIG_ADD_CLASS( classname, classinclude, nspace ) class nspace ## :: ## classname ## ; class nspace ## :: ## classname ## ::Pointer; MITKSWIG_MITKSMARTPOINTER_TEMPLATE(classname, classinclude, nspace) MITKSWIG_AUTOMATED_CASTING(classname, classinclude, nspace) %enddef // // SWIG_ADD_MITK_CLASS is a helper macro in order to do // all important stuff before an mitk::Class is included. // Requires the name of the class as it is in c++ as classname // and the include file, in which the class is defined. // It is assumed that the class is somehow inherited from // mitk::BaseData, and supports smartpointers. // %define SWIG_ADD_MITK_CLASS(classname, classinclude, nspace) %include < ## classinclude ## > MITKSWIG_MITKSMARTPOINTER_INITIALIZATION(classname, classinclude, nspace) MITKSWIG_ADD_CLASS( classname, classinclude, nspace ) class nspace ## :: ## classname ## ; class nspace ## :: ## classname ## ::Pointer; // It is important to first define the Vectors and // then define the Smartpointer. Otherwise a SWIG-bug ... MITKSWIG_SMARTPOINTERVECTOR(classname, classinclude, nspace) MITKSWIG_MITKSMARTPOINTER_TEMPLATE(classname, classinclude, nspace) MITKSWIG_AUTOMATED_CASTING(classname, classinclude, nspace) %enddef // // SWIG_ADD_NONOBJECT_CLASS is a helper macro in order to do // all important stuff before an mitk::Class is included. // Requires the name of the class as it is in c++ as classname // and the include file, in which the class is defined. // It is assumed that the class is somehow inherited from // mitk::BaseData, and supports smartpointers. // %define SWIG_ADD_NONOBJECT_CLASS(classname, classinclude, nspace) %include < ## classinclude ## > MITKSWIG_ADD_CLASS( classname, classinclude, nspace ) // Typedef is necessary to overcome ambigiouties resulting in the fact that SWIG // ignores namespaces. This can lead to some problems with templates. typedef nspace ## :: ## classname classname ## ; class nspace ## :: ## classname ## ; MITKSWIG_POINTERVECTOR(classname, classinclude, nspace) %enddef // // SWIG_ADD_NONOBJECT_CLASS is a helper macro in order to do // all important stuff before an mitk::Class is included. // Requires the name of the class as it is in c++ as classname // and the include file, in which the class is defined. // It is assumed that the class is somehow inherited from // mitk::BaseData, and supports smartpointers. // %define SWIG_ADD_NONOBJECT_NOVECTOR_CLASS(classname, classinclude, nspace) %include < ## classinclude ## > MITKSWIG_ADD_CLASS( classname, classinclude, nspace ) // Typedef is necessary to overcome ambigiouties resulting in the fact that SWIG // ignores namespaces. This can lead to some problems with templates. typedef nspace ## :: ## classname classname ## ; // Initianziation of std. vectors containing pointers to these classes. This allows to use // vectors of these types as target language arrays. %template(Vector ## classname ## Pointer) std::vector< nspace ## :: ## classname * >; %enddef diff --git a/Wrapping/Python/CMakeLists.txt b/Wrapping/Python/CMakeLists.txt index 260623b192..cca64accd3 100644 --- a/Wrapping/Python/CMakeLists.txt +++ b/Wrapping/Python/CMakeLists.txt @@ -1,77 +1,77 @@ -# Version 2.8.1 is the minium requirement for this script. +# Version 2.8.1 is the minimum requirement for this script. # this is lower than the general minimum requirement. #cmake_minimum_required ( VERSION 2.8.1 FATAL_ERROR ) include(mitkTargetLinkLibrariesWithDynamicLookup) project( MITK_Python ) set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "" FORCE) set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "" FORCE) mitk_check_dynamic_lookup(MODULE SHARED MITK_UNDEFINED_SYMBOLS_ALLOWED ) # # Find the necessary libraries etc.. # if ( MITK_UNDEFINED_SYMBOLS_ALLOWED ) set( _QUIET_LIBRARY "QUIET" ) else() set( _QUIET_LIBRARY "REQUIRED" ) endif() find_package ( PythonInterp REQUIRED ) find_package ( PythonLibs ${_QUIET_LIBRARY} ) include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ) # # Options # option ( MITK_PYTHON_THREADS "Enable threaded python usage by unlocking the GIL." ON ) mark_as_advanced( MITK_PYTHON_THREADS ) option ( MITK_PYTHON_EGG "Add building of python eggs to the dist target." OFF ) mark_as_advanced( MITK_PYTHON_EGG ) option ( MITK_PYTHON_WHEEL "Add building of python wheels to the dist target." ON ) mark_as_advanced( MITK_PYTHON_WHEEL ) # Prepare the SWIG-File, i.e. especially add necessary include folders mitkSwigPrepareFiles(pyMITK MITK.i "MitkCore;MitkCLCore;MitkCLUtilities;ITKCommon;MitkMatchPointRegistration;MitkSegmentation;MitkMultilabel;MitkDICOM;MitkDICOMImageIO;MitkRT") # Add additional SWIG Parameters # These parameters depend on the target language set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS} -features autodoc=1 -keyword ) if( MITK_PYTHON_THREADS ) set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} -threads) endif() set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) # Create the actual SWIG project swig_add_module(pyMITK python MITK.i ) mitkSwigAddLibraryDependencies(pyMITK "MitkCore;MitkCLCore;MitkCLUtilities;ITKCommon;MitkMatchPointRegistration;MitkSegmentation;MitkMultilabel;MitkDICOM;MitkDICOMImageIO;MitkRT") mitk_target_link_libraries_with_dynamic_lookup(${SWIG_MODULE_pyMITK_REAL_NAME} ${PYTHON_LIBRARIES}) if(DEFINED SKBUILD) message(WARNING "SKBuild exists") # Currently this installation install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pyMITK.py ${CMAKE_CURRENT_SOURCE_DIR}/Packaging/__init__.py # ${MITK_DOC_FILES} DESTINATION pyMITK COMPONENT Runtime ) install(TARGETS ${SWIG_MODULE_pyMITK_REAL_NAME} RUNTIME DESTINATION pyMITK LIBRARY DESTINATION pyMITK COMPONENT Runtime ) else() message(WARNING "SKBuild missing") include(LegacyPackaging.cmake) endif() diff --git a/Wrapping/Python/LegacyPackaging.cmake b/Wrapping/Python/LegacyPackaging.cmake index 41ff58f18e..f50a11f74e 100644 --- a/Wrapping/Python/LegacyPackaging.cmake +++ b/Wrapping/Python/LegacyPackaging.cmake @@ -1,113 +1,113 @@ if ( MITK_DOC_FILES ) # create a python list for the import documents to include in # packaging # specially handle the first element list( GET MITK_DOC_FILES 0 d ) file(TO_NATIVE_PATH "${d}" d ) set( MITK_DOC_FILES_AS_LIST "[r'${d}'") set( _doc_list "${MITK_DOC_FILES}" ) list( REMOVE_AT _doc_list 0 ) foreach( d ${_doc_list} ) file(TO_NATIVE_PATH "${d}" d ) set( MITK_DOC_FILES_AS_LIST "${MITK_DOC_FILES_AS_LIST},r'${d}'") endforeach() set( MITK_DOC_FILES_AS_LIST "${MITK_DOC_FILES_AS_LIST}]") endif() # Step 1: # Do initial configuration of setup.py with variable a available # at configuration time. set(MITK_BINARY_MODULE "@MITK_BINARY_MODULE@") set(MITK_RUNTIME_PATH "@MITK_RUNTIME_PATH@") set(PYTHON_LIB_DEPENDENCIES "@PYTHON_LIB_DEPENDENCIES@") set(TMP_MITK_BINARY_MODULE "@MITK_BINARY_MODULE@" ) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/Packaging/setup.py.in" "${CMAKE_CURRENT_BINARY_DIR}/Packaging/setup.py.in" ) set(MITK_BINARY_MODULE) # Step 2: # Do file configuration during compilation with generator expressions mitkFunctionGetLibrarySearchPaths(MITK_RUNTIME_PATH release) add_custom_command(TARGET ${SWIG_MODULE_pyMITK_REAL_NAME} POST_BUILD WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMAND ${CMAKE_COMMAND} "-DMITK_BINARY_MODULE=$" "-DMITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY=${MITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "-\"DMITK_RUNTIME_PATH=${MITK_RUNTIME_PATH}\"" "-DCONFIGUREBUILDTIME_filename=${CMAKE_CURRENT_BINARY_DIR}/Packaging/setup.py.in" "-DCONFIGUREBUILDTIME_out_filename=${CMAKE_CURRENT_BINARY_DIR}/Packaging/setup.py" -P "${MITK_SOURCE_DIR}/CMake/mitkSWIGConfigurePythonfileBuildtime.cmake" COMMENT "Generating setup.py..." ) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/Packaging/__init__.py" "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" COPYONLY ) # Hopefully being able to turn this option on at some point in future. option(MITK_PYTHON_USE_VIRTUALENV "Create a Python Virtual Environment for testing." OFF) mark_as_advanced(MITK_PYTHON_USE_VIRTUALENV) set(VIRTUAL_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) if (MITK_PYTHON_USE_VIRTUALENV) # Executable to setup a new Python virtual environment find_package( PythonVirtualEnv REQUIRED ) sitk_enforce_forbid_downloads( MITK_PYTHON_USE_VIRTUALENV ) if (MITK_PYTHON_WHEEL AND PYTHON_VIRTUALENV_VERSION_STRING VERSION_LESS "13") - message(SEND_ERROR "In sufficient version of virutalenv for \ + message(SEND_ERROR "In sufficient version of virtualenv for \ building wheels. Require virtualenv>=13.0.") endif() # # Setup Python Virtual Environment for testing and packaging # set( PythonVirtualenvHome "${${CMAKE_PROJECT_NAME}_BINARY_DIR}/Testing/Installation/PythonVirtualenv" ) # virtualenv places the python executable in different # locations. Also note than on windows installations where python is # installed only for a single user the may be a missing dll issue. if( WIN32 ) set( VIRTUAL_PYTHON_EXECUTABLE "${PythonVirtualenvHome}/Scripts/python") else( ) set( VIRTUAL_PYTHON_EXECUTABLE "${PythonVirtualenvHome}/bin/python" ) endif() set(MITK_PYTHON_TEST_EXECUTABLE "${VIRTUAL_PYTHON_EXECUTABLE}" CACHE INTERNAL "Python executable for testing." FORCE ) # configure a scripts which creates the virtualenv and installs numpy configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/PythonVirtualEnvInstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/PythonVirtualEnvInstall.cmake" @ONLY ) set( PythonVirtualEnv_ALL "" ) if ( BUILD_TESTING ) set( PythonVirtualEnv_ALL "ALL" ) endif() add_custom_target( PythonVirtualEnv ${PythonVirtualEnv_ALL} DEPENDS "${VIRTUAL_PYTHON_EXECUTABLE}" SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/PythonVirtualEnvInstall.cmake.in ) add_custom_command( OUTPUT "${VIRTUAL_PYTHON_EXECUTABLE}" COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/PythonVirtualEnvInstall.cmake" DEPENDS "${SWIG_MODULE_pyMITK_REAL_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/PythonVirtualEnvInstall.cmake" - COMMENT "Creating python virtual enviroment..." + COMMENT "Creating python virtual environment..." ) endif() # Packaging for distribution add_subdirectory(dist) diff --git a/Wrapping/Python/MITK.i b/Wrapping/Python/MITK.i index f7a188f7ed..83649ee83b 100644 --- a/Wrapping/Python/MITK.i +++ b/Wrapping/Python/MITK.i @@ -1,167 +1,167 @@ %module pyMITK %include %{ #include "mitkNumpyArrayConversion.cxx" %} // Numpy array conversion support %native(_GetMemoryViewFromImage) PyObject *mitk_GetMemoryViewFromImage( PyObject *self, PyObject *args ); %native(_SetImageFromArray) PyObject *mitk_SetImageFromArray( PyObject *(self), PyObject *args ); %pythoncode %{ HAVE_NUMPY = True try: import numpy except ImportError: HAVE_NUMPY = False def _get_numpy_dtype( mitkImage ): """Given a MITK image, returns the numpy.dtype which describes the data""" if not HAVE_NUMPY: raise ImportError('Numpy not available.') # this is a mapping from MITK's pixel id to numpy's dtype _mitk_np = {ComponentTypeUInt8:numpy.uint8, ComponentTypeUInt16:numpy.uint16, ComponentTypeUInt32:numpy.uint32, ComponentTypeInt8:numpy.int8, ComponentTypeInt16:numpy.int16, ComponentTypeInt32:numpy.int32, ComponentTypeFloat:numpy.float32, ComponentTypeDouble:numpy.float64, } return _mitk_np[ mitkImage.GetPixelType().GetComponentType() ] def _get_mitk_pixelid(numpy_array_type): """Returns a MITK PixelID given a numpy array.""" if not HAVE_NUMPY: raise ImportError('Numpy not available.') # This is a Mapping from numpy array types to sitks pixel types. _np_mitk = {numpy.character:ComponentTypeUInt8, numpy.uint8:ComponentTypeUInt8, numpy.uint16:ComponentTypeUInt16, numpy.uint32:ComponentTypeUInt32, numpy.int8:ComponentTypeInt8, numpy.int16:ComponentTypeInt16, numpy.int32:ComponentTypeInt32, numpy.float32:ComponentTypeFloat, numpy.float64:ComponentTypeDouble, } try: return _np_mitk[numpy_array_type.dtype] except KeyError: for key in _np_mitk: if numpy.issubdtype(numpy_array_type.dtype, key): return _np_mitk[key] raise TypeError('dtype: {0} is not supported.'.format(numpy_array_type.dtype)) def _get_sitk_vector_pixelid(numpy_array_type): - """Returns a MITK vecotr PixelID given a numpy array.""" + """Returns a MITK vector PixelID given a numpy array.""" if not HAVE_NUMPY: raise ImportError('Numpy not available.') # This is a Mapping from numpy array types to sitks pixel types. _np_sitk = {numpy.character:sitkVectorUInt8, numpy.uint8:sitkVectorUInt8, numpy.uint16:sitkVectorUInt16, numpy.uint32:sitkVectorUInt32, numpy.uint64:sitkVectorUInt64, numpy.int8:sitkVectorInt8, numpy.int16:sitkVectorInt16, numpy.int32:sitkVectorInt32, numpy.int64:sitkVectorInt64, numpy.float32:sitkVectorFloat32, numpy.float64:sitkVectorFloat64, } try: return _np_sitk[numpy_array_type.dtype] except KeyError: for key in _np_sitk: if numpy.issubdtype(numpy_array_type.dtype, key): return _np_sitk[key] raise TypeError('dtype: {0} is not supported.'.format(numpy_array_type.dtype)) # MITK <-> Numpy Array conversion support. #http://www.nickdarnell.com/swig-casting-revisited/ def GetArrayViewFromImage(image): """Get a NumPy ndarray view of a MITK Image. Returns a Numpy ndarray object as a "view" of the MITK's Image buffer. This reduces pixel buffer copies, but requires that the MITK image object is kept around while the buffer is being used. """ if not HAVE_NUMPY: raise ImportError('NumPy not available.') dtype = _get_numpy_dtype( image ) shape = GetImageSize(image); if image.GetPixelType().GetNumberOfComponents() > 1: shape = ( image.GetPixelType().GetNumberOfComponents(), ) + shape imageMemoryView = _pyMITK._GetMemoryViewFromImage(image) arrayView = numpy.asarray(imageMemoryView).view(dtype = dtype) arrayView.shape = shape[::-1] return arrayView def GetArrayFromImage(image): """Get a NumPy ndarray from a MITK Image. This is a deep copy of the image buffer and is completely safe and without potential side effects. """ # TODO: If the image is already not unique then a second copy may be made before the numpy copy is done. arrayView = GetArrayViewFromImage(image) # perform deep copy of the image buffer return numpy.array(arrayView, copy=True) def GetImageFromArray( arr, isVector=False): """Get a MITK Image from a numpy array. If isVector is True, then a 3D array will be treated as a 2D vector image, otherwise it will be treated as a 3D image""" if not HAVE_NUMPY: raise ImportError('Numpy not available.') z = numpy.asarray( arr ) assert z.ndim in ( 2, 3, 4 ), \ "Only arrays of 2, 3 or 4 dimensions are supported." id = _get_mitk_pixelid( z ) #img = Image_New() if ( z.ndim == 3 and isVector ) or (z.ndim == 4): pixelType=MakePixelTypeFromTypeID(id, z.shape[-1]) newShape=VectorUInt32(z.shape[-2::-1]) img = MakeImage(pixelType, newShape) #img.Initialize(pixelType, z.ndim - 1, z.shape[-2::-1]) elif z.ndim in ( 2, 3 ): pixelType=MakePixelTypeFromTypeID(id, 1) newShape=VectorUInt32(z.shape[::-1]) img = MakeImage(pixelType, newShape) #img.Initialize(pixelType, z.ndim, z.shape[::-1]) _pyMITK._SetImageFromArray( z.tostring(), img ) return img %} diff --git a/Wrapping/Python/PackageUtility/imagefiles/imagefiles/install-gcc.sh b/Wrapping/Python/PackageUtility/imagefiles/imagefiles/install-gcc.sh index b36458f281..6d095a83db 100755 --- a/Wrapping/Python/PackageUtility/imagefiles/imagefiles/install-gcc.sh +++ b/Wrapping/Python/PackageUtility/imagefiles/imagefiles/install-gcc.sh @@ -1,680 +1,680 @@ #!/bin/bash # # Date: 2015-09-29 # # This downloads, builds and installs the gcc-4.9.3 compiler and boost # 1.58. It handles the dependent packages like gmp-6.0.0a, mpfr-3.1.3, # mpc-1.0.2, ppl-1.1, cloog-0.18.0 and binutils-2.24. # # To install gcc-4.9.3 in ~/tmp/gcc-4.9.3/rtf/bin you would run this # script as follows: # # % # Install in ~/tmp/gcc-4.9.3/rtf/bin # % bld.sh ~/tmp/gcc-4.9.3 2>&1 | tee bld.log # # If you do not specify a directory, then it will install in the # current directory which means that following command will also # install in ~/tmp/gcc-4.9.3/rtf/bin: # # % # Install in ~/tmp/gcc-4.9.3/rtf/bin # % mkdir -p ~/tmp/gcc-4.9.3 # % cd ~/tmp/gcc-4.9.3 # % bld.sh 2>&1 | tee bld.log # # This script creates 4 subdirectories: # # Directory Description # ========= ================================================== # archives This is where the package archives are downloaded. # src This is where the package source is located. # bld This is where the packages are built from source. # rtf This is where the packages are installed. # # When the build is complete you can safely remove the archives, bld # and src directory trees to save disk space. # # Copyright (C) 2014 Joe Linoff # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ================================================================ # Trim a string, remove internal spaces, convert to lower case. # ================================================================ function get-platform-trim { local s=$(echo "$1" | tr -d '[ \t]' | tr 'A-Z' 'a-z') echo $s } # ================================================================ # Get the platform root name. # ================================================================ function get-platform-root { if which uname >/dev/null 2>&1 ; then # Greg Moeller reported that the original code didn't # work because the -o option is not available on solaris. # I modified the script to correctly identify that # case and recover by using the -s option. if uname -o >/dev/null 2>&1 ; then # Linux distro uname -o | tr 'A-Z' 'a-z' elif uname -s >/dev/null 2>&1 ; then # Solaris variant uname -s | tr 'A-Z' 'a-z' else - echo "unkown" + echo "unknown" fi else - echo "unkown" + echo "unknown" fi } # ================================================================ # Get the platform identifier. # # The format of the output is: # --- # ^ ^ ^ ^ # | | | +----- architecture: x86_64, i86pc, etc. # | | +----------- version: 5.5, 6.4, 10.9, etc. # | +------------------ distribution: centos, rhel, nexenta, darwin # +------------------------- platform: linux, sunos, macos # # ================================================================ function get-platform { local plat=$(get-platform-root) case "$plat" in "gnu/linux") d=$(get-platform-trim "$(lsb_release -i)" | awk -F: '{print $2;}') r=$(get-platform-trim "$(lsb_release -r)" | awk -F: '{print $2;}') m=$(get-platform-trim "$(uname -m)") if [[ "$d" == "redhatenterprise"* ]] ; then # Need a little help for Red Hat because # they don't make the minor version obvious. d="rhel_${d:16}" # keep the tail (e.g., es or client) x=$(get-platform-trim "$(lsb_release -c)" | \ awk -F: '{print $2;}' | \ sed -e 's/[^0-9]//g') r="$r.$x" fi echo "linux-$d-$r-$m" ;; "cygwin") x=$(get-platform-trim "$(uname)") echo "linux-$x" ;; "sunos") d=$(get-platform-trim "$(uname -v)") r=$(get-platform-trim "$(uname -r)") m=$(get-platform-trim "$(uname -m)") echo "sunos-$d-$r-$m" ;; "darwin") d=$(get-platform-trim "$(uname -s)") r=$(get-platform-trim "$(uname -r)") m=$(get-platform-trim "$(uname -m)") echo "macos-$d-$r-$m" ;; "unknown") echo "unk-unk-unk-unk" ;; *) echo "$plat-unk-unk-unk" ;; esac } # ================================================================ # Command header # Usage : docmd_hdr $ar $* # Example: docmd_hdr $ar # ================================================================ function docmd_hdr { local ar=$1 shift local cmd=($*) echo echo " # ================================================================" if [[ "$ar" != "" ]] ; then echo " # Archive: $ar" fi echo " # PWD: "$(pwd) echo " # CMD: "${cmd[@]} echo " # ================================================================" } # ================================================================ # Execute command with decorations and status testing. # Usage : docmd $ar # Example: docmd $ar ls -l # ================================================================ function docmd { docmd_hdr $* shift local cmd=($*) ${cmd[@]} local st=$? echo "STATUS = $st" if (( $st != 0 )) ; then exit $st; fi } # ================================================================ # Report an error and exit. # Usage : doerr [ .. ] # Example: doerr "line 1 msg" # Example: doerr "line 1 msg" "line 2 msg" # ================================================================ function doerr { local prefix="ERROR: " for ln in "$@" ; do echo "${prefix}${ln}" prefix=" " done exit 1 } # ================================================================ # Extract archive information. # Usage : ard=( $(extract-ar-info $ar) ) # Example: ard=( $(extract-ar-info $ar) ) # fn=${ard[1]} # ext=${ard[2]} # d=${ard[3]} # ================================================================ function extract-ar-info { local ar=$1 local fn=$(basename $ar) local ext=$(echo $fn | awk -F. '{print $NF}') local d=${fn%.*tar.$ext} echo $ar echo $fn echo $ext echo $d } # ================================================================ # Print a banner for a new section. # Usage : banner STEP $ar # Example: banner "DOWNLOAD" $ar # Example: banner "BUILD" $ar # ================================================================ function banner { local step=$1 local ard=( $(extract-ar-info $2) ) local ar=${ard[0]} local fn=${ard[1]} local ext=${ard[2]} local d=${ard[3]} echo echo '# ================================================================' echo "# Step : $step" echo "# Archive: $ar" echo "# File : $fn" echo "# Ext : $ext" echo "# Dir : $d" echo '# ================================================================' } # ================================================================ # Make a set of directories # Usage : mkdirs [ .. ] # Example: mkdirs foo bar spam spam/foo/bar # ================================================================ function mkdirs { local ds=($*) #echo "mkdirs" for d in ${ds[@]} ; do #echo " testing $d" if [ ! -d $d ] ; then #echo " creating $d" mkdir -p $d fi done } # ================================================================ # Check the current platform to see if it is in the tested list, # if it isn't, then issue a warning. # It doesn't work on CentOS 5.x. # It doesn't work on Mac OS X 10.9 (Maverick) but is close. # ================================================================ function check-platform { local plat=$(get-platform) local tested_plats=( 'linux-centos-6.4-x86_64') local plat_found=0 echo "PLATFORM: $plat" for tested_plat in ${tested_plats[@]} ; do if [[ "$plat" == "$tested_plat" ]] ; then plat_found=1 break fi done if (( $plat_found == 0 )) ; then echo "WARNING: This platform ($plat) has not been tested." fi } # ================================================================ # my-readlink # Some platforms (like darwin) do not support "readlink -f". # This function checks to see if readlink -f is available, # if it isn't then it uses a more POSIX compliant approach. # ================================================================ function my-readlink { # First make sure that the command works. readlink -f "$1" 1>/dev/null 2>/dev/null local st=$? if (( $st )) ; then # If readlink didn't work then this may be a platform # like Mac OS X. local abspath="$(cd $(dirname .); pwd)" else local abspath=$(readlink -f "$1" 2>/dev/null) fi echo "$abspath" } # ================================================================ # DATA # ================================================================ # List of archives # The order is important. ARS=( http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 http://www.mpfr.org/mpfr-current/mpfr-3.1.3.tar.bz2 http://www.multiprecision.org/mpc/download/mpc-1.0.2.tar.gz http://bugseng.com/products/ppl/download/ftp/releases/1.1/ppl-1.1.tar.bz2 http://www.bastoul.net/cloog/pages/download/cloog-0.18.1.tar.gz http://ftp.gnu.org/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.bz2 http://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2 #http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2 # # Why glibc is disabled (for now). # # glibc does not work on CentOS because the versions of the shared - # libraries we are building are not compatiable with installed + # libraries we are building are not compatible with installed # shared libraries. # # This is the run-time error: ELF file OS ABI invalid that I see # when I try to run binaries compiled with the local glibc-2.15. # # Note that the oldest supported ABI for glibc-2.15 is 2.2. The # CentOS 5.5 ABI is 0. # http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.bz2 ) # ================================================================ # MAIN # ================================================================ umask 0 check-platform # Read the command line argument, if it exists. ROOTDIR=$(my-readlink .) if (( $# == 1 )) ; then ROOTDIR=$(my-readlink $1) elif (( $# > 1 )) ; then doerr "too many command line arguments ($#), only zero or one is allowed" "foo" fi # Setup the directories. ARDIR="/tmp/archives" RTFDIR="$ROOTDIR" SRCDIR="/tmp/src" BLDDIR="/tmp/bld" TSTDIR="/tmp/LOCAL-TEST" export PATH="${RTFDIR}/bin:${PATH}" export LD_LIBRARY_PATH="${RTFDIR}/lib:${RTFDIR}/lib64:${LD_LIBRARY_PATH}" echo echo "# ================================================================" echo '# Version : gcc-4.9.3 2015-08-15' echo "# RootDir : $ROOTDIR" echo "# ArchiveDir : $ARDIR" echo "# RtfDir : $RTFDIR" echo "# SrcDir : $SRCDIR" echo "# BldDir : $BLDDIR" echo "# TstDir : $TSTDIR" echo "# Gcc : "$(which gcc) echo "# GccVersion : "$(gcc --version | head -1) echo "# Hostname : "$(hostname) echo "# O/S : "$(uname -s -r -v -m) echo "# Date : "$(date) echo "# Platform : "$(get-platform) echo "# ================================================================" mkdirs $ARDIR $RTFDIR $SRCDIR $BLDDIR # ================================================================ # Download # ================================================================ #for ar in ${ARS[@]} ; do # banner 'DOWNLOAD' $ar # ard=( $(extract-ar-info $ar) ) # fn=${ard[1]} # ext=${ard[2]} # d=${ard[3]} # if [ -f "${ARDIR}/$fn" ] ; then # echo "skipping $fn" # else # # get # docmd $ar wget $ar -O "${ARDIR}/$fn" # fi #done # ================================================================ # Extract # ================================================================ for ar in ${ARS[@]} ; do banner 'EXTRACT' $ar ard=( $(extract-ar-info $ar) ) fn=${ard[1]} ext=${ard[2]} d=${ard[3]} sd="$SRCDIR/$d" if [ -d $sd ] ; then echo "skipping $fn" else # unpack pushd $SRCDIR case "$ext" in "bz2") docmd $ar tar jxf ${ARDIR}/$fn ;; "gz") docmd $ar tar zxf ${ARDIR}/$fn ;; "tar") docmd $ar tar xf ${ARDIR}/$fn ;; *) doerr "unrecognized extension: $ext" "Can't continue." ;; esac popd if [ ! -d $sd ] ; then # Some archives (like gcc-g++) overlay. We create a dummy # directory to avoid extracting them every time. mkdir -p $sd fi fi # special hack for gmp-6.0.0a if [[ $d == "gmp-6.0.0a" ]] ; then if [ ! -f $sd/configure ] ; then sdn="$SRCDIR/gmp-6.0.0" echo "fixing $sdn --> $sd" docmd $sd rm -rf $sd docmd $sd ln -s $sdn $sd fi fi done # ================================================================ # Build # ================================================================ for ar in ${ARS[@]} ; do banner 'BUILD' $ar ard=( $(extract-ar-info $ar) ) fn=${ard[1]} ext=${ard[2]} d=${ard[3]} sd="$SRCDIR/$d" bd="$BLDDIR/$d" if [ -d $bd ] ; then echo "skipping $sd" else # Build regex='^gcc-g\+\+.*' if [[ $fn =~ $regex ]] ; then # Don't build/configure the gcc-g++ package explicitly because # it is part of the regular gcc package. echo "skipping $sd" # Dummy continue fi # Set the CONF_ARGS plat=$(get-platform) run_conf=1 run_boost_bootstrap=0 case "$d" in binutils-*) # Binutils will not compile with strict error # checking on so I disabled -Werror by setting # --disable-werror. CONF_ARGS=( --disable-cloog-version-check --disable-ppl-version-check --disable-werror --enable-cloog-backend=isl --enable-lto --enable-libssp --enable-gold --prefix=${RTFDIR} --with-cloog=${RTFDIR} --with-gmp=${RTFDIR} --with-mlgmp=${RTFDIR} --with-mpc=${RTFDIR} --with-mpfr=${RTFDIR} --with-ppl=${RTFDIR} CC=${RTFDIR}/bin/gcc CXX=${RTFDIR}/bin/g++ ) ;; boost_*) # The boost configuration scheme requires # that the build occur in the source directory. run_conf=0 run_boost_bootstrap=1 CONF_ARGS=( --prefix=${RTFDIR} --with-python=python2.7 ) ;; cloog-*) GMPDIR=$(ls -1d ${BLDDIR}/gmp-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp-builddir=${GMPDIR} --with-gmp=build ) ;; gcc-*) # We are using a newer version of CLooG (0.18.0). # I have also made stack protection available # (similar to DEP in windows). CONF_ARGS=( --disable-cloog-version-check --disable-ppl-version-check --enable-cloog-backend=isl --enable-gold --enable-languages='c,c++' --enable-lto --enable-libssp --prefix=${RTFDIR} --with-cloog=${RTFDIR} --with-gmp=${RTFDIR} --with-mlgmp=${RTFDIR} --with-mpc=${RTFDIR} --with-mpfr=${RTFDIR} --with-ppl=${RTFDIR} ) macplats=("macos-darwin-13.0.0-x86_64" "macos-darwin-13.1.0-x86_64") for macplat in ${macplats[@]} ; do if [[ "$plat" == "$macplat" ]] ; then # Special handling for Mac OS X 10.9. # Fix the bad reference to CFBase.h in # src/gcc-4.9.3/libsanitizer/asan/asan_malloc_mac.cc src="$sd/libsanitizer/asan/asan_malloc_mac.cc" if [ -f $src ] ; then if [ ! -f $src.orig ] ; then cp $src $src.orig cat $src.orig |\ sed -e 's@#include @//#include @' >$src fi fi fi done ;; glibc-*) CONF_ARGS=( --enable-static-nss=no --prefix=${RTFDIR} --with-binutils=${RTFDIR} --with-elf CC=${RTFDIR}/bin/gcc CXX=${RTFDIR}/bin/g++ ) ;; gmp-*) CONF_ARGS=( --enable-cxx --prefix=${RTFDIR} ) if [[ "$plat" == "linux-cygwin_nt-6.1-wow64" ]] ; then CONF_ARGS+=('--enable-static') CONF_ARGS+=('--disable-shared') fi ;; libiconv-*) CONF_ARGS=( --prefix=${RTFDIR} ) ;; mpc-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp=${RTFDIR} --with-mpfr=${RTFDIR} ) if [[ "$plat" == "linux-cygwin_nt-6.1-wow64" ]] ; then CONF_ARGS+=('--enable-static') CONF_ARGS+=('--disable-shared') fi ;; mpfr-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp=${RTFDIR} ) ;; ppl-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp=${RTFDIR} ) if [[ "$plat" == "linux-cygwin_nt-6.1-wow64" ]] ; then # Cygwin does not implement long double so I cheated. CONF_ARGS+=('--enable-static') CONF_ARGS+=('--disable-shared') fi # We need a special fix for the pax archive prompt. # Change the configure code. if [ ! -f "$sd/configure.orig" ] ; then # Fix the configure code so that it does not use 'pax -r'. # The problem with 'pax -r' is that it expects a "." input # from stdin which breaks the flow. cp $sd/configure{,.orig} sed -e "s/am__untar='pax -r'/am__untar='tar -xf' #am__untar='pax -r'/" \ $sd/configure.orig >$sd/configure fi # We need to make a special fix here src="$sd/src/mp_std_bits.defs.hh" if [ -f $src ] ; then if [ ! -f $src.orig ] ; then if ! grep -q '__GNU_MP_VERSION' $src ; then cp $src $src.orig cat $src.orig | \ awk \ '{ \ if($1=="namespace" && $2 == "std") { \ printf("// Automatically patched by bld.sh for gcc-4.9.3.\n"); \ printf("#define tininess_before tinyness_before\n"); \ printf("#if __GNU_MP_VERSION < 5 || (__GNU_MP_VERSION == 5 && __GNU_MP_VERSION_MINOR < 1)\n"); } \ print $0; \ if($1 == "}" && $2=="//" && $3=="namespace") { \ printf("#endif // #if __GNU_MP_VERSION < 5 || (__GNU_MP_VERSION == 5 && __GNU_MP_VERSION_MINOR < 1)\n"); } \ }' >$src fi fi fi ;; *) doerr "unrecognized package: $d" ;; esac mkdir -p $bd pushd $bd if (( $run_conf )) ; then docmd $ar $sd/configure --help docmd $ar $sd/configure ${CONF_ARGS[@]} docmd $ar make docmd $ar make install fi if (( $run_boost_bootstrap )) ; then pushd $sd docmd $ar which g++ docmd $ar gcc --version docmd $ar $sd/bootstrap.sh --help docmd $ar $sd/bootstrap.sh ${CONF_ARGS[@]} docmd $ar ./b2 --help docmd $ar ./b2 --clean docmd $ar ./b2 --reconfigure docmd $ar ./b2 -a -d+2 --build-dir $bd docmd $ar ./b2 -d+2 --build-dir $bd install docmd $ar ./b2 install popd fi # Redo the tests if anything changed. if [ -d $TSTDIR ] ; then rm -rf $TSTDIR fi popd fi done diff --git a/Wrapping/Python/PackageUtility/imagefiles/install-gcc.sh b/Wrapping/Python/PackageUtility/imagefiles/install-gcc.sh index b36458f281..6d095a83db 100755 --- a/Wrapping/Python/PackageUtility/imagefiles/install-gcc.sh +++ b/Wrapping/Python/PackageUtility/imagefiles/install-gcc.sh @@ -1,680 +1,680 @@ #!/bin/bash # # Date: 2015-09-29 # # This downloads, builds and installs the gcc-4.9.3 compiler and boost # 1.58. It handles the dependent packages like gmp-6.0.0a, mpfr-3.1.3, # mpc-1.0.2, ppl-1.1, cloog-0.18.0 and binutils-2.24. # # To install gcc-4.9.3 in ~/tmp/gcc-4.9.3/rtf/bin you would run this # script as follows: # # % # Install in ~/tmp/gcc-4.9.3/rtf/bin # % bld.sh ~/tmp/gcc-4.9.3 2>&1 | tee bld.log # # If you do not specify a directory, then it will install in the # current directory which means that following command will also # install in ~/tmp/gcc-4.9.3/rtf/bin: # # % # Install in ~/tmp/gcc-4.9.3/rtf/bin # % mkdir -p ~/tmp/gcc-4.9.3 # % cd ~/tmp/gcc-4.9.3 # % bld.sh 2>&1 | tee bld.log # # This script creates 4 subdirectories: # # Directory Description # ========= ================================================== # archives This is where the package archives are downloaded. # src This is where the package source is located. # bld This is where the packages are built from source. # rtf This is where the packages are installed. # # When the build is complete you can safely remove the archives, bld # and src directory trees to save disk space. # # Copyright (C) 2014 Joe Linoff # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ================================================================ # Trim a string, remove internal spaces, convert to lower case. # ================================================================ function get-platform-trim { local s=$(echo "$1" | tr -d '[ \t]' | tr 'A-Z' 'a-z') echo $s } # ================================================================ # Get the platform root name. # ================================================================ function get-platform-root { if which uname >/dev/null 2>&1 ; then # Greg Moeller reported that the original code didn't # work because the -o option is not available on solaris. # I modified the script to correctly identify that # case and recover by using the -s option. if uname -o >/dev/null 2>&1 ; then # Linux distro uname -o | tr 'A-Z' 'a-z' elif uname -s >/dev/null 2>&1 ; then # Solaris variant uname -s | tr 'A-Z' 'a-z' else - echo "unkown" + echo "unknown" fi else - echo "unkown" + echo "unknown" fi } # ================================================================ # Get the platform identifier. # # The format of the output is: # --- # ^ ^ ^ ^ # | | | +----- architecture: x86_64, i86pc, etc. # | | +----------- version: 5.5, 6.4, 10.9, etc. # | +------------------ distribution: centos, rhel, nexenta, darwin # +------------------------- platform: linux, sunos, macos # # ================================================================ function get-platform { local plat=$(get-platform-root) case "$plat" in "gnu/linux") d=$(get-platform-trim "$(lsb_release -i)" | awk -F: '{print $2;}') r=$(get-platform-trim "$(lsb_release -r)" | awk -F: '{print $2;}') m=$(get-platform-trim "$(uname -m)") if [[ "$d" == "redhatenterprise"* ]] ; then # Need a little help for Red Hat because # they don't make the minor version obvious. d="rhel_${d:16}" # keep the tail (e.g., es or client) x=$(get-platform-trim "$(lsb_release -c)" | \ awk -F: '{print $2;}' | \ sed -e 's/[^0-9]//g') r="$r.$x" fi echo "linux-$d-$r-$m" ;; "cygwin") x=$(get-platform-trim "$(uname)") echo "linux-$x" ;; "sunos") d=$(get-platform-trim "$(uname -v)") r=$(get-platform-trim "$(uname -r)") m=$(get-platform-trim "$(uname -m)") echo "sunos-$d-$r-$m" ;; "darwin") d=$(get-platform-trim "$(uname -s)") r=$(get-platform-trim "$(uname -r)") m=$(get-platform-trim "$(uname -m)") echo "macos-$d-$r-$m" ;; "unknown") echo "unk-unk-unk-unk" ;; *) echo "$plat-unk-unk-unk" ;; esac } # ================================================================ # Command header # Usage : docmd_hdr $ar $* # Example: docmd_hdr $ar # ================================================================ function docmd_hdr { local ar=$1 shift local cmd=($*) echo echo " # ================================================================" if [[ "$ar" != "" ]] ; then echo " # Archive: $ar" fi echo " # PWD: "$(pwd) echo " # CMD: "${cmd[@]} echo " # ================================================================" } # ================================================================ # Execute command with decorations and status testing. # Usage : docmd $ar # Example: docmd $ar ls -l # ================================================================ function docmd { docmd_hdr $* shift local cmd=($*) ${cmd[@]} local st=$? echo "STATUS = $st" if (( $st != 0 )) ; then exit $st; fi } # ================================================================ # Report an error and exit. # Usage : doerr [ .. ] # Example: doerr "line 1 msg" # Example: doerr "line 1 msg" "line 2 msg" # ================================================================ function doerr { local prefix="ERROR: " for ln in "$@" ; do echo "${prefix}${ln}" prefix=" " done exit 1 } # ================================================================ # Extract archive information. # Usage : ard=( $(extract-ar-info $ar) ) # Example: ard=( $(extract-ar-info $ar) ) # fn=${ard[1]} # ext=${ard[2]} # d=${ard[3]} # ================================================================ function extract-ar-info { local ar=$1 local fn=$(basename $ar) local ext=$(echo $fn | awk -F. '{print $NF}') local d=${fn%.*tar.$ext} echo $ar echo $fn echo $ext echo $d } # ================================================================ # Print a banner for a new section. # Usage : banner STEP $ar # Example: banner "DOWNLOAD" $ar # Example: banner "BUILD" $ar # ================================================================ function banner { local step=$1 local ard=( $(extract-ar-info $2) ) local ar=${ard[0]} local fn=${ard[1]} local ext=${ard[2]} local d=${ard[3]} echo echo '# ================================================================' echo "# Step : $step" echo "# Archive: $ar" echo "# File : $fn" echo "# Ext : $ext" echo "# Dir : $d" echo '# ================================================================' } # ================================================================ # Make a set of directories # Usage : mkdirs [ .. ] # Example: mkdirs foo bar spam spam/foo/bar # ================================================================ function mkdirs { local ds=($*) #echo "mkdirs" for d in ${ds[@]} ; do #echo " testing $d" if [ ! -d $d ] ; then #echo " creating $d" mkdir -p $d fi done } # ================================================================ # Check the current platform to see if it is in the tested list, # if it isn't, then issue a warning. # It doesn't work on CentOS 5.x. # It doesn't work on Mac OS X 10.9 (Maverick) but is close. # ================================================================ function check-platform { local plat=$(get-platform) local tested_plats=( 'linux-centos-6.4-x86_64') local plat_found=0 echo "PLATFORM: $plat" for tested_plat in ${tested_plats[@]} ; do if [[ "$plat" == "$tested_plat" ]] ; then plat_found=1 break fi done if (( $plat_found == 0 )) ; then echo "WARNING: This platform ($plat) has not been tested." fi } # ================================================================ # my-readlink # Some platforms (like darwin) do not support "readlink -f". # This function checks to see if readlink -f is available, # if it isn't then it uses a more POSIX compliant approach. # ================================================================ function my-readlink { # First make sure that the command works. readlink -f "$1" 1>/dev/null 2>/dev/null local st=$? if (( $st )) ; then # If readlink didn't work then this may be a platform # like Mac OS X. local abspath="$(cd $(dirname .); pwd)" else local abspath=$(readlink -f "$1" 2>/dev/null) fi echo "$abspath" } # ================================================================ # DATA # ================================================================ # List of archives # The order is important. ARS=( http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 http://www.mpfr.org/mpfr-current/mpfr-3.1.3.tar.bz2 http://www.multiprecision.org/mpc/download/mpc-1.0.2.tar.gz http://bugseng.com/products/ppl/download/ftp/releases/1.1/ppl-1.1.tar.bz2 http://www.bastoul.net/cloog/pages/download/cloog-0.18.1.tar.gz http://ftp.gnu.org/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.bz2 http://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2 #http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.bz2 # # Why glibc is disabled (for now). # # glibc does not work on CentOS because the versions of the shared - # libraries we are building are not compatiable with installed + # libraries we are building are not compatible with installed # shared libraries. # # This is the run-time error: ELF file OS ABI invalid that I see # when I try to run binaries compiled with the local glibc-2.15. # # Note that the oldest supported ABI for glibc-2.15 is 2.2. The # CentOS 5.5 ABI is 0. # http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.bz2 ) # ================================================================ # MAIN # ================================================================ umask 0 check-platform # Read the command line argument, if it exists. ROOTDIR=$(my-readlink .) if (( $# == 1 )) ; then ROOTDIR=$(my-readlink $1) elif (( $# > 1 )) ; then doerr "too many command line arguments ($#), only zero or one is allowed" "foo" fi # Setup the directories. ARDIR="/tmp/archives" RTFDIR="$ROOTDIR" SRCDIR="/tmp/src" BLDDIR="/tmp/bld" TSTDIR="/tmp/LOCAL-TEST" export PATH="${RTFDIR}/bin:${PATH}" export LD_LIBRARY_PATH="${RTFDIR}/lib:${RTFDIR}/lib64:${LD_LIBRARY_PATH}" echo echo "# ================================================================" echo '# Version : gcc-4.9.3 2015-08-15' echo "# RootDir : $ROOTDIR" echo "# ArchiveDir : $ARDIR" echo "# RtfDir : $RTFDIR" echo "# SrcDir : $SRCDIR" echo "# BldDir : $BLDDIR" echo "# TstDir : $TSTDIR" echo "# Gcc : "$(which gcc) echo "# GccVersion : "$(gcc --version | head -1) echo "# Hostname : "$(hostname) echo "# O/S : "$(uname -s -r -v -m) echo "# Date : "$(date) echo "# Platform : "$(get-platform) echo "# ================================================================" mkdirs $ARDIR $RTFDIR $SRCDIR $BLDDIR # ================================================================ # Download # ================================================================ #for ar in ${ARS[@]} ; do # banner 'DOWNLOAD' $ar # ard=( $(extract-ar-info $ar) ) # fn=${ard[1]} # ext=${ard[2]} # d=${ard[3]} # if [ -f "${ARDIR}/$fn" ] ; then # echo "skipping $fn" # else # # get # docmd $ar wget $ar -O "${ARDIR}/$fn" # fi #done # ================================================================ # Extract # ================================================================ for ar in ${ARS[@]} ; do banner 'EXTRACT' $ar ard=( $(extract-ar-info $ar) ) fn=${ard[1]} ext=${ard[2]} d=${ard[3]} sd="$SRCDIR/$d" if [ -d $sd ] ; then echo "skipping $fn" else # unpack pushd $SRCDIR case "$ext" in "bz2") docmd $ar tar jxf ${ARDIR}/$fn ;; "gz") docmd $ar tar zxf ${ARDIR}/$fn ;; "tar") docmd $ar tar xf ${ARDIR}/$fn ;; *) doerr "unrecognized extension: $ext" "Can't continue." ;; esac popd if [ ! -d $sd ] ; then # Some archives (like gcc-g++) overlay. We create a dummy # directory to avoid extracting them every time. mkdir -p $sd fi fi # special hack for gmp-6.0.0a if [[ $d == "gmp-6.0.0a" ]] ; then if [ ! -f $sd/configure ] ; then sdn="$SRCDIR/gmp-6.0.0" echo "fixing $sdn --> $sd" docmd $sd rm -rf $sd docmd $sd ln -s $sdn $sd fi fi done # ================================================================ # Build # ================================================================ for ar in ${ARS[@]} ; do banner 'BUILD' $ar ard=( $(extract-ar-info $ar) ) fn=${ard[1]} ext=${ard[2]} d=${ard[3]} sd="$SRCDIR/$d" bd="$BLDDIR/$d" if [ -d $bd ] ; then echo "skipping $sd" else # Build regex='^gcc-g\+\+.*' if [[ $fn =~ $regex ]] ; then # Don't build/configure the gcc-g++ package explicitly because # it is part of the regular gcc package. echo "skipping $sd" # Dummy continue fi # Set the CONF_ARGS plat=$(get-platform) run_conf=1 run_boost_bootstrap=0 case "$d" in binutils-*) # Binutils will not compile with strict error # checking on so I disabled -Werror by setting # --disable-werror. CONF_ARGS=( --disable-cloog-version-check --disable-ppl-version-check --disable-werror --enable-cloog-backend=isl --enable-lto --enable-libssp --enable-gold --prefix=${RTFDIR} --with-cloog=${RTFDIR} --with-gmp=${RTFDIR} --with-mlgmp=${RTFDIR} --with-mpc=${RTFDIR} --with-mpfr=${RTFDIR} --with-ppl=${RTFDIR} CC=${RTFDIR}/bin/gcc CXX=${RTFDIR}/bin/g++ ) ;; boost_*) # The boost configuration scheme requires # that the build occur in the source directory. run_conf=0 run_boost_bootstrap=1 CONF_ARGS=( --prefix=${RTFDIR} --with-python=python2.7 ) ;; cloog-*) GMPDIR=$(ls -1d ${BLDDIR}/gmp-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp-builddir=${GMPDIR} --with-gmp=build ) ;; gcc-*) # We are using a newer version of CLooG (0.18.0). # I have also made stack protection available # (similar to DEP in windows). CONF_ARGS=( --disable-cloog-version-check --disable-ppl-version-check --enable-cloog-backend=isl --enable-gold --enable-languages='c,c++' --enable-lto --enable-libssp --prefix=${RTFDIR} --with-cloog=${RTFDIR} --with-gmp=${RTFDIR} --with-mlgmp=${RTFDIR} --with-mpc=${RTFDIR} --with-mpfr=${RTFDIR} --with-ppl=${RTFDIR} ) macplats=("macos-darwin-13.0.0-x86_64" "macos-darwin-13.1.0-x86_64") for macplat in ${macplats[@]} ; do if [[ "$plat" == "$macplat" ]] ; then # Special handling for Mac OS X 10.9. # Fix the bad reference to CFBase.h in # src/gcc-4.9.3/libsanitizer/asan/asan_malloc_mac.cc src="$sd/libsanitizer/asan/asan_malloc_mac.cc" if [ -f $src ] ; then if [ ! -f $src.orig ] ; then cp $src $src.orig cat $src.orig |\ sed -e 's@#include @//#include @' >$src fi fi fi done ;; glibc-*) CONF_ARGS=( --enable-static-nss=no --prefix=${RTFDIR} --with-binutils=${RTFDIR} --with-elf CC=${RTFDIR}/bin/gcc CXX=${RTFDIR}/bin/g++ ) ;; gmp-*) CONF_ARGS=( --enable-cxx --prefix=${RTFDIR} ) if [[ "$plat" == "linux-cygwin_nt-6.1-wow64" ]] ; then CONF_ARGS+=('--enable-static') CONF_ARGS+=('--disable-shared') fi ;; libiconv-*) CONF_ARGS=( --prefix=${RTFDIR} ) ;; mpc-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp=${RTFDIR} --with-mpfr=${RTFDIR} ) if [[ "$plat" == "linux-cygwin_nt-6.1-wow64" ]] ; then CONF_ARGS+=('--enable-static') CONF_ARGS+=('--disable-shared') fi ;; mpfr-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp=${RTFDIR} ) ;; ppl-*) CONF_ARGS=( --prefix=${RTFDIR} --with-gmp=${RTFDIR} ) if [[ "$plat" == "linux-cygwin_nt-6.1-wow64" ]] ; then # Cygwin does not implement long double so I cheated. CONF_ARGS+=('--enable-static') CONF_ARGS+=('--disable-shared') fi # We need a special fix for the pax archive prompt. # Change the configure code. if [ ! -f "$sd/configure.orig" ] ; then # Fix the configure code so that it does not use 'pax -r'. # The problem with 'pax -r' is that it expects a "." input # from stdin which breaks the flow. cp $sd/configure{,.orig} sed -e "s/am__untar='pax -r'/am__untar='tar -xf' #am__untar='pax -r'/" \ $sd/configure.orig >$sd/configure fi # We need to make a special fix here src="$sd/src/mp_std_bits.defs.hh" if [ -f $src ] ; then if [ ! -f $src.orig ] ; then if ! grep -q '__GNU_MP_VERSION' $src ; then cp $src $src.orig cat $src.orig | \ awk \ '{ \ if($1=="namespace" && $2 == "std") { \ printf("// Automatically patched by bld.sh for gcc-4.9.3.\n"); \ printf("#define tininess_before tinyness_before\n"); \ printf("#if __GNU_MP_VERSION < 5 || (__GNU_MP_VERSION == 5 && __GNU_MP_VERSION_MINOR < 1)\n"); } \ print $0; \ if($1 == "}" && $2=="//" && $3=="namespace") { \ printf("#endif // #if __GNU_MP_VERSION < 5 || (__GNU_MP_VERSION == 5 && __GNU_MP_VERSION_MINOR < 1)\n"); } \ }' >$src fi fi fi ;; *) doerr "unrecognized package: $d" ;; esac mkdir -p $bd pushd $bd if (( $run_conf )) ; then docmd $ar $sd/configure --help docmd $ar $sd/configure ${CONF_ARGS[@]} docmd $ar make docmd $ar make install fi if (( $run_boost_bootstrap )) ; then pushd $sd docmd $ar which g++ docmd $ar gcc --version docmd $ar $sd/bootstrap.sh --help docmd $ar $sd/bootstrap.sh ${CONF_ARGS[@]} docmd $ar ./b2 --help docmd $ar ./b2 --clean docmd $ar ./b2 --reconfigure docmd $ar ./b2 -a -d+2 --build-dir $bd docmd $ar ./b2 -d+2 --build-dir $bd install docmd $ar ./b2 install popd fi # Redo the tests if anything changed. if [ -d $TSTDIR ] ; then rm -rf $TSTDIR fi popd fi done