commit:     8d75a00db98a0b522aa32267d67b7cf59a707cee
Author:     Felix Janda <felix.janda <AT> posteo <DOT> de>
AuthorDate: Wed Jan  7 21:06:52 2015 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jan 31 21:56:46 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/hardened-dev.git;a=commit;h=8d75a00d

sys-devel/llvm: Hack around linux=glibc assumptions

---
 .../clang-3.4-darwin_prefix-include-paths.patch    |  18 +
 .../llvm/files/clang-3.5-gentoo-install.patch      |  57 +++
 ...clang-3.5-gentoo-runtime-gcc-detection-v3.patch |  42 ++
 sys-devel/llvm/files/llvm-3.2-nodoctargz.patch     |  45 ++
 sys-devel/llvm/files/llvm-3.5-gcc-4.9.patch        |  43 ++
 sys-devel/llvm/files/llvm-3.5-gentoo-install.patch |  83 ++++
 .../llvm/files/llvm-3.5-musl-compiler-rt.patch     |  58 +++
 sys-devel/llvm/files/llvm-3.5-musl-fixes.patch     |  77 +++
 sys-devel/llvm/files/llvm-3.5-musl-support.patch   | 124 +++++
 .../files/llvm-3.5.0-fix_LLVMExports_cmake.patch   |  39 ++
 sys-devel/llvm/llvm-3.5.0-r99.ebuild               | 530 +++++++++++++++++++++
 sys-devel/llvm/metadata.xml                        |  28 ++
 12 files changed, 1144 insertions(+)

diff --git a/sys-devel/llvm/files/clang-3.4-darwin_prefix-include-paths.patch 
b/sys-devel/llvm/files/clang-3.4-darwin_prefix-include-paths.patch
new file mode 100644
index 0000000..f5f1d9e
--- /dev/null
+++ b/sys-devel/llvm/files/clang-3.4-darwin_prefix-include-paths.patch
@@ -0,0 +1,18 @@
+--- tools/clang/lib/Frontend/InitHeaderSearch.cpp
++++ tools/clang/lib/Frontend/InitHeaderSearch.cpp
+@@ -233,6 +233,7 @@
+     case llvm::Triple::Bitrig:
+       break;
+     default:
++      AddPath("@GENTOO_PORTAGE_EPREFIX@/usr/include", System, false);
+       // FIXME: temporary hack: hard-coded paths.
+       AddPath("/usr/local/include", System, false);
+       break;
+@@ -505,6 +506,7 @@
+   // Add the default framework include paths on Darwin.
+   if (HSOpts.UseStandardSystemIncludes) {
+     if (triple.isOSDarwin()) {
++      AddPath("@GENTOO_PORTAGE_EPREFIX@/Frameworks", System, true);
+       AddPath("/System/Library/Frameworks", System, true);
+       AddPath("/Library/Frameworks", System, true);
+     }

diff --git a/sys-devel/llvm/files/clang-3.5-gentoo-install.patch 
b/sys-devel/llvm/files/clang-3.5-gentoo-install.patch
new file mode 100644
index 0000000..5d4261d
--- /dev/null
+++ b/sys-devel/llvm/files/clang-3.5-gentoo-install.patch
@@ -0,0 +1,57 @@
+---
+ tools/clang/lib/Driver/Tools.cpp        | 2 +-
+ tools/clang/tools/scan-build/scan-build | 4 ++--
+ tools/clang/tools/scan-view/scan-view   | 2 +-
+ 3 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/tools/clang/lib/Driver/Tools.cpp 
b/tools/clang/lib/Driver/Tools.cpp
+index 187ed38..55bcd99 100644
+--- a/tools/clang/lib/Driver/Tools.cpp
++++ b/tools/clang/lib/Driver/Tools.cpp
+@@ -1404,7 +1404,7 @@ static void AddGoldPlugin(const ToolChain &ToolChain, 
const ArgList &Args,
+   // as gold requires -plugin to come before any -plugin-opt that -Wl might
+   // forward.
+   CmdArgs.push_back("-plugin");
+-  std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so";
++  std::string Plugin = ToolChain.getDriver().Dir + "/../@libdir@/LLVMgold.so";
+   CmdArgs.push_back(Args.MakeArgString(Plugin));
+ 
+   // Try to pass driver level flags relevant to LTO code generation down to
+diff --git a/tools/clang/tools/scan-build/scan-build 
b/tools/clang/tools/scan-build/scan-build
+index 0f119f6..58f78d9 100755
+--- a/tools/clang/tools/scan-build/scan-build
++++ b/tools/clang/tools/scan-build/scan-build
+@@ -419,7 +419,7 @@
+
+   my $Dir = shift;
+
+-  my $JS = Cwd::realpath("$RealBin/sorttable.js");
++  my $JS = Cwd::realpath("@EPREFIX@/usr/share/llvm/sorttable.js");
+
+   DieDiag("Cannot find 'sorttable.js'.\n")
+     if (! -r $JS);
+@@ -429,7 +429,7 @@
+   DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
+     if (! -r "$Dir/sorttable.js");
+
+-  my $CSS = Cwd::realpath("$RealBin/scanview.css");
++  my $CSS = Cwd::realpath("@EPREFIX@/usr/share/llvm/scanview.css");
+
+   DieDiag("Cannot find 'scanview.css'.\n")
+     if (! -r $CSS);
+diff --git a/tools/clang/tools/scan-view/scan-view 
b/tools/clang/tools/scan-view/scan-view
+index fb27da6..1f8ddb8 100755
+--- a/tools/clang/tools/scan-view/scan-view
++++ b/tools/clang/tools/scan-view/scan-view
+@@ -54,7 +54,7 @@ def start_browser(port, options):
+     webbrowser.open(url)
+ 
+ def run(port, options, root):
+-    import ScanView
++    from clang import ScanView
+     try:
+         print 'Starting scan-view at: http://%s:%d'%(options.host,
+                                                      port)
+-- 
+1.8.4.4
+

diff --git 
a/sys-devel/llvm/files/clang-3.5-gentoo-runtime-gcc-detection-v3.patch 
b/sys-devel/llvm/files/clang-3.5-gentoo-runtime-gcc-detection-v3.patch
new file mode 100644
index 0000000..1f81af0
--- /dev/null
+++ b/sys-devel/llvm/files/clang-3.5-gentoo-runtime-gcc-detection-v3.patch
@@ -0,0 +1,42 @@
+From 916572e1243633ddf913c8f32771a3a7f70fd853 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <[email protected]>
+Date: Fri, 5 Sep 2014 16:49:35 +0200
+Subject: [PATCH] Support obtaining active toolchain from gcc-config.
+
+---
+ tools/clang/lib/Driver/ToolChains.cpp | 19 +++++++++++++++++++
+ 1 file changed, 19 insertions(+)
+
+diff --git a/tools/clang/lib/Driver/ToolChains.cpp 
b/tools/clang/lib/Driver/ToolChains.cpp
+index b46f69d..2d4374d 100644
+--- a/tools/clang/lib/Driver/ToolChains.cpp
++++ b/tools/clang/lib/Driver/ToolChains.cpp
+@@ -1253,6 +1253,25 @@ Generic_GCC::GCCInstallationDetector::init(
+       Prefixes.push_back("/usr");
+   }
+ 
++  for (unsigned k = 0, ke = CandidateTripleAliases.size(); k < ke; ++k) {
++    llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
++        llvm::MemoryBuffer::getFile(D.SysRoot + "/etc/env.d/gcc/config-" + 
CandidateTripleAliases[k].str());
++    if (File)
++    {
++      const std::string VersionText = 
File.get()->getBuffer().rsplit('-').second.substr(0,5).str();
++      const std::string GentooPath = D.SysRoot + "/usr/lib/gcc/" + 
CandidateTripleAliases[k].str() + "/" + VersionText;
++      if (llvm::sys::fs::exists(GentooPath + "/crtbegin.o"))
++      {
++        Version = GCCVersion::Parse(VersionText);
++        GCCInstallPath = GentooPath;
++        GCCParentLibPath = GCCInstallPath + "/../../..";
++        GCCTriple.setTriple(CandidateTripleAliases[k]);
++        IsValid = true;
++        return;
++      }
++    }
++  }
++
+   // Loop over the various components which exist and select the best GCC
+   // installation available. GCC installs are ranked by version number.
+   Version = GCCVersion::Parse("0.0.0");
+-- 
+2.1.0
+

diff --git a/sys-devel/llvm/files/llvm-3.2-nodoctargz.patch 
b/sys-devel/llvm/files/llvm-3.2-nodoctargz.patch
new file mode 100644
index 0000000..3a622b5
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.2-nodoctargz.patch
@@ -0,0 +1,45 @@
+--- docs/Makefile.orig 2012-04-30 17:00:01.000000000 +0200
++++ docs/Makefile      2012-04-30 17:15:52.000000000 +0200
+@@ -52,11 +52,10 @@
+ # 'make generated BUILD_FOR_WEBSITE=1'
+ generated:: $(generated_targets)
+ 
+-install-html: $(PROJ_OBJ_DIR)/html.tar.gz
++install-html:
+       $(Echo) Installing HTML documentation
+       $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_docsdir)/html
+       $(Verb) $(DataInstall) $(HTML) $(DESTDIR)$(PROJ_docsdir)/html
+-      $(Verb) $(DataInstall) $(PROJ_OBJ_DIR)/html.tar.gz 
$(DESTDIR)$(PROJ_docsdir)
+ 
+ $(PROJ_OBJ_DIR)/html.tar.gz: $(HTML)
+       $(Echo) Packaging HTML documentation
+@@ -68,12 +67,11 @@
+ install-doxygen: doxygen
+       $(Echo) Installing doxygen documentation
+       $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_docsdir)/html/doxygen
+-      $(Verb) $(DataInstall) $(PROJ_OBJ_DIR)/doxygen.tar.gz 
$(DESTDIR)$(PROJ_docsdir)
+       $(Verb) cd $(PROJ_OBJ_DIR)/doxygen && \
+         $(FIND) . -type f -exec \
+           $(DataInstall) {} $(DESTDIR)$(PROJ_docsdir)/html/doxygen \;
+ 
+-doxygen: regendoc $(PROJ_OBJ_DIR)/doxygen.tar.gz
++doxygen: regendoc
+ 
+ regendoc:
+       $(Echo) Building doxygen documentation
+@@ -99,7 +97,6 @@
+ install-ocamldoc: ocamldoc
+       $(Echo) Installing ocamldoc documentation
+       $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_docsdir)/ocamldoc/html
+-      $(Verb) $(DataInstall) $(PROJ_OBJ_DIR)/ocamldoc.tar.gz 
$(DESTDIR)$(PROJ_docsdir)
+       $(Verb) cd $(PROJ_OBJ_DIR)/ocamldoc && \
+         $(FIND) . -type f -exec \
+           $(DataInstall) {} $(DESTDIR)$(PROJ_docsdir)/ocamldoc/html \;
+@@ -109,7 +106,6 @@
+       $(Verb) $(RM) -rf $(PROJ_OBJ_DIR)/ocamldoc.tar*
+       $(Verb) $(TAR) cf $(PROJ_OBJ_DIR)/ocamldoc.tar ocamldoc
+       $(Verb) $(GZIPBIN) $(PROJ_OBJ_DIR)/ocamldoc.tar
+-      $(Verb) $(CP) $(PROJ_OBJ_DIR)/ocamldoc.tar.gz 
$(PROJ_OBJ_DIR)/ocamldoc/html/
+ 
+ regen-ocamldoc:
+       $(Echo) Building ocamldoc documentation

