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