2
1

helpers.mk 9.0 KB

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