c_tools: add attribute `ExternFile::pkgconfigs` to stores needed libraries.
authorJean Privat <jean@pryen.org>
Tue, 4 Nov 2014 16:25:34 +0000 (11:25 -0500)
committerJean Privat <jean@pryen.org>
Tue, 4 Nov 2014 16:25:34 +0000 (11:25 -0500)
Thew will be resolved at the `make` time.

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

src/c_tools.nit
src/compiler/abstract_compiler.nit

index 07934dd..7e235b0 100644 (file)
@@ -115,6 +115,10 @@ class ExternFile
        fun compiles_to_o_file: Bool do return false
 
        fun add_to_jar: Bool do return false
+
+       # Additional libraries needed for the compilation
+       # Will be used with pkg-config
+       var pkgconfigs = new Array[String]
 end
 
 # An extern C file to compile
@@ -128,7 +132,7 @@ class ExternCFile
                self.cflags = cflags
        end
 
-       # Additionnal specific CC compiler -c flags
+       # Additional specific CC compiler -c flags
        var cflags: String
 
        redef fun hash do return filename.hash
@@ -143,7 +147,11 @@ class ExternCFile
        redef fun makefile_rule_content do
                var ff = filename.basename("")
                var o = makefile_rule_name
-               return "$(CC) $(CFLAGS) {self.cflags} -c -o {o} {ff}"
+               var pkg = ""
+               if not pkgconfigs.is_empty then
+                       pkg = "`pkg-config --cflags {pkgconfigs.join(" ")}`"
+               end
+               return "$(CC) $(CFLAGS) {self.cflags} {pkg} -c -o {o} {ff}"
        end
 
        redef fun compiles_to_o_file do return true
index e3c2fdf..f9be9e1 100644 (file)
@@ -399,6 +399,10 @@ class MakefileToolchain
 
                var java_files = new Array[ExternFile]
 
+               var pkgconfigs = new Array[String]
+               for f in compiler.extern_bodies do
+                       pkgconfigs.add_all f.pkgconfigs
+               end
                # Compile each required extern body into a specific .o
                for f in compiler.extern_bodies do
                        var o = f.makefile_rule_name
@@ -424,7 +428,11 @@ class MakefileToolchain
                end
 
                # Link edition
-               makefile.write("{outpath}: {dep_rules.join(" ")}\n\t$(CC) $(LDFLAGS) -o {outpath} {ofiles.join(" ")} $(LDLIBS)\n\n")
+               var pkg = ""
+               if not pkgconfigs.is_empty then
+                       pkg = "`pkg-config --libs {pkgconfigs.join(" ")}`"
+               end
+               makefile.write("{outpath}: {dep_rules.join(" ")}\n\t$(CC) $(LDFLAGS) -o {outpath} {ofiles.join(" ")} $(LDLIBS) {pkg}\n\n")
                # Clean
                makefile.write("clean:\n\trm {ofiles.join(" ")} 2>/dev/null\n\n")
                makefile.close