Author: Ole Streicher <olebole@debian.org>
Description: Create a shared library to link to gdl executable and Python extension
 The library is called libgnudatalanguage.so to avoid confusion with the
 libgdl from the GNOME project.
Forwarded: https://sourceforge.net/p/gnudatalanguage/patches/95/
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -920,9 +920,7 @@
 	endif(WIN32 AND NOT CYGWIN)
 endif(X11)
 add_subdirectory(src)
-if(NOT PYTHON_MODULE)
-	add_subdirectory(testsuite)
-endif(NOT PYTHON_MODULE)
+add_subdirectory(testsuite)
 
 install(FILES ${CMAKE_SOURCE_DIR}/AUTHORS ${CMAKE_SOURCE_DIR}/README DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_DATA_DIR})
 install(FILES ${CMAKE_SOURCE_DIR}/doc/gdl.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
@@ -932,14 +930,12 @@
 
 # create a link src/gdl -> ${BUILD}/.../gdl
 # for windows, just copy the file
-if(NOT PYTHON_MODULE)
 	get_target_property(GDLLOCATION gdl LOCATION)
 	if(WIN32)
 	add_custom_target(copy_gdl ALL ${CMAKE_COMMAND} -E copy ${GDLLOCATION} ${CMAKE_SOURCE_DIR}/src/gdl DEPENDS gdl)
 	else(WIN32)
 	add_custom_target(symlink_gdl ALL ${CMAKE_COMMAND} -E create_symlink ${GDLLOCATION} ${CMAKE_SOURCE_DIR}/src/gdl DEPENDS gdl)
 	endif(WIN32)
-endif(NOT PYTHON_MODULE)
 
 # display macro
 macro(MODULE MOD NAME)
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -271,23 +271,30 @@
 include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/antlr ${CMAKE_BINARY_DIR})
 link_directories(${LINK_DIRECTORIES})
 
+add_library(gnudatalanguage SHARED ${SOURCES})
+SET_TARGET_PROPERTIES(gnudatalanguage PROPERTIES SOVERSION 0)
 if(PYTHON_MODULE) #GDL.so
-	set(SOURCES ${SOURCES} pythongdl.cpp)
-	add_library(gdl SHARED ${SOURCES})
+	add_library(pythongdl SHARED pythongdl.cpp)
 	SET_TARGET_PROPERTIES(pythongdl PROPERTIES PREFIX "")
 	SET_TARGET_PROPERTIES(pythongdl PROPERTIES OUTPUT_NAME GDL)
 	SET_TARGET_PROPERTIES(pythongdl PROPERTIES NO_SONAME TRUE)
-else(PYTHON_MODULE) #gdl
-	set(SOURCES ${SOURCES} gdl.cpp)
-	add_executable(gdl ${SOURCES})
+	target_link_libraries(pythongdl gnudatalanguage)
 endif(PYTHON_MODULE)
+add_executable(gdl gdl.cpp)
+target_link_libraries(gdl gnudatalanguage)
+if (OPENMP)
+	target_link_libraries(gdl -fopenmp)
+endif (OPENMP)
+if (READLINE)
+	target_link_libraries(gdl readline)
+endif (READLINE)
 
-add_dependencies(gdl antlr) # be sure that antlr is built before gdl
-target_link_libraries(gdl antlr) # link antlr against gdl
+add_dependencies(gnudatalanguage antlr) # be sure that antlr is built before gdl
+target_link_libraries(gnudatalanguage antlr) # link antlr against gdl
 if (MINGW)
-target_link_libraries(gdl ws2_32)
+target_link_libraries(gnudatalanguage ws2_32)
 endif (MINGW)
-target_link_libraries(gdl ${LIBRARIES})
+target_link_libraries(gnudatalanguage PRIVATE ${LIBRARIES})
 add_definitions(-DHAVE_CONFIG_H)
 
 if(PYTHON_MODULE)
@@ -302,11 +309,11 @@
 	file( TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR )
 	string( REGEX REPLACE "^${PYTHON_PREFIX}/" ""
 	       PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
-	install(TARGETS gdl DESTINATION ${PYTHON_SITE_DIR})
-else(PYTHON_MODULE)
-	install(TARGETS gdl DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
-	set_target_properties(gdl PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+	install(TARGETS pythongdl DESTINATION ${PYTHON_SITE_DIR})
 endif(PYTHON_MODULE)
+install(TARGETS gdl DESTINATION bin)
+set_target_properties(gdl PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+install(TARGETS gnudatalanguage DESTINATION lib)
 
 install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/pro/ DESTINATION ${CMAKE_INSTALL_PREFIX}/${GDL_DATA_DIR}/lib
 	PATTERN CVS EXCLUDE
--- a/src/gdl.cpp
+++ b/src/gdl.cpp
@@ -17,9 +17,6 @@
 
 #include "includefirst.hpp"
 
-// should (Makefile.am) not be used anyway for the python module
-#ifndef PYTHON_MODULE
-
 // #ifndef VERSION
 // #define VERSION "0.9"
 // #endif
@@ -174,7 +171,7 @@
 
 // SA: for use in COMMAND_LINE_ARGS()
 namespace lib {
-  std::vector<char*> command_line_args;
+  extern std::vector<char*> command_line_args;
 }
 
 int main(int argc, char *argv[])
@@ -386,5 +383,3 @@
 
   return 0;
 }
-
-#endif
--- a/src/basic_fun.cpp
+++ b/src/basic_fun.cpp
@@ -99,6 +99,9 @@
 
 namespace lib {
 
+  // for use in COMMAND_LINE_ARGS()
+  std::vector<char*> command_line_args;
+
   //  using namespace std;
   using std::isnan;
   using namespace antlr;
@@ -6690,11 +6693,7 @@
   //     defined and filled with data (pointers) in gdl.cpp
   BaseGDL* command_line_args_fun(EnvT* e)
   {
-#ifdef PYTHON_MODULE
-    e->Throw("no command line arguments available (GDL built as a Python module)");
-#else
     static int countIx = e->KeywordIx("COUNT");
-    extern std::vector<char*> command_line_args; 
 
     // setting the COUNT keyword value
     if (e->KeywordPresent(countIx))
@@ -6712,7 +6711,6 @@
 	  (*static_cast<DStringGDL*>(ret))[i] = command_line_args[i];
 	return ret;
       }
-#endif
   }
 
   // SA: relies in the uname() from libc (must be there if POSIX)
--- a/src/includefirst.hpp
+++ b/src/includefirst.hpp
@@ -54,12 +54,6 @@
 //#warning "_POSIX_C_SOURCE not defined in Python.h (remove #undef)"
 //#endif
 
-// for the python module pyhton's readline is used
-// this is ok as long as there is no GDL prompt within python
-#ifdef PYTHON_MODULE
-#undef HAVE_LIBREADLINE
-#endif
-
 #ifdef GDL_NOT_HAVE_READLINE
 #undef HAVE_LIBREADLINE
 #endif
