diff mbox

scripts: refine static linking check to better guide the user

Message ID 163f86b5216fc08c672a.1353459722@nipigon.dssd.com
State Accepted
Commit 333d3e40cbd1
Headers show

Commit Message

Daniel Price Nov. 21, 2012, 1:02 a.m. UTC
# HG changeset patch
# User Daniel Price <daniel.price@gmail.com>
# Date 1353459557 28800
# Node ID 163f86b5216fc08c672a687d549dd90b062c81ef
# Parent  5df2d60ca8476069f3dccf7526940058a47bc837
scripts: refine static linking check to better guide the user
scripts: fail on ':' in paths

Signed-off-by: Daniel Price <daniel.price@gmail.com>


--
For unsubscribe information see http://sourceware.org/lists.html#faq

Comments

Daniel Price Nov. 21, 2012, 1:06 a.m. UTC | #1
Minor commentary: I implemented Yann's suggested cleanups-- thanks,
it's vastly better, and should be easier to extend in the future.  And
I also pushed this stuff down just slightly in the code so that (a) we
can test using the CFLAGS we've derived and (b) we can note to the
user the high level point: testing that the host compiler is working--
which seems like a separate activity from "Building Environment."
Yann, if you disagree I can of course move it back up.

        -dp

On Tue, Nov 20, 2012 at 5:02 PM, Daniel Price <daniel.price@gmail.com> wrote:
> # HG changeset patch
> # User Daniel Price <daniel.price@gmail.com>
> # Date 1353459557 28800
> # Node ID 163f86b5216fc08c672a687d549dd90b062c81ef
> # Parent  5df2d60ca8476069f3dccf7526940058a47bc837
> scripts: refine static linking check to better guide the user
> scripts: fail on ':' in paths
>
> Signed-off-by: Daniel Price <daniel.price@gmail.com>
>
> diff -r 5df2d60ca847 -r 163f86b5216f scripts/crosstool-NG.sh.in
> --- a/scripts/crosstool-NG.sh.in        Mon Nov 19 15:23:05 2012 -0800
> +++ b/scripts/crosstool-NG.sh.in        Tue Nov 20 16:59:17 2012 -0800
> @@ -66,6 +66,9 @@
>              *" "*)
>                  CT_Abort "'CT_${d}_DIR'='${dir}' contains a space in it.\nDon't use spaces in paths, it breaks things."
>                  ;;
> +            *":"*)
> +                CT_Abort "'CT_${d}_DIR'='${dir}' contains a colon in it.\nDon't use colons in paths, it breaks things."
> +                ;;
>          esac
>  done
>
> @@ -421,8 +424,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}"
> @@ -474,25 +476,13 @@
>          *)  ;;
>      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 gcc
>      # Explicitly optimise, else the lines below will overide the
>      # package's default optimisation flags
>      CT_CFLAGS_FOR_HOST="-O2 -g"
>      [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST+=" -pipe"
>      CT_CFLAGS_FOR_HOST+=" ${CT_EXTRA_FLAGS_FOR_HOST}"
> +    CT_DoLog DEBUG "gcc CFLAGS for host compiler: ${CT_CFLAGS_FOR_HOST}"
>
>      # Set the shell to be used by ./configure scripts and by Makefiles (those
>      # that support it!).
> @@ -510,6 +500,36 @@
>      [ ${CT_PARALLEL_JOBS} -gt 0 ] && JOBSFLAGS="${JOBSFLAGS} -j${CT_PARALLEL_JOBS}"
>      [ ${CT_LOAD} -ne 0 ] && JOBSFLAGS="${JOBSFLAGS} -l${CT_LOAD}"
>
> +    CT_DoLog INFO "Testing host compiler"
> +    # 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_DoLog DEBUG "Checking that we can run gcc -v"
> +    CT_DoExecLog DEBUG "${CT_HOST}-gcc" -v
> +
> +    # 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_DoLog DEBUG "Checking that gcc can compile a trivial program"
> +    CT_DoExecLog DEBUG "${CT_HOST}-gcc" ${CT_CFLAGS_FOR_HOST} -xc "${testc}" -o "${gccout}"
> +    rm -f "${gccout}"
> +
> +    if [ "${CT_WANTS_STATIC_LINK}" = "y" ]; then
> +        CT_DoLog 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} -xc "${testc}" -static -o "${gccout}"
> +        rm -f "${gccout}"
> +    fi
> +
> +    if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
> +        CT_DoLog 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} -xc "${testc}" -static -lstdc++ -o "${gccout}"
> +        rm -f "${gccout}"
> +    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"
Yann E. MORIN Nov. 21, 2012, 8:54 p.m. UTC | #2
Daniel, All,

