]> git.tdb.fi Git - builder.git/commitdiff
Add target and tools for compiling Objective-C sources
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 May 2013 10:07:46 +0000 (13:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 May 2013 10:07:46 +0000 (13:07 +0300)
source/clangobjccompiler.cpp [new file with mode: 0644]
source/clangobjccompiler.h [new file with mode: 0644]
source/clangtools.cpp
source/csourcefile.cpp
source/csourcefile.h
source/gnulinker.cpp
source/gnuobjccompiler.cpp [new file with mode: 0644]
source/gnuobjccompiler.h [new file with mode: 0644]
source/gnutools.cpp
source/objcsourcefile.cpp [new file with mode: 0644]
source/objcsourcefile.h [new file with mode: 0644]

diff --git a/source/clangobjccompiler.cpp b/source/clangobjccompiler.cpp
new file mode 100644 (file)
index 0000000..557bf3e
--- /dev/null
@@ -0,0 +1,7 @@
+#include "clangobjccompiler.h"
+
+ClangObjCCompiler::ClangObjCCompiler(Builder &b, const Architecture &a):
+       GnuObjCCompiler(b, a)
+{
+       set_command("clang", true);
+}
diff --git a/source/clangobjccompiler.h b/source/clangobjccompiler.h
new file mode 100644 (file)
index 0000000..64b96d0
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef CLANGOBJCCOMPILER_H_
+#define CLANGOBJCCOMPILER_H_
+
+#include "gnuobjccompiler.h"
+
+class ClangObjCCompiler: public GnuObjCCompiler
+{
+public:
+       ClangObjCCompiler(Builder &, const Architecture &);
+};
+
+#endif
index 1c7c8d6cc791ae63ef5931d80e2df12878ac597f..a4f005cc2b5d5d3274eb2fa9ada45c6655da6a9c 100644 (file)
@@ -1,9 +1,11 @@
 #include "clangccompiler.h"
 #include "clangcxxcompiler.h"
+#include "clangobjccompiler.h"
 #include "clangtools.h"
 
 ClangTools::ClangTools(Builder &builder, const Architecture &arch)
 {
        add_tool(new ClangCCompiler(builder, arch));
        add_tool(new ClangCxxCompiler(builder, arch));
+       add_tool(new ClangObjCCompiler(builder, arch));
 }
index 13c74b9dcef247402490da7d7638de379c50f067..e34ff279cc4c98d199b491c075e17bc4c689a449 100644 (file)
@@ -22,6 +22,16 @@ CSourceFile::CSourceFile(Builder &b, const Component &c, const FS::Path &p):
                install_location = FS::Path("include")/package->get_name();
 }
 
+void CSourceFile::parse_includes(IO::Base &in)
+{
+       static Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
+
+       string line;
+       while(in.getline(line))
+               if(RegMatch match = r_include.match(line))
+                       includes.push_back(match[1].str);
+}
+
 void CSourceFile::find_dependencies()
 {
        if(!component || !mtime)
@@ -38,13 +48,7 @@ void CSourceFile::find_dependencies()
 
                builder.get_logger().log("files", format("Reading includes from %s", path.str()));
 
-               Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
-
-               string line;
-               while(in.getline(line))
-                       if(RegMatch match = r_include.match(line))
-                               includes.push_back(match[1].str);
-
+               parse_includes(in);
                cache.set_values(this, "includes", includes);
        }
 
index 9ed736a4f770566e943cbdbf447235d37af9b067..dce6e19c7a478bbbe3744811800de844a71f1e87 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef CSOURCEFILE_H_
 #define CSOURCEFILE_H_
 
+#include <msp/io/base.h>
 #include "sourcefile.h"
 
 /**
@@ -11,7 +12,7 @@ class CSourceFile: public SourceFile
 public:
        typedef std::list<std::string> IncludeList;
 
-private:
+protected:
        IncludeList includes;
 
 public:
@@ -20,7 +21,8 @@ public:
 
        virtual const char *get_type() const { return "CSourceFile"; }
        const IncludeList &get_includes() const { return includes; }
-private:
+protected:
+       virtual void parse_includes(Msp::IO::Base &);
        virtual void find_dependencies();
        virtual void modified();
 };
index b2df14cbc9c90e7bff446411654ebf1ce445c7de..b2516d6394eab3ddec5733d10347e0d43923e721 100644 (file)
@@ -212,6 +212,7 @@ Task *GnuLinker::Linker::run(const Target &target) const
        argv.push_back(relative(bin.get_path(), work_dir).str());
 
        bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC);
+       bool need_l_objc = false;
 
        const Target::Dependencies &depends = target.get_dependencies();
        for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
@@ -220,7 +221,13 @@ Task *GnuLinker::Linker::run(const Target &target) const
                Target *tgt = (*i)->get_real_target();
 
                if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
+               {
                        argv.push_back(relative(obj->get_path(), work_dir).str());
+                       /* XXX This is a hack.  A more generic way is needed for tools to pass
+                       information down the chain. */
+                       if(obj->get_tool()->get_tag()=="OBJC")
+                               need_l_objc = true;
+               }
                else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
                        argv.push_back((file?file:stlib)->get_path().str());
                else if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(tgt))
