From: Mikko Rasa Date: Fri, 24 May 2013 17:29:52 +0000 (+0300) Subject: Initial support for building on Darwin (a.k.a. Mac OS X) X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6e02286dcbd62b8f5ef56987c2298d54b689ad9c;p=builder.git Initial support for building on Darwin (a.k.a. Mac OS X) --- diff --git a/bootstrap.sh b/bootstrap.sh index dd0e8a6..48a4f20 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -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" diff --git a/source/architecture.cpp b/source/architecture.cpp index 7faefeb..3905f40 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -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("%")); } diff --git a/source/builder.cpp b/source/builder.cpp index cf49f41..e501f69 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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 index 0000000..c92e3d7 --- /dev/null +++ b/source/clangccompiler.cpp @@ -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 index 0000000..2a4ec29 --- /dev/null +++ b/source/clangccompiler.h @@ -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 index 0000000..4dcb9d3 --- /dev/null +++ b/source/clangcxxcompiler.cpp @@ -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 index 0000000..95b901c --- /dev/null +++ b/source/clangcxxcompiler.h @@ -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 index 0000000..1c7c8d6 --- /dev/null +++ b/source/clangtools.cpp @@ -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 index 0000000..bdfa118 --- /dev/null +++ b/source/clangtools.h @@ -0,0 +1,12 @@ +#ifndef CLANGTOOLS_H_ +#define CLANGTOOLS_H_ + +#include "toolchain.h" + +class ClangTools: public Toolchain +{ +public: + ClangTools(Builder &, const Architecture &); +}; + +#endif diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index cd7391f..da579ba 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -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"); diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index ea448ac..b2df14c 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -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(); diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index e94ffeb..ae44f2c 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -36,6 +36,13 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const listget_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);