From 55c07e4637e084adc205d6c7427edb37d2d41321 Mon Sep 17 00:00:00 2001
From: Valerio Mariani <valerio.mariani@unibas.ch>
Date: Thu, 6 Jun 2013 16:15:30 +0200
Subject: [PATCH] Implemented UBUNTU_LAYOUT flag

Substitutes DEBIAN_STYLE_LIBEXEC flag and manages location and name of lib and libexec folders on Debian/Ubuntu-based systems
---
 CMakeLists.txt                                | 42 +++++++++----------
 cmake_support/OST.cmake                       | 13 +++---
 modules/config/CMakeLists.txt                 |  6 +--
 modules/config/config.hh.in                   |  2 +-
 modules/gui/src/gosty.cc                      |  4 +-
 scripts/CMakeLists.txt                        |  3 ++
 scripts/{ost_startup.py => ost_startup.py.in} |  5 +--
 7 files changed, 36 insertions(+), 39 deletions(-)
 rename scripts/{ost_startup.py => ost_startup.py.in} (92%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3cdb0fba0..d4e3ab60c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,7 +48,7 @@ option(ENABLE_SPNAV "whether 3DConnexion devices should be supported"
 option(STATIC_PROPERTY_WORKAROUND "workaround for static property bug with some boost/boost_python combinations" OFF)
 option(COMPILE_TESTS "whether unit tests should be compiled by default" OFF)
 option(ENABLE_STATIC "whether static libraries should be compiled" OFF)
-option(DEBIAN_STYLE_LIBEXEC "whether 'libexec' should be put under 'lib/openstructure" OFF)
+option(UBUNTU_LAYOUT "whether Debian/Ubuntu's lib and libexec directory layout should be used" OFF)
 option(HIDDEN_VISIBILITY "on gcc, use -fvisibility=hidden" OFF)
 
 if (CXX)
@@ -140,10 +140,10 @@ else()
   set(_PROFILE OFF)
 endif()
 
-if (DEBIAN_STYLE_LIBEXEC)
-  set(_DEBIAN_STYLE_LIBEXEC ON)
+if (UBUNTU_LAYOUT)
+  set(_UBUNTU_LAYOUT ON)
 else()
-  set(_DEBIAN_STYLE_LIBEXEC OFF)
+  set(_UBUNTU_LAYOUT OFF)
 endif()
 
 add_definitions(-DEIGEN2_SUPPORT)
@@ -333,22 +333,22 @@ if (CMAKE_COMPILER_IS_GNUCXX)
 endif()
 message(STATUS 
         "OpenStructure will be built with the following options:\n"
-        "   Install Prefix                       (-DPREFIX) : ${CMAKE_INSTALL_PREFIX}\n"
-        "   RPath in install                  (-DUSE_RPATH) : ${_USE_RPATH}\n"
-        "   Info support                    (-DENABLE_INFO) : ${_INFO}\n"
-        "   Graphical interface              (-DENABLE_GUI) : ${_UI}\n"
-        "   OpenGL support                   (-DENABLE_GFX) : ${_OPENGL}\n"
-        "   OpenGL via Mesa                    (-DUSE_MESA) : ${_USE_MESA}\n"
-        "   Image Processing support         (-DENABLE_IMG) : ${_IMG}\n"
-        "   Shader support                   (-DUSE_SHADER) : ${_SHADER}\n"
-        "   Numpy support                     (-DUSE_NUMPY) : ${_NUMPY}\n"
-        "   SpaceNav Device support        (-DENABLE_SPNAV) : ${_SPNAV}\n"
-        "   Optimize                           (-DOPTIMIZE) : ${_OPT}\n"
-        "   Profiling support                   (-DPROFILE) : ${_PROFILE}\n"
-        "   Double Precision       (-DUSE_DOUBLE_PRECISION) : ${_DOUBLE_PREC}\n"
-        "   Compound Lib                   (-DCOMPOUND_LIB) : ${_COMP_LIB}\n"
-        "   TMAlign and TMScore         (-DCOMPILE_TMTOOLS) : ${_TM_TOOLS}\n"
-        "   Static Libraries              (-DENABLE_STATIC) : ${ENABLE_STATIC}\n"
-        "   Debian-style 'libexec' (-DDEBIAN_STYLE_LIBEXEC) : ${_DEBIAN_STYLE_LIBEXEC}"
+        "   Install Prefix                        (-DPREFIX) : ${CMAKE_INSTALL_PREFIX}\n"
+        "   RPath in install                   (-DUSE_RPATH) : ${_USE_RPATH}\n"
+        "   Info support                     (-DENABLE_INFO) : ${_INFO}\n"
+        "   Graphical interface               (-DENABLE_GUI) : ${_UI}\n"
+        "   OpenGL support                    (-DENABLE_GFX) : ${_OPENGL}\n"
+        "   OpenGL via Mesa                     (-DUSE_MESA) : ${_USE_MESA}\n"
+        "   Image Processing support          (-DENABLE_IMG) : ${_IMG}\n"
+        "   Shader support                    (-DUSE_SHADER) : ${_SHADER}\n"
+        "   Numpy support                      (-DUSE_NUMPY) : ${_NUMPY}\n"
+        "   SpaceNav Device support         (-DENABLE_SPNAV) : ${_SPNAV}\n"
+        "   Optimize                            (-DOPTIMIZE) : ${_OPT}\n"
+        "   Profiling support                    (-DPROFILE) : ${_PROFILE}\n"
+        "   Double Precision        (-DUSE_DOUBLE_PRECISION) : ${_DOUBLE_PREC}\n"
+        "   Compound Lib                    (-DCOMPOUND_LIB) : ${_COMP_LIB}\n"
+        "   TMAlign and TMScore          (-DCOMPILE_TMTOOLS) : ${_TM_TOOLS}\n"
+        "   Static Libraries               (-DENABLE_STATIC) : ${ENABLE_STATIC}\n"
+        "   Debian/Ubuntu directory layout (-DUBUNTU_LAYOUT) : ${_UBUNTU_LAYOUT}"
         ${HIDDEN_VIS_MSG})
 
diff --git a/cmake_support/OST.cmake b/cmake_support/OST.cmake
index 1018dbac0..3c98c78cd 100644
--- a/cmake_support/OST.cmake
+++ b/cmake_support/OST.cmake
@@ -829,24 +829,21 @@ macro(setup_stage)
     check_architecture()
   endif()
   set (ARCH ${CMAKE_NATIVE_ARCH})
-  if ("${ARCH}" MATCHES "64")
+  if ("${ARCH}" MATCHES "64" AND NOT _UBUNTU_LAYOUT)
     set(LIB_DIR lib64  )
     set(LIB_STAGE_PATH "${STAGE_DIR}/lib64"  )
   else()
     set(LIB_DIR lib  )
     set(LIB_STAGE_PATH "${STAGE_DIR}/lib"  )
   endif()
-  if (_DEBIAN_STYLE_LIBEXEC)
+  if (_UBUNTU_LAYOUT)
     set(LIBEXEC_PATH ${LIB_DIR}/openstructure/libexec  )
-  else()
-    set(LIBEXEC_PATH libexec/openstructure  )
-  endif()
-  if (_DEBIAN_STYLE_LIBEXEC)
     set(LIBEXEC_STAGE_PATH ${LIB_STAGE_PATH}/openstructure/libexec  )
-  else()
+   else()
+    set(LIBEXEC_PATH libexec/openstructure  )
     set(LIBEXEC_STAGE_PATH ${STAGE_DIR}/libexec/openstructure  )
   endif()
-
+ 
   include_directories("${HEADER_STAGE_PATH}")
   link_directories(${LIB_STAGE_PATH})
 
diff --git a/modules/config/CMakeLists.txt b/modules/config/CMakeLists.txt
index 4f7e645ae..391a70c9a 100644
--- a/modules/config/CMakeLists.txt
+++ b/modules/config/CMakeLists.txt
@@ -57,10 +57,10 @@ if (FFTW_USE_THREADS)
 else()
   set(fftw_use_threads 0)
 endif()
-if (_DEBIAN_STYLE_LIBEXEC)
-  set(debian_style_libexec 1)
+if (_UBUNTU_LAYOUT)
+  set(ubuntu_layout 1)
 else()
-  set(debian_style_libexec 0)
+  set(ubuntu_layout 0)
 endif()
 if (ENABLE_INFO)
   set(info_enabled 1)
diff --git a/modules/config/config.hh.in b/modules/config/config.hh.in
index 23027e248..5a5b2bb4c 100644
--- a/modules/config/config.hh.in
+++ b/modules/config/config.hh.in
@@ -32,7 +32,7 @@
 #define OST_STATIC_PROPERTY_WORKAROUND @static_props@
 #define OST_FFT_USE_THREADS @fftw_use_threads@
 #define OST_NUMPY_SUPPORT_ENABLED @numpy_support@
-#define OST_DEBIAN_STYLE_LIBEXEC @debian_style_libexec@
+#define OST_UBUNTU_LAYOUT @ubuntu_layout@
 #define OST_INFO_ENABLED @info_enabled@
 
 #endif
diff --git a/modules/gui/src/gosty.cc b/modules/gui/src/gosty.cc
index 952b2f46f..a767d1b9f 100644
--- a/modules/gui/src/gosty.cc
+++ b/modules/gui/src/gosty.cc
@@ -82,7 +82,7 @@ String get_ost_root()
 {
   QDir dir(QApplication::applicationDirPath());
 
-#if OST_DEBIAN_STYLE_LIBEXEC  
+#if OST_UBUNTU_LAYOUT  
   #ifdef _MSC_VER
     dir.cdUp();
     dir.cdUp();
@@ -111,7 +111,7 @@ String setup_python_search_path(const String& root, PythonInterpreter& pi)
 #ifdef _MSC_VER
   String loc=root+"\\lib\\"+site_pkgs.str()+"\\site-packages";
 #else  
-# if (defined(__ppc64__) || defined(__x86_64__)) && !defined(__APPLE__)
+# if (defined(__ppc64__) || defined(__x86_64__)) && !defined(__APPLE__) && !OST_UBUNTU_LAYOUT
   String loc=root+"/lib64/"+site_pkgs.str()+"/site-packages";
 # else
   String loc=root+"/lib/"+site_pkgs.str()+"/site-packages";
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index 0c8f2c680..d79f6f54b 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -29,6 +29,9 @@ if (NOT ENABLE_STATIC)
     endif()
   endif()
 
+  script(NAME ost_startup.py INPUT ost_startup.py.in SUBSTITUTE ${SUBST_DICT} 
+         TARGET ost_scripts OUTPUT_DIR "${LIB_DIR}/python${PYTHON_VERSION}/site-packages/ost" )    
+
   set(INIT_SCRIPTS 
     ost_startup.py
   )
diff --git a/scripts/ost_startup.py b/scripts/ost_startup.py.in
similarity index 92%
rename from scripts/ost_startup.py
rename to scripts/ost_startup.py.in
index 553d54cb9..df65597b2 100644
--- a/scripts/ost_startup.py
+++ b/scripts/ost_startup.py.in
@@ -28,10 +28,7 @@ parser.disable_interspersed_args()
 
 _site_packs='python%d.%d/site-packages' % sys.version_info[0:2]
 _base_dir=os.getenv('DNG_ROOT')
-if platform.machine()=='x86_64' and platform.system()!='Darwin' :
-  sys.path.insert(0, os.path.join(_base_dir, 'lib64', _site_packs))
-else:
-  sys.path.insert(0,os.path.join(_base_dir, 'lib', _site_packs))
+sys.path.insert(0, os.path.join(_base_dir, '@LIBDIR@', _site_packs))
      
 from ost import *
 import ost
-- 
GitLab