@@ -239,6 +246,8 @@ Task *GnuLinker::Linker::run(const Target &target) const
                }
        }
 
+       if(need_l_objc)
+               argv.push_back("-lobjc");
        if(static_link_ok)
                argv.push_back("-static");
        else if(architecture->get_system()=="windows")
diff --git a/source/gnuobjccompiler.cpp b/source/gnuobjccompiler.cpp
new file mode 100644 (file)
index 0000000..eddca5f
--- /dev/null
@@ -0,0 +1,21 @@
+#include "gnuobjccompiler.h"
+#include "objcsourcefile.h"
+
+using namespace Msp;
+
+GnuObjCCompiler::GnuObjCCompiler(Builder &b, const Architecture &a):
+       GnuCompiler(b, a, "OBJC")
+{
+       set_command("gcc", true);
+       input_suffixes.push_back(".m");
+}
+
+Target *GnuObjCCompiler::create_source(const Component &comp, const FS::Path &path) const
+{
+       return new ObjCSourceFile(builder, comp, path);
+}
+
+Target *GnuObjCCompiler::create_source(const FS::Path &path) const
+{
+       return new ObjCSourceFile(builder, path);
+}
diff --git a/source/gnuobjccompiler.h b/source/gnuobjccompiler.h
new file mode 100644 (file)
index 0000000..11fbd91
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef GNUOBJCCOMPILER_H_
+#define GNUOBJCCOMPILER_H_
+
+#include "gnucompiler.h"
+
+class GnuObjCCompiler: public GnuCompiler
+{
+public:
+       GnuObjCCompiler(Builder &, const Architecture &);
+
+       virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
+       virtual Target *create_source(const Msp::FS::Path &) const;
+};
+
+#endif
index 20463e6b42e493c1dbb37575f46af1f71c4db5c6..0dc2749383c0bcb36fae9d2ee3e111a7e5b95750 100644 (file)
@@ -3,6 +3,7 @@
 #include "gnuccompiler.h"
 #include "gnucxxcompiler.h"
 #include "gnulinker.h"
+#include "gnuobjccompiler.h"
 #include "gnutools.h"
 #include "mingwdlltool.h"
 
@@ -10,6 +11,7 @@ GnuTools::GnuTools(Builder &builder, const Architecture &arch)
 {
        add_tool(new GnuCCompiler(builder, arch));
        add_tool(new GnuCxxCompiler(builder, arch));
+       add_tool(new GnuObjCCompiler(builder, arch));
        add_tool(new GnuLinker(builder, arch));
        add_tool(new GnuArchiver(builder, arch));
        if(arch.get_system()=="windows")
diff --git a/source/objcsourcefile.cpp b/source/objcsourcefile.cpp
new file mode 100644 (file)
index 0000000..ed334fc
--- /dev/null
@@ -0,0 +1,23 @@
+#include <msp/strings/regex.h>
+#include "objcsourcefile.h"
+
+using namespace std;
+using namespace Msp;
+
+ObjCSourceFile::ObjCSourceFile(Builder &b, const FS::Path &p):
+       CSourceFile(b, p)
+{ }
+
+ObjCSourceFile::ObjCSourceFile(Builder &b, const Component &c, const FS::Path &p):
+       CSourceFile(b, c, p)
+{ }
+
+void ObjCSourceFile::parse_includes(IO::Base &in)
+{
+       static Regex r_include("^[ \t]*#(include|import)[ \t]+([\"<].*)[\">]");
+
+       string line;
+       while(in.getline(line))
+               if(RegMatch match = r_include.match(line))
+                       includes.push_back(match[2].str);
+}
diff --git a/source/objcsourcefile.h b/source/objcsourcefile.h
new file mode 100644 (file)
index 0000000..2069615
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef OBJCSOURCEFILE_H_
+#define OBJCSOURCEFILE_H_
+
+#include "csourcefile.h"
+
+/**
+Represents an Objective-C source file.
+*/
+class ObjCSourceFile: public CSourceFile
+{
+public:
+       ObjCSourceFile(Builder &, const Msp::FS::Path &);
+       ObjCSourceFile(Builder &, const Component &, const Msp::FS::Path &);
+
+       virtual const char *get_type() const { return "ObjCSourceFile"; }
+
+protected:
+       virtual void parse_includes(Msp::IO::Base &);
+};
+
+#endif