diff --git a/sys-devel/llvm/files/llvm-3.5-gcc-4.9.patch 
b/sys-devel/llvm/files/llvm-3.5-gcc-4.9.patch
new file mode 100644
index 0000000..7da657f
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.5-gcc-4.9.patch
@@ -0,0 +1,43 @@
+commit 080fb498017d17af2e4d7563608c7d8a848f20da
+Author: Sanjoy Das <sanjoy at azulsystems.com>
+Date:   Thu Jun 19 15:38:02 2014 -0700
+
+    Fix the --enable-shared build.
+    
+    Currently a build configured with ./configure --enable-shared breaks
+    with an undefined "llvm::cl::parser<llvm::PassInfo
+    const*>::getOption(unsigned int) const" symbol when linking opt.  This
+    body for this symbol gets emitted into Pass.o (along with the destructor
+    for PassNameParser), but gets linked into libLLVM-3.5svn.so with local
+    visibility, causing the link error.
+    
+    This fix uses the existing EXTERN_TEMPLATE machinery to force a globally
+    visible definition for the functions in parser<const PassInfo *> into
+    Pass.o.
+
+diff --git a/include/llvm/IR/LegacyPassNameParser.h 
b/include/llvm/IR/LegacyPassNameParser.h
+index e2e4912..a07e3fd 100644
+--- a/include/llvm/IR/LegacyPassNameParser.h
++++ b/include/llvm/IR/LegacyPassNameParser.h
+@@ -95,6 +95,8 @@ private:
+   }
+ };
+ 
++EXTERN_TEMPLATE_INSTANTIATION(class cl::parser<const PassInfo *>);
++
+ 
///===----------------------------------------------------------------------===//
+ /// FilteredPassNameParser class - Make use of the pass registration
+ /// mechanism to automatically add a command line argument to opt for
+diff --git a/lib/IR/Pass.cpp b/lib/IR/Pass.cpp
+index 91d86ae..00ce223 100644
+--- a/lib/IR/Pass.cpp
++++ b/lib/IR/Pass.cpp
+@@ -234,6 +234,8 @@ PassNameParser::~PassNameParser() {
+   // attempting to remove the registration listener is an error.
+ }
+ 
++TEMPLATE_INSTANTIATION(class cl::parser<const PassInfo *>);
++
+ 
//===----------------------------------------------------------------------===//
+ //   AnalysisUsage Class Implementation
+ //

