2
1

helpers.mk 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # This Makefile fragment declares helper functions, usefull to handle
  2. # non- buildroot-built toolchains, eg. purely external toolchains or
  3. # toolchains (internally) built using crosstool-NG.
  4. #
  5. # Copy a toolchain library and its symbolic links from the sysroot
  6. # directory to the target directory. Also optionaly strips the
  7. # library.
  8. #
  9. # Most toolchains have their libraries either in /lib or /usr/lib
  10. # relative to their ARCH_SYSROOT_DIR. Buildroot toolchains, however,
  11. # have basic libraries in /lib, and libstdc++/libgcc_s in
  12. # /usr/<target-name>/lib(64).
  13. #
  14. # $1: arch specific sysroot directory
  15. # $2: library name
  16. # $3: destination directory of the libary, relative to $(TARGET_DIR)
  17. # $4: strip (y|n), default is to strip
  18. #
  19. copy_toolchain_lib_root = \
  20. ARCH_SYSROOT_DIR="$(strip $1)"; \
  21. LIB="$(strip $2)"; \
  22. DESTDIR="$(strip $3)" ; \
  23. STRIP="$(strip $4)"; \
  24. \
  25. LIBS=`(cd $${ARCH_SYSROOT_DIR}; \
  26. find -L . -path "./lib/$${LIB}.*" -o \
  27. -path "./usr/lib/$${LIB}.*" -o \
  28. -path "./usr/$(TOOLCHAIN_EXTERNAL_PREFIX)/lib*/$${LIB}.*" \
  29. )` ; \
  30. for FILE in $${LIBS} ; do \
  31. LIB=`basename $${FILE}`; \
  32. LIBDIR=`dirname $${FILE}` ; \
  33. while test \! -z "$${LIB}"; do \
  34. FULLPATH="$${ARCH_SYSROOT_DIR}/$${LIBDIR}/$${LIB}" ; \
  35. rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIB}; \
  36. mkdir -p $(TARGET_DIR)/$${DESTDIR}; \
  37. if test -h $${FULLPATH} ; then \
  38. cp -d $${FULLPATH} $(TARGET_DIR)/$${DESTDIR}/; \
  39. elif test -f $${FULLPATH}; then \
  40. $(INSTALL) -D -m0755 $${FULLPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIB}; \
  41. case "$${STRIP}" in \
  42. (0 | n | no) \
  43. ;; \
  44. (*) \
  45. $(TARGET_CROSS)strip "$(TARGET_DIR)/$${DESTDIR}/$${LIB}"; \
  46. ;; \
  47. esac; \
  48. else \
  49. exit -1; \
  50. fi; \
  51. LIB="`readlink $${FULLPATH}`"; \
  52. done; \
  53. done; \
  54. \
  55. echo -n
  56. #
  57. # Copy the full external toolchain sysroot directory to the staging
  58. # dir. The operation of this function is rendered a little bit
  59. # complicated by the support for multilib toolchains.
  60. #
  61. # We start by copying etc, lib, sbin and usr from the sysroot of the
  62. # selected architecture variant (as pointed by ARCH_SYSROOT_DIR). This
  63. # allows to import into the staging directory the C library and
  64. # companion libraries for the correct architecture variant. We
  65. # explictly only copy etc, lib, sbin and usr since other directories
  66. # might exist for other architecture variants (on Codesourcery
  67. # toolchain, the sysroot for the default architecture variant contains
  68. # the armv4t and thumb2 subdirectories, which are the sysroot for the
  69. # corresponding architecture variants), and we don't want to import
  70. # them.
  71. #
  72. # Then, if the selected architecture variant is not the default one
  73. # (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we :
  74. #
  75. # * Import the header files from the default architecture
  76. # variant. Header files are typically shared between the sysroots
  77. # for the different architecture variants. If we use the
  78. # non-default one, header files were not copied by the previous
  79. # step, so we copy them here from the sysroot of the default
  80. # architecture variant.
  81. #
  82. # * Create a symbolic link that matches the name of the subdirectory
  83. # for the architecture variant in the original sysroot. This is
  84. # required as the compiler will by default look in
  85. # sysroot_dir/arch_variant/ for libraries and headers, when the
  86. # non-default architecture variant is used. Without this, the
  87. # compiler fails to find libraries and headers.
  88. #
  89. # $1: main sysroot directory of the toolchain
  90. # $2: arch specific sysroot directory of the toolchain
  91. # $3: arch specific subdirectory in the sysroot
  92. #
  93. copy_toolchain_sysroot = \
  94. SYSROOT_DIR="$(strip $1)"; \
  95. ARCH_SYSROOT_DIR="$(strip $2)"; \
  96. ARCH_SUBDIR="$(strip $3)"; \
  97. for i in etc lib sbin usr ; do \
  98. if [ -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \
  99. cp -a $${ARCH_SYSROOT_DIR}/$$i $(STAGING_DIR)/ ; \
  100. fi ; \
  101. done ; \
  102. if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \
  103. if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \
  104. cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \
  105. fi ; \
  106. ln -s . $(STAGING_DIR)/$(ARCH_SUBDIR) ; \
  107. fi ; \
  108. find $(STAGING_DIR) -type d | xargs chmod 755
  109. #
  110. # Create lib64 -> lib and usr/lib64 -> usr/lib symbolic links in the
  111. # target and staging directories. This is needed for some 64 bits
  112. # toolchains such as the Crosstool-NG toolchains, for which the path
  113. # to the dynamic loader and other libraries is /lib64, but the
  114. # libraries are stored in /lib.
  115. #
  116. create_lib64_symlinks = \
  117. (cd $(TARGET_DIR) ; ln -s lib lib64) ; \
  118. (cd $(TARGET_DIR)/usr ; ln -s lib lib64) ; \
  119. (cd $(STAGING_DIR) ; ln -s lib lib64) ; \
  120. (cd $(STAGING_DIR)/usr ; ln -s lib lib64)
  121. #
  122. # Check the availability of a particular glibc feature. We assume that
  123. # all Buildroot toolchain options are supported by glibc, so we just
  124. # check that they are enabled.
  125. #
  126. # $1: Buildroot option name
  127. # $2: feature description
  128. #
  129. check_glibc_feature = \
  130. if [ x$($(1)) != x"y" ] ; then \
  131. echo "$(2) available in C library, please enable $(1)" ; \
  132. exit 1 ; \
  133. fi
  134. #
  135. # Check the correctness of a glibc external toolchain configuration.
  136. # 1. Check that the C library selected in Buildroot matches the one
  137. # of the external toolchain
  138. # 2. Check that all the C library-related features are enabled in the
  139. # config, since glibc always supports all of them
  140. #
  141. # $1: sysroot directory
  142. #
  143. check_glibc = \
  144. SYSROOT_DIR="$(strip $1)"; \
  145. if ! test -f $${SYSROOT_DIR}/lib/ld-linux*.so.* -o -f $${SYSROOT_DIR}/lib/ld.so.* ; then \
  146. echo "Incorrect selection of the C library"; \
  147. exit -1; \
  148. fi; \
  149. $(call check_glibc_feature,BR2_LARGEFILE,Large file support) ;\
  150. $(call check_glibc_feature,BR2_INET_IPV6,IPv6 support) ;\
  151. $(call check_glibc_feature,BR2_INET_RPC,RPC support) ;\
  152. $(call check_glibc_feature,BR2_ENABLE_LOCALE,Locale support) ;\
  153. $(call check_glibc_feature,BR2_USE_WCHAR,Wide char support) ;\
  154. $(call check_glibc_feature,BR2_PROGRAM_INVOCATION,Program invocation support)
  155. #
  156. # Check the conformity of Buildroot configuration with regard to the
  157. # uClibc configuration of the external toolchain, for a particular
  158. # feature.
  159. #
  160. # $1: uClibc macro name
  161. # $2: Buildroot option name
  162. # $3: uClibc config file
  163. # $4: feature description
  164. #
  165. check_uclibc_feature = \
  166. IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \
  167. if [ x$($(2)) != x"y" -a x$${IS_IN_LIBC} = x"y" ] ; then \
  168. echo "$(4) available in C library, please enable $(2)" ; \
  169. exit 1 ; \
  170. fi ; \
  171. if [ x$($(2)) = x"y" -a x$${IS_IN_LIBC} != x"y" ] ; then \
  172. echo "$(4) not available in C library, please disable $(2)" ; \
  173. exit 1 ; \
  174. fi
  175. #
  176. # Check the correctness of a uclibc external toolchain configuration
  177. # 1. Check that the C library selected in Buildroot matches the one
  178. # of the external toolchain
  179. # 2. Check that the features enabled in the Buildroot configuration
  180. # match the features available in the uClibc of the external
  181. # toolchain
  182. #
  183. # $1: sysroot directory
  184. #
  185. check_uclibc = \
  186. SYSROOT_DIR="$(strip $1)"; \
  187. if ! test -f $${SYSROOT_DIR}/lib/ld*-uClibc.so.* ; then \
  188. echo "Incorrect selection of the C library"; \
  189. exit -1; \
  190. fi; \
  191. UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \
  192. $(call check_uclibc_feature,__UCLIBC_HAS_LFS__,BR2_LARGEFILE,$${UCLIBC_CONFIG_FILE},Large file support) ;\
  193. $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,BR2_INET_IPV6,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\
  194. $(call check_uclibc_feature,__UCLIBC_HAS_RPC__,BR2_INET_RPC,$${UCLIBC_CONFIG_FILE},RPC support) ;\
  195. $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\
  196. $(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\
  197. $(call check_uclibc_feature,__UCLIBC_HAS_PROGRAM_INVOCATION_NAME__,BR2_PROGRAM_INVOCATION,$${UCLIBC_CONFIG_FILE},Program invocation support) ;\
  198. #
  199. # Check that the Buildroot configuration of the ABI matches the
  200. # configuration of the external toolchain.
  201. #
  202. check_arm_abi = \
  203. EXT_TOOLCHAIN_TARGET=$(shell LANG=C $(TARGET_CC) -v 2>&1 | grep ^Target | cut -f2 -d ' ') ; \
  204. if echo $${EXT_TOOLCHAIN_TARGET} | grep -q 'eabi$$' ; then \
  205. EXT_TOOLCHAIN_ABI="eabi" ; \
  206. else \
  207. EXT_TOOLCHAIN_ABI="oabi" ; \
  208. fi ; \
  209. if [ x$(BR2_ARM_OABI) = x"y" -a $${EXT_TOOLCHAIN_ABI} = "eabi" ] ; then \
  210. echo "Incorrect ABI setting" ; \
  211. exit 1 ; \
  212. fi ; \
  213. if [ x$(BR2_ARM_EABI) = x"y" -a $${EXT_TOOLCHAIN_ABI} = "oabi" ] ; then \
  214. echo "Incorrect ABI setting" ; \
  215. exit 1 ; \
  216. fi ; \
  217. #
  218. # Check that the external toolchain supports C++
  219. #
  220. check_cplusplus = \
  221. $(TARGET_CXX) -v > /dev/null 2>&1 ; \
  222. if test $$? -ne 0 ; then \
  223. echo "BR2_INSTALL_LIBSTDCPP is selected but C++ support not available in external toolchain" ; \
  224. exit 1 ; \
  225. fi ; \
  226. #
  227. # Check that the cross-compiler given in the configuration exists
  228. #
  229. check_cross_compiler_exists = \
  230. $(TARGET_CC) -v > /dev/null 2>&1 ; \
  231. if test $$? -ne 0 ; then \
  232. echo "Cannot execute cross-compiler '$(TARGET_CC)'" ; \
  233. exit 1 ; \
  234. fi ; \