abstract_compiler: add `AModule::collect_linker_libs` to be refined in compiler_ffi
authorJean Privat <jean@pryen.org>
Wed, 2 Apr 2014 14:10:17 +0000 (10:10 -0400)
committerJean Privat <jean@pryen.org>
Wed, 2 Apr 2014 14:10:17 +0000 (10:10 -0400)
This separate `abstract_compiler` from `common_ffi` since the last link
`c_linker_options` is now removed.

One other great separation of concern!

Signed-off-by: Jean Privat <jean@pryen.org>

src/abstract_compiler.nit
src/compiler_ffi.nit

index 08cc0e1..6f20839 100644 (file)
@@ -21,7 +21,6 @@ import literal
 import typing
 import auto_super_init
 import frontend
-import common_ffi
 import platform
 import c_tools
 
@@ -303,7 +302,8 @@ class MakefileToolchain
                var m2m = toolcontext.modelbuilder.mmodule2nmodule
                for m in mainmodule.in_importation.greaters do if m2m.keys.has(m) then
                        var amod = m2m[m]
-                       linker_options.add(amod.c_linker_options)
+                       var libs = amod.collect_linker_libs
+                       if libs != null then linker_options.add_all(libs)
                end
 
                if not toolcontext.opt_no_stacktrace.value then linker_options.add("-lunwind")
@@ -2623,4 +2623,8 @@ redef class AModule
 
        # Write nitni results to file
        fun finalize_nitni(v: AbstractCompilerVisitor) do end
+
+       # Give requided addinional system libraries (as given to LD_LIBS)
+       # Note: can return null instead of an empty set
+       fun collect_linker_libs: nullable Set[String] do return null
 end
index ee2f52f..adc3075 100644 (file)
@@ -53,6 +53,15 @@ redef class AModule
                end
        end
 
+       redef fun collect_linker_libs
+       do
+               var s = c_linker_options
+               if s.is_empty then return null
+               var res = new ArraySet[String]
+               res.add s
+               return res
+       end
+
        var compiled_callbacks: Array[NitniCallback] = new Array[NitniCallback]
 
        # Returns true if callbacks has yet to be generated and register it as being generated