]> git.tdb.fi Git - builder.git/commitdiff
Initial support for building on Darwin (a.k.a. Mac OS X)
authorMikko Rasa <tdb@tdb.fi>
Fri, 24 May 2013 17:29:52 +0000 (20:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 24 May 2013 17:49:41 +0000 (20:49 +0300)
12 files changed:
bootstrap.sh
source/architecture.cpp
source/builder.cpp
source/clangccompiler.cpp [new file with mode: 0644]
source/clangccompiler.h [new file with mode: 0644]
source/clangcxxcompiler.cpp [new file with mode: 0644]
source/clangcxxcompiler.h [new file with mode: 0644]
source/clangtools.cpp [new file with mode: 0644]
source/clangtools.h [new file with mode: 0644]
source/gnucompiler.cpp
source/gnulinker.cpp
source/sharedlibrary.cpp

index dd0e8a6e09748f5f8e9eddc2f0caaeb2bcef6bd2..48a4f206bb75b673280bc5fc331dc8ec2608b4e5 100755 (executable)
@@ -8,11 +8,17 @@ REQUIRED="core datafile"
 CFLAGS="-I$INCLUDEDIR `pkg-config --cflags sigc++-2.0`"
 LIBS="`pkg-config --libs sigc++-2.0` -lpthread"
 MACHINE="`uname -m`"
+SYSTEM="`uname -s`"
 if [ "$MACHINE" = "x86_64" ]; then
        MULTIARCH="x86_64-linux-gnu"
 else
        MULTIARCH="i386-linux-gnu"
 fi
+if [ "$SYSTEM" = "Darwin" ]; then
+       COMPILER="clang++"
+else
+       COMPILER="g++"
+fi
 if [ -e /usr/lib/libdl.so -o -e /usr/lib/$MULTIARCH/libdl.so ]; then
        LIBS="$LIBS -ldl"
 fi
@@ -83,17 +89,19 @@ fi
 echo "Compiling builder-stage1.  This may take several minutes."
 objects=""
 for i in $sources; do
-       obj=`mktemp --tmpdir=temp/bootstrap XXXXXX.o`
+       obj=`mktemp temp/bootstrap/XXXXXX`
+       mv $obj $obj.o
+       obj=$obj.o
        dir=${i%/*}
        dir=${dir%/unix}
        flags="$CFLAGS"
        if [ -d "$dir/unix" ]; then
                flags="$flags -iquote $dir -iquote $dir/unix"
        fi
-       g++ -c $i -o $obj $flags
+       $COMPILER -c $i -o $obj $flags
        objects="$objects $obj"
 done
-g++ $objects -o builder-stage1 $LIBS
+$COMPILER $objects -o builder-stage1 $LIBS
 
 if [ "$KEEP_TEMP" != "yes" ]; then
        echo "Cleaning up"
index 7faefeb456f3953548084782c63079fc466a59fc..3905f40c872dcb7f04e6c05ed72a970dde31f2dd 100644 (file)
@@ -41,6 +41,7 @@ const char *systems[] =
 {
        "linux",
        "freebsd",
+       "darwin",
        "windows",
        0
 };
@@ -116,7 +117,10 @@ Architecture::Architecture(Builder &b, const string &spec):
        }
        else
        {
-               sharedlib_patterns.push_back(Pattern("lib%.so"));
+               if(system=="darwin")
+                       sharedlib_patterns.push_back(Pattern("lib%.dylib"));
+               else
+                       sharedlib_patterns.push_back(Pattern("lib%.so"));
                staticlib_patterns.push_back(Pattern("lib%.a"));
                executable_patterns.push_back(Pattern("%"));
        }
index cf49f41663e71b45d16dd16bc2a73d0ff5915449..e501f69e0513631d8611830ae2c2b1f7cd75a963 100644 (file)
@@ -12,6 +12,7 @@
 #include "binarypackage.h"
 #include "builder.h"
 #include "builtintools.h"
+#include "clangtools.h"
 #include "datatool.h"
 #include "gnutools.h"
 #include "installedfile.h"
@@ -75,6 +76,8 @@ void Builder::set_temp_directory(const FS::Path &p)
 
 void Builder::add_default_tools()
 {
+       if(current_arch->get_system()=="darwin")
+               toolchain.add_toolchain(new ClangTools(*this, *current_arch));
        toolchain.add_toolchain(new GnuTools(*this, *current_arch));
        toolchain.add_toolchain(new BuiltinTools(*this));
        toolchain.add_tool(new DataTool(*this));
diff --git a/source/clangccompiler.cpp b/source/clangccompiler.cpp
new file mode 100644 (file)
index 0000000..c92e3d7
--- /dev/null
@@ -0,0 +1,7 @@
+#include "clangccompiler.h"
+
+ClangCCompiler::ClangCCompiler(Builder &b, const Architecture &a):
+       GnuCCompiler(b, a)
+{
+       set_command("clang", true);
+}
diff --git a/source/clangccompiler.h b/source/clangccompiler.h
new file mode 100644 (file)
index 0000000..2a4ec29
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef CLANGCCOMPILER_H_
+#define CLANGCCOMPILER_H_
+
+#include "gnuccompiler.h"
+
+class ClangCCompiler: public GnuCCompiler
+{
+public:
+       ClangCCompiler(Builder &, const Architecture &);
+};
+
+#endif
diff --git a/source/clangcxxcompiler.cpp b/source/clangcxxcompiler.cpp
new file mode 100644 (file)
index 0000000..4dcb9d3
--- /dev/null
@@ -0,0 +1,7 @@
+#include "clangcxxcompiler.h"
+
+ClangCxxCompiler::ClangCxxCompiler(Builder &b, const Architecture &a):
+       GnuCxxCompiler(b, a)
+{
+       set_command("clang++", true);
+}
diff --git a/source/clangcxxcompiler.h b/source/clangcxxcompiler.h
new file mode 100644 (file)
index 0000000..95b901c
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef CLANGCXXCOMPILER_H_
+#define CLANGCXXCOMPILER_H_
+
+#include "gnucxxcompiler.h"
+
+class ClangCxxCompiler: public GnuCxxCompiler
+{
+public:
+       ClangCxxCompiler(Builder &, const Architecture &);
+};
+
+#endif
diff --git a/source/clangtools.cpp b/source/clangtools.cpp
new file mode 100644 (file)
index 0000000..1c7c8d6
--- /dev/null
@@ -0,0 +1,9 @@
+#include "clangccompiler.h"
+#include "clangcxxcompiler.h"
+#include "clangtools.h"
+
+ClangTools::ClangTools(Builder &builder, const Architecture &arch)
+{
+       add_tool(new ClangCCompiler(builder, arch));
+       add_tool(new ClangCxxCompiler(builder, arch));
+}
diff --git a/source/clangtools.h b/source/clangtools.h
new file mode 100644 (file)
index 0000000..bdfa118
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef CLANGTOOLS_H_
+#define CLANGTOOLS_H_
+
+#include "toolchain.h"
+
+class ClangTools: public Toolchain
+{
+public:
+       ClangTools(Builder &, const Architecture &);
+};
+
+#endif
index cd7391f0277175578a22536e1bd3d5bb7a122368..da579ba5d0c132caf0b7c09d17e87bd3281e762e 100644 (file)
@@ -115,7 +115,7 @@ Task *GnuCompiler::run(const Target &target) const
                else
                        argv.push_back(format("-O%d", binfo.optimize));
        }
-       if(binfo.threads && architecture->get_system()!="windows")
+       if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin")
                argv.push_back("-pthread");
        if((comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE) && architecture->get_system()!="windows")
                argv.push_back("-fPIC");
index ea448acdcf3105980709bca561a1c1b3bc2ceb28..b2df14cbc9c90e7bff446411654ebf1ce445c7de 100644 (file)
@@ -175,7 +175,25 @@ Task *GnuLinker::Linker::run(const Target &target) const
                argv.push_back("-shared");
                argv.push_back("-fPIC");
                if(architecture->get_system()!="windows" && !shlib->get_soname().empty())
-                       argv.push_back("-Wl,-soname,"+shlib->get_soname());
+               {
+                       if(architecture->get_system()=="darwin")
+                       {
+                               argv.push_back("-install_name");
+                               argv.push_back(shlib->get_soname());
+
+                               const string &ver = shlib->get_package()->get_version();
+                               const string &if_ver = shlib->get_package()->get_interface_version();
+                               if(!ver.empty() && !if_ver.empty())
+                               {
+                                       argv.push_back("-current_version");
+                                       argv.push_back(ver);
+                                       argv.push_back("-compatibility_version");
+                                       argv.push_back(if_ver);
+                               }
+                       }
+                       else
+                               argv.push_back("-Wl,-soname,"+shlib->get_soname());
+               }
        }
 
        const BuildInfo &binfo = comp.get_build_info();
@@ -183,7 +201,7 @@ Task *GnuLinker::Linker::run(const Target &target) const
                argv.push_back("-L"+i->str());
        if(binfo.strip)
                argv.push_back("-s");
-       if(binfo.threads && architecture->get_system()!="windows")
+       if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin")
                argv.push_back("-pthread");
 
        const Architecture &native_arch = builder.get_native_arch();
index e94ffeb6d46867813b4c18a23e7fbb74bb00e3c3..ae44f2cd5751701dff67a5e18dc29183960adb6b 100644 (file)
@@ -36,6 +36,13 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFi
                const Pattern &pattern = arch.get_shared_library_patterns().front();
                if(arch.get_system()=="windows")
                        soname = pattern.apply(format("%s-%s", component->get_name(), version));
+               else if(arch.get_system()=="darwin")
+               {
+                       string filename = pattern.apply(component->get_name());
+                       string base = FS::basepart(filename);
+                       string ext = FS::extpart(filename);
+                       soname = format("%s.%s%s", base, version, ext);
+               }
                else
                        soname = format("%s.%s", pattern.apply(component->get_name()), version);