Enable Tizen Toolchain paths detection 88/125288/7 accepted/tizen/base/20170707.183521 submit/tizen_base/20170622.094219 submit/tizen_base/20170705.023439
authorSlava Barinov <v.barinov@samsung.com>
Fri, 14 Apr 2017 08:45:19 +0000 (11:45 +0300)
committerSlava Barinov <v.barinov@samsung.com>
Thu, 1 Jun 2017 08:43:18 +0000 (11:43 +0300)
This allows acceleration of clang with qemu-accel and allows to get rid of '-B'
options during build. All the paths to tools and libraries are detected
automatically by clang built-in mechanisms.

Change-Id: I8f48377fdbf5b8be2941a54e0105cfdd8e991d20
Signed-off-by: Slava Barinov <v.barinov@samsung.com>
packaging/driver_patch [new file with mode: 0644]
packaging/libstdcxx_path_patch [new file with mode: 0644]
packaging/llvm.spec

diff --git a/packaging/driver_patch b/packaging/driver_patch
new file mode 100644 (file)
index 0000000..0a92afa
--- /dev/null
@@ -0,0 +1,24 @@
+--- tools/clang/lib/Driver/Driver.cpp  2017-03-16 16:12:19.870312677 +0300
++++ tools/clang/lib/Driver/Driver.cpp  2017-03-17 11:21:40.124870280 +0300
+@@ -64,6 +64,11 @@
+   if (!this->VFS)
+     this->VFS = vfs::getRealFileSystem();
+
++  // Skip /emul if we work in accelerated environment
++#define QEMU_ACCEL_DIR "/emul"
++  if (ClangExecutable.substr(0, sizeof(QEMU_ACCEL_DIR) - 1) ==  QEMU_ACCEL_DIR)
++    ClangExecutable = ClangExecutable.drop_front(sizeof(QEMU_ACCEL_DIR) - 1);
++
+   Name = llvm::sys::path::filename(ClangExecutable);
+   Dir = llvm::sys::path::parent_path(ClangExecutable);
+   InstalledDir = Dir; // Provide a sensible default installed dir.
+@@ -74,7 +79,8 @@
+   if (ClangResourceDir != "") {
+     llvm::sys::path::append(P, ClangResourceDir);
+   } else {
+-    StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);
++    const char* NO_LIBDIR_SUFFIX = std::getenv("CLANG_NO_LIBDIR_SUFFIX");
++    StringRef ClangLibdirSuffix(NO_LIBDIR_SUFFIX?"":CLANG_LIBDIR_SUFFIX);
+     llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang",
+                             CLANG_VERSION_STRING);
+   }
diff --git a/packaging/libstdcxx_path_patch b/packaging/libstdcxx_path_patch
new file mode 100644 (file)
index 0000000..8e199a2
--- /dev/null
@@ -0,0 +1,10 @@
+--- tools/clang/lib/Driver/ToolChains.cpp      2016-02-16 22:56:48.000000000 +0300
++++ tools/clang/lib/Driver/ToolChains.cpp      2017-03-16 12:32:25.743632003 +0300
+@@ -4111,6 +4111,7 @@
+       // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
+       // without a subdirectory corresponding to the gcc version.
+       LibDir.str() + "/../include/c++",
++      InstallDir.str() + "/include/c++",
+   };
+
+   for (const auto &IncludePath : LibStdCXXIncludePathCandidates) {
index f7f6d33..79e01f4 100644 (file)
@@ -9,13 +9,16 @@ Source1: clang.tar.gz
 Source2: lldb.tar.gz
 Source1001: llvm.manifest
 
+Source1002: libstdcxx_path_patch
+Source1003: driver_patch
+
 BuildRequires: cmake
 BuildRequires: python
 BuildRequires: python-devel
 #BuildRequires: swig
 Requires: libllvm = %{version}-%{release}
 
-%define install_prefix /usr/local
+%define install_prefix /usr/
 %define sdk_install_prefix /home/owner/share/tmp/sdk_tools/lldb
 %define sdk_bin_dir %{sdk_install_prefix}/bin
 
@@ -29,6 +32,24 @@ Requires: libllvm = %{version}-%{release}
 %define system_lib_dir /usr/lib
 %endif
 
+%ifarch armv7l
+%define ARCH armv7l
+%define ABI eabi
+%endif
+%ifarch armv7hl
+%define ARCH armv7hl
+%define ABI eabihf
+%endif
+%ifarch %ix86
+%define ARCH i586
+%endif
+%ifarch x86_64
+%define ARCH x86_64
+%endif
+%ifarch aarch64
+%define ARCH aarch64
+%endif
+%define host_arch %{ARCH}-tizen-linux-gnu%{?ABI}
 
 %description
 LLVM is a compiler infrastructure designed for compile-time, link-time, runtime,
@@ -37,7 +58,7 @@ LLVM is written in C++ and has been developed since 2000 at the University of
 Illinois and Apple. It currently supports compilation of C and C++ programs,
 using front-ends derived from GCC 4.0.1. A new front-end for the C family of
 languages is in development. The compiler infrastructure
-includes mirror sets of programming tools as well as libraries with equivalent 
+includes mirror sets of programming tools as well as libraries with equivalent
 functionality.
 
 %package devel
@@ -113,6 +134,9 @@ gzip -dc %{SOURCE1} | tar -xf -
 gzip -dc %{SOURCE2} | tar -xf -
 %endif
 pwd
+# Enable Tizen Toolchain libraries search for Clang
+patch -p1 < %{SOURCE1002}
+patch -p1 < %{SOURCE1003}
 #cd lldb
 #%patch2001 -p0
 #cd ../..
@@ -122,7 +146,6 @@ pwd
 
 mkdir build
 cd build
-%ifnarch aarch64
 cmake \
     -DCMAKE_C_COMPILER=/usr/bin/gcc \
     -DCMAKE_CXX_COMPILER=/usr/bin/g++ \
@@ -133,37 +156,26 @@ cmake \
     -DLLVM_BUILD_LLVM_DYLIB=1 \
     -DLLDB_DISABLE_LIBEDIT=1 \
     -DLLDB_DISABLE_PYTHON=1 \
-%ifarch x86_64
+    -DLLVM_TARGET_ARCH=%{ARCH} \
+    -DLLVM_HOST_TRIPLE=%{host_arch} \
+    -DLLDB_DISABLE_CURSES=1 \
+%ifarch x86_64 aarch64
     -DLLVM_LIBDIR_SUFFIX=64 \
 %endif
 %ifarch %ix86
-     -DCMAKE_LIBRARY_ARCHITECTURE=i386-linux-gnu \
-     -DLLVM_TARGET_ARCH=X86 \
-     -DLLVM_HOST_TRIPLE=i386-linux-gnu \
-     -DCMAKE_C_FLAGS="-m32" \
-     -DCMAKE_CXX_FLAGS="-m32" \
+    -DCMAKE_C_FLAGS="-m32" \
+    -DCMAKE_CXX_FLAGS="-m32" \
 %endif
-    -DLLDB_DISABLE_CURSES=1 \
     ..
-%else
-cmake \
-    -DCMAKE_C_COMPILER=/usr/bin/gcc \
-    -DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-    -DCMAKE_BUILD_TYPE=Release \
-    -DCMAKE_INSTALL_PREFIX=%{install_prefix} \
-    -DLLVM_ENABLE_ASSERTIONS=No \
-    -DLLVM_TARGETS_TO_BUILD='X86;ARM;AArch64' \
-    -DLLVM_BUILD_LLVM_DYLIB=1 \
-    -DLLVM_LIBDIR_SUFFIX=64 \
-    ..
-%endif
 
 make %{?jobs:-j%jobs}
 
 %install
 cd build
 %make_install
+ln -sf %{install_prefix}/bin/clang++ %{buildroot}%{install_prefix}/bin/clang++-3.8
 
+mkdir -p %{buildroot}%{bindir}
 # copy lldb for sdk
 mkdir -p %{buildroot}%{sdk_bin_dir}
 mkdir -p %{buildroot}%{sdk_lib_dir}
@@ -276,6 +288,7 @@ echo Cleaning %{buildroot}
 %{install_prefix}/bin/clang
 %{install_prefix}/bin/clang++
 %{install_prefix}/bin/clang-3.8
+%{install_prefix}/bin/clang++-3.8
 %{install_prefix}/bin/clang-check
 %{install_prefix}/bin/clang-cl
 %{install_prefix}/bin/clang-format