diff --git a/sys-devel/llvm/files/llvm-3.5-gentoo-install.patch 
b/sys-devel/llvm/files/llvm-3.5-gentoo-install.patch
new file mode 100644
index 0000000..7a8c9f7
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.5-gentoo-install.patch
@@ -0,0 +1,83 @@
+From b8846d389ff5e2b768a114f752cf39788accba26 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <[email protected]>
+Date: Mon, 19 Aug 2013 13:22:46 +0200
+Subject: [PATCH] gentoo install fixes
+
+---
+ Makefile.config.in                      | 6 +++---
+ Makefile.rules                          | 6 +++---
+ tools/llvm-config/BuildVariables.inc.in | 2 ++
+ tools/llvm-config/Makefile              | 4 ++++
+ tools/llvm-config/llvm-config.cpp       | 5 +++--
+ utils/FileCheck/Makefile                | 2 +-
+ 7 files changed, 17 insertions(+), 10 deletions(-)
+
+diff --git a/Makefile.config.in b/Makefile.config.in
+index dcca45f..e75ae2e 100644
+--- a/Makefile.config.in
++++ b/Makefile.config.in
+@@ -95,10 +95,10 @@ PROJ_internal_prefix := $(prefix)
+ endif
+ 
+ PROJ_bindir     := $(PROJ_prefix)/bin
+-PROJ_libdir     := $(PROJ_prefix)/lib
++PROJ_libdir     := $(PROJ_prefix)/$(GENTOO_LIBDIR)
+ PROJ_datadir    := $(PROJ_prefix)/share
+-PROJ_docsdir    := $(PROJ_prefix)/docs/llvm
+-PROJ_etcdir     := $(PROJ_prefix)/etc/llvm
++PROJ_docsdir    := $(PROJ_prefix)/share/doc/@PF@
++PROJ_etcdir     := @EPREFIX@/etc/llvm
+ PROJ_includedir := $(PROJ_prefix)/include
+ PROJ_infodir    := $(PROJ_prefix)/info
+ PROJ_mandir     := $(PROJ_prefix)/share/man
+diff --git a/Makefile.rules b/Makefile.rules
+index e53598b..217f754 100644
+--- a/Makefile.rules
++++ b/Makefile.rules
+@@ -275,7 +275,7 @@ ifeq ($(ENABLE_OPTIMIZED),1)
+   BuildMode := Release
+   # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
+   ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin Darwin DragonFly FreeBSD 
GNU/kFreeBSD))
+-    OmitFramePointer := -fomit-frame-pointer
++    OmitFramePointer :=
+   endif
+ 
+   CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
+diff --git a/tools/llvm-config/BuildVariables.inc.in 
b/tools/llvm-config/BuildVariables.inc.in
+index fe87afb..fd9f2c6 100644
+--- a/tools/llvm-config/BuildVariables.inc.in
++++ b/tools/llvm-config/BuildVariables.inc.in
+@@ -25,3 +25,4 @@
+ #define LLVM_BUILDMODE "@LLVM_BUILDMODE@"
+ #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
+ #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
++#define LLVM_LIBDIR "@LLVM_LIBDIR@"
+diff --git a/tools/llvm-config/Makefile b/tools/llvm-config/Makefile
+index b20b6bf..fc56781 100644
+--- a/tools/llvm-config/Makefile
++++ b/tools/llvm-config/Makefile
+@@ -55,6 +55,8 @@ $(ObjDir)/BuildVariables.inc: $(BUILDVARIABLES_SRCPATH) 
Makefile $(ObjDir)/.dir
+         >> temp.sed
+       $(Verb) $(ECHO) 's/@LLVM_TARGETS_BUILT@/$(subst 
/,\/,$(TARGETS_TO_BUILD))/' \
+         >> temp.sed
++      $(Verb) $(ECHO) 's/@LLVM_LIBDIR@/$(subst /,\/,$(GENTOO_LIBDIR))/' \
++        >> temp.sed
+       $(Verb) $(SED) -f temp.sed < $< > $@
+       $(Verb) $(RM) temp.sed
+ 
+diff --git a/tools/llvm-config/llvm-config.cpp 
b/tools/llvm-config/llvm-config.cpp
+index 3924e2e..f439c60 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -250,7 +250,7 @@ int main(int argc, char **argv) {
+     ActivePrefix = CurrentExecPrefix;
+     ActiveIncludeDir = ActivePrefix + "/include";
+     ActiveBinDir = ActivePrefix + "/bin";
+-    ActiveLibDir = ActivePrefix + "/lib";
++    ActiveLibDir = ActivePrefix + "/" LLVM_LIBDIR;
+     ActiveIncludeOption = "-I" + ActiveIncludeDir;
+   }
+ 
+-- 
+1.8.4.2
+

diff --git a/sys-devel/llvm/files/llvm-3.5-musl-compiler-rt.patch 
b/sys-devel/llvm/files/llvm-3.5-musl-compiler-rt.patch
new file mode 100644
index 0000000..b1646b8
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.5-musl-compiler-rt.patch
@@ -0,0 +1,58 @@
+diff -ur a/llvm-3.5.0.src/projects/compiler-rt/lib/Makefile.mk 
b/llvm-3.5.0.src/projects/compiler-rt/lib/Makefile.mk
+--- a/llvm-3.5.0.src/projects/compiler-rt/lib/Makefile.mk      2014-02-14 
10:20:33.000000000 -0100
++++ b/llvm-3.5.0.src/projects/compiler-rt/lib/Makefile.mk      2015-01-07 
13:56:00.362944069 -0100
+@@ -10,13 +10,13 @@
+ SubDirs :=
+ 
+ # Add submodules.
+-SubDirs += asan
++#SubDirs += asan
+ SubDirs += builtins
+-SubDirs += dfsan
++#SubDirs += dfsan
+ SubDirs += interception
+-SubDirs += lsan
+-SubDirs += msan
++#SubDirs += lsan
++#SubDirs += msan
+ SubDirs += profile
+-SubDirs += sanitizer_common
+-SubDirs += tsan
+-SubDirs += ubsan
++#SubDirs += sanitizer_common
++#SubDirs += tsan
++#SubDirs += ubsan
+diff -ur 
a/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.cc 
b/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.cc
+--- 
a/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.cc    
   2014-02-24 09:37:41.000000000 -0100
++++ 
b/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.cc    
   2015-01-07 13:56:56.609240893 -0100
+@@ -24,12 +24,6 @@
+   return real == wrapper;
+ }
+ 
+-#if !defined(__ANDROID__)  // android does not have dlvsym
+-void *GetFuncAddrVer(const char *func_name, const char *ver) {
+-  return dlvsym(RTLD_NEXT, func_name, ver);
+-}
+-#endif  // !defined(__ANDROID__)
+-
+ }  // namespace __interception
+ 
+ 
+diff -ur 
a/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.h 
b/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.h
+--- 
a/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.h     
   2014-02-24 09:37:41.000000000 -0100
++++ 
b/llvm-3.5.0.src/projects/compiler-rt/lib/interception/interception_linux.h     
   2015-01-07 13:56:41.617428317 -0100
