# HG changeset patch # User Daniel Price # Date 1353459557 28800 # Node ID 333d3e40cbd145f247f3f5111d1b7cfc824a9167 # Parent 15cd5dc25929d0ccd0e1f187fe721a1ca0d48919 scripts: refine static linking check to better guide the user The current mechanism to check if static linking is possible, and the mesage displayed on failure, can be puzzling to the unsuspecting user. Also, the current implementation is not using the existing infrastructure, and is thus difficult to enhance with new tests. So, switch to using the standard CT_DoExecLog infra, and use four tests to check for the host compiler: - check we can run it - check it can build a trivial program - check it can statically link that program - check if it statically link with libstdc++ That should cover most of the problems. Hopefully. (At the same time, fix a typo in a comment) Signed-off-by: Daniel Price [yann.morin.1998@free.fr: split original patch for self-contained changes] [yann.morin.1998@free.fr: use steps to better see gcc's output] [yann.morin.1998@free.fr: commit log] Signed-off-by: "Yann E. MORIN" Message-Id: <163f86b5216fc08c672a.1353459722@nipigon.dssd.com> Patchwork-Id: 200536 diff -r 15cd5dc25929 -r 333d3e40cbd1 scripts/crosstool-NG.sh.in --- a/scripts/crosstool-NG.sh.in Tue Nov 20 16:59:17 2012 -0800 +++ b/scripts/crosstool-NG.sh.in Tue Nov 20 16:59:17 2012 -0800 @@ -423,8 +423,7 @@ where=$(CT_Which "${tool}") fi - # Not all tools are available for all platforms, but some are really, - # bally needed + # Not all tools are available for all platforms, but some are required. if [ -n "${where}" ]; then CT_DoLog DEBUG " '${!v}-${tool}' -> '${where}'" printf "#${BANG}${CT_CONFIG_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_BUILDTOOLS_PREFIX_DIR}/bin/${!v}-${tool}" @@ -476,19 +475,6 @@ *) ;; esac - # Now we know our host and where to find the host tools, we can check - # if static link was requested, but only if it was requested - if [ "${CT_WANTS_STATIC_LINK}" = "y" ]; then - tmp="${CT_BUILD_DIR}/.static-test" - if ! "${CT_HOST}-gcc" -xc - -static -o "${tmp}" >/dev/null 2>&1 <<-_EOF_ - int main() { return 0; } - _EOF_ - then - CT_Abort "Static linking impossible on the host system '${CT_HOST}'" - fi - rm -f "${tmp}" - fi - # Help build gcc # Explicitly optimise, else the lines below will overide the # package's default optimisation flags @@ -505,6 +491,8 @@ CT_CFLAGS_FOR_HOST+=" ${CT_EXTRA_CFLAGS_FOR_HOST}" CT_LDFLAGS_FOR_HOST= CT_LDFLAGS_FOR_HOST+=" ${CT_EXTRA_LDFLAGS_FOR_HOST}" + CT_DoLog DEBUG "CFLAGS for host compiler: '${CT_CFLAGS_FOR_HOST}'" + CT_DoLog DEBUG "LDFLAGS for host compiler: '${CT_LDFLAGS_FOR_HOST}'" # Set the shell to be used by ./configure scripts and by Makefiles (those # that support it!). @@ -522,6 +510,39 @@ [ ${CT_PARALLEL_JOBS} -gt 0 ] && JOBSFLAGS="${JOBSFLAGS} -j${CT_PARALLEL_JOBS}" [ ${CT_LOAD} -ne 0 ] && JOBSFLAGS="${JOBSFLAGS} -l${CT_LOAD}" + # Now that we've set up $PATH and $CT_CFLAGS_FOR_HOST, sanity test that gcc + # is runnable so that the user can troubleshoot problems if not. + CT_DoStep DEBUG "Checking that we can run gcc -v" + CT_DoExecLog DEBUG "${CT_HOST}-gcc" -v + CT_EndStep + + # Create a simple C program for testing. + testc="${CT_BUILD_DIR}/test.c" + printf "int main() { return 0; }\n" >"${testc}" + gccout="${CT_BUILD_DIR}/.gccout" + + CT_DoStep DEBUG "Checking that gcc can compile a trivial program" + CT_DoExecLog DEBUG "${CT_HOST}-gcc" ${CT_CFLAGS_FOR_HOST} ${CT_LDFLAGS_FOR_HOST} "${testc}" -o "${gccout}" + rm -f "${gccout}" + CT_EndStep + + if [ "${CT_WANTS_STATIC_LINK}" = "y" ]; then + CT_DoStep DEBUG "Checking that gcc can compile a trivial statically linked program (CT_WANTS_STATIC_LINK)" + CT_DoLog DEBUG "You may need to ensure that static libraries such as libc.a are installed on your system" + CT_DoExecLog DEBUG "${CT_HOST}-gcc" ${CT_CFLAGS_FOR_HOST} ${CT_LDFLAGS_FOR_HOST} "${testc}" -static -o "${gccout}" + rm -f "${gccout}" + CT_EndStep + fi + + if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then + CT_DoStep DEBUG "Checking that gcc can statically link libstdc++ (CT_CC_STATIC_LIBSTDCXX)" + CT_DoLog DEBUG "You may need to ensure that libstdc++.a is installed on your system" + CT_DoExecLog DEBUG "${CT_HOST}-gcc" ${CT_CFLAGS_FOR_HOST} ${CT_LDFLAGS_FOR_HOST} "${testc}" -static -lstdc++ -o "${gccout}" + rm -f "${gccout}" + CT_EndStep + fi + rm -f "${testc}" + # We need to save the real .config with kconfig's value, # not our mangled .config.2 with arrays. CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"