1*4882a593Smuzhiyun################################################################################ 2*4882a593Smuzhiyun# 3*4882a593Smuzhiyun# clang 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun################################################################################ 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun# LLVM, Clang and lld should be version bumped together 8*4882a593SmuzhiyunCLANG_VERSION = 9.0.1 9*4882a593SmuzhiyunCLANG_SITE = https://github.com/llvm/llvm-project/releases/download/llvmorg-$(CLANG_VERSION) 10*4882a593SmuzhiyunCLANG_SOURCE = clang-$(CLANG_VERSION).src.tar.xz 11*4882a593SmuzhiyunCLANG_LICENSE = Apache-2.0 with exceptions 12*4882a593SmuzhiyunCLANG_LICENSE_FILES = LICENSE.TXT 13*4882a593SmuzhiyunCLANG_CPE_ID_VENDOR = llvm 14*4882a593SmuzhiyunCLANG_SUPPORTS_IN_SOURCE_BUILD = NO 15*4882a593SmuzhiyunCLANG_INSTALL_STAGING = YES 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunHOST_CLANG_DEPENDENCIES = host-llvm host-libxml2 18*4882a593SmuzhiyunCLANG_DEPENDENCIES = llvm host-clang 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun# LLVM >= 9.0 will soon require C++14 support, building llvm 8.x using a 21*4882a593Smuzhiyun# toolchain using gcc < 5.1 gives an error but actually still works. Setting 22*4882a593Smuzhiyun# this option makes it still build with gcc >= 4.8. 23*4882a593Smuzhiyun# https://reviews.llvm.org/D57264 24*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON 25*4882a593SmuzhiyunCLANG_CONF_OPTS += -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun# This option is needed, otherwise multiple shared libs 28*4882a593Smuzhiyun# (libclangAST.so, libclangBasic.so, libclangFrontend.so, etc.) will 29*4882a593Smuzhiyun# be generated. As a final shared lib containing all these components 30*4882a593Smuzhiyun# (libclang.so) is also generated, this resulted in the following 31*4882a593Smuzhiyun# error when trying to use tools that use libclang: 32*4882a593Smuzhiyun# $ CommandLine Error: Option 'track-memory' registered more than once! 33*4882a593Smuzhiyun# $ LLVM ERROR: inconsistency in registered CommandLine options 34*4882a593Smuzhiyun# By setting BUILD_SHARED_LIBS to OFF, we generate multiple static 35*4882a593Smuzhiyun# libraries (the same way as host's clang build) and finally 36*4882a593Smuzhiyun# libclang.so to be installed on the target. 37*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += -DBUILD_SHARED_LIBS=OFF 38*4882a593SmuzhiyunCLANG_CONF_OPTS += -DBUILD_SHARED_LIBS=OFF 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun# Default is Debug build, which requires considerably more disk space 41*4882a593Smuzhiyun# and build time. Release build is selected for host and target 42*4882a593Smuzhiyun# because the linker can run out of memory in Debug mode. 43*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += -DCMAKE_BUILD_TYPE=Release 44*4882a593SmuzhiyunCLANG_CONF_OPTS += -DCMAKE_BUILD_TYPE=Release 45*4882a593Smuzhiyun 46*4882a593SmuzhiyunCLANG_CONF_OPTS += -DCMAKE_CROSSCOMPILING=1 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun# We need to build tools because libclang is a tool 49*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON 50*4882a593SmuzhiyunCLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += \ 53*4882a593Smuzhiyun -DCLANG_BUILD_EXAMPLES=OFF \ 54*4882a593Smuzhiyun -DCLANG_INCLUDE_DOCS=OFF \ 55*4882a593Smuzhiyun -DCLANG_INCLUDE_TESTS=OFF 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunCLANG_CONF_OPTS += \ 58*4882a593Smuzhiyun -DCLANG_BUILD_EXAMPLES=OFF \ 59*4882a593Smuzhiyun -DCLANG_INCLUDE_DOCS=OFF \ 60*4882a593Smuzhiyun -DCLANG_INCLUDE_TESTS=OFF 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += -DLLVM_DIR=$(HOST_DIR)/lib/cmake/llvm \ 63*4882a593Smuzhiyun -DCLANG_DEFAULT_LINKER=$(TARGET_LD) 64*4882a593SmuzhiyunCLANG_CONF_OPTS += -DLLVM_DIR=$(STAGING_DIR)/usr/lib/cmake/llvm \ 65*4882a593Smuzhiyun -DCLANG_TABLEGEN:FILEPATH=$(HOST_DIR)/bin/clang-tblgen \ 66*4882a593Smuzhiyun -DLLVM_TABLEGEN_EXE:FILEPATH=$(HOST_DIR)/bin/llvm-tblgen 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun# Clang can't be used as compiler on the target since there are no 69*4882a593Smuzhiyun# development files (headers) and other build tools. So remove clang 70*4882a593Smuzhiyun# binaries and some other unnecessary files from target. 71*4882a593SmuzhiyunCLANG_FILES_TO_REMOVE = \ 72*4882a593Smuzhiyun /usr/bin/clang* \ 73*4882a593Smuzhiyun /usr/bin/c-index-test \ 74*4882a593Smuzhiyun /usr/bin/git-clang-format \ 75*4882a593Smuzhiyun /usr/bin/scan-build \ 76*4882a593Smuzhiyun /usr/bin/scan-view \ 77*4882a593Smuzhiyun /usr/libexec/c++-analyzer \ 78*4882a593Smuzhiyun /usr/libexec/ccc-analyzer \ 79*4882a593Smuzhiyun /usr/share/clang \ 80*4882a593Smuzhiyun /usr/share/opt-viewer \ 81*4882a593Smuzhiyun /usr/share/scan-build \ 82*4882a593Smuzhiyun /usr/share/scan-view \ 83*4882a593Smuzhiyun /usr/share/man/man1/scan-build.1 \ 84*4882a593Smuzhiyun /usr/lib/clang 85*4882a593Smuzhiyun 86*4882a593Smuzhiyundefine CLANG_CLEANUP_TARGET 87*4882a593Smuzhiyun rm -rf $(addprefix $(TARGET_DIR),$(CLANG_FILES_TO_REMOVE)) 88*4882a593Smuzhiyunendef 89*4882a593SmuzhiyunCLANG_POST_INSTALL_TARGET_HOOKS += CLANG_CLEANUP_TARGET 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun# clang-tblgen is not installed by default, however it is necessary 92*4882a593Smuzhiyun# for cross-compiling clang 93*4882a593Smuzhiyundefine HOST_CLANG_INSTALL_CLANG_TBLGEN 94*4882a593Smuzhiyun $(INSTALL) -D -m 0755 $(HOST_CLANG_BUILDDIR)/bin/clang-tblgen \ 95*4882a593Smuzhiyun $(HOST_DIR)/bin/clang-tblgen 96*4882a593Smuzhiyunendef 97*4882a593SmuzhiyunHOST_CLANG_POST_INSTALL_HOOKS = HOST_CLANG_INSTALL_CLANG_TBLGEN 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun# This option must be enabled to link libclang dynamically against libLLVM.so 100*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += -DLLVM_LINK_LLVM_DYLIB=ON 101*4882a593SmuzhiyunCLANG_CONF_OPTS += -DLLVM_LINK_LLVM_DYLIB=ON 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun# Prevent clang binaries from linking against LLVM static libs 104*4882a593SmuzhiyunHOST_CLANG_CONF_OPTS += -DLLVM_DYLIB_COMPONENTS=all 105*4882a593SmuzhiyunCLANG_CONF_OPTS += -DLLVM_DYLIB_COMPONENTS=all 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun$(eval $(cmake-package)) 108*4882a593Smuzhiyun$(eval $(host-cmake-package)) 109