+@@ -34,14 +34,8 @@
+       (::__interception::uptr) & (func),                                   \
+       (::__interception::uptr) & WRAP(func))
+ 
+-#if !defined(__ANDROID__)  // android does not have dlvsym
+-# define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
+-     ::__interception::real_##func = (func##_f)(unsigned long) \
+-         ::__interception::GetFuncAddrVer(#func, symver)
+-#else
+ # define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
+      INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
+-#endif  // !defined(__ANDROID__)
+ 
+ #endif  // INTERCEPTION_LINUX_H
+ #endif  // __linux__ || __FreeBSD__

diff --git a/sys-devel/llvm/files/llvm-3.5-musl-fixes.patch 
b/sys-devel/llvm/files/llvm-3.5-musl-fixes.patch
new file mode 100644
index 0000000..98d6133
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.5-musl-fixes.patch
@@ -0,0 +1,77 @@
+llvm-musl.patch from alpine linux
+
+diff -ru llvm-3.5.0.src.orig/include/llvm/Target/TargetLibraryInfo.h 
llvm-3.5.0.src/include/llvm/Target/TargetLibraryInfo.h
+--- llvm-3.5.0.src.orig/include/llvm/Target/TargetLibraryInfo.h        
2014-11-13 12:51:53.341455401 +0000
++++ llvm-3.5.0.src/include/llvm/Target/TargetLibraryInfo.h     2014-11-13 
12:52:35.078889077 +0000
+@@ -13,6 +13,15 @@
+ #include "llvm/ADT/DenseMap.h"
+ #include "llvm/Pass.h"
+ 
++#undef fopen64
++#undef fseeko64
++#undef fstat64
++#undef fstatvfs64
++#undef ftello64
++#undef lstat64
++#undef stat64
++#undef tmpfile64
++
+ namespace llvm {
+   class Triple;
+ 
+diff -ru llvm-3.5.0.src.orig/lib/Support/DynamicLibrary.cpp 
llvm-3.5.0.src/lib/Support/DynamicLibrary.cpp
+--- llvm-3.5.0.src.orig/lib/Support/DynamicLibrary.cpp 2014-11-13 
12:51:53.341455401 +0000
++++ llvm-3.5.0.src/lib/Support/DynamicLibrary.cpp      2014-11-13 
12:52:07.781720766 +0000
+@@ -138,7 +138,7 @@
+ 
+ // This macro returns the address of a well-known, explicit symbol
+ #define EXPLICIT_SYMBOL(SYM) \
+-   if (!strcmp(symbolName, #SYM)) return &SYM
++   if (!strcmp(symbolName, #SYM)) return (void *) &SYM
+ 
+ // On linux we have a weird situation. The stderr/out/in symbols are both
+ // macros and global variables because of standards requirements. So, we
+diff -ru llvm-3.5.0.src.orig/lib/Support/Unix/Signals.inc 
llvm-3.5.0.src/lib/Support/Unix/Signals.inc
+--- llvm-3.5.0.src.orig/lib/Support/Unix/Signals.inc   2014-11-13 
12:51:53.341455401 +0000
++++ llvm-3.5.0.src/lib/Support/Unix/Signals.inc        2014-11-13 
12:52:07.781720766 +0000
+@@ -266,7 +266,7 @@
+ // On glibc systems we have the 'backtrace' function, which works nicely, but
+ // doesn't demangle symbols.
+ void llvm::sys::PrintStackTrace(FILE *FD) {
+-#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
++#if defined(__GLIBC__) && defined(HAVE_BACKTRACE) && 
defined(ENABLE_BACKTRACES)
+   static void* StackTrace[256];
+   // Use backtrace() to output a backtrace on Linux systems with glibc.
+   int depth = backtrace(StackTrace,
+diff -ru llvm-3.5.0.src.orig/lib/Target/TargetLibraryInfo.cpp 
llvm-3.5.0.src/lib/Target/TargetLibraryInfo.cpp
+--- llvm-3.5.0.src.orig/lib/Target/TargetLibraryInfo.cpp       2014-11-13 
12:51:53.341455401 +0000
++++ llvm-3.5.0.src/lib/Target/TargetLibraryInfo.cpp    2014-11-13 
12:52:07.785054160 +0000
+@@ -653,14 +653,15 @@
+   }
+ 
+   // The following functions are available on at least Linux:
+-  if (!T.isOSLinux()) {
++  if (!T.isOSLinux())
++    TLI.setUnavailable(LibFunc::memalign);
++  if (1 /*!T.isGlibc()*/) {
+     TLI.setUnavailable(LibFunc::dunder_strdup);
+     TLI.setUnavailable(LibFunc::dunder_strtok_r);
+     TLI.setUnavailable(LibFunc::dunder_isoc99_scanf);
+     TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf);
+     TLI.setUnavailable(LibFunc::under_IO_getc);
+     TLI.setUnavailable(LibFunc::under_IO_putc);
+-    TLI.setUnavailable(LibFunc::memalign);
+     TLI.setUnavailable(LibFunc::fopen64);
+     TLI.setUnavailable(LibFunc::fseeko64);
+     TLI.setUnavailable(LibFunc::fstat64);
+diff -ru llvm-3.5.0.src.orig/utils/unittest/googletest/src/gtest.cc 
llvm-3.5.0.src/utils/unittest/googletest/src/gtest.cc
+--- llvm-3.5.0.src.orig/utils/unittest/googletest/src/gtest.cc 2014-11-13 
12:51:53.341455401 +0000
++++ llvm-3.5.0.src/utils/unittest/googletest/src/gtest.cc      2014-11-13 
12:52:07.785054160 +0000
+@@ -120,6 +120,7 @@
+ 
+ #if GTEST_CAN_STREAM_RESULTS_
+ # include <arpa/inet.h>  // NOLINT
++# include <sys/socket.h>  // NOLINT
+ # include <netdb.h>  // NOLINT
+ #endif
+ 

diff --git a/sys-devel/llvm/files/llvm-3.5-musl-support.patch 
b/sys-devel/llvm/files/llvm-3.5-musl-support.patch
new file mode 100644
index 0000000..be92809
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.5-musl-support.patch
@@ -0,0 +1,124 @@
+adapted from llvm-alpine-linux.patch from Alpine
+
+diff -ru llvm-3.5.0.src.orig/include/llvm/ADT/Triple.h 
llvm-3.5.0.src/include/llvm/ADT/Triple.h
+--- llvm-3.5.0.src.orig/include/llvm/ADT/Triple.h      2014-07-18 
17:28:19.000000000 -0300
++++ llvm-3.5.0.src/include/llvm/ADT/Triple.h   2014-11-12 14:44:41.738448045 
-0200
+@@ -149,6 +149,10 @@
+     EABIHF,
+     Android,
+ 
++    Musl,
++    MuslEABI,
++    MuslEABIHF,
++
+     MSVC,
+     Itanium,
+     Cygnus,
+Only in llvm-3.5.0.src/include/llvm/ADT: Triple.h.orig
+diff -ru llvm-3.5.0.src.orig/lib/Support/Triple.cpp 
llvm-3.5.0.src/lib/Support/Triple.cpp
+--- llvm-3.5.0.src.orig/lib/Support/Triple.cpp 2014-07-18 17:28:19.000000000 
-0300
++++ llvm-3.5.0.src/lib/Support/Triple.cpp      2014-11-12 14:47:06.565122146 
-0200
+@@ -168,6 +168,9 @@
+   case CODE16: return "code16";
+   case EABI: return "eabi";
+   case EABIHF: return "eabihf";
++  case Musl: return "musl";
++  case MuslEABI: return "musleabi";
++  case MuslEABIHF: return "musleabihf";
+   case Android: return "android";
+   case MSVC: return "msvc";
+   case Itanium: return "itanium";
+@@ -344,6 +347,9 @@
+     .StartsWith("gnux32", Triple::GNUX32)
+     .StartsWith("code16", Triple::CODE16)
+     .StartsWith("gnu", Triple::GNU)
++    .StartsWith("musl", Triple::Musl)
++    .StartsWith("musleabi", Triple::MuslEABI)
++    .StartsWith("musleabihf", Triple::MuslEABIHF)
+     .StartsWith("android", Triple::Android)
+     .StartsWith("msvc", Triple::MSVC)
+     .StartsWith("itanium", Triple::Itanium)
+Only in llvm-3.5.0.src/lib/Support: Triple.cpp.orig
+diff -ru llvm-3.5.0.src.orig/lib/Target/ARM/ARMSubtarget.cpp 
llvm-3.5.0.src/lib/Target/ARM/ARMSubtarget.cpp
+--- llvm-3.5.0.src.orig/lib/Target/ARM/ARMSubtarget.cpp        2014-07-16 
23:13:31.000000000 -0300
++++ llvm-3.5.0.src/lib/Target/ARM/ARMSubtarget.cpp     2014-11-12 
14:50:40.025133104 -0200
+@@ -273,6 +273,8 @@
+     case Triple::EABIHF:
+     case Triple::GNUEABI:
+     case Triple::GNUEABIHF:
++    case Triple::MuslEABI:
++    case Triple::MuslEABIHF:
+       TargetABI = ARM_ABI_AAPCS;
+       break;
+     default:
+diff -ru llvm-3.5.0.src.orig/lib/Target/ARM/ARMSubtarget.h 
llvm-3.5.0.src/lib/Target/ARM/ARMSubtarget.h
+--- llvm-3.5.0.src.orig/lib/Target/ARM/ARMSubtarget.h  2014-07-16 
23:13:31.000000000 -0300
++++ llvm-3.5.0.src/lib/Target/ARM/ARMSubtarget.h       2014-11-12 
14:53:36.571808822 -0200
+@@ -372,8 +372,10 @@
+   bool isTargetEHABICompatible() const {
+     return (TargetTriple.getEnvironment() == Triple::EABI ||
+             TargetTriple.getEnvironment() == Triple::GNUEABI ||
++            TargetTriple.getEnvironment() == Triple::MuslEABI ||
+             TargetTriple.getEnvironment() == Triple::EABIHF ||
+             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
++            TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
+             TargetTriple.getEnvironment() == Triple::Android) &&
+            !isTargetDarwin() && !isTargetWindows();
+   }
+diff -ru llvm-3.5.0.src.orig/tools/clang/lib/Driver/Tools.cpp 
llvm-3.5.0.src/tools/clang/lib/Driver/Tools.cpp
+--- llvm-3.5.0.src.orig/tools/clang/lib/Driver/Tools.cpp       2014-08-07 
07:51:51.000000000 -0300
++++ llvm-3.5.0.src/tools/clang/lib/Driver/Tools.cpp    2014-11-12 
15:11:31.901864030 -0200
+@@ -7182,8 +7182,14 @@
+       return "/system/bin/linker64";
+     else
+       return "/system/bin/linker";
+-  } else if (ToolChain.getArch() == llvm::Triple::x86 ||
+-             ToolChain.getArch() == llvm::Triple::sparc)
++  } else if (ToolChain.getArch() == llvm::Triple::x86) {
++    switch (ToolChain.getTriple().getEnvironment()) {
++    case llvm::Triple::Musl:
++      return "/lib/ld-musl-i386.so.1";
++    default:
++      return "/lib/ld-linux.so.2";
++    }
++  } else if (ToolChain.getArch() == llvm::Triple::sparc)
+     return "/lib/ld-linux.so.2";
+   else if (ToolChain.getArch() == llvm::Triple::aarch64 ||
+            ToolChain.getArch() == llvm::Triple::arm64)
+@@ -7193,10 +7199,17 @@
+     return "/lib/ld-linux-aarch64_be.so.1";
+   else if (ToolChain.getArch() == llvm::Triple::arm ||
+            ToolChain.getArch() == llvm::Triple::thumb) {
+-    if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
++    switch (ToolChain.getTriple().getEnvironment()) {
++    case llvm::Triple::Musl:
++    case llvm::Triple::MuslEABI:
++      return "/lib/ld-musl-arm.so.3";
++    case llvm::Triple::MuslEABIHF:
++      return "/lib/ld-musl-armhf.so.3";
++    case llvm::Triple::GNUEABIHF:
+       return "/lib/ld-linux-armhf.so.3";
+-    else
++    default:
+       return "/lib/ld-linux.so.3";
++    }
+   } else if (ToolChain.getArch() == llvm::Triple::armeb ||
+              ToolChain.getArch() == llvm::Triple::thumbeb) {
+     if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
+@@ -7227,8 +7240,14 @@
+   else if (ToolChain.getArch() == llvm::Triple::x86_64 &&
+            ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUX32)
+     return "/libx32/ld-linux-x32.so.2";
+-  else
+-    return "/lib64/ld-linux-x86-64.so.2";
++  else {
++    switch (ToolChain.getTriple().getEnvironment()) {
++    case llvm::Triple::Musl:
++      return "/lib/ld-musl-x86_64.so.1";
++    default:
++      return "/lib64/ld-linux-x86-64.so.2";
++    }
++  }
+ }
+ 
+ static void AddRunTimeLibs(const ToolChain &TC, const Driver &D,

diff --git a/sys-devel/llvm/files/llvm-3.5.0-fix_LLVMExports_cmake.patch 
b/sys-devel/llvm/files/llvm-3.5.0-fix_LLVMExports_cmake.patch
new file mode 100644
index 0000000..9fbd7b7
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.5.0-fix_LLVMExports_cmake.patch
@@ -0,0 +1,39 @@
+Index: cmake/modules/Makefile
+===================================================================
+--- cmake/modules/Makefile     (revision 217451)
++++ cmake/modules/Makefile     (working copy)
+@@ -33,6 +33,16 @@
+       LLVM_ENABLE_RTTI := 0
+ endif
+ 
++LLVM_LIBS_TO_EXPORT := $(subst -l,,$(shell $(LLVM_CONFIG) --libs 
$(LINK_COMPONENTS) || echo Error))
++
++ifeq ($(LLVM_LIBS_TO_EXPORT),Error)
++$(error llvm-config --libs failed)
++endif
++
++ifndef LLVM_LIBS_TO_EXPORT
++$(error LLVM_LIBS_TO_EXPORT cannot be empty)
++endif
++
+ OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake LLVMExports.cmake
+ 
+ $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag)
+@@ -45,7 +55,7 @@
+         -e 's/@LLVM_VERSION_PATCH@/'"$(LLVM_VERSION_PATCH)"'/' \
+         -e 's/@PACKAGE_VERSION@/'"$(LLVMVersion)"'/' \
+         -e 's/@LLVM_COMMON_DEPENDS@//' \
+-        -e 's/@LLVM_AVAILABLE_LIBS@/'"$(subst -l,,$(LLVMConfigLibs))"'/' \
++        -e 's/@LLVM_AVAILABLE_LIBS@/'"$(LLVM_LIBS_TO_EXPORT)"'/' \
+         -e 's/@LLVM_ALL_TARGETS@/'"$(ALL_TARGETS)"'/' \
+         -e 's/@LLVM_TARGETS_TO_BUILD@/'"$(TARGETS_TO_BUILD)"'/' \
+         -e 's/@LLVM_TARGETS_WITH_JIT@/'"$(TARGETS_WITH_JIT)"'/' \
+@@ -83,7 +93,7 @@
+       $(Echo) 'Generating LLVM CMake target exports file'
+       $(Verb) ( \
+         echo '# LLVM CMake target exports.  Do not include directly.' && \
+-        for lib in $(subst -l,,$(LLVMConfigLibs)); do \
++        for lib in $(LLVM_LIBS_TO_EXPORT); do \
+           echo 'add_library('"$$lib"' STATIC IMPORTED)' && \
+           echo 'set_property(TARGET '"$$lib"' PROPERTY IMPORTED_LOCATION 
"'"$(PROJ_libdir)/lib$$lib.a"'")' ; \
+         done && \

diff --git a/sys-devel/llvm/llvm-3.5.0-r99.ebuild 
b/sys-devel/llvm/llvm-3.5.0-r99.ebuild
new file mode 100644
index 0000000..9db3f59
--- /dev/null
+++ b/sys-devel/llvm/llvm-3.5.0-r99.ebuild
@@ -0,0 +1,530 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sys-devel/llvm/llvm-3.5.0.ebuild,v 1.11 
2015/01/01 20:53:32 maekke Exp $
+
+EAPI=5
+
+PYTHON_COMPAT=( python2_7 pypy )
+
+inherit eutils flag-o-matic multibuild multilib \
+       multilib-minimal python-r1 toolchain-funcs pax-utils check-reqs prefix
+
+DESCRIPTION="Low Level Virtual Machine"
+HOMEPAGE="http://llvm.org/";
+SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz
+       clang? ( http://llvm.org/releases/${PV}/compiler-rt-${PV}.src.tar.xz
+               http://llvm.org/releases/${PV}/cfe-${PV}.src.tar.xz
+               
http://llvm.org/releases/${PV}/clang-tools-extra-${PV}.src.tar.xz )
+       !doc? ( http://dev.gentoo.org/~voyageur/distfiles/${P}-manpages.tar.bz2 
)"
+
+LICENSE="UoI-NCSA"
+SLOT="0/3.5"
+KEYWORDS="amd64 arm ppc x86"
+IUSE="clang debug doc gold libedit +libffi multitarget ncurses ocaml python
+       +static-analyzer test xml video_cards_radeon
+       kernel_Darwin kernel_FreeBSD"
+
+COMMON_DEPEND="
+       sys-libs/zlib:0=
+       clang? (
+               python? ( ${PYTHON_DEPS} )
+               static-analyzer? (
+                       dev-lang/perl:*
+                       ${PYTHON_DEPS}
+               )
+               xml? ( dev-libs/libxml2:2= )
+       )
+       gold? ( >=sys-devel/binutils-2.22:*[cxx] )
+       libedit? ( dev-libs/libedit:0=[${MULTILIB_USEDEP}] )
+       libffi? ( >=virtual/libffi-3.0.13-r1:0=[${MULTILIB_USEDEP}] )
+       ncurses? ( >=sys-libs/ncurses-5.9-r3:5=[${MULTILIB_USEDEP}] )
+       ocaml? ( dev-lang/ocaml:0= )"
+# configparser-3.2 breaks the build (3.3 or none at all are fine)
+DEPEND="${COMMON_DEPEND}
+       app-arch/xz-utils
+       dev-lang/perl
+       >=sys-devel/make-3.81
+       >=sys-devel/flex-2.5.4
+       >=sys-devel/bison-1.875d
+       || ( >=sys-devel/gcc-3.0 >=sys-devel/gcc-apple-4.2.1
+               ( >=sys-freebsd/freebsd-lib-9.1-r10 sys-libs/libcxx )
+       )
+       || ( >=sys-devel/binutils-2.18 >=sys-devel/binutils-apple-3.2.3 )
+       clang? ( xml? ( virtual/pkgconfig ) )
+       doc? ( dev-python/sphinx )
+       libffi? ( virtual/pkgconfig )
+       !!<dev-python/configparser-3.3.0.2
+       ${PYTHON_DEPS}"
+RDEPEND="${COMMON_DEPEND}
+       clang? ( !<=sys-devel/clang-${PV}-r99
+               !>=sys-devel/clang-9999 )
+       abi_x86_32? ( !<=app-emulation/emul-linux-x86-baselibs-20130224-r2
+               !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)] )"
+PDEPEND="clang? ( =sys-devel/clang-${PV}-r100 )"
+
+# pypy gives me around 1700 unresolved tests due to open file limit
+# being exceeded. probably GC does not close them fast enough.
+REQUIRED_USE="${PYTHON_REQUIRED_USE}
+       test? ( || ( $(python_gen_useflags 'python*') ) )"
+
+S=${WORKDIR}/${P}.src
+
+# Some people actually override that in make.conf. That sucks since
+# we need to run install per-directory, and ninja can't do that...
+# so why did it call itself ninja in the first place?
+CMAKE_MAKEFILE_GENERATOR=emake
+
+pkg_pretend() {
+       # in megs
+       # !clang !debug !multitarget -O2       400
+       # !clang !debug  multitarget -O2       550
+       #  clang !debug !multitarget -O2       950
+       #  clang !debug  multitarget -O2      1200
+       # !clang  debug  multitarget -O2      5G
+       #  clang !debug  multitarget -O0 -g  12G
+       #  clang  debug  multitarget -O2     16G
+       #  clang  debug  multitarget -O0 -g  14G
+
+       local build_size=550
+       use clang && build_size=1200
+
+       if use debug; then
+               ewarn "USE=debug is known to increase the size of package 
considerably"
+               ewarn "and cause the tests to fail."
+               ewarn
+
+               (( build_size *= 14 ))
+       elif is-flagq -g || is-flagq -ggdb; then
+               ewarn "The C++ compiler -g option is known to increase the size 
of the package"
+               ewarn "considerably. If you run out of space, please consider 
removing it."
+               ewarn
+
+               (( build_size *= 10 ))
+       fi
+
+       # Multiply by number of ABIs :).
+       local abis=( $(multilib_get_enabled_abis) )
+       (( build_size *= ${#abis[@]} ))
+
+       local CHECKREQS_DISK_BUILD=${build_size}M
+       check-reqs_pkg_pretend
+
+       if [[ ${MERGE_TYPE} != binary ]]; then
+               echo 'int main() {return 0;}' > "${T}"/test.cxx || die
+               ebegin "Trying to build a C++11 test program"
+               if ! $(tc-getCXX) -std=c++11 -o /dev/null "${T}"/test.cxx; then
+                       eerror "LLVM-${PV} requires C++11-capable C++ compiler. 
Your current compiler"
+                       eerror "does not seem to support -std=c++11 option. 
Please upgrade your compiler"
+                       eerror "to gcc-4.7 or an equivalent version supporting 
C++11."
+                       die "Currently active compiler does not support 
-std=c++11"
+               fi
+               eend ${?}
+       fi
+}
+
+pkg_setup() {
+       pkg_pretend
+}
+
+src_unpack() {
+       default
+
+       rm -f "${S}"/tools/clang "${S}"/projects/compiler-rt \
+               || die "symlinks removal failed"
+
+       if use clang; then
+               mv "${WORKDIR}"/cfe-${PV}.src "${S}"/tools/clang \
+                       || die "clang source directory move failed"
+               mv "${WORKDIR}"/compiler-rt-${PV}.src 
"${S}"/projects/compiler-rt \
+                       || die "compiler-rt source directory move failed"
+               mv "${WORKDIR}"/clang-tools-extra-${PV}.src 
"${S}"/tools/clang/tools/extra \
+                       || die "clang-tools-extra source directory move failed"
+       fi
+}
+
+src_prepare() {
+       epatch "${FILESDIR}"/${PN}-3.2-nodoctargz.patch
+       epatch "${FILESDIR}"/${PN}-3.5-gcc-4.9.patch
+       epatch "${FILESDIR}"/${PN}-3.5-gentoo-install.patch
+
+       epatch "${FILESDIR}"/${PN}-3.5-musl-fixes.patch
+       epatch "${FILESDIR}"/${PN}-3.5-musl-support.patch
+       epatch "${FILESDIR}"/${PN}-3.5-musl-compiler-rt.patch
+
+       epatch "${FILESDIR}"/${P}-fix_LLVMExports_cmake.patch
+
+       if use clang; then
+               # Automatically select active system GCC's libraries, bugs 
#406163 and #417913
+               epatch 
"${FILESDIR}"/clang-3.5-gentoo-runtime-gcc-detection-v3.patch
+
+               epatch "${FILESDIR}"/clang-3.5-gentoo-install.patch
+               epatch "${FILESDIR}"/clang-3.4-darwin_prefix-include-paths.patch
+               eprefixify tools/clang/lib/Frontend/InitHeaderSearch.cpp
+       fi
+
+       if use prefix && use clang; then
+               sed -i -e "/^CFLAGS /s@-Werror@-I${EPREFIX}/usr/include@" \
+                       projects/compiler-rt/make/platform/clang_*.mk || die
+       fi
+
+       local sub_files=(
+               Makefile.config.in
+               Makefile.rules
+               tools/llvm-config/llvm-config.cpp
+       )
+       use clang && sub_files+=(
+               tools/clang/lib/Driver/Tools.cpp
+               tools/clang/tools/scan-build/scan-build
+       )
+
+       # unfortunately ./configure won't listen to --mandir and the-like, so 
take
+       # care of this.
+       # note: we're setting the main libdir intentionally.
+       # where per-ABI is appropriate, we use $(GENTOO_LIBDIR) make.
+       einfo "Fixing install dirs"
+       sed -e "s,@libdir@,$(get_libdir),g" \
+               -e "s,@PF@,${PF},g" \
+               -e "s,@EPREFIX@,${EPREFIX},g" \
+               -i "${sub_files[@]}" \
+               || die "install paths sed failed"
+
+       if use clang; then
+               # constantly fails for a long time, likely due to our patches
+               rm tools/clang/test/Driver/cross-linux.c || die
+       fi
+
+       # User patches
+       epatch_user
+
+       python_setup
+}
+
+multilib_src_configure() {
+       # disable timestamps since they confuse ccache
+       local conf_flags=(
+               --disable-timestamps
+               --enable-keep-symbols
+               --enable-shared
+               --with-optimize-option=
+               $(tc-is-static-only && echo --disable-shared)
+               $(use_enable !debug optimized)
+               $(use_enable debug assertions)
+               $(use_enable debug expensive-checks)
+               $(use_enable libedit)
+               $(use_enable ncurses terminfo)
+               $(use_enable libffi)
+       )
+
+       # well, it's used only by clang executable c-index-test
+       if multilib_is_native_abi && use clang && use xml; then
+               conf_flags+=( XML2CONFIG="$(tc-getPKG_CONFIG) libxml-2.0" )
+       else
+               conf_flags+=( ac_cv_prog_XML2CONFIG="" )
+       fi
+
+       local targets bindings
+       if use multitarget; then
+               targets='all'
+       else
+               targets='host,cpp'
+               use video_cards_radeon && targets+=',r600'
+       fi
+       conf_flags+=( --enable-targets=${targets} )
+
+       if multilib_is_native_abi; then
+               use gold && conf_flags+=( 
--with-binutils-include="${EPREFIX}"/usr/include/ )
+               # extra commas don't hurt
+               use ocaml && bindings+=',ocaml'
+       fi
+
+       [[ ${bindings} ]] || bindings='none'
+       conf_flags+=( --enable-bindings=${bindings} )
+
+       if use libffi; then
+               local CPPFLAGS=${CPPFLAGS}
+               append-cppflags "$(pkg-config --cflags libffi)"
+       fi
+
+       # llvm prefers clang over gcc, so we may need to force that
+       tc-export CC CXX
+
+       ECONF_SOURCE=${S} \
+       econf "${conf_flags[@]}"
+}
+
+set_makeargs() {
+       MAKEARGS=(
+               VERBOSE=1
+               REQUIRES_RTTI=1
+               GENTOO_LIBDIR=$(get_libdir)
+       )
+
+       # for tests, we want it all! otherwise, we may use a little filtering...
+       # adding ONLY_TOOLS also disables unittest building...
+       if [[ ${EBUILD_PHASE_FUNC} != src_test ]]; then
+               local tools=( llvm-config )
+               use clang && tools+=( clang )
+
+               if multilib_is_native_abi; then
+                       tools+=(
+                               opt llvm-as llvm-dis llc llvm-ar llvm-nm 
llvm-link lli
+                               llvm-extract llvm-mc llvm-bcanalyzer llvm-diff 
macho-dump
+                               llvm-objdump llvm-readobj llvm-rtdyld 
llvm-dwarfdump llvm-cov
+                               llvm-size llvm-stress llvm-mcmarkup 
llvm-profdata
+                               llvm-symbolizer obj2yaml yaml2obj lto bugpoint
+                       )
+
+                       # the build system runs explicitly specified tools in 
parallel,
+                       # so we need to split it into two runs
+                       if [[ ${1} != -1 ]]; then
+                               # those require lto
+                               tools+=( llvm-lto )
+                               use gold && tools+=( gold )
+
+                               # those require clang :)
+                               # we need to explicitly specify all its tools
+                               # since we're passing BUILD_CLANG_ONLY
+                               use clang && tools+=(
+                                       
clang/tools/{clang-check,clang-format,extra}
+                               )
+                       fi
+               fi
+
+               MAKEARGS+=(
+                       # filter tools + disable unittests implicitly
+                       ONLY_TOOLS="${tools[*]}"
+
+                       # this disables unittests & docs from clang
+                       BUILD_CLANG_ONLY=YES
+               )
+       fi
+}
+
+multilib_src_compile() {
+       local MAKEARGS
+       set_makeargs -1
+       emake "${MAKEARGS[@]}"
+
+       if multilib_is_native_abi; then
+               set_makeargs
+               emake -C tools "${MAKEARGS[@]}"
+
+               if use doc; then
+                       emake -C "${S}"/docs -f Makefile.sphinx man
+                       use clang && emake -C "${S}"/tools/clang/docs/tools \
+                               BUILD_FOR_WEBSITE=1 DST_MAN_DIR="${T}"/ man
+                       emake -C "${S}"/docs -f Makefile.sphinx html
+               fi
+       fi
+
+       if use debug; then
+               pax-mark m Debug+Asserts+Checks/bin/llvm-rtdyld
+               pax-mark m Debug+Asserts+Checks/bin/lli
+               pax-mark m Debug+Asserts+Checks/bin/lli-child-target
+       else
+               pax-mark m Release/bin/llvm-rtdyld
+               pax-mark m Release/bin/lli
+               pax-mark m Release/bin/lli-child-target
+       fi
+}
+
+multilib_src_test() {
+       local MAKEARGS
+       set_makeargs
+
+       # build the remaining tools & unittests
+       emake "${MAKEARGS[@]}"
+
+       pax-mark m unittests/ExecutionEngine/JIT/Release/JITTests
+       pax-mark m unittests/ExecutionEngine/MCJIT/Release/MCJITTests
+       pax-mark m unittests/Support/Release/SupportTests
+
+       # respect TMPDIR!
+       local -x LIT_PRESERVES_TMP=1
+       emake "${MAKEARGS[@]}" check
+       use clang && emake "${MAKEARGS[@]}" -C tools/clang test
+}
+
+src_install() {
+       local MULTILIB_CHOST_TOOLS=(
+               /usr/bin/llvm-config
+       )
+
+       local MULTILIB_WRAPPED_HEADERS=(
+               /usr/include/llvm/Config/config.h
+               /usr/include/llvm/Config/llvm-config.h
+       )
+
+       if use clang; then
+               # note: magic applied below
+               MULTILIB_CHOST_TOOLS+=(
+                       /usr/bin/clang
+                       /usr/bin/clang++
+                       /usr/bin/clang-${PV}
+                       /usr/bin/clang++-${PV}
+               )
+
+               MULTILIB_WRAPPED_HEADERS+=(
+                       /usr/include/clang/Config/config.h
+               )
+       fi
+
+       multilib-minimal_src_install
+
+       # Remove unnecessary headers on FreeBSD, bug #417171
+       use kernel_FreeBSD && use clang && rm 
"${ED}"usr/lib/clang/${PV}/include/{std,float,iso,limits,tgmath,varargs}*.h
+}
+
+multilib_src_install() {
+       local MAKEARGS
+       set_makeargs
+
+       local root=${D}/_${ABI}
+
+       emake "${MAKEARGS[@]}" DESTDIR="${root}" install
+       multibuild_merge_root "${root}" "${D}"
+
+       if ! multilib_is_native_abi; then
+               # Backwards compat, will be happily removed someday.
+               dosym "${CHOST}"-llvm-config /usr/bin/llvm-config.${ABI}
+       else
+               # Install docs.
+               if use doc; then
+                       doman "${S}"/docs/_build/man/*.1
+                       use clang && doman "${T}"/clang.1
+                       dohtml -r "${S}"/docs/_build/html/
+               else
+                       if ! use clang; then
+                               rm "${WORKDIR}"/${P}-manpages/clang.1 || die
+                       fi
+                       doman "${WORKDIR}"/${P}-manpages/*.1
+               fi
+
+               # Symlink the gold plugin.
+               if use gold; then
+                       dodir /usr/${CHOST}/binutils-bin/lib/bfd-plugins
+                       dosym ../../../../$(get_libdir)/LLVMgold.so \
+                               
/usr/${CHOST}/binutils-bin/lib/bfd-plugins/LLVMgold.so
+               fi
+       fi
+
+       # apply CHOST and PV to clang executables
+       # they're statically linked so we don't have to worry about the lib
+       if use clang; then
+               local clang_tools=( clang clang++ )
+               local i
+
+               # append ${PV} and symlink back
+               # TODO: use alternatives.eclass? does that make any sense?
+               # maybe with USE=-clang on :0 and USE=clang on older
+               for i in "${clang_tools[@]}"; do
+                       mv "${ED%/}/usr/bin/${i}"{,-${PV}} || die
+                       dosym "${i}"-${PV} /usr/bin/${i}
+               done
+
+               # now prepend ${CHOST} and let the multilib-build.eclass 
symlink it
+               if ! multilib_is_native_abi; then
+                       # non-native? let's replace it with a simple wrapper
+                       for i in "${clang_tools[@]}"; do
+                               rm "${ED%/}/usr/bin/${i}-${PV}" || die
+                               cat > "${T}"/wrapper.tmp <<-_EOF_
+                                       #!${EPREFIX}/bin/sh
+                                       exec "${i}-${PV}" $(get_abi_CFLAGS) 
"\${@}"
+                               _EOF_
+                               newbin "${T}"/wrapper.tmp "${i}-${PV}"
+                       done
+               fi
+       fi
+
+       # Fix install_names on Darwin.  The build system is too complicated
+       # to just fix this, so we correct it post-install
+       local lib= f= odylib= ndylib= libpv=${PV}
+       if [[ ${CHOST} == *-darwin* ]] ; then
+               eval $(grep PACKAGE_VERSION= configure)
+               [[ -n ${PACKAGE_VERSION} ]] && libpv=${PACKAGE_VERSION}
+               for lib in 
lib{EnhancedDisassembly,LLVM-${libpv},LTO,profile_rt,clang}.dylib 
LLVMHello.dylib clang/${libpv}/lib/darwin/libclang_rt.asan_osx_dynamic.dylib; do
+                       # libEnhancedDisassembly is Darwin10 only, so non-fatal
+                       # + omit clang libs if not enabled
+                       [[ -f ${ED}/usr/lib/${lib} ]] || continue
+
+                       ebegin "fixing install_name of $lib"
+                       install_name_tool \
+                               -id "${EPREFIX}"/usr/lib/${lib} \
+                               "${ED}"/usr/lib/${lib}
+                       eend $?
+               done
+               for f in "${ED}"/usr/bin/* "${ED}"/usr/lib/lib*.dylib 
"${ED}"/usr/lib/clang/${libpv}/lib/darwin/*.dylib ; do
+                       # omit clang libs if not enabled
+                       [[ -f ${ED}/usr/lib/${lib} ]] || continue
+
+                       scanmacho -BF'%n#f' "${f}" | tr ',' '\n' | \
+                       while read odylib ; do
+                               ndylib=
+                               case ${odylib} in
+                                       */libclang.dylib)
+                                               
ndylib="${EPREFIX}"/usr/lib/libclang.dylib
+                                               ;;
+                                       */libLLVM-${libpv}.dylib)
+                                               
ndylib="${EPREFIX}"/usr/lib/libLLVM-${libpv}.dylib
+                                               ;;
+                                       */libLTO.dylib)
+                                               
ndylib="${EPREFIX}"/usr/lib/libLTO.dylib
+                                               ;;
+                               esac
+                               if [[ -n ${ndylib} ]] ; then
+                                       ebegin "fixing install_name reference 
to ${odylib} of ${f##*/}"
+                                       install_name_tool \
+                                               -change "${odylib}" "${ndylib}" 
\
+                                               "${f}"
+                                       eend $?
+                               fi
+                       done
+               done
+       fi
+}
+
+multilib_src_install_all() {
+       insinto /usr/share/vim/vimfiles/syntax
+       doins utils/vim/*.vim
+
+       if use clang; then
+               cd tools/clang || die
+
+               if use static-analyzer ; then
+                       dobin tools/scan-build/ccc-analyzer
+                       dosym ccc-analyzer /usr/bin/c++-analyzer
+                       dobin tools/scan-build/scan-build
+
+                       insinto /usr/share/${PN}
+                       doins tools/scan-build/scanview.css
+                       doins tools/scan-build/sorttable.js
+               fi
+
+               python_inst() {
+                       if use static-analyzer ; then
+                               pushd tools/scan-view >/dev/null || die
+
+                               python_doscript scan-view
+
+                               touch __init__.py || die
+                               python_moduleinto clang
+                               python_domodule __init__.py Reporter.py 
Resources ScanView.py startfile.py
+
+                               popd >/dev/null || die
+                       fi
+
+                       if use python ; then
+                               pushd bindings/python/clang >/dev/null || die
+
+                               python_moduleinto clang
+                               python_domodule __init__.py cindex.py 
enumerations.py
+
+                               popd >/dev/null || die
+                       fi
+
+                       # AddressSanitizer symbolizer (currently separate)
+                       python_doscript 
"${S}"/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py
+               }
+               python_foreach_impl python_inst
+       fi
+}

diff --git a/sys-devel/llvm/metadata.xml b/sys-devel/llvm/metadata.xml
new file mode 100644
index 0000000..1a63066
--- /dev/null
+++ b/sys-devel/llvm/metadata.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+       <maintainer>
+               <email>[email protected]</email>
+               <name>Bernard Cafarelli</name>
+       </maintainer>
+       <maintainer>
+               <email>[email protected]</email>
+               <name>Michał Górny</name>
+       </maintainer>
+       <longdescription>Low Level Virtual Machine (LLVM) is:
+   1. A compilation strategy designed to enable effective program optimization 
across the entire lifetime of a program. LLVM supports effective optimization 
at compile time, link-time (particularly interprocedural), run-time and offline 
(i.e., after software is installed), while remaining transparent to developers 
and maintaining compatibility with existing build scripts.
+   2. A virtual instruction set - LLVM is a low-level object code 
representation that uses simple RISC-like instructions, but provides rich, 
language-independent, type information and dataflow (SSA) information about 
operands. This combination enables sophisticated transformations on object 
code, while remaining light-weight enough to be attached to the executable. 
This combination is key to allowing link-time, run-time, and offline 
transformations.
+   3. A compiler infrastructure - LLVM is also a collection of source code 
that implements the language and compilation strategy. The primary components 
of the LLVM infrastructure are a GCC-based C and C++ front-end, a link-time 
optimization framework with a growing set of global and interprocedural 
analyses and transformations, static back-ends for many popular (and some 
obscure) architectures, a back-end which emits portable C code, and a 
Just-In-Time compilers for several architectures.
+   4. LLVM does not imply things that you would expect from a high-level 
virtual machine. It does not require garbage collection or run-time code 
generation (In fact, LLVM makes a great static compiler!). Note that optional 
LLVM components can be used to build high-level virtual machines and other 
systems that need these services.</longdescription>
+       <use>
+               <flag name='clang'>Build the clang C/C++ compiler</flag>
+               <flag name='cmake'>Enable cmake support (experimental)</flag>
+               <flag name='doc'>Build and install the HTML documentation and 
regenerate the man pages</flag>
+               <flag name='gold'>Build the gold linker plugin</flag>
+               <flag name='llvm-gcc'>Build LLVM with 
<pkg>sys-devel/llvm-gcc</pkg></flag>
+               <flag name='multitarget'>Build all host targets (default: host 
only)</flag>
+               <flag name='ncurses'>Support querying terminal properties using 
ncurses' terminfo</flag>
+               <flag name='static-analyzer'>Install the Clang static analyzer 
(requires USE=clang)</flag>
+               <flag name='udis86'>Enable support for 
<pkg>dev-libs/udis86</pkg> disassembler library</flag>
+       </use>
+</pkgmetadata>

Reply via email to