helpers.mk 9.0 KB

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