boinc/m4/sah_select_bitness.m4

74 lines
2.6 KiB
Plaintext
Raw Normal View History

AC_DEFUN([SAH_DEFAULT_BITNESS],[
2021-01-21 15:35:13 +00:00
if test -z "${COMPILER_MODEL_BITS}"; then
AC_LANG_PUSH([C])
AC_MSG_CHECKING([default bitness of C compiler])
echo "int main() { return 0; }" >conftest.$ac_ext
AC_REQUIRE_CPP
${CC} ${CFLAGS} ${CPPFLAGS} -fno-lto -c conftest.$ac_ext 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
COMPILER_MODEL_BITS=32
if test -f conftest.${OBJEXT}; then
if test -n "$(${OBJDUMP} --file-headers conftest.${OBJEXT} | grep 'file format' | grep 64)" -o -n "$(file conftest.${OBJEXT} | grep -i 64-bit)"; then
COMPILER_MODEL_BITS=64
#else
#if test -n "$(${OBJDUMP} --file-headers conftest.${OBJEXT} | grep 'file format' | grep 16)"; then
#COMPILER_MODEL_BITS=16
#fi
fi
fi
2021-01-21 15:35:13 +00:00
/bin/rm conftest.$ac_ext conftest.${OBJEXT}
AC_MSG_RESULT([$COMPILER_MODEL_BITS])
AC_LANG_POP([C])
AC_LANG_PUSH([C++])
AC_MSG_CHECKING([default bitness of C++ compiler])
echo "int main() { return 0; }" >conftest.$ac_ext
AC_REQUIRE_CPP
${CXX} ${CXXFLAGS} ${CPPFLAGS} -fno-lto -c conftest.$ac_ext 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
if test -f conftest.${OBJEXT}; then
if test -n "$(${OBJDUMP} --file-headers conftest.${OBJEXT} | grep 'file format' | grep 64)" -o -n "$(file conftest.${OBJEXT} | grep -i 64-bit)"; then
if test "${COMPILER_MODEL_BITS}" != "64"; then
AC_MSG_ERROR([64 but not same as bitness in C])
fi
fi
fi
/bin/rm conftest.$ac_ext conftest.${OBJEXT}
AC_MSG_RESULT([$COMPILER_MODEL_BITS])
AC_LANG_POP([C++])
fi
])
AC_DEFUN([SAH_SELECT_BITNESS],[
SAH_DEFAULT_BITNESS
2021-01-21 15:56:57 +00:00
AC_LANG_PUSH([C])
AC_MSG_CHECKING([if C compiler can use -m$1])
if test "$1" != "${COMPILER_MODEL_BITS}"; then
echo "int main() { return 0; }" >conftest.$ac_ext
AC_REQUIRE_CPP
${CC} ${CFLAGS} ${CPPFLAGS} -m$1 -fno-lto -c conftest.$ac_ext 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
if test -f conftest.${OBJEXT}; then
if test -n "$(file conftest.${OBJEXT} | grep -i ${1}-bit)"; then
CFLAGS="${CFLAGS} -m$1"
AC_MSG_RESULT([ok use $1])
else
AC_MSG_ERROR([failed still $COMPILER_MODEL_BITS])
fi
fi
2021-01-21 15:56:57 +00:00
/bin/rm conftest.$ac_ext conftest.${OBJEXT}
fi
2021-01-21 15:56:57 +00:00
AC_MSG_RESULT([ok use $1])
AC_LANG_POP([C])
COMPILER_MODEL_BITS=$1
])
AC_DEFUN([SAH_OPTION_BITNESS],[
AC_ARG_ENABLE(bitness,
AC_HELP_STRING([--enable-bitness=(32,64)],
[enable 32 or 64 bit object/executable files]
),
[SAH_SELECT_BITNESS(${enableval})],
[SAH_DEFAULT_BITNESS]
)
])