Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/llvm/, sys-devel/llvm/files/
Date: Mon, 28 Mar 2016 15:57:58
Message-Id: 1459180640.b14c1f316ec560606a2606f5b6d821f41b2844de.mgorny@gentoo
1 commit: b14c1f316ec560606a2606f5b6d821f41b2844de
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Sun Mar 27 21:04:33 2016 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Mon Mar 28 15:57:20 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b14c1f31
7
8 sys-devel/llvm: Update llvm-config patches for improved compatibility
9
10 Backport upstream r252532 that improves llvm-config support for shared
11 libraries, adding --shared-mode option in particular, along with
12 --build-system option needed for it. Also fix --build-mode to report
13 "Release" rather than non-standard "Gentoo" type.
14
15 Bug: https://bugs.gentoo.org/show_bug.cgi?id=578304
16
17 .../llvm/files/llvm-3.7.1-llvm-config-0.patch | 83 +++
18 .../llvm/files/llvm-3.7.1-llvm-config-1.patch | 453 +++++++++++++++++
19 .../llvm/files/llvm-3.7.1-llvm-config-2.patch | 113 +++++
20 .../llvm/files/llvm-3.7.1-llvm-config-3.patch | 29 ++
21 sys-devel/llvm/llvm-3.7.1-r1.ebuild | 559 +++++++++++++++++++++
22 5 files changed, 1237 insertions(+)
23
24 diff --git a/sys-devel/llvm/files/llvm-3.7.1-llvm-config-0.patch b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-0.patch
25 new file mode 100644
26 index 0000000..87f9ff8
27 --- /dev/null
28 +++ b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-0.patch
29 @@ -0,0 +1,83 @@
30 +From a59464503a7e059ddfd3fb4308753b692d03d996 Mon Sep 17 00:00:00 2001
31 +From: Tom Stellard <thomas.stellard@×××.com>
32 +Date: Wed, 9 Sep 2015 16:39:30 +0000
33 +Subject: [PATCH 1/4] llvm-config: Add --build-system option
34 +
35 +Summary:
36 +This can be used for distinguishing between cmake and autoconf builds.
37 +Users may need this in order to handle inconsistencies between the
38 +outputs of the two build systems.
39 +
40 +Reviewers: echristo, chandlerc, beanz
41 +
42 +Subscribers: llvm-commits
43 +
44 +Differential Revision: http://reviews.llvm.org/D11838
45 +
46 +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247159 91177308-0d34-0410-b5e6-96231b3b80d8
47 +---
48 + tools/llvm-config/BuildVariables.inc.in | 1 +
49 + tools/llvm-config/CMakeLists.txt | 2 ++
50 + tools/llvm-config/Makefile | 2 ++
51 + tools/llvm-config/llvm-config.cpp | 3 +++
52 + 4 files changed, 8 insertions(+)
53 +
54 +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
55 +index 3f51f49..0f28fad 100644
56 +--- a/tools/llvm-config/BuildVariables.inc.in
57 ++++ b/tools/llvm-config/BuildVariables.inc.in
58 +@@ -26,3 +26,4 @@
59 + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
60 + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
61 + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
62 ++#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
63 +diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
64 +index edbd8c9..dd53460 100644
65 +--- a/tools/llvm-config/CMakeLists.txt
66 ++++ b/tools/llvm-config/CMakeLists.txt
67 +@@ -24,6 +24,8 @@ set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
68 + set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
69 + set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
70 + set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
71 ++set(LLVM_BUILD_SYSTEM cmake)
72 ++
73 + # Use the C++ link flags, since they should be a superset of C link flags.
74 + set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
75 + set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
76 +diff --git a/tools/llvm-config/Makefile b/tools/llvm-config/Makefile
77 +index 1ff8b6f..c2b5e8f 100644
78 +--- a/tools/llvm-config/Makefile
79 ++++ b/tools/llvm-config/Makefile
80 +@@ -65,6 +65,8 @@ $(ObjDir)/BuildVariables.inc: $(BUILDVARIABLES_SRCPATH) Makefile $(ObjDir)/.dir
81 + >> temp.sed
82 + $(Verb) $(ECHO) 's/@LLVM_TARGETS_BUILT@/$(subst /,\/,$(TARGETS_TO_BUILD))/' \
83 + >> temp.sed
84 ++ $(Verb) $(ECHO) 's/@LLVM_BUILD_SYSTEM@/autoconf/' \
85 ++ >> temp.sed
86 + $(Verb) $(SED) -f temp.sed < $< > $@
87 + $(Verb) $(RM) temp.sed
88 +
89 +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
90 +index 879b9ab..4ce8f10 100644
91 +--- a/tools/llvm-config/llvm-config.cpp
92 ++++ b/tools/llvm-config/llvm-config.cpp
93 +@@ -157,6 +157,7 @@ Options:\n\
94 + --host-target Target triple used to configure LLVM.\n\
95 + --build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\
96 + --assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
97 ++ --build-system Print the build system used to build LLVM (autoconf or cmake).\n\
98 + Typical components:\n\
99 + all All LLVM libraries (default).\n\
100 + engine Either a native JIT or a bitcode interpreter.\n";
101 +@@ -323,6 +324,8 @@ int main(int argc, char **argv) {
102 + #else
103 + OS << "ON\n";
104 + #endif
105 ++ } else if (Arg == "--build-system") {
106 ++ OS << LLVM_BUILD_SYSTEM << '\n';
107 + } else if (Arg == "--obj-root") {
108 + OS << ActivePrefix << '\n';
109 + } else if (Arg == "--src-root") {
110 +--
111 +2.7.4
112 +
113
114 diff --git a/sys-devel/llvm/files/llvm-3.7.1-llvm-config-1.patch b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-1.patch
115 new file mode 100644
116 index 0000000..214a3bb
117 --- /dev/null
118 +++ b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-1.patch
119 @@ -0,0 +1,453 @@
120 +From 55433193c56e6b2e0792c3ca1b0ef3881ab01138 Mon Sep 17 00:00:00 2001
121 +From: Richard Diamond <wichard@×××××××××××××××.com>
122 +Date: Mon, 9 Nov 2015 23:15:38 +0000
123 +Subject: [PATCH 2/4] Fix `llvm-config` to adapt to the install environment.
124 +
125 +Summary:
126 +This patch does a couple of things:
127 +
128 + - Adds a new argument `--shared-mode` which accepts a list of components and prints whether or not the provided components need to be linked statically or shared.
129 + - Fixes `--libnames` when CMake BUILD_SHARED_LIBS is used.
130 + - Fixes `--libnames`, `--libs`, and `--libfiles` for dylib when static components aren't installed.
131 + - Fixes `--libnames`, `--libs`, `--libfiles`, and `--components` to use LLVM_DYLIB_COMPONENTS as the component manifest for dylib linking.
132 + - Uses the host platform's usual convention for filename extensions and such, instead of always defaulting to Unix-izms.
133 +
134 +Because I don't own a Mac, I am not able to test the Mac platform dependent stuff locally. If someone would be willing to run a build for me on their machine (unless there's a better option), I'd appreciate it.
135 +
136 +Reviewers: jfb, brad.king, whitequark, beanz
137 +
138 +Subscribers: beanz, jauhien, llvm-commits
139 +
140 +Differential Revision: http://reviews.llvm.org/D13198
141 +
142 +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252532 91177308-0d34-0410-b5e6-96231b3b80d8
143 +---
144 + bindings/ocaml/Makefile.ocaml | 2 +
145 + tools/llvm-config/BuildVariables.inc.in | 3 +
146 + tools/llvm-config/CMakeLists.txt | 5 +
147 + tools/llvm-config/llvm-config.cpp | 265 +++++++++++++++++++++++++++++---
148 + 4 files changed, 253 insertions(+), 22 deletions(-)
149 +
150 +diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml
151 +index 1f65a7b..22b96a2 100644
152 +--- a/bindings/ocaml/Makefile.ocaml
153 ++++ b/bindings/ocaml/Makefile.ocaml
154 +@@ -277,6 +277,8 @@ uninstall-local:: uninstall-deplibs
155 +
156 + build-deplibs: $(OutputLibs)
157 +
158 ++$(OcamlDir)/%.so: $(LibDir)/%.so
159 ++ $(Verb) ln -sf $< $@
160 + $(OcamlDir)/%.a: $(LibDir)/%.a
161 + $(Verb) ln -sf $< $@
162 +
163 +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
164 +index 0f28fad..e384838 100644
165 +--- a/tools/llvm-config/BuildVariables.inc.in
166 ++++ b/tools/llvm-config/BuildVariables.inc.in
167 +@@ -27,3 +27,6 @@
168 + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
169 + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
170 + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
171 ++#define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@"
172 ++#define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@"
173 ++#define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@"
174 +diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
175 +index dd53460..173f6dc 100644
176 +--- a/tools/llvm-config/CMakeLists.txt
177 ++++ b/tools/llvm-config/CMakeLists.txt
178 +@@ -30,6 +30,11 @@ set(LLVM_BUILD_SYSTEM cmake)
179 + set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
180 + set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
181 + set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
182 ++if(BUILD_SHARED_LIBS)
183 ++ set(LLVM_ENABLE_SHARED ON)
184 ++else()
185 ++ set(LLVM_ENABLE_SHARED OFF)
186 ++endif()
187 + string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
188 + configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
189 +
190 +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
191 +index 4ce8f10..51efbd8 100644
192 +--- a/tools/llvm-config/llvm-config.cpp
193 ++++ b/tools/llvm-config/llvm-config.cpp
194 +@@ -30,6 +30,7 @@
195 + #include <cstdlib>
196 + #include <set>
197 + #include <vector>
198 ++#include <unordered_set>
199 +
200 + using namespace llvm;
201 +
202 +@@ -51,12 +52,16 @@ using namespace llvm;
203 + /// \param Name - The component to traverse.
204 + /// \param ComponentMap - A prebuilt map of component names to descriptors.
205 + /// \param VisitedComponents [in] [out] - The set of already visited components.
206 +-/// \param RequiredLibs [out] - The ordered list of required libraries.
207 ++/// \param RequiredLibs [out] - The ordered list of required
208 ++/// libraries.
209 ++/// \param GetComponentNames - Get the component names instead of the
210 ++/// library name.
211 + static void VisitComponent(StringRef Name,
212 + const StringMap<AvailableComponent*> &ComponentMap,
213 + std::set<AvailableComponent*> &VisitedComponents,
214 + std::vector<StringRef> &RequiredLibs,
215 +- bool IncludeNonInstalled) {
216 ++ bool IncludeNonInstalled, bool GetComponentNames,
217 ++ const std::string *ActiveLibDir, bool *HasMissing) {
218 + // Lookup the component.
219 + AvailableComponent *AC = ComponentMap.lookup(Name);
220 + assert(AC && "Invalid component name!");
221 +@@ -74,12 +79,22 @@ static void VisitComponent(StringRef Name,
222 + // Otherwise, visit all the dependencies.
223 + for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
224 + VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
225 +- RequiredLibs, IncludeNonInstalled);
226 ++ RequiredLibs, IncludeNonInstalled, GetComponentNames,
227 ++ ActiveLibDir, HasMissing);
228 ++ }
229 ++
230 ++ if (GetComponentNames) {
231 ++ RequiredLibs.push_back(Name);
232 ++ return;
233 + }
234 +
235 + // Add to the required library list.
236 +- if (AC->Library)
237 ++ if (AC->Library) {
238 ++ if (!IncludeNonInstalled && HasMissing && !*HasMissing && ActiveLibDir) {
239 ++ *HasMissing = !sys::fs::exists(*ActiveLibDir + "/" + AC->Library);
240 ++ }
241 + RequiredLibs.push_back(AC->Library);
242 ++ }
243 + }
244 +
245 + /// \brief Compute the list of required libraries for a given list of
246 +@@ -91,9 +106,12 @@ static void VisitComponent(StringRef Name,
247 + /// are required to link the given components.
248 + /// \param IncludeNonInstalled - Whether non-installed components should be
249 + /// reported.
250 ++/// \param GetComponentNames - True if one would prefer the component names.
251 + static void ComputeLibsForComponents(const std::vector<StringRef> &Components,
252 + std::vector<StringRef> &RequiredLibs,
253 +- bool IncludeNonInstalled) {
254 ++ bool IncludeNonInstalled, bool GetComponentNames,
255 ++ const std::string *ActiveLibDir,
256 ++ bool *HasMissing) {
257 + std::set<AvailableComponent*> VisitedComponents;
258 +
259 + // Build a map of component names to information.
260 +@@ -116,7 +134,8 @@ static void ComputeLibsForComponents(const std::vector<StringRef> &Components,
261 + }
262 +
263 + VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
264 +- RequiredLibs, IncludeNonInstalled);
265 ++ RequiredLibs, IncludeNonInstalled, GetComponentNames,
266 ++ ActiveLibDir, HasMissing);
267 + }
268 +
269 + // The list is now ordered with leafs first, we want the libraries to printed
270 +@@ -157,6 +176,7 @@ Options:\n\
271 + --host-target Target triple used to configure LLVM.\n\
272 + --build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\
273 + --assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
274 ++ --shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\
275 + --build-system Print the build system used to build LLVM (autoconf or cmake).\n\
276 + Typical components:\n\
277 + all All LLVM libraries (default).\n\
278 +@@ -172,10 +192,38 @@ std::string GetExecutablePath(const char *Argv0) {
279 + return llvm::sys::fs::getMainExecutable(Argv0, P);
280 + }
281 +
282 ++/// \brief Expand the semi-colon delimited LLVM_DYLIB_COMPONENTS into
283 ++/// the full list of components.
284 ++std::vector<StringRef> GetAllDyLibComponents(const bool IsInDevelopmentTree,
285 ++ const bool GetComponentNames) {
286 ++ std::vector<StringRef> DyLibComponents;
287 ++ {
288 ++ StringRef DyLibComponentsStr(LLVM_DYLIB_COMPONENTS);
289 ++ size_t Offset = 0;
290 ++ while (true) {
291 ++ const size_t NextOffset = DyLibComponentsStr.find(';', Offset);
292 ++ DyLibComponents.push_back(DyLibComponentsStr.substr(Offset, NextOffset));
293 ++ if (NextOffset == std::string::npos) {
294 ++ break;
295 ++ }
296 ++ Offset = NextOffset + 1;
297 ++ }
298 ++
299 ++ assert(DyLibComponents.size() > 0);
300 ++ }
301 ++
302 ++ std::vector<StringRef> Components;
303 ++ ComputeLibsForComponents(DyLibComponents, Components,
304 ++ /*IncludeNonInstalled=*/IsInDevelopmentTree,
305 ++ GetComponentNames, nullptr, nullptr);
306 ++
307 ++ return std::move(Components);
308 ++}
309 ++
310 + int main(int argc, char **argv) {
311 + std::vector<StringRef> Components;
312 + bool PrintLibs = false, PrintLibNames = false, PrintLibFiles = false;
313 +- bool PrintSystemLibs = false;
314 ++ bool PrintSystemLibs = false, PrintSharedMode = false;
315 + bool HasAnyOption = false;
316 +
317 + // llvm-config is designed to support being run both from a development tree
318 +@@ -270,6 +318,108 @@ int main(int argc, char **argv) {
319 + ActiveIncludeOption = "-I" + ActiveIncludeDir;
320 + }
321 +
322 ++ /// We only use `shared library` mode in cases where the static library form
323 ++ /// of the components provided are not available; note however that this is
324 ++ /// skipped if we're run from within the build dir. However, once installed,
325 ++ /// we still need to provide correct output when the static archives are
326 ++ /// removed or, as in the case of CMake's `BUILD_SHARED_LIBS`, never present
327 ++ /// in the first place. This can't be done at configure/build time.
328 ++
329 ++ StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
330 ++ StaticPrefix, StaticDir = "lib";
331 ++ const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));
332 ++ if (HostTriple.isOSWindows()) {
333 ++ SharedExt = "dll";
334 ++ SharedVersionedExt = PACKAGE_VERSION ".dll";
335 ++ StaticExt = "a";
336 ++ SharedDir = ActiveBinDir;
337 ++ StaticDir = ActiveLibDir;
338 ++ StaticPrefix = SharedPrefix = "";
339 ++ } else if (HostTriple.isOSDarwin()) {
340 ++ SharedExt = "dylib";
341 ++ SharedVersionedExt = PACKAGE_VERSION ".dylib";
342 ++ StaticExt = "a";
343 ++ StaticDir = SharedDir = ActiveLibDir;
344 ++ StaticPrefix = SharedPrefix = "lib";
345 ++ } else {
346 ++ // default to the unix values:
347 ++ SharedExt = "so";
348 ++ SharedVersionedExt = PACKAGE_VERSION ".so";
349 ++ StaticExt = "a";
350 ++ StaticDir = SharedDir = ActiveLibDir;
351 ++ StaticPrefix = SharedPrefix = "lib";
352 ++ }
353 ++
354 ++ const bool BuiltDyLib = (std::strcmp(LLVM_ENABLE_DYLIB, "ON") == 0);
355 ++
356 ++ enum { CMake, AutoConf } ConfigTool;
357 ++ if (std::strcmp(LLVM_BUILD_SYSTEM, "cmake") == 0) {
358 ++ ConfigTool = CMake;
359 ++ } else {
360 ++ ConfigTool = AutoConf;
361 ++ }
362 ++
363 ++ /// CMake style shared libs, ie each component is in a shared library.
364 ++ const bool BuiltSharedLibs =
365 ++ (ConfigTool == CMake && std::strcmp(LLVM_ENABLE_SHARED, "ON") == 0);
366 ++
367 ++ bool DyLibExists = false;
368 ++ const std::string DyLibName =
369 ++ (SharedPrefix + "LLVM-" + SharedVersionedExt).str();
370 ++
371 ++ if (BuiltDyLib) {
372 ++ DyLibExists = sys::fs::exists(SharedDir + "/" + DyLibName);
373 ++ }
374 ++
375 ++ /// Get the component's library name without the lib prefix and the
376 ++ /// extension. Returns true if Lib is in a recognized format.
377 ++ auto GetComponentLibraryNameSlice = [&](const StringRef &Lib,
378 ++ StringRef &Out) {
379 ++ if (Lib.startswith("lib")) {
380 ++ unsigned FromEnd;
381 ++ if (Lib.endswith(StaticExt)) {
382 ++ FromEnd = StaticExt.size() + 1;
383 ++ } else if (Lib.endswith(SharedExt)) {
384 ++ FromEnd = SharedExt.size() + 1;
385 ++ } else {
386 ++ FromEnd = 0;
387 ++ }
388 ++
389 ++ if (FromEnd != 0) {
390 ++ Out = Lib.slice(3, Lib.size() - FromEnd);
391 ++ return true;
392 ++ }
393 ++ }
394 ++
395 ++ return false;
396 ++ };
397 ++ /// Maps Unixizms to the host platform.
398 ++ auto GetComponentLibraryFileName = [&](const StringRef &Lib,
399 ++ const bool ForceShared) {
400 ++ std::string LibFileName = Lib;
401 ++ StringRef LibName;
402 ++ if (GetComponentLibraryNameSlice(Lib, LibName)) {
403 ++ if (BuiltSharedLibs || ForceShared) {
404 ++ LibFileName = (SharedPrefix + LibName + "." + SharedExt).str();
405 ++ } else {
406 ++ // default to static
407 ++ LibFileName = (StaticPrefix + LibName + "." + StaticExt).str();
408 ++ }
409 ++ }
410 ++
411 ++ return LibFileName;
412 ++ };
413 ++ /// Get the full path for a possibly shared component library.
414 ++ auto GetComponentLibraryPath = [&](const StringRef &Name,
415 ++ const bool ForceShared) {
416 ++ auto LibFileName = GetComponentLibraryFileName(Name, ForceShared);
417 ++ if (BuiltSharedLibs || ForceShared) {
418 ++ return (SharedDir + "/" + LibFileName).str();
419 ++ } else {
420 ++ return (StaticDir + "/" + LibFileName).str();
421 ++ }
422 ++ };
423 ++
424 + raw_ostream &OS = outs();
425 + for (int i = 1; i != argc; ++i) {
426 + StringRef Arg = argv[i];
427 +@@ -303,13 +453,33 @@ int main(int argc, char **argv) {
428 + } else if (Arg == "--libfiles") {
429 + PrintLibFiles = true;
430 + } else if (Arg == "--components") {
431 ++ /// If there are missing static archives and a dylib was
432 ++ /// built, print LLVM_DYLIB_COMPONENTS instead of everything
433 ++ /// in the manifest.
434 ++ std::vector<StringRef> Components;
435 + for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) {
436 + // Only include non-installed components when in a development tree.
437 + if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree)
438 + continue;
439 +
440 +- OS << ' ';
441 +- OS << AvailableComponents[j].Name;
442 ++ Components.push_back(AvailableComponents[j].Name);
443 ++ if (AvailableComponents[j].Library && !IsInDevelopmentTree) {
444 ++ if (DyLibExists &&
445 ++ !sys::fs::exists(GetComponentLibraryPath(
446 ++ AvailableComponents[j].Library, false))) {
447 ++ Components = GetAllDyLibComponents(IsInDevelopmentTree, true);
448 ++ std::sort(Components.begin(), Components.end());
449 ++ break;
450 ++ }
451 ++ }
452 ++ }
453 ++
454 ++ for (unsigned I = 0; I < Components.size(); ++I) {
455 ++ if (I) {
456 ++ OS << ' ';
457 ++ }
458 ++
459 ++ OS << Components[I];
460 + }
461 + OS << '\n';
462 + } else if (Arg == "--targets-built") {
463 +@@ -324,6 +494,8 @@ int main(int argc, char **argv) {
464 + #else
465 + OS << "ON\n";
466 + #endif
467 ++ } else if (Arg == "--shared-mode") {
468 ++ PrintSharedMode = true;
469 + } else if (Arg == "--build-system") {
470 + OS << LLVM_BUILD_SYSTEM << '\n';
471 + } else if (Arg == "--obj-root") {
472 +@@ -341,35 +513,84 @@ int main(int argc, char **argv) {
473 + if (!HasAnyOption)
474 + usage();
475 +
476 +- if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs) {
477 ++ if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs ||
478 ++ PrintSharedMode) {
479 ++
480 ++ if (PrintSharedMode && BuiltSharedLibs) {
481 ++ OS << "shared\n";
482 ++ return 0;
483 ++ }
484 ++
485 + // If no components were specified, default to "all".
486 + if (Components.empty())
487 + Components.push_back("all");
488 +
489 + // Construct the list of all the required libraries.
490 + std::vector<StringRef> RequiredLibs;
491 ++ bool HasMissing = false;
492 + ComputeLibsForComponents(Components, RequiredLibs,
493 +- /*IncludeNonInstalled=*/IsInDevelopmentTree);
494 ++ /*IncludeNonInstalled=*/IsInDevelopmentTree, false,
495 ++ &ActiveLibDir, &HasMissing);
496 ++
497 ++ if (PrintSharedMode) {
498 ++ std::unordered_set<std::string> FullDyLibComponents;
499 ++ std::vector<StringRef> DyLibComponents =
500 ++ GetAllDyLibComponents(IsInDevelopmentTree, false);
501 ++
502 ++ for (auto &Component : DyLibComponents) {
503 ++ FullDyLibComponents.insert(Component);
504 ++ }
505 ++ DyLibComponents.clear();
506 ++
507 ++ for (auto &Lib : RequiredLibs) {
508 ++ if (!FullDyLibComponents.count(Lib)) {
509 ++ OS << "static\n";
510 ++ return 0;
511 ++ }
512 ++ }
513 ++ FullDyLibComponents.clear();
514 ++
515 ++ if (HasMissing && DyLibExists) {
516 ++ OS << "shared\n";
517 ++ return 0;
518 ++ } else {
519 ++ OS << "static\n";
520 ++ return 0;
521 ++ }
522 ++ }
523 +
524 + if (PrintLibs || PrintLibNames || PrintLibFiles) {
525 +- for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
526 +- StringRef Lib = RequiredLibs[i];
527 +- if (i)
528 +- OS << ' ';
529 +
530 ++ auto PrintForLib = [&](const StringRef &Lib, const bool ForceShared) {
531 + if (PrintLibNames) {
532 +- OS << Lib;
533 ++ OS << GetComponentLibraryFileName(Lib, ForceShared);
534 + } else if (PrintLibFiles) {
535 +- OS << ActiveLibDir << '/' << Lib;
536 ++ OS << GetComponentLibraryPath(Lib, ForceShared);
537 + } else if (PrintLibs) {
538 + // If this is a typical library name, include it using -l.
539 +- if (Lib.startswith("lib") && Lib.endswith(".a")) {
540 +- OS << "-l" << Lib.slice(3, Lib.size()-2);
541 +- continue;
542 ++ StringRef LibName;
543 ++ if (Lib.startswith("lib")) {
544 ++ if (GetComponentLibraryNameSlice(Lib, LibName)) {
545 ++ OS << "-l" << LibName;
546 ++ } else {
547 ++ OS << "-l:" << GetComponentLibraryFileName(Lib, ForceShared);
548 ++ }
549 ++ } else {
550 ++ // Otherwise, print the full path.
551 ++ OS << GetComponentLibraryPath(Lib, ForceShared);
552 + }
553 ++ }
554 ++ };
555 ++
556 ++ if (HasMissing && DyLibExists) {
557 ++ PrintForLib(DyLibName, true);
558 ++ } else {
559 ++ for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
560 ++ StringRef Lib = RequiredLibs[i];
561 ++ if (i)
562 ++ OS << ' ';
563 +
564 +- // Otherwise, print the full path.
565 +- OS << ActiveLibDir << '/' << Lib;
566 ++ PrintForLib(Lib, false);
567 + }
568 + }
569 + OS << '\n';
570 +--
571 +2.7.4
572 +
573
574 diff --git a/sys-devel/llvm/files/llvm-3.7.1-llvm-config-2.patch b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-2.patch
575 new file mode 100644
576 index 0000000..2895d38
577 --- /dev/null
578 +++ b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-2.patch
579 @@ -0,0 +1,113 @@
580 +From 4abc261d14c886c21d24f639293a60ce45c1dca3 Mon Sep 17 00:00:00 2001
581 +From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@g.o>
582 +Date: Wed, 2 Dec 2015 16:04:56 +0100
583 +Subject: [PATCH 3/4] llvm-config: Clean up exported values, update for shared
584 + linking
585 +
586 +Gentoo-specific fixup for llvm-config, including:
587 +- wiping build-specific CFLAGS, CXXFLAGS,
588 +- updating library suffixes for shared libs,
589 +- wiping --system-libs for shared linking,
590 +- banning --obj-root and --src-root due to no sources installed,
591 +- making --build-mode return "Release" rather than "Gentoo".
592 +
593 +Thanks to Steven Newbury for the initial patch.
594 +
595 +Bug: https://bugs.gentoo.org/565358
596 +Bug: https://bugs.gentoo.org/501684
597 +---
598 + tools/llvm-config/CMakeLists.txt | 11 ++++++++---
599 + tools/llvm-config/llvm-config.cpp | 20 +++++++++++++++-----
600 + utils/llvm-build/llvmbuild/main.py | 4 +++-
601 + 3 files changed, 26 insertions(+), 9 deletions(-)
602 +
603 +diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
604 +index 173f6dc..013ea8c 100644
605 +--- a/tools/llvm-config/CMakeLists.txt
606 ++++ b/tools/llvm-config/CMakeLists.txt
607 +@@ -22,14 +22,19 @@ get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
608 + set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
609 + set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
610 + set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
611 +-set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
612 +-set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
613 ++# Just use CMAKE_CPP_FLAGS for CFLAGS and CXXFLAGS, otherwise compiler
614 ++# specific flags will be set when we don't know what compiler will be used
615 ++# with external project utilising llvm-config. C++ Standard is required.
616 ++# TODO: figure out if we can remove -std=c++11 and move it to revdeps.
617 ++set(LLVM_CFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
618 ++set(LLVM_CXXFLAGS "${CMAKE_CPP_FLAGS} -std=c++11 ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
619 + set(LLVM_BUILD_SYSTEM cmake)
620 +
621 + # Use the C++ link flags, since they should be a superset of C link flags.
622 + set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
623 + set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
624 +-set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
625 ++# We don't do static libs, so we don't need to supply any system-libs
626 ++set(LLVM_SYSTEM_LIBS "")
627 + if(BUILD_SHARED_LIBS)
628 + set(LLVM_ENABLE_SHARED ON)
629 + else()
630 +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
631 +index 51efbd8..315e5e1 100644
632 +--- a/tools/llvm-config/llvm-config.cpp
633 ++++ b/tools/llvm-config/llvm-config.cpp
634 +@@ -487,7 +487,8 @@ int main(int argc, char **argv) {
635 + } else if (Arg == "--host-target") {
636 + OS << Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE) << '\n';
637 + } else if (Arg == "--build-mode") {
638 +- OS << build_mode << '\n';
639 ++ // force Release since we force non-standard Gentoo build mode
640 ++ OS << "Release" << '\n';
641 + } else if (Arg == "--assertion-mode") {
642 + #if defined(NDEBUG)
643 + OS << "OFF\n";
644 +@@ -498,10 +499,19 @@ int main(int argc, char **argv) {
645 + PrintSharedMode = true;
646 + } else if (Arg == "--build-system") {
647 + OS << LLVM_BUILD_SYSTEM << '\n';
648 +- } else if (Arg == "--obj-root") {
649 +- OS << ActivePrefix << '\n';
650 +- } else if (Arg == "--src-root") {
651 +- OS << LLVM_SRC_ROOT << '\n';
652 ++ } else if (Arg == "--obj-root" || Arg == "--src-root") {
653 ++ if (IsInDevelopmentTree) {
654 ++ if (Arg == "--obj-root") {
655 ++ OS << ActivePrefix << '\n';
656 ++ } else {
657 ++ OS << LLVM_SRC_ROOT << '\n';
658 ++ }
659 ++ } else {
660 ++ // sources are not installed
661 ++ llvm::errs() << "llvm-config: sources not installed, "
662 ++ << Arg << " not available\n";
663 ++ exit(1);
664 ++ }
665 + } else {
666 + usage();
667 + }
668 +diff --git a/utils/llvm-build/llvmbuild/main.py b/utils/llvm-build/llvmbuild/main.py
669 +index 353741f..4ba5e91 100644
670 +--- a/utils/llvm-build/llvmbuild/main.py
671 ++++ b/utils/llvm-build/llvmbuild/main.py
672 +@@ -393,6 +393,8 @@ subdirectories = %s
673 + //
674 + //===----------------------------------------------------------------------===//
675 +
676 ++#include "llvm/Config/config.h"
677 ++
678 + """)
679 + f.write('struct AvailableComponent {\n')
680 + f.write(' /// The name of the component.\n')
681 +@@ -413,7 +415,7 @@ subdirectories = %s
682 + if library_name is None:
683 + library_name_as_cstr = '0'
684 + else:
685 +- library_name_as_cstr = '"lib%s.a"' % library_name
686 ++ library_name_as_cstr = '"lib%s" LTDL_SHLIB_EXT' % library_name
687 + f.write(' { "%s", %s, %d, { %s } },\n' % (
688 + name, library_name_as_cstr, is_installed,
689 + ', '.join('"%s"' % dep
690 +--
691 +2.7.4
692 +
693
694 diff --git a/sys-devel/llvm/files/llvm-3.7.1-llvm-config-3.patch b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-3.patch
695 new file mode 100644
696 index 0000000..7a1547e
697 --- /dev/null
698 +++ b/sys-devel/llvm/files/llvm-3.7.1-llvm-config-3.patch
699 @@ -0,0 +1,29 @@
700 +From 9308d1858852bdc6f099025ca0482d7b3a32a9aa Mon Sep 17 00:00:00 2001
701 +From: NAKAMURA Takumi <geek4civic@×××××.com>
702 +Date: Wed, 10 Feb 2016 01:12:55 +0000
703 +Subject: [PATCH 4/4] llvm-config: Quick fix for cross compilation. Don't be
704 + confsed between host and target. It has been there since r252532.
705 +
706 +FIXME: The clause may use conditions of host compiler, not HOST_TRIPLE.
707 +
708 +git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260343 91177308-0d34-0410-b5e6-96231b3b80d8
709 +---
710 + tools/llvm-config/llvm-config.cpp | 2 +-
711 + 1 file changed, 1 insertion(+), 1 deletion(-)
712 +
713 +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
714 +index 315e5e1..346c9d9 100644
715 +--- a/tools/llvm-config/llvm-config.cpp
716 ++++ b/tools/llvm-config/llvm-config.cpp
717 +@@ -327,7 +327,7 @@ int main(int argc, char **argv) {
718 +
719 + StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
720 + StaticPrefix, StaticDir = "lib";
721 +- const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));
722 ++ const Triple HostTriple(Triple::normalize(LLVM_HOST_TRIPLE));
723 + if (HostTriple.isOSWindows()) {
724 + SharedExt = "dll";
725 + SharedVersionedExt = PACKAGE_VERSION ".dll";
726 +--
727 +2.7.4
728 +
729
730 diff --git a/sys-devel/llvm/llvm-3.7.1-r1.ebuild b/sys-devel/llvm/llvm-3.7.1-r1.ebuild
731 new file mode 100644
732 index 0000000..5ae3bc6
733 --- /dev/null
734 +++ b/sys-devel/llvm/llvm-3.7.1-r1.ebuild
735 @@ -0,0 +1,559 @@
736 +# Copyright 1999-2016 Gentoo Foundation
737 +# Distributed under the terms of the GNU General Public License v2
738 +# $Id$
739 +
740 +EAPI=5
741 +
742 +: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
743 +PYTHON_COMPAT=( python2_7 )
744 +
745 +inherit check-reqs cmake-utils eutils flag-o-matic multilib \
746 + multilib-minimal python-single-r1 toolchain-funcs pax-utils prefix
747 +
748 +DESCRIPTION="Low Level Virtual Machine"
749 +HOMEPAGE="http://llvm.org/"
750 +SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz
751 + clang? ( http://llvm.org/releases/${PV}/compiler-rt-${PV}.src.tar.xz
752 + http://llvm.org/releases/${PV}/cfe-${PV}.src.tar.xz
753 + http://llvm.org/releases/${PV}/clang-tools-extra-${PV}.src.tar.xz )
754 + lldb? ( http://llvm.org/releases/${PV}/lldb-${PV}.src.tar.xz )
755 + !doc? ( http://dev.gentoo.org/~voyageur/distfiles/${PN}-3.7.0-manpages.tar.bz2 )"
756 +
757 +LICENSE="UoI-NCSA"
758 +SLOT="0/${PV}"
759 +KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~x64-freebsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos"
760 +IUSE="clang debug doc gold libedit +libffi lldb multitarget ncurses ocaml
761 + python +static-analyzer test xml video_cards_radeon
762 + kernel_Darwin kernel_FreeBSD"
763 +
764 +COMMON_DEPEND="
765 + sys-libs/zlib:0=
766 + clang? (
767 + python? ( ${PYTHON_DEPS} )
768 + static-analyzer? (
769 + dev-lang/perl:*
770 + ${PYTHON_DEPS}
771 + )
772 + xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
773 + )
774 + gold? ( >=sys-devel/binutils-2.22:*[cxx] )
775 + libedit? ( dev-libs/libedit:0=[${MULTILIB_USEDEP}] )
776 + libffi? ( >=virtual/libffi-3.0.13-r1:0=[${MULTILIB_USEDEP}] )
777 + ncurses? ( >=sys-libs/ncurses-5.9-r3:0=[${MULTILIB_USEDEP}] )
778 + ocaml? (
779 + >=dev-lang/ocaml-4.00.0:0=
780 + dev-ml/findlib
781 + dev-ml/ocaml-ctypes
782 + !!<=sys-devel/llvm-3.7.0-r1[ocaml] )"
783 +# configparser-3.2 breaks the build (3.3 or none at all are fine)
784 +DEPEND="${COMMON_DEPEND}
785 + dev-lang/perl
786 + >=sys-devel/make-3.81
787 + >=sys-devel/flex-2.5.4
788 + >=sys-devel/bison-1.875d
789 + || ( >=sys-devel/gcc-3.0 >=sys-devel/llvm-3.5
790 + ( >=sys-freebsd/freebsd-lib-9.1-r10 sys-libs/libcxx )
791 + )
792 + || ( >=sys-devel/binutils-2.18 >=sys-devel/binutils-apple-5.1 )
793 + kernel_Darwin? ( <sys-libs/libcxx-${PV%_rc*}.9999 )
794 + clang? ( xml? ( virtual/pkgconfig ) )
795 + doc? ( dev-python/sphinx )
796 + gold? ( sys-libs/binutils-libs )
797 + libffi? ( virtual/pkgconfig )
798 + lldb? ( dev-lang/swig )
799 + !!<dev-python/configparser-3.3.0.2
800 + ocaml? ( test? ( dev-ml/ounit ) )
801 + ${PYTHON_DEPS}"
802 +RDEPEND="${COMMON_DEPEND}
803 + clang? ( !<=sys-devel/clang-${PV}-r99 )
804 + abi_x86_32? ( !<=app-emulation/emul-linux-x86-baselibs-20130224-r2
805 + !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)] )"
806 +PDEPEND="clang? ( =sys-devel/clang-${PV}-r100 )"
807 +
808 +# pypy gives me around 1700 unresolved tests due to open file limit
809 +# being exceeded. probably GC does not close them fast enough.
810 +REQUIRED_USE="${PYTHON_REQUIRED_USE}
811 + lldb? ( clang xml )"
812 +
813 +S=${WORKDIR}/${P/_}.src
814 +
815 +pkg_pretend() {
816 + # in megs
817 + # !clang !debug !multitarget -O2 400
818 + # !clang !debug multitarget -O2 550
819 + # clang !debug !multitarget -O2 950
820 + # clang !debug multitarget -O2 1200
821 + # !clang debug multitarget -O2 5G
822 + # clang !debug multitarget -O0 -g 12G
823 + # clang debug multitarget -O2 16G
824 + # clang debug multitarget -O0 -g 14G
825 +
826 + local build_size=550
827 + use clang && build_size=1200
828 +
829 + if use debug; then
830 + ewarn "USE=debug is known to increase the size of package considerably"
831 + ewarn "and cause the tests to fail."
832 + ewarn
833 +
834 + (( build_size *= 14 ))
835 + elif is-flagq '-g?(gdb)?([1-9])'; then
836 + ewarn "The C++ compiler -g option is known to increase the size of the package"
837 + ewarn "considerably. If you run out of space, please consider removing it."
838 + ewarn
839 +
840 + (( build_size *= 10 ))
841 + fi
842 +
843 + # Multiply by number of ABIs :).
844 + local abis=( $(multilib_get_enabled_abis) )
845 + (( build_size *= ${#abis[@]} ))
846 +
847 + local CHECKREQS_DISK_BUILD=${build_size}M
848 + check-reqs_pkg_pretend
849 +
850 + if [[ ${MERGE_TYPE} != binary ]]; then
851 + echo 'int main() {return 0;}' > "${T}"/test.cxx || die
852 + ebegin "Trying to build a C++11 test program"
853 + if ! $(tc-getCXX) -std=c++11 -o /dev/null "${T}"/test.cxx; then
854 + eerror "LLVM-${PV} requires C++11-capable C++ compiler. Your current compiler"
855 + eerror "does not seem to support -std=c++11 option. Please upgrade your compiler"
856 + eerror "to gcc-4.7 or an equivalent version supporting C++11."
857 + die "Currently active compiler does not support -std=c++11"
858 + fi
859 + eend ${?}
860 + fi
861 +}
862 +
863 +pkg_setup() {
864 + pkg_pretend
865 +}
866 +
867 +src_unpack() {
868 + default
869 +
870 + if use clang; then
871 + mv "${WORKDIR}"/cfe-${PV/_}.src "${S}"/tools/clang \
872 + || die "clang source directory move failed"
873 + mv "${WORKDIR}"/compiler-rt-${PV/_}.src "${S}"/projects/compiler-rt \
874 + || die "compiler-rt source directory move failed"
875 + mv "${WORKDIR}"/clang-tools-extra-${PV/_}.src "${S}"/tools/clang/tools/extra \
876 + || die "clang-tools-extra source directory move failed"
877 + fi
878 +
879 + if use lldb; then
880 + mv "${WORKDIR}"/lldb-${PV/_}.src "${S}"/tools/lldb \
881 + || die "lldb source directory move failed"
882 + fi
883 +}
884 +
885 +src_prepare() {
886 + # Make ocaml warnings non-fatal, bug #537308
887 + sed -e "/RUN/s/-warn-error A//" -i test/Bindings/OCaml/*ml || die
888 + # Fix libdir for ocaml bindings install, bug #559134
889 + epatch "${FILESDIR}"/cmake/${PN}-3.7.0-ocaml-multilib.patch
890 + # Do not build/install ocaml docs with USE=-doc, bug #562008
891 + epatch "${FILESDIR}"/cmake/${PN}-3.7.0-ocaml-build_doc.patch
892 +
893 + # Make it possible to override Sphinx HTML install dirs
894 + # https://llvm.org/bugs/show_bug.cgi?id=23780
895 + epatch "${FILESDIR}"/cmake/0002-cmake-Support-overriding-Sphinx-HTML-doc-install-dir.patch
896 +
897 + # Prevent race conditions with parallel Sphinx runs
898 + # https://llvm.org/bugs/show_bug.cgi?id=23781
899 + epatch "${FILESDIR}"/cmake/0003-cmake-Add-an-ordering-dep-between-HTML-man-Sphinx-ta.patch
900 +
901 + # Prevent installing libgtest
902 + # https://llvm.org/bugs/show_bug.cgi?id=18341
903 + epatch "${FILESDIR}"/cmake/0004-cmake-Do-not-install-libgtest.patch
904 +
905 + # Fix llvm-config for shared linking, sane flags and return values
906 + # in order:
907 + # - backported r247159 that adds --build-system (needed for later code)
908 + # - backported r252532 that adds better shared linking support
909 + # - our fixes
910 + # - backported r260343 that fixes cross-compilation
911 + # combination of backported upstream r252532 with our patch
912 + # https://bugs.gentoo.org/show_bug.cgi?id=565358
913 + epatch "${FILESDIR}"/llvm-3.7.1-llvm-config-0.patch
914 + epatch "${FILESDIR}"/llvm-3.7.1-llvm-config-1.patch
915 + epatch "${FILESDIR}"/llvm-3.7.1-llvm-config-2.patch
916 + epatch "${FILESDIR}"/llvm-3.7.1-llvm-config-3.patch
917 +
918 + # Fix msan with newer kernels, #569894
919 + epatch "${FILESDIR}"/llvm-3.7-msan-fix.patch
920 +
921 + # disable use of SDK on OSX, bug #568758
922 + sed -i -e 's/xcrun/false/' utils/lit/lit/util.py || die
923 +
924 + if use clang; then
925 + # Automatically select active system GCC's libraries, bugs #406163 and #417913
926 + epatch "${FILESDIR}"/clang-3.5-gentoo-runtime-gcc-detection-v3.patch
927 +
928 + epatch "${FILESDIR}"/clang-3.6-gentoo-install.patch
929 +
930 + epatch "${FILESDIR}"/clang-3.4-darwin_prefix-include-paths.patch
931 + eprefixify tools/clang/lib/Frontend/InitHeaderSearch.cpp
932 +
933 + sed -i -e "s^@EPREFIX@^${EPREFIX}^" \
934 + tools/clang/tools/scan-build/scan-build || die
935 +
936 + # Install clang runtime into /usr/lib/clang
937 + # https://llvm.org/bugs/show_bug.cgi?id=23792
938 + epatch "${FILESDIR}"/cmake/clang-0001-Install-clang-runtime-into-usr-lib-without-suffix.patch
939 + epatch "${FILESDIR}"/cmake/compiler-rt-0001-cmake-Install-compiler-rt-into-usr-lib-without-suffi.patch
940 +
941 + # Do not force -march flags on arm platforms
942 + # https://bugs.gentoo.org/show_bug.cgi?id=562706
943 + epatch "${FILESDIR}"/cmake/${PN}-3.7.0-compiler_rt_arm_march_flags.patch
944 +
945 + # Make it possible to override CLANG_LIBDIR_SUFFIX
946 + # (that is used only to find LLVMgold.so)
947 + # https://llvm.org/bugs/show_bug.cgi?id=23793
948 + epatch "${FILESDIR}"/cmake/clang-0002-cmake-Make-CLANG_LIBDIR_SUFFIX-overridable.patch
949 +
950 + pushd projects/compiler-rt >/dev/null || die
951 +
952 + # Fix msan with newer kernels, compiler-rt part, #569894
953 + epatch "${FILESDIR}"/compiler-rt-3.7-msan-fix.patch
954 +
955 + # Fix WX sections, bug #421527
956 + find lib/builtins -type f -name '*.S' -exec sed \
957 + -e '$a\\n#if defined(__linux__) && defined(__ELF__)\n.section .note.GNU-stack,"",%progbits\n#endif' \
958 + -i {} + || die
959 +
960 + popd >/dev/null || die
961 + fi
962 +
963 + if use lldb; then
964 + # Do not install dummy readline.so module from
965 + # https://llvm.org/bugs/show_bug.cgi?id=18841
966 + sed -e 's/add_subdirectory(readline)/#&/' \
967 + -i tools/lldb/scripts/Python/modules/CMakeLists.txt || die
968 +
969 + # Fix Python paths, bugs #562436 and #562438
970 + epatch "${FILESDIR}"/${PN}-3.7-lldb_python.patch
971 + sed -e "s/GENTOO_LIBDIR/$(get_libdir)/" \
972 + -i tools/lldb/scripts/Python/finishSwigPythonLLDB.py || die
973 +
974 + # Fix build with ncurses[tinfo], #560474
975 + # http://llvm.org/viewvc/llvm-project?view=revision&revision=247842
976 + epatch "${FILESDIR}"/cmake/${PN}-3.7.0-lldb_tinfo.patch
977 + fi
978 +
979 + # User patches
980 + epatch_user
981 +
982 + python_setup
983 +
984 + # Native libdir is used to hold LLVMgold.so
985 + NATIVE_LIBDIR=$(get_libdir)
986 +}
987 +
988 +multilib_src_configure() {
989 + local targets
990 + if use multitarget; then
991 + targets=all
992 + else
993 + targets='host;BPF;CppBackend'
994 + use video_cards_radeon && targets+=';AMDGPU'
995 + fi
996 +
997 + local ffi_cflags ffi_ldflags
998 + if use libffi; then
999 + ffi_cflags=$(pkg-config --cflags-only-I libffi)
1000 + ffi_ldflags=$(pkg-config --libs-only-L libffi)
1001 + fi
1002 +
1003 + local libdir=$(get_libdir)
1004 + local mycmakeargs=(
1005 + -DLLVM_LIBDIR_SUFFIX=${libdir#lib}
1006 +
1007 + -DBUILD_SHARED_LIBS=ON
1008 + -DLLVM_ENABLE_TIMESTAMPS=OFF
1009 + -DLLVM_TARGETS_TO_BUILD="${targets}"
1010 + -DLLVM_BUILD_TESTS=$(usex test)
1011 +
1012 + -DLLVM_ENABLE_FFI=$(usex libffi)
1013 + -DLLVM_ENABLE_TERMINFO=$(usex ncurses)
1014 + -DLLVM_ENABLE_ASSERTIONS=$(usex debug)
1015 + -DLLVM_ENABLE_EH=ON
1016 + -DLLVM_ENABLE_RTTI=ON
1017 +
1018 + -DWITH_POLLY=OFF # TODO
1019 +
1020 + -DLLVM_HOST_TRIPLE="${CHOST}"
1021 +
1022 + -DFFI_INCLUDE_DIR="${ffi_cflags#-I}"
1023 + -DFFI_LIBRARY_DIR="${ffi_ldflags#-L}"
1024 +
1025 + -DHAVE_HISTEDIT_H=$(usex libedit)
1026 + )
1027 +
1028 + if use clang; then
1029 + mycmakeargs+=(
1030 + -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
1031 + # libgomp support fails to find headers without explicit -I
1032 + # furthermore, it provides only syntax checking
1033 + -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
1034 + )
1035 + fi
1036 +
1037 + if use lldb; then
1038 + mycmakeargs+=(
1039 + -DLLDB_DISABLE_LIBEDIT=$(usex !libedit)
1040 + -DLLDB_DISABLE_CURSES=$(usex !ncurses)
1041 + -DLLDB_ENABLE_TERMINFO=$(usex ncurses)
1042 + )
1043 + fi
1044 +
1045 + if ! multilib_is_native_abi || ! use ocaml; then
1046 + mycmakeargs+=(
1047 + -DOCAMLFIND=NO
1048 + )
1049 + fi
1050 +# Note: go bindings have no CMake rules at the moment
1051 +# but let's kill the check in case they are introduced
1052 +# if ! multilib_is_native_abi || ! use go; then
1053 + mycmakeargs+=(
1054 + -DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND
1055 + )
1056 +# fi
1057 +
1058 + if multilib_is_native_abi; then
1059 + mycmakeargs+=(
1060 + -DLLVM_BUILD_DOCS=$(usex doc)
1061 + -DLLVM_ENABLE_SPHINX=$(usex doc)
1062 + -DLLVM_ENABLE_DOXYGEN=OFF
1063 + -DLLVM_INSTALL_HTML="${EPREFIX}/usr/share/doc/${PF}/html"
1064 + -DSPHINX_WARNINGS_AS_ERRORS=OFF
1065 + -DLLVM_INSTALL_UTILS=ON
1066 + )
1067 +
1068 + if use clang; then
1069 + mycmakeargs+=(
1070 + -DCLANG_INSTALL_HTML="${EPREFIX}/usr/share/doc/${PF}/clang"
1071 + )
1072 + fi
1073 +
1074 + if use gold; then
1075 + mycmakeargs+=(
1076 + -DLLVM_BINUTILS_INCDIR="${EPREFIX}"/usr/include
1077 + )
1078 + fi
1079 +
1080 + if use lldb; then
1081 + mycmakeargs+=(
1082 + -DLLDB_DISABLE_PYTHON=$(usex !python)
1083 + )
1084 + fi
1085 +
1086 + else
1087 + if use clang; then
1088 + mycmakeargs+=(
1089 + # disable compiler-rt on non-native ABI because:
1090 + # 1. it fails to configure because of -m32
1091 + # 2. it is shared between ABIs so no point building
1092 + # it multiple times
1093 + -DLLVM_EXTERNAL_COMPILER_RT_BUILD=OFF
1094 + -DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_BUILD=OFF
1095 + )
1096 + fi
1097 + if use lldb; then
1098 + mycmakeargs+=(
1099 + # only run swig on native abi
1100 + -DLLDB_DISABLE_PYTHON=ON
1101 + )
1102 + fi
1103 + fi
1104 +
1105 + if use clang; then
1106 + mycmakeargs+=(
1107 + -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
1108 + -DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
1109 + -DCLANG_LIBDIR_SUFFIX="${NATIVE_LIBDIR#lib}"
1110 + )
1111 +
1112 + # -- not needed when compiler-rt is built with host compiler --
1113 + # cmake passes host C*FLAGS to compiler-rt build
1114 + # which is performed using clang, so we need to filter out
1115 + # some flags clang does not support
1116 + # (if you know some more flags that don't work, let us know)
1117 + #filter-flags -msahf -frecord-gcc-switches
1118 + fi
1119 +
1120 + cmake-utils_src_configure
1121 +}
1122 +
1123 +multilib_src_compile() {
1124 + cmake-utils_src_compile
1125 + # TODO: not sure why this target is not correctly called
1126 + multilib_is_native_abi && use doc && use ocaml && cmake-utils_src_make docs/ocaml_doc
1127 +
1128 + pax-mark m "${BUILD_DIR}"/bin/llvm-rtdyld
1129 + pax-mark m "${BUILD_DIR}"/bin/lli
1130 + pax-mark m "${BUILD_DIR}"/bin/lli-child-target
1131 +
1132 + if use test; then
1133 + pax-mark m "${BUILD_DIR}"/unittests/ExecutionEngine/Orc/OrcJITTests
1134 + pax-mark m "${BUILD_DIR}"/unittests/ExecutionEngine/MCJIT/MCJITTests
1135 + pax-mark m "${BUILD_DIR}"/unittests/Support/SupportTests
1136 + fi
1137 +}
1138 +
1139 +multilib_src_test() {
1140 + # respect TMPDIR!
1141 + local -x LIT_PRESERVES_TMP=1
1142 + local test_targets=( check )
1143 + # clang tests won't work on non-native ABI because we skip compiler-rt
1144 + multilib_is_native_abi && use clang && test_targets+=( check-clang )
1145 + cmake-utils_src_make "${test_targets[@]}"
1146 +}
1147 +
1148 +src_install() {
1149 + local MULTILIB_CHOST_TOOLS=(
1150 + /usr/bin/llvm-config
1151 + )
1152 +
1153 + local MULTILIB_WRAPPED_HEADERS=(
1154 + /usr/include/llvm/Config/config.h
1155 + /usr/include/llvm/Config/llvm-config.h
1156 + )
1157 +
1158 + if use clang; then
1159 + # note: magic applied in multilib_src_install()!
1160 + CLANG_VERSION=${PV%.*}
1161 +
1162 + MULTILIB_CHOST_TOOLS+=(
1163 + /usr/bin/clang
1164 + /usr/bin/clang++
1165 + /usr/bin/clang-cl
1166 + /usr/bin/clang-${CLANG_VERSION}
1167 + /usr/bin/clang++-${CLANG_VERSION}
1168 + /usr/bin/clang-cl-${CLANG_VERSION}
1169 + )
1170 +
1171 + MULTILIB_WRAPPED_HEADERS+=(
1172 + /usr/include/clang/Config/config.h
1173 + )
1174 + fi
1175 +
1176 + multilib-minimal_src_install
1177 +
1178 + # Remove unnecessary headers on FreeBSD, bug #417171
1179 + if use kernel_FreeBSD && use clang; then
1180 + rm "${ED}"usr/lib/clang/${PV}/include/{std,float,iso,limits,tgmath,varargs}*.h || die
1181 + fi
1182 +}
1183 +
1184 +multilib_src_install() {
1185 + cmake-utils_src_install
1186 +
1187 + if multilib_is_native_abi; then
1188 + # Install man pages.
1189 + use doc || doman "${WORKDIR}"/${PN}-3.7.0-manpages/*.1
1190 +
1191 + # Symlink the gold plugin.
1192 + if use gold; then
1193 + dodir "/usr/${CHOST}/binutils-bin/lib/bfd-plugins"
1194 + dosym "../../../../$(get_libdir)/LLVMgold.so" \
1195 + "/usr/${CHOST}/binutils-bin/lib/bfd-plugins/LLVMgold.so"
1196 + fi
1197 + fi
1198 +
1199 + # apply CHOST and CLANG_VERSION to clang executables
1200 + # they're statically linked so we don't have to worry about the lib
1201 + if use clang; then
1202 + local clang_tools=( clang clang++ clang-cl )
1203 + local i
1204 +
1205 + # cmake gives us:
1206 + # - clang-X.Y
1207 + # - clang -> clang-X.Y
1208 + # - clang++, clang-cl -> clang
1209 + # we want to have:
1210 + # - clang-X.Y
1211 + # - clang++-X.Y, clang-cl-X.Y -> clang-X.Y
1212 + # - clang, clang++, clang-cl -> clang*-X.Y
1213 + # so we need to fix the two tools
1214 + for i in "${clang_tools[@]:1}"; do
1215 + rm "${ED%/}/usr/bin/${i}" || die
1216 + dosym "clang-${CLANG_VERSION}" "/usr/bin/${i}-${CLANG_VERSION}"
1217 + dosym "${i}-${CLANG_VERSION}" "/usr/bin/${i}"
1218 + done
1219 +
1220 + # now prepend ${CHOST} and let the multilib-build.eclass symlink it
1221 + if ! multilib_is_native_abi; then
1222 + # non-native? let's replace it with a simple wrapper
1223 + for i in "${clang_tools[@]}"; do
1224 + rm "${ED%/}/usr/bin/${i}-${CLANG_VERSION}" || die
1225 + cat > "${T}"/wrapper.tmp <<-_EOF_
1226 + #!${EPREFIX}/bin/sh
1227 + exec "${i}-${CLANG_VERSION}" $(get_abi_CFLAGS) "\${@}"
1228 + _EOF_
1229 + newbin "${T}"/wrapper.tmp "${i}-${CLANG_VERSION}"
1230 + done
1231 + fi
1232 + fi
1233 +}
1234 +
1235 +multilib_src_install_all() {
1236 + insinto /usr/share/vim/vimfiles
1237 + doins -r utils/vim/*/.
1238 + # some users may find it useful
1239 + dodoc utils/vim/vimrc
1240 +
1241 + if use clang; then
1242 + pushd tools/clang >/dev/null || die
1243 +
1244 + if use static-analyzer ; then
1245 + pushd tools/scan-build >/dev/null || die
1246 +
1247 + dobin ccc-analyzer scan-build
1248 + dosym ccc-analyzer /usr/bin/c++-analyzer
1249 + doman scan-build.1
1250 +
1251 + insinto /usr/share/llvm
1252 + doins scanview.css sorttable.js
1253 +
1254 + popd >/dev/null || die
1255 + fi
1256 +
1257 + if use static-analyzer ; then
1258 + pushd tools/scan-view >/dev/null || die
1259 +
1260 + python_doscript scan-view
1261 +
1262 + touch __init__.py || die
1263 + python_moduleinto clang
1264 + python_domodule *.py Resources
1265 +
1266 + popd >/dev/null || die
1267 + fi
1268 +
1269 + if use python ; then
1270 + pushd bindings/python/clang >/dev/null || die
1271 +
1272 + python_moduleinto clang
1273 + python_domodule *.py
1274 +
1275 + popd >/dev/null || die
1276 + fi
1277 +
1278 + # AddressSanitizer symbolizer (currently separate)
1279 + dobin "${S}"/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py
1280 +
1281 + popd >/dev/null || die
1282 +
1283 + python_fix_shebang "${ED}"
1284 + if use lldb && use python; then
1285 + python_optimize
1286 + fi
1287 + fi
1288 +}
1289 +
1290 +pkg_postinst() {
1291 + if use clang && ! has_version sys-libs/libomp; then
1292 + elog "To enable OpenMP support in clang, install sys-libs/libomp."
1293 + fi
1294 +}