clang.mk 4.0 KB

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