Your patch:
    scripts: fail on ':' in paths

has been applied as: #15cd5dc25929
    http://crosstool-ng.org/hg/crosstool-ng/rev/15cd5dc25929

Thank you!

Regards,
Yann E. MORIN.



--
For unsubscribe information see http://sourceware.org/lists.html#faq
Yann E. MORIN Nov. 21, 2012, 8:54 p.m. UTC | #3
Daniel, All,

Your patch:
    scripts: refine static linking check to better guide the user

has been applied as: #333d3e40cbd1
    http://crosstool-ng.org/hg/crosstool-ng/rev/333d3e40cbd1

Thank you!

Regards,
Yann E. MORIN.



--
For unsubscribe information see http://sourceware.org/lists.html#faq
Yann E. MORIN Nov. 22, 2012, 9:44 p.m. UTC | #4
Daniel, All,

Your patch:
    scripts: fail on ':' in paths

has been applied on branch 1.17, as: #b8e00eab8f81
    http://crosstool-ng.org/hg/crosstool-ng/rev/b8e00eab8f81

Thank you!

Regards,
Yann E. MORIN.



--
For unsubscribe information see http://sourceware.org/lists.html#faq
diff mbox

Patch

diff -r 5df2d60ca847 -r 163f86b5216f scripts/crosstool-NG.sh.in
--- a/scripts/crosstool-NG.sh.in	Mon Nov 19 15:23:05 2012 -0800
+++ b/scripts/crosstool-NG.sh.in	Tue Nov 20 16:59:17 2012 -0800
@@ -66,6 +66,9 @@ 
             *" "*)
                 CT_Abort "'CT_${d}_DIR'='${dir}' contains a space in it.\nDon't use spaces in paths, it breaks things."
                 ;;
+            *":"*)
+                CT_Abort "'CT_${d}_DIR'='${dir}' contains a colon in it.\nDon't use colons in paths, it breaks things."
+                ;;
         esac
 done
 
@@ -421,8 +424,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}"
@@ -474,25 +476,13 @@ 
         *)  ;;
     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 gcc
     # Explicitly optimise, else the lines below will overide the
     # package's default optimisation flags
     CT_CFLAGS_FOR_HOST="-O2 -g"
     [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST+=" -pipe"
     CT_CFLAGS_FOR_HOST+=" ${CT_EXTRA_FLAGS_FOR_HOST}"
+    CT_DoLog DEBUG "gcc CFLAGS for host compiler: ${CT_CFLAGS_FOR_HOST}"
 
     # Set the shell to be used by ./configure scripts and by Makefiles (those
     # that support it!).
@@ -510,6 +500,36 @@ 
     [ ${CT_PARALLEL_JOBS} -gt 0 ] && JOBSFLAGS="${JOBSFLAGS} -j${CT_PARALLEL_JOBS}"
     [ ${CT_LOAD} -ne 0 ] && JOBSFLAGS="${JOBSFLAGS} -l${CT_LOAD}"
 
+    CT_DoLog INFO "Testing host compiler"
+    # 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_DoLog DEBUG "Checking that we can run gcc -v"
+    CT_DoExecLog DEBUG "${CT_HOST}-gcc" -v
+
+    # 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_DoLog DEBUG "Checking that gcc can compile a trivial program"
+    CT_DoExecLog DEBUG "${CT_HOST}-gcc" ${CT_CFLAGS_FOR_HOST} -xc "${testc}" -o "${gccout}"
+    rm -f "${gccout}"
+
+    if [ "${CT_WANTS_STATIC_LINK}" = "y" ]; then
+        CT_DoLog 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} -xc "${testc}" -static -o "${gccout}"
+        rm -f "${gccout}"
+    fi
+
+    if [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
+        CT_DoLog 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} -xc "${testc}" -static -lstdc++ -o "${gccout}"
+        rm -f "${gccout}"
+    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"