Commit 8bf9b114 authored by Simon McVittie's avatar Simon McVittie

build: Check that the compiler and --host are consistent

libcapsule's use with biarch containers like the Steam Runtime will
frequently make it necessary to compile it for both x86_64 and i386.

On recent Debian-derived OSs this is OK, because the toolchain is
provided as a complete set of cross-compiler-style prefixed tools like
i686-linux-gnu-gcc; but some OSs, like Arch Linux and very old versions
of Debian, rely on 'gcc -m32' for their biarch support. This makes it
very easy to do

    ./configure --build=x86_64-linux-gnu --host=i686-linux-gnu

and accidentally produce x86_64 binaries, because there is no
i686-linux-gnu-gcc. Give the user a hint towards the correct invocation
in this case, which is:

    ./configure --build=x86_64-linux-gnu --host=i686-linux-gnu CC='gcc -m32'

I've implemented this as a reusable macro, in case we want to add it to
other projects that are likely to be cross-compiled by inexperienced
cross-compiler users.
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 610c7004
......@@ -65,3 +65,4 @@ libcapsule-*.txt
!/build-aux/git-version-gen
!/m4/ax_is_release.m4
!/m4/capsule_*.m4
......@@ -38,6 +38,9 @@ AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE
# So we can install x86_64-linux-gnu-capsule-symbols etc.
AC_CANONICAL_HOST
# Make sure we are not mixing up --host=i686-linux-gnu with a 64-bit compiler
# or vice versa
CAPSULE_MATCHING_ABI
LT_INIT
......
......@@ -25,9 +25,10 @@ License: GPL-3+
Files:
m4/ax_is_release.m4
m4/capsule_matching_abi.m4
Copyright:
© 2015 Philip Withnall
© 2016 Collabora Ltd.
© 2016-2019 Collabora Ltd.
License: Autoconf-permissive
License: LGPL-2.1+
......
# Copyright 2019 Collabora Ltd.
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
dnl CAPSULE_MATCHING_ABI()
dnl
dnl Assert that the --host architecture is consistent with the selected
dnl compiler.
AC_DEFUN([CAPSULE_MATCHING_ABI], [
AC_CANONICAL_HOST
AC_LANG_PUSH([C])
AS_CASE([${host_cpu}-${host_os}],
[i?86-*], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
#if defined(__i386__)
/* OK */
#else
#error not i386
#endif
]]
)],
[],
[
AC_MSG_ERROR([Host system $host must use an i386 compiler such as CC='gcc -m32' or CC='${host_cpu}-${host_os}-gcc'])
]
)
],
[x86_64-*-gnu], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
#if defined(__x86_64__) && defined(__LP64__)
/* OK */
#else
#error not x86_64
#endif
]]
)],
[],
[
AC_MSG_ERROR([Host system $host must use an x86_64 compiler such as CC='gcc -m64' or CC='${host_cpu}-${host_os}-gcc'])
]
)
],
# libcapsule doesn't actually support x32, but for completeness...
[x86_64-*-gnux32], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
#if defined(__x86_64__) && defined(__ILP32__)
/* OK */
#else
#error not x32
#endif
]]
)],
[],
[
AC_MSG_ERROR([Host system $host must use an x32 compiler such as CC='gcc -mx32' or CC='${host_cpu}-${host_os}-gcc'])
]
)
],
# For non-x86 we assume users are more aware of how to select the
# right cross-compiler. (libcapsule doesn't support non-x86 yet
# anyway.)
)
AC_LANG_POP([C])
])dnl CAPSULE_MATCHING_ABI
# vim:set sw=4 sts=4 et:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment