Fix shared library compilation for Python

Untested. AFAIU, the static library built for Python is linked into
a shared library later. This requires to use -fPIC and define
CFP_CFISH.

I think it would be better if the Python bindings followed the
approach I took for Perl: Pass a list of object files instead of
using a static library.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/3764180f
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/3764180f
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/3764180f

Branch: refs/heads/master
Commit: 3764180f0e7b5893f79d7ecb806b7106dd530b29
Parents: bad95e0
Author: Nick Wellnhofer <wellnho...@aevum.de>
Authored: Fri Jul 8 13:57:39 2016 +0200
Committer: Nick Wellnhofer <wellnho...@aevum.de>
Committed: Fri Jul 8 14:35:42 2016 +0200

----------------------------------------------------------------------
 runtime/common/charmonizer.c    | 18 ++++++++++++++++++
 runtime/common/charmonizer.main | 18 ++++++++++++++++++
 runtime/python/cfext/CFBind.c   |  1 +
 3 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3764180f/runtime/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.c b/runtime/common/charmonizer.c
index 37cfaf4..102970e 100644
--- a/runtime/common/charmonizer.c
+++ b/runtime/common/charmonizer.c
@@ -8930,6 +8930,15 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags 
*extra_link_flags) {
         self->lib
             = chaz_MakeFile_add_static_lib(self->makefile, NULL, "clownfish");
         lib_objs = "$(CLOWNFISH_STATIC_LIB_OBJS)";
+
+        if (strcmp(host, "python") == 0) {
+            /* For Python, the static library is linked into a shared
+             * library.
+             */
+            compile_flags = chaz_MakeBinary_get_compile_flags(self->lib);
+            chaz_CFlags_compile_shared_library(compile_flags);
+            chaz_CFlags_add_define(compile_flags, "CFP_CFISH", NULL);
+        }
     }
 
     if (self->host_src_dir) {
@@ -8967,6 +8976,15 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags 
*extra_link_flags) {
         self->test_lib
             = chaz_MakeFile_add_static_lib(self->makefile, NULL, "testcfish");
         test_lib_objs = "$(TESTCFISH_STATIC_LIB_OBJS)";
+
+        if (strcmp(host, "python") == 0) {
+            /* For Python, the static library is linked into a shared
+             * library.
+             */
+            compile_flags = chaz_MakeBinary_get_compile_flags(self->test_lib);
+            chaz_CFlags_compile_shared_library(compile_flags);
+            chaz_CFlags_add_define(compile_flags, "CFP_TESTCFISH", NULL);
+        }
     }
 
     chaz_MakeBinary_add_src_dir(self->test_lib, self->test_dir);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3764180f/runtime/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main
index 124541c..fc68fd4 100644
--- a/runtime/common/charmonizer.main
+++ b/runtime/common/charmonizer.main
@@ -382,6 +382,15 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags 
*extra_link_flags) {
         self->lib
             = chaz_MakeFile_add_static_lib(self->makefile, NULL, "clownfish");
         lib_objs = "$(CLOWNFISH_STATIC_LIB_OBJS)";
+
+        if (strcmp(host, "python") == 0) {
+            /* For Python, the static library is linked into a shared
+             * library.
+             */
+            compile_flags = chaz_MakeBinary_get_compile_flags(self->lib);
+            chaz_CFlags_compile_shared_library(compile_flags);
+            chaz_CFlags_add_define(compile_flags, "CFP_CFISH", NULL);
+        }
     }
 
     if (self->host_src_dir) {
@@ -419,6 +428,15 @@ cfish_MakeFile_write(cfish_MakeFile *self, chaz_CFlags 
*extra_link_flags) {
         self->test_lib
             = chaz_MakeFile_add_static_lib(self->makefile, NULL, "testcfish");
         test_lib_objs = "$(TESTCFISH_STATIC_LIB_OBJS)";
+
+        if (strcmp(host, "python") == 0) {
+            /* For Python, the static library is linked into a shared
+             * library.
+             */
+            compile_flags = chaz_MakeBinary_get_compile_flags(self->test_lib);
+            chaz_CFlags_compile_shared_library(compile_flags);
+            chaz_CFlags_add_define(compile_flags, "CFP_TESTCFISH", NULL);
+        }
     }
 
     chaz_MakeBinary_add_src_dir(self->test_lib, self->test_dir);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3764180f/runtime/python/cfext/CFBind.c
----------------------------------------------------------------------
diff --git a/runtime/python/cfext/CFBind.c b/runtime/python/cfext/CFBind.c
index 4c5780e..0703880 100644
--- a/runtime/python/cfext/CFBind.c
+++ b/runtime/python/cfext/CFBind.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#define CFP_CFISH
 #define C_CFISH_OBJ
 #define C_CFISH_CLASS
 #define C_CFISH_METHOD

Reply via email to