helpers.mk 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. # This Makefile fragment declares toolchain related helper functions.
  2. # The copy_toolchain_lib_root function copies a toolchain library and
  3. # its symbolic links from the sysroot directory to the target
  4. # directory. Note that this function is used both by the external
  5. # toolchain logic, and the glibc package, so care must be taken when
  6. # changing this function.
  7. #
  8. # $1: library name pattern (can include glob wildcards)
  9. #
  10. copy_toolchain_lib_root = \
  11. LIBPATTERN="$(strip $1)"; \
  12. LIBPATHS=`find $(STAGING_DIR)/ -name "$${LIBPATTERN}" 2>/dev/null` ; \
  13. for LIBPATH in $${LIBPATHS} ; do \
  14. while true ; do \
  15. LIBNAME=`basename $${LIBPATH}`; \
  16. DESTDIR=`echo $${LIBPATH} | sed "s,^$(STAGING_DIR)/,," | xargs dirname` ; \
  17. mkdir -p $(TARGET_DIR)/$${DESTDIR}; \
  18. rm -fr $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
  19. if test -h $${LIBPATH} ; then \
  20. cp -d $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
  21. LIBPATH="`readlink -f $${LIBPATH}`"; \
  22. elif test -f $${LIBPATH}; then \
  23. $(INSTALL) -D -m0755 $${LIBPATH} $(TARGET_DIR)/$${DESTDIR}/$${LIBNAME}; \
  24. break ; \
  25. else \
  26. exit -1; \
  27. fi; \
  28. done; \
  29. done
  30. #
  31. # Copy the full external toolchain sysroot directory to the staging
  32. # dir. The operation of this function is rendered a little bit
  33. # complicated by the support for multilib toolchains.
  34. #
  35. # We start by copying etc, 'lib', sbin, usr and usr/'lib' from the
  36. # sysroot of the selected architecture variant (as pointed to by
  37. # ARCH_SYSROOT_DIR). This allows to import into the staging directory
  38. # the C library and companion libraries for the correct architecture
  39. # variant. 'lib' may not be literally 'lib' but could be something else,
  40. # e.g. lib32-fp (as determined by ARCH_LIB_DIR) and we only want to copy
  41. # that lib directory and no other. When copying usr, we therefore need
  42. # to be extra careful not to include usr/lib* but we _do_ want to
  43. # include usr/libexec.
  44. # We are selective in the directories we copy since other directories
  45. # might exist for other architecture variants (on Codesourcery
  46. # toolchain, the sysroot for the default architecture variant contains
  47. # the armv4t and thumb2 subdirectories, which are the sysroot for the
  48. # corresponding architecture variants), and we don't want to import
  49. # them.
  50. #
  51. # If ARCH_LIB_DIR is not a singular directory component, e.g.
  52. # 'lib32/octeon2', then symbolic links in ARCH_LIB_DIR and
  53. # usr/ARCH_LIB_DIR may be broken because Buildroot will flatten the
  54. # directory structure (e.g. lib32/octeon2/foo is actually stored in
  55. # lib/foo). This is only relevant for links that contain one or more ../
  56. # components, as links to the current directory are always fine.
  57. # We need to fix the broken links by removing the right amount of ../
  58. # dots from the link destination.
  59. # Once the link destination is valid again, it can be simplified to
  60. # remove the dependency on intermediate directory symlinks.
  61. #
  62. # It is possible that ARCH_LIB_DIR does not contain the dynamic loader
  63. # (ld*.so or similar) because it (or the main symlink to it) normally
  64. # resides in /lib while ARCH_LIB_DIR may be something else (e.g. lib64,
  65. # lib/<tuple>, ...). Therefore, copy the dynamic loader separately.
  66. #
  67. # Then, if the selected architecture variant is not the default one
  68. # (i.e, if SYSROOT_DIR != ARCH_SYSROOT_DIR), then we :
  69. #
  70. # * Import the header files from the default architecture
  71. # variant. Header files are typically shared between the sysroots
  72. # for the different architecture variants. If we use the
  73. # non-default one, header files were not copied by the previous
  74. # step, so we copy them here from the sysroot of the default
  75. # architecture variant.
  76. #
  77. # * Create a symbolic link that matches the name of the subdirectory
  78. # for the architecture variant in the original sysroot. This is
  79. # required as the compiler will by default look in
  80. # sysroot_dir/arch_variant/ for libraries and headers, when the
  81. # non-default architecture variant is used. Without this, the
  82. # compiler fails to find libraries and headers.
  83. #
  84. # Some toolchains (i.e Linaro binary toolchains) store support
  85. # libraries (libstdc++, libgcc_s) outside of the sysroot, so we simply
  86. # copy all the libraries from the "support lib directory" into our
  87. # sysroot.
  88. #
  89. # Note that the 'locale' directories are not copied. They are huge
  90. # (400+MB) in CodeSourcery toolchains, and they are not really useful.
  91. #
  92. # $1: main sysroot directory of the toolchain
  93. # $2: arch specific sysroot directory of the toolchain
  94. # $3: arch specific subdirectory in the sysroot
  95. # $4: directory of libraries ('lib', 'lib32' or 'lib64')
  96. # $5: support lib directories (for toolchains storing libgcc_s,
  97. # libstdc++ and other gcc support libraries outside of the
  98. # sysroot)
  99. copy_toolchain_sysroot = \
  100. SYSROOT_DIR="$(strip $1)"; \
  101. ARCH_SYSROOT_DIR="$(strip $2)"; \
  102. ARCH_SUBDIR="$(strip $3)"; \
  103. ARCH_LIB_DIR="$(strip $4)" ; \
  104. SUPPORT_LIB_DIR="$(strip $5)" ; \
  105. for i in etc $${ARCH_LIB_DIR} sbin usr usr/$${ARCH_LIB_DIR}; do \
  106. if [ ! -d $${ARCH_SYSROOT_DIR}/$$i ] ; then \
  107. continue ; \
  108. fi ; \
  109. if [ "$$i" = "usr" ]; then \
  110. rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
  111. --include '/libexec*/' --exclude '/lib*/' \
  112. $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
  113. else \
  114. rsync -au --chmod=u=rwX,go=rX --exclude 'locale/' \
  115. $${ARCH_SYSROOT_DIR}/$$i/ $(STAGING_DIR)/$$i/ ; \
  116. fi ; \
  117. done ; \
  118. for link in $$(find $(STAGING_DIR) -type l); do \
  119. target=$$(readlink $${link}) ; \
  120. if [ "$${target}" == "$${target$(SHARP_SIGN)/}" ] ; then \
  121. continue ; \
  122. fi ; \
  123. relpath="$(call relpath_prefix,$${target$(SHARP_SIGN)/})" ; \
  124. echo "Fixing symlink $${link} from $${target} to $${relpath}$${target$(SHARP_SIGN)/}" ; \
  125. ln -sf $${relpath}$${target$(SHARP_SIGN)/} $${link} ; \
  126. done ; \
  127. relpath="$(call relpath_prefix,$${ARCH_LIB_DIR})" ; \
  128. if [ "$${relpath}" != "" ]; then \
  129. for i in $$(find -H $(STAGING_DIR)/$${ARCH_LIB_DIR} $(STAGING_DIR)/usr/$${ARCH_LIB_DIR} -type l -xtype l); do \
  130. LINKTARGET=`readlink $$i` ; \
  131. NEWLINKTARGET=$${LINKTARGET\#$$relpath} ; \
  132. ln -sf $${NEWLINKTARGET} $$i ; \
  133. $(call simplify_symlink,$$i,$(STAGING_DIR)) ; \
  134. done ; \
  135. fi ; \
  136. if [ ! -e $(STAGING_DIR)/lib/ld*.so.* ]; then \
  137. if [ -e $${ARCH_SYSROOT_DIR}/lib/ld*.so.* ]; then \
  138. cp -a $${ARCH_SYSROOT_DIR}/lib/ld*.so.* $(STAGING_DIR)/lib/ ; \
  139. fi ; \
  140. fi ; \
  141. if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \
  142. if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \
  143. cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \
  144. fi ; \
  145. mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \
  146. relpath="$(call relpath_prefix,$${ARCH_SUBDIR})./" ; \
  147. ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \
  148. echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \
  149. fi ; \
  150. if test -n "$${SUPPORT_LIB_DIR}" ; then \
  151. cp -a $${SUPPORT_LIB_DIR}/* $(STAGING_DIR)/lib/ ; \
  152. fi ; \
  153. find $(STAGING_DIR) -type d | xargs chmod 755
  154. #
  155. # Check the specified kernel headers version actually matches the
  156. # version in the toolchain.
  157. #
  158. # $1: build directory
  159. # $2: sysroot directory
  160. # $3: kernel version string, in the form: X.Y
  161. # $4: test to do for the latest kernel version, 'strict' or 'loose'
  162. # always 'strict' if this is not the latest version.
  163. #
  164. check_kernel_headers_version = \
  165. if ! support/scripts/check-kernel-headers.sh $(1) $(2) $(3) \
  166. $(if $(BR2_TOOLCHAIN_HEADERS_LATEST),$(4),strict); \
  167. then \
  168. exit 1; \
  169. fi
  170. #
  171. # Check the specific gcc version actually matches the version in the
  172. # toolchain
  173. #
  174. # $1: path to gcc
  175. # $2: expected gcc version
  176. #
  177. check_gcc_version = \
  178. expected_version="$(strip $2)" ; \
  179. if [ -z "$${expected_version}" ]; then \
  180. exit 0 ; \
  181. fi; \
  182. real_version=`$(1) -dumpversion` ; \
  183. if [[ ! "$${real_version}." =~ ^$${expected_version}\. ]] ; then \
  184. printf "Incorrect selection of gcc version: expected %s.x, got %s\n" \
  185. "$${expected_version}" "$${real_version}" ; \
  186. exit 1 ; \
  187. fi
  188. #
  189. # Check the availability of a particular glibc feature. This function
  190. # is used to check toolchain options that are always supported by
  191. # glibc, so we simply check that the corresponding option is properly
  192. # enabled.
  193. #
  194. # $1: Buildroot option name
  195. # $2: feature description
  196. #
  197. check_glibc_feature = \
  198. if [ "$($(1))" != "y" ] ; then \
  199. echo "$(2) available in C library, please enable $(1)" ; \
  200. exit 1 ; \
  201. fi
  202. #
  203. # Check the availability of RPC support in a glibc toolchain
  204. #
  205. # $1: sysroot directory
  206. #
  207. check_glibc_rpc_feature = \
  208. IS_IN_LIBC=`test -f $(1)/usr/include/rpc/rpc.h && echo y` ; \
  209. if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \
  210. echo "RPC support available in C library, please enable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \
  211. exit 1 ; \
  212. fi ; \
  213. if [ "$(BR2_TOOLCHAIN_HAS_NATIVE_RPC)" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \
  214. echo "RPC support not available in C library, please disable BR2_TOOLCHAIN_EXTERNAL_INET_RPC" ; \
  215. exit 1 ; \
  216. fi
  217. #
  218. # Check the correctness of a glibc external toolchain configuration.
  219. # 1. Check that the C library selected in Buildroot matches the one
  220. # of the external toolchain
  221. # 2. Check that all the C library-related features are enabled in the
  222. # config, since glibc always supports all of them
  223. #
  224. # $1: sysroot directory
  225. #
  226. check_glibc = \
  227. SYSROOT_DIR="$(strip $1)"; \
  228. if test `find -L $${SYSROOT_DIR}/ -maxdepth 2 -name 'ld-linux*.so.*' -o -name 'ld.so.*' -o -name 'ld64.so.*' | wc -l` -eq 0 ; then \
  229. echo "Incorrect selection of the C library"; \
  230. exit -1; \
  231. fi; \
  232. $(call check_glibc_feature,BR2_USE_MMU,MMU support) ;\
  233. $(call check_glibc_rpc_feature,$${SYSROOT_DIR})
  234. #
  235. # Check that the selected C library really is musl
  236. #
  237. # $1: cross-gcc path
  238. # $2: cross-readelf path
  239. check_musl = \
  240. __CROSS_CC=$(strip $1) ; \
  241. libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \
  242. if ! strings $${libc_a_path} | grep -q MUSL_LOCPATH ; then \
  243. echo "Incorrect selection of the C library" ; \
  244. exit -1; \
  245. fi
  246. #
  247. # Check the conformity of Buildroot configuration with regard to the
  248. # uClibc configuration of the external toolchain, for a particular
  249. # feature.
  250. #
  251. # If 'Buildroot option name' ($2) is empty it means the uClibc option
  252. # is mandatory.
  253. #
  254. # $1: uClibc macro name
  255. # $2: Buildroot option name
  256. # $3: uClibc config file
  257. # $4: feature description
  258. #
  259. check_uclibc_feature = \
  260. IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \
  261. if [ -z "$(2)" ] ; then \
  262. if [ "$${IS_IN_LIBC}" != "y" ] ; then \
  263. echo "$(4) not available in C library, toolchain unsuitable for Buildroot" ; \
  264. exit 1 ; \
  265. fi ; \
  266. else \
  267. if [ "$($(2))" != "y" -a "$${IS_IN_LIBC}" = "y" ] ; then \
  268. echo "$(4) available in C library, please enable $(2)" ; \
  269. exit 1 ; \
  270. fi ; \
  271. if [ "$($(2))" = "y" -a "$${IS_IN_LIBC}" != "y" ] ; then \
  272. echo "$(4) not available in C library, please disable $(2)" ; \
  273. exit 1 ; \
  274. fi ; \
  275. fi
  276. #
  277. # Check the correctness of a uclibc external toolchain configuration
  278. # 1. Check that the C library selected in Buildroot matches the one
  279. # of the external toolchain
  280. # 2. Check that the features enabled in the Buildroot configuration
  281. # match the features available in the uClibc of the external
  282. # toolchain
  283. #
  284. # $1: sysroot directory
  285. #
  286. check_uclibc = \
  287. SYSROOT_DIR="$(strip $1)"; \
  288. if ! test -f $${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; then \
  289. echo "Incorrect selection of the C library"; \
  290. exit -1; \
  291. fi; \
  292. UCLIBC_CONFIG_FILE=$${SYSROOT_DIR}/usr/include/bits/uClibc_config.h ; \
  293. $(call check_uclibc_feature,__ARCH_USE_MMU__,BR2_USE_MMU,$${UCLIBC_CONFIG_FILE},MMU support) ;\
  294. $(call check_uclibc_feature,__UCLIBC_HAS_LFS__,,$${UCLIBC_CONFIG_FILE},Large file support) ;\
  295. $(call check_uclibc_feature,__UCLIBC_HAS_IPV6__,,$${UCLIBC_CONFIG_FILE},IPv6 support) ;\
  296. $(call check_uclibc_feature,__UCLIBC_HAS_RPC__,BR2_TOOLCHAIN_HAS_NATIVE_RPC,$${UCLIBC_CONFIG_FILE},RPC support) ;\
  297. $(call check_uclibc_feature,__UCLIBC_HAS_LOCALE__,BR2_ENABLE_LOCALE,$${UCLIBC_CONFIG_FILE},Locale support) ;\
  298. $(call check_uclibc_feature,__UCLIBC_HAS_WCHAR__,BR2_USE_WCHAR,$${UCLIBC_CONFIG_FILE},Wide char support) ;\
  299. $(call check_uclibc_feature,__UCLIBC_HAS_THREADS__,BR2_TOOLCHAIN_HAS_THREADS,$${UCLIBC_CONFIG_FILE},Thread support) ;\
  300. $(call check_uclibc_feature,__PTHREADS_DEBUG_SUPPORT__,BR2_TOOLCHAIN_HAS_THREADS_DEBUG,$${UCLIBC_CONFIG_FILE},Thread debugging support) ;\
  301. $(call check_uclibc_feature,__UCLIBC_HAS_THREADS_NATIVE__,BR2_TOOLCHAIN_HAS_THREADS_NPTL,$${UCLIBC_CONFIG_FILE},NPTL thread support)
  302. #
  303. # Check that the Buildroot configuration of the ABI matches the
  304. # configuration of the external toolchain.
  305. #
  306. # $1: cross-gcc path
  307. # $2: cross-readelf path
  308. #
  309. check_arm_abi = \
  310. __CROSS_CC=$(strip $1) ; \
  311. EXT_TOOLCHAIN_TARGET=`LANG=C $${__CROSS_CC} -v 2>&1 | grep ^Target | cut -f2 -d ' '` ; \
  312. if ! echo $${EXT_TOOLCHAIN_TARGET} | grep -qE 'eabi(hf)?$$' ; then \
  313. echo "External toolchain uses the unsuported OABI" ; \
  314. exit 1 ; \
  315. fi ; \
  316. if ! echo 'int main(void) {}' | $${__CROSS_CC} -x c -o $(BUILD_DIR)/.br-toolchain-test.tmp - ; then \
  317. rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*; \
  318. abistr_$(BR2_ARM_EABI)='EABI'; \
  319. abistr_$(BR2_ARM_EABIHF)='EABIhf'; \
  320. echo "Incorrect ABI setting: $${abistr_y} selected, but toolchain is incompatible"; \
  321. exit 1 ; \
  322. fi ; \
  323. rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
  324. #
  325. # Check that the external toolchain supports C++
  326. #
  327. # $1: cross-g++ path
  328. #
  329. check_cplusplus = \
  330. __CROSS_CXX=$(strip $1) ; \
  331. $${__CROSS_CXX} -v > /dev/null 2>&1 ; \
  332. if test $$? -ne 0 ; then \
  333. echo "C++ support is selected but is not available in external toolchain" ; \
  334. exit 1 ; \
  335. fi
  336. #
  337. #
  338. # Check that the external toolchain supports D language
  339. #
  340. # $1: cross-gdc path
  341. #
  342. check_dlang = \
  343. __CROSS_GDC=$(strip $1) ; \
  344. __o=$(BUILD_DIR)/.br-toolchain-test-dlang.tmp ; \
  345. printf 'import std.stdio;\nvoid main() { writeln("Hello World!"); }\n' | \
  346. $${__CROSS_GDC} -x d -o $${__o} - ; \
  347. if test $$? -ne 0 ; then \
  348. rm -f $${__o}* ; \
  349. echo "D language support is selected but is not available in external toolchain" ; \
  350. exit 1 ; \
  351. fi ; \
  352. rm -f $${__o}* \
  353. #
  354. #
  355. # Check that the external toolchain supports Fortran
  356. #
  357. # $1: cross-gfortran path
  358. #
  359. check_fortran = \
  360. __CROSS_FC=$(strip $1) ; \
  361. __o=$(BUILD_DIR)/.br-toolchain-test-fortran.tmp ; \
  362. printf 'program hello\n\tprint *, "Hello Fortran!\\n"\nend program hello\n' | \
  363. $${__CROSS_FC} -x f95 -o $${__o} - ; \
  364. if test $$? -ne 0 ; then \
  365. rm -f $${__o}* ; \
  366. echo "Fortran support is selected but is not available in external toolchain" ; \
  367. exit 1 ; \
  368. fi ; \
  369. rm -f $${__o}* \
  370. #
  371. #
  372. # Check that the external toolchain supports OpenMP
  373. #
  374. # $1: cross-gcc path
  375. #
  376. check_openmp = \
  377. __CROSS_CC=$(strip $1) ; \
  378. __o=$(BUILD_DIR)/.br-toolchain-test-openmp.tmp ; \
  379. printf '\#include <omp.h>\nint main(void) { return omp_get_thread_num(); }' | \
  380. $${__CROSS_CC} -fopenmp -x c -o $${__o} - ; \
  381. if test $$? -ne 0 ; then \
  382. rm -f $${__o}* ; \
  383. echo "OpenMP support is selected but is not available in external toolchain"; \
  384. exit 1 ; \
  385. fi ; \
  386. rm -f $${__o}* \
  387. #
  388. # Check that the cross-compiler given in the configuration exists
  389. #
  390. # $1: cross-gcc path
  391. #
  392. check_cross_compiler_exists = \
  393. __CROSS_CC=$(strip $1) ; \
  394. $${__CROSS_CC} -v > /dev/null 2>&1 ; \
  395. if test $$? -ne 0 ; then \
  396. echo "Cannot execute cross-compiler '$${__CROSS_CC}'" ; \
  397. exit 1 ; \
  398. fi
  399. #
  400. # Check for toolchains known not to work with Buildroot.
  401. # - For the Angstrom toolchains, we check by looking at the vendor part of
  402. # the host tuple.
  403. # - Exclude distro-class toolchains which are not relocatable.
  404. # - Exclude broken toolchains which return "libc.a" with -print-file-name.
  405. # - Exclude toolchains which doesn't support --sysroot option.
  406. #
  407. # $1: cross-gcc path
  408. #
  409. check_unusable_toolchain = \
  410. __CROSS_CC=$(strip $1) ; \
  411. vendor=`$${__CROSS_CC} -dumpmachine | cut -f2 -d'-'` ; \
  412. if test "$${vendor}" = "angstrom" ; then \
  413. echo "Angstrom toolchains are not pure toolchains: they contain" ; \
  414. echo "many other libraries than just the C library, which makes" ; \
  415. echo "them unsuitable as external toolchains for build systems" ; \
  416. echo "such as Buildroot." ; \
  417. exit 1 ; \
  418. fi; \
  419. with_sysroot=`$${__CROSS_CC} -v 2>&1 |sed -r -e '/.* --with-sysroot=([^[:space:]]+)[[:space:]].*/!d; s//\1/'`; \
  420. if test "$${with_sysroot}" = "/" ; then \
  421. echo "Distribution toolchains are unsuitable for use by Buildroot," ; \
  422. echo "as they were configured in a way that makes them non-relocatable,"; \
  423. echo "and contain a lot of pre-built libraries that would conflict with"; \
  424. echo "the ones Buildroot wants to build."; \
  425. exit 1; \
  426. fi; \
  427. libc_a_path=`$${__CROSS_CC} -print-file-name=libc.a` ; \
  428. if test "$${libc_a_path}" = "libc.a" ; then \
  429. echo "Unable to detect the toolchain sysroot, Buildroot cannot use this toolchain." ; \
  430. exit 1 ; \
  431. fi ; \
  432. sysroot_dir="$(call toolchain_find_sysroot,$${__CROSS_CC})" ; \
  433. if test -z "$${sysroot_dir}" ; then \
  434. echo "External toolchain doesn't support --sysroot. Cannot use." ; \
  435. exit 1 ; \
  436. fi
  437. #
  438. # Check if the toolchain has SSP (stack smashing protector) support
  439. #
  440. # $1: cross-gcc path
  441. # $2: gcc ssp option
  442. #
  443. check_toolchain_ssp = \
  444. __CROSS_CC=$(strip $1) ; \
  445. __HAS_SSP=`echo 'void main(){}' | $${__CROSS_CC} -Werror -fstack-protector -x c - -o $(BUILD_DIR)/.br-toolchain-test.tmp >/dev/null 2>&1 && echo y` ; \
  446. if [ "$(BR2_TOOLCHAIN_HAS_SSP)" != "y" -a "$${__HAS_SSP}" = "y" ] ; then \
  447. echo "SSP support available in this toolchain, please enable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
  448. exit 1 ; \
  449. fi ; \
  450. if [ "$(BR2_TOOLCHAIN_HAS_SSP)" = "y" -a "$${__HAS_SSP}" != "y" ] ; then \
  451. echo "SSP support not available in this toolchain, please disable BR2_TOOLCHAIN_EXTERNAL_HAS_SSP" ; \
  452. exit 1 ; \
  453. fi ; \
  454. __SSP_OPTION=$(2); \
  455. if [ -n "$${__SSP_OPTION}" ] ; then \
  456. if ! echo 'void main(){}' | $${__CROSS_CC} -Werror $${__SSP_OPTION} -x c - -o $(BUILD_DIR)/.br-toolchain-test.tmp >/dev/null 2>&1 ; then \
  457. echo "SSP option $${__SSP_OPTION} not available in this toolchain, please select another SSP level" ; \
  458. exit 1 ; \
  459. fi; \
  460. fi; \
  461. rm -f $(BUILD_DIR)/.br-toolchain-test.tmp*
  462. #
  463. # Generate gdbinit file for use with Buildroot
  464. #
  465. gen_gdbinit_file = \
  466. mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \
  467. echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit
  468. # Given a path, determine the relative prefix (../) needed to return to the
  469. # root level. Note that the last component is treated as a file component; use a
  470. # trailing slash to force treating it as a directory. Examples:
  471. # relpath_prefix(lib32) = ""
  472. # relpath_prefix(lib32/octeon2) = "../"
  473. # relpath_prefix(lib32/octeon2/) = "../../"
  474. #
  475. # $1: input path
  476. define relpath_prefix
  477. $$( \
  478. prefix="" ; \
  479. nbslashs=`printf $1 | sed 's%[^/]%%g' | wc -c` ; \
  480. for slash in `seq 1 $${nbslashs}` ; do \
  481. prefix=$${prefix}"../" ; \
  482. done ; \
  483. printf "$$prefix" ; \
  484. )
  485. endef
  486. # Replace the destination of a symbolic link with a simpler version
  487. # For example,
  488. # usr/lib/libfoo.so -> ../../lib32/libfoo.so.1
  489. # becomes
  490. # usr/lib/libfoo.so -> ../../lib/libfoo.so.1
  491. # since 'lib32' is a symlink to 'lib'.
  492. #
  493. # Likewise,
  494. # usr/lib/octeon2/libbar.so -> ../../../lib32/octeon2/libbar.so.1
  495. # becomes
  496. # usr/lib/octeon2/libbar.so -> ../../lib/libbar.so.1
  497. # assuming lib32->lib and lib/octeon2->lib.
  498. #
  499. # $1: symlink
  500. # $2: base path
  501. define simplify_symlink
  502. ( \
  503. FULL_SRC="$$(readlink -f $$(dirname $1))/$$(basename $1)" ; \
  504. FULL_DEST="$$(readlink -f $1)" ; \
  505. FULL_BASE="$$(readlink -f $2)" ; \
  506. REL_SRC="$${FULL_SRC#$${FULL_BASE}/}" ; \
  507. REL_DEST="$${FULL_DEST#$${FULL_BASE}/}" ; \
  508. DOTS="$(call relpath_prefix,$${REL_SRC})" ; \
  509. ln -sf "$${DOTS}$${REL_DEST}" "$${FULL_SRC}" ; \
  510. )
  511. endef