[MLton-commit] r6899

Wesley Terpstra wesley at mlton.org
Thu Oct 2 02:56:34 PDT 2008


Improve the export header:
  Support c++ (extern "C")
  Support dynamic/static/internal linkage via macros:
    #define PART_OF_xxx
    #define STATIC_LINK_xxx
    #define DYNAMIC_LINK_xxx
    these control how the C header imports symbols.
  Setup default values for the linkage if none are specified:
    archive    => STATIC_LINK
    library    => DYNAMIC_LINK
    executable => PART_OF
  The user can override these defaults by defining a macro before include.
    For C files linked into an archive/library, PART_OF_xxx is needed.
  The libarchive format has no default.
    The library is by it's nature intended to be statically linked into a
    dynamic library. Therefore there is no default; some code statically
    links it, and potentially users of the resulting library dynamically
    link to it.



----------------------------------------------------------------------

U   mlton/trunk/mlton/main/compile.fun
U   mlton/trunk/regression/library/libm1.c
U   mlton/trunk/regression/library/libm2.c
U   mlton/trunk/regression/library/libm3.c
U   mlton/trunk/regression/library/libm4.c
U   mlton/trunk/regression/library/libm5.c
U   mlton/trunk/regression/library/library-test

----------------------------------------------------------------------

Modified: mlton/trunk/mlton/main/compile.fun
===================================================================
--- mlton/trunk/mlton/main/compile.fun	2008-10-01 11:59:28 UTC (rev 6898)
+++ mlton/trunk/mlton/main/compile.fun	2008-10-02 09:56:28 UTC (rev 6899)
@@ -431,17 +431,38 @@
                       File.outputContents
                       (concat [!Control.libDir, "/include/export.h"], out)
                    val _ = print "\n"
+                   (* How do programs link against this library by default *)
+                   val defaultLinkage =
+                      case !Control.format of
+                         Control.Archive    => "STATIC_LINK"
+                       | Control.Executable => "PART_OF"
+                       | Control.LibArchive => "NO_DEFAULT_LINK"
+                       | Control.Library    => "DYNAMIC_LINK"
                    val _ = 
-                      if !Control.format = Control.Executable
-                      then print "#if 1 /* C executables compile with same symbol scope as ML executables */\n"
-                      else print ("#ifdef PART_OF_LIBRARY_" ^ libcap ^ "\n")
+                      print ("#if !defined(PART_OF_"      ^ libcap ^ ") && \n\
+                             \    !defined(STATIC_LINK_"  ^ libcap ^ ") && \n\
+                             \    !defined(DYNAMIC_LINK_" ^ libcap ^ ")\n")
+                   val _ = 
+                      print ("#define " ^ defaultLinkage ^ "_" ^ libcap ^ "\n")
+                   val _ = print "#endif\n"
+                   val _ = print "\n"
+                   val _ = print ("#if defined(PART_OF_" ^ libcap ^ ")\n")
                    val _ = print "#define MLLIB_PRIVATE(x) PRIVATE x\n"
                    val _ = print "#define MLLIB_PUBLIC(x) PUBLIC x\n"
-                   val _ = print "#else\n"
+                   val _ = print ("#elif defined(STATIC_LINK_" ^ libcap ^ ")\n")
                    val _ = print "#define MLLIB_PRIVATE(x)\n"
+                   val _ = print "#define MLLIB_PUBLIC(x) PUBLIC x\n"
+                   val _ = print ("#elif defined(DYNAMIC_LINK_" ^ libcap ^ ")\n")
+                   val _ = print "#define MLLIB_PRIVATE(x)\n"
                    val _ = print "#define MLLIB_PUBLIC(x) EXTERNAL x\n"
+                   val _ = print "#else\n"
+                   val _ = print ("#error Must specify linkage for " ^ libname ^ "\n")
                    val _ = print "#endif\n"
                    val _ = print "\n"
