# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1594322392 -7200
#      Thu Jul 09 21:19:52 2020 +0200
# Node ID 9dcbe1d8ea8120695d9cdfb14be908e66253a2be
# Parent  b838179c67d2b889cba65185fe2b640d63385847
Update LLVM to 7.0.0 (bug #58689).

* src/llvm.mk: Update version, checksum and download url. Rename LLVM.dll.
Install native llvm-config when cross-compiling
* src/llvm-1-config.patch: Patch llvm-config so the native version returns what
is needed for a cross build.
* dist-files.mk: Add new patch to list.

diff -r b838179c67d2 -r 9dcbe1d8ea81 dist-files.mk
--- a/dist-files.mk	Thu Jul 02 17:53:59 2020 +0200
+++ b/dist-files.mk	Thu Jul 09 21:19:52 2020 +0200
@@ -310,6 +310,7 @@
   libxml2.mk \
   libxshmfence.mk \
   libxslt.mk \
+  llvm-1-config.patch \
   llvm.mk \
   log4cxx-1-gcc.4.4.patch \
   log4cxx-2-pkgconfig.patch \
diff -r b838179c67d2 -r 9dcbe1d8ea81 src/llvm-1-config.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/llvm-1-config.patch	Thu Jul 09 21:19:52 2020 +0200
@@ -0,0 +1,64 @@
+diff --git "a/tools/llvm-config/llvm-config.cpp" "b/tools/llvm-config/llvm-config.cpp"
+index 08b096a..a35422e 100644
+--- "a/tools/llvm-config/llvm-config.cpp"	
++++ "b/tools/llvm-config/llvm-config.cpp"
+@@ -352,14 +352,16 @@ int main(int argc, char **argv) {
+   StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
+       StaticPrefix, StaticDir = "lib", DirSep = "/";
+   const Triple HostTriple(Triple::normalize(LLVM_HOST_TRIPLE));
+-  if (HostTriple.isOSWindows()) {
++  const Triple TargetTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));
++  if (TargetTriple.isOSWindows()) {
+     SharedExt = "dll";
+     SharedVersionedExt = LLVM_DYLIB_VERSION ".dll";
+-    if (HostTriple.isOSCygMing()) {
++    if (TargetTriple.isOSCygMing()) {
+       StaticExt = "a";
+       StaticPrefix = "lib";
+     } else {
+       StaticExt = "lib";
++      if (HostTriple.isOSWindows()) {
+       DirSep = "\\";
+       std::replace(ActiveObjRoot.begin(), ActiveObjRoot.end(), '/', '\\');
+       std::replace(ActivePrefix.begin(), ActivePrefix.end(), '/', '\\');
+@@ -368,10 +370,11 @@ int main(int argc, char **argv) {
+       std::replace(ActiveCMakeDir.begin(), ActiveCMakeDir.end(), '/', '\\');
+       std::replace(ActiveIncludeOption.begin(), ActiveIncludeOption.end(), '/',
+                    '\\');
++      }
+     }
+     SharedDir = ActiveBinDir;
+     StaticDir = ActiveLibDir;
+-  } else if (HostTriple.isOSDarwin()) {
++  } else if (TargetTriple.isOSDarwin()) {
+     SharedExt = "dylib";
+     SharedVersionedExt = LLVM_DYLIB_VERSION ".dylib";
+     StaticExt = "a";
+@@ -386,7 +389,7 @@ int main(int argc, char **argv) {
+     StaticPrefix = SharedPrefix = "lib";
+   }
+ 
+-  const bool BuiltDyLib = !!LLVM_ENABLE_DYLIB;
++  const bool BuiltDyLib = true;
+ 
+   /// CMake style shared libs, ie each component is in a shared library.
+   const bool BuiltSharedLibs = !!LLVM_ENABLE_SHARED;
+@@ -398,7 +401,7 @@ int main(int argc, char **argv) {
+   // If LLVM_LINK_DYLIB is ON, the single shared library will be returned
+   // for "--libs", etc, if they exist. This behaviour can be overridden with
+   // --link-static or --link-shared.
+-  bool LinkDyLib = !!LLVM_LINK_DYLIB;
++  bool LinkDyLib = true;
+ 
+   if (BuiltDyLib) {
+     std::string path((SharedDir + DirSep + DyLibName).str());
+@@ -670,7 +673,7 @@ int main(int argc, char **argv) {
+         } else if (PrintLibs) {
+           // On Windows, output full path to library without parameters.
+           // Elsewhere, if this is a typical library name, include it using -l.
+-          if (HostTriple.isWindowsMSVCEnvironment()) {
++          if (TargetTriple.isWindowsMSVCEnvironment()) {
+             OS << GetComponentLibraryPath(Lib, Shared);
+           } else {
+             StringRef LibName;
+
diff -r b838179c67d2 -r 9dcbe1d8ea81 src/llvm.mk
--- a/src/llvm.mk	Thu Jul 02 17:53:59 2020 +0200
+++ b/src/llvm.mk	Thu Jul 09 21:19:52 2020 +0200
@@ -3,11 +3,11 @@
 
 PKG             := llvm
 $(PKG)_IGNORE   :=
-$(PKG)_VERSION  := 6.0.1
-$(PKG)_CHECKSUM := 09a6316c5225cab255ba12391e7abe5ff4d28935
+$(PKG)_VERSION  := 7.0.0
+$(PKG)_CHECKSUM := 27503a22614626e935a05b609ab4211be72cd78b
 $(PKG)_SUBDIR   := llvm-$($(PKG)_VERSION).src
 $(PKG)_FILE     := llvm-$($(PKG)_VERSION).src.tar.xz
-$(PKG)_URL      := http://releases.llvm.org/$($(PKG)_VERSION)/$($(PKG)_FILE)
+$(PKG)_URL      := https://releases.llvm.org/$($(PKG)_VERSION)/$($(PKG)_FILE)
 $(PKG)_DEPS     :=
 
 define $(PKG)_UPDATE
@@ -88,7 +88,17 @@
       -DLLVM_BUILD_RUNTIMES=OFF \
       -DLLVM_INCLUDE_RUNTIMES=OFF \
       $($(PKG)_CCACHE_OPTIONS)
-    $(MAKE) -C '$(1)/.build' -j $(JOBS) llvm-tblgen
+
+    $(MAKE) -C '$(1)/.build' -j $(JOBS) LLVMSupport
+    $(MAKE) -C '$(1)/.build' -j $(JOBS) llvm-config
     $(MAKE) -C '$(1)/.build' -j $(JOBS) install DESTDIR='$(3)'
+    
+    # rename shared library so that llvm-config can find it
+    mv '$(3)/$(HOST_BINDIR)/LLVM.dll' '$(3)/$(HOST_BINDIR)/LLVM-$(word 1,$(subst ., ,$($(PKG)_VERSION))).dll'
+
+    # install native llvm-config in HOST_BINDIR because it won't find the libs otherwise
+    $(INSTALL) -d '$(HOST_BINDIR)'
+    $(INSTALL) -m755 '$(1)/.build/NATIVE/bin/llvm-config' '$(HOST_BINDIR)/$(MXE_TOOL_PREFIX)llvm-config'
+    
   endef
 endif