+                   val _ = print "#ifdef __cplusplus\n"
+                   val _ = print "extern \"C\" {\n"
+                   val _ = print "#endif\n"
+                   val _ = print "\n"
                    val _ = 
                       if !Control.format = Control.Executable then () else
                           (print ("MLLIB_PUBLIC(void " ^ libname ^ "_open(int argc, const char** argv);)\n")
@@ -451,6 +472,10 @@
                    val _ = print "#undef MLLIB_PRIVATE\n"
                    val _ = print "#undef MLLIB_PUBLIC\n"
                    val _ = print "\n"
+                   val _ = print "#ifdef __cplusplus\n"
+                   val _ = print "}\n"
+                   val _ = print "#endif\n"
+                   val _ = print "\n"
                    val _ = print ("#endif /* __" ^ libcap ^ "_ML_H__ */\n")
                 in
                    ()

Modified: mlton/trunk/regression/library/libm1.c
===================================================================
--- mlton/trunk/regression/library/libm1.c	2008-10-01 11:59:28 UTC (rev 6898)
+++ mlton/trunk/regression/library/libm1.c	2008-10-02 09:56:28 UTC (rev 6899)
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#define PART_OF_LIBRARY_M1
+#define PART_OF_M1
 #include "m1.h"
 
 PRIVATE void* libm1cSymPrivate = 0;

Modified: mlton/trunk/regression/library/libm2.c
===================================================================
--- mlton/trunk/regression/library/libm2.c	2008-10-01 11:59:28 UTC (rev 6898)
+++ mlton/trunk/regression/library/libm2.c	2008-10-02 09:56:28 UTC (rev 6899)
@@ -1,7 +1,8 @@
 #include <assert.h>
 
-#define PART_OF_LIBRARY_M2
+#define PART_OF_M2
 #include "m2.h"
+#define STATIC_LINK_M2
 #include "m1.h"
 
 extern PUBLIC void* libm1cSymPublic;

Modified: mlton/trunk/regression/library/libm3.c
===================================================================
--- mlton/trunk/regression/library/libm3.c	2008-10-01 11:59:28 UTC (rev 6898)
+++ mlton/trunk/regression/library/libm3.c	2008-10-02 09:56:28 UTC (rev 6899)
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#define PART_OF_LIBRARY_M3
+#define PART_OF_M3
 #include "m3.h"
 #include "m2.h"
 #include "m1.h"

Modified: mlton/trunk/regression/library/libm4.c
===================================================================
--- mlton/trunk/regression/library/libm4.c	2008-10-01 11:59:28 UTC (rev 6898)
+++ mlton/trunk/regression/library/libm4.c	2008-10-02 09:56:28 UTC (rev 6899)
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#define PART_OF_LIBRARY_M4
+#define PART_OF_M4
 #include "m4.h"
 #include "m3.h"
 #include "m2.h"

Modified: mlton/trunk/regression/library/libm5.c
===================================================================
--- mlton/trunk/regression/library/libm5.c	2008-10-01 11:59:28 UTC (rev 6898)
+++ mlton/trunk/regression/library/libm5.c	2008-10-02 09:56:28 UTC (rev 6899)
@@ -1,6 +1,6 @@
 #include <assert.h>
 
-#define PART_OF_LIBRARY_M5
+#define PART_OF_M5
 #include "m5.h"
 #include "m4.h"
 #include "m3.h"

Modified: mlton/trunk/regression/library/library-test
===================================================================
--- mlton/trunk/regression/library/library-test	2008-10-01 11:59:28 UTC (rev 6898)
+++ mlton/trunk/regression/library/library-test	2008-10-02 09:56:28 UTC (rev 6899)
@@ -1,6 +1,6 @@
 #! /usr/bin/env bash
 
-ML=../../build/bin/mlton
+ML=mlton #../../build/bin/mlton
 
 O[0]='-default-ann'
 O[1]='allowFFI true'




More information about the MLton-commit mailing list