cf: Set CC before calling AC_PROG_CC

On some platforms (HPUX, SOLARIS, AIX), we forcibly set CC or set a
default CC, because we must use a specific compiler to build kernel
modules, and we specify certain compiler-specific flags. But we do
this after AC_PROG_CC has run, which also searches for a compiler to
use, and runs a few tests against it. AC_PROG_CC often chooses a
different compiler (it prefers gcc if it's available).

As a result, some compiler-derived info may be wrong, which can yield
confusing results, even breaking the build depending on what the
user's PATH is, or what compilers are installed on the system.

We can avoid all of this if we move our CC-setting logic to before
AC_PROG_CC is called. This is a little tricky, because our logic to
set AFS_SYSNAME requires the C compiler, so we must do this before
OPENAFS_SYSNAME, and also before AC_USE_SYSTEM_EXTENSIONS, or any
other autoconf macro that uses the C compiler.

Move our CC-setting logic into a new macro, OPENAFS_PATH_CC, which is
separate from OPENAFS_CONFIGURE_COMMON and must be called before
OPENAFS_CONFIGURE_COMMON. Add some safeguards to try to detect if
AC_PROG_CC is already called to try to prevent future changes from
breaking this; this isn't perfect, but it's better than nothing.

Change-Id: I7c327df5acc5d1ff701b70825eecaaaab4aa44a8
Reviewed-on: https://gerrit.openafs.org/15456
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Ben Huntsman <ben@huntsmans.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Andrew Deason 2023-05-19 16:53:55 -05:00 committed by Michael Meffie
parent aa82a8894f
commit dba6ec9548
6 changed files with 131 additions and 43 deletions

View File

@ -5,9 +5,14 @@ dnl NB: Because this code is a macro, references to positional shell
dnl parameters must be done like $[]1 instead of $1
AC_DEFUN([OPENAFS_CONFIGURE_COMMON],[
dnl If the user hasn't specified CFLAGS don't let configure pick -g -O2
AS_IF([test -z "$CFLAGS"], [CFLAGS=" "])
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC
OPENAFS_AUTOHEADER_TOP
OPENAFS_AUTOHEADER_BOTTOM
AC_CANONICAL_HOST
SRCDIR_PARENT=`pwd`
#BOZO_SAVE_CORES pam

View File

@ -8,10 +8,7 @@ MACOS_VERSION=1.9.1
AC_SUBST([MACOS_VERSION])
dnl If the user hasn't specified CFLAGS don't let configure pick -g -O2
AS_IF([test -z "$CFLAGS"], [CFLAGS=" "], [])
AC_PROG_CC
OPENAFS_PATH_CC
OPENAFS_CONFIGURE_COMMON
AC_CONFIG_FILES([

View File

@ -9,15 +9,10 @@ MACOS_VERSION=1.9.1
AC_SUBST([MACOS_VERSION])
dnl If the user hasn't specified CFLAGS don't let configure pick -g -O2
AS_IF([test -z "$CFLAGS"], [CFLAGS=" "])
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC
AC_PATH_PROGS([PATH_CPP], [cpp], [${CC-cc} -E], [$PATH:/lib:/usr/ccs/lib])
AC_SUBST([PATH_CPP])
OPENAFS_PATH_CC
OPENAFS_CONFIGURE_COMMON
OPENAFS_KRB5
OPENAFS_GSS

122
src/cf/cc.m4 Normal file
View File

@ -0,0 +1,122 @@
dnl OPENAFS_PATH_CC
dnl
dnl Set the CC var, to specify the C compiler to use.
dnl
dnl This is needed on some platforms where kernel modules must be built with
dnl certain compilers. For some platforms, we forcibly set CC to certain values,
dnl even if the user has given a different CC. We shouldn't do this on new
dnl platforms, but this behavior is kept for older platforms to make sure we don't
dnl change their behavior. For most modern platforms, we try to honor a CC
dnl given by the user, but provide a more helpful default CC if they didn't give
dnl one.
dnl
dnl This macro must be called early, before anything calls AC_PROG_CC directly
dnl or indirectly (many autoconf macros AC_REQUIRE([AC_PROG_CC]), because
dnl AC_PROG_CC runs some compiler checks with the detected compiler that we can't
dnl easily undo later. That means before this is called, you cannot call
dnl AC_COMPILE_IFELSE, AC_TRY_KBUILD, etc; no running the compiler.
AC_DEFUN([OPENAFS_PATH_CC], [
AC_REQUIRE([AC_CANONICAL_HOST])
dnl If someone called AC_PROG_CC before us, this will throw an error during
dnl 'regen'. This isn't completely foolproof; if something in here calls
dnl something that requires AC_PROG_CC (e.g. AC_USE_SYSTEM_EXTENSIONS), then
dnl AC_PROG_CC will effectively called before we reach here, but this check
dnl won't trigger. This is just the best we can do.
AC_PROVIDE_IFELSE([AC_PROG_CC],
[AC_FATAL([AC_PROG_CC was called before $0])])
AS_CASE([$host],
dnl hp_ux102
[hppa*-hp-hpux10*],
[CC="/opt/ansic/bin/cc -Ae"],
dnl hp_ux11*
[hppa*-hp-hpux11.*],
[CC="/opt/ansic/bin/cc"],
dnl ia64_hpux*
[ia64-hp-hpux*],
[CC="/opt/ansic/bin/cc"],
dnl ppc_darwin_70
[powerpc-apple-darwin7*],
[CC="cc"],
dnl *_darwin_80
[powerpc-apple-darwin8.* | i386-apple-darwin8.*],
[CC="cc"],
dnl rs_aix4*
[power*-ibm-aix4.*],
[CC="cc"],
dnl rs_aix5*
[power*-ibm-aix5.*],
[CC="cc"],
dnl rs_aix61 | rs_aix71
[power*-ibm-aix6.* | power*-ibm-aix7.1],
[CC="cc"],
dnl rs_aix7*
[power*-ibm-aix7.*],
[AIX7_PATH_CC],
dnl sgi_65
[mips-sgi-irix6.5],
[CC="/usr/bin/cc"],
dnl sun4x_5*
[sparc-sun-solaris2.*],
[SOLARIS_PATH_CC],
dnl sunx86_5*
[i386-pc-solaris2.*],
[SOLARIS_PATH_CC],
[])
])
AC_DEFUN([AIX7_PATH_CC], [
# On AIX, we need to use the xlc compiler. Starting with AIX 7.2, a new
# version of the compiler (17.1) is available, which is invoked via
# 'ibm-clang'. The old compiler (16.x and below) may still be available, and
# is invoked via 'xlc' or 'cc'. Traditionally we have invoked the old
# compiler via 'cc', so look for that.
# First, try to find ibm-clang in the user's PATH. If we can't find that, try
# to find 'cc' in the user's PATH.
AS_IF([test x"$CC" = x],
[AC_PATH_PROGS([CC], [ibm-clang cc])])
AS_IF([test x"$CC" = x],
[AC_MSG_FAILURE([m4_join([ ],
[Could not find the ibm-clang or cc compiler.],
[Please set CC to specify the path to the compiler.])])])
])
AC_DEFUN([SOLARIS_PATH_CC], [
# If the user specified a path with SOLARISCC, use that. We used to pick a
# compiler based on the SOLARISCC var, so continue to preserve the behavior
# of setting SOLARISCC.
AS_IF([test x"$SOLARISCC" != x], [CC="$SOLARISCC"])
AS_IF([test x"$CC" = x], [
# If the user didn't specify a CC, try to find one in the common locations
# for the SUNWspro-y compiler.
AC_PATH_PROG([CC], [cc], [],
[m4_join([:],
[/opt/SUNWspro/bin],
[/opt/SunStudioExpress/bin],
[/opt/developerstudio12.6/bin],
[/opt/developerstudio12.5/bin],
[/opt/solarisstudio12.4/bin],
[/opt/solarisstudio12.3/bin],
[/opt/solstudio12.2/bin],
[/opt/sunstudio12.1/bin])])
AS_IF([test x"$CC" = x],
[AC_MSG_FAILURE([m4_join([ ],
[Could not find the solaris cc program.],
[Please set CC to specify the path to the compiler.])])])
])
])

View File

@ -54,7 +54,6 @@ case $AFS_SYSNAME in
hp_ux102)
AS="/usr/ccs/bin/as"
CC="/opt/ansic/bin/cc -Ae"
DBM="/lib/libndbm.a"
LD="/bin/ld"
LEX="/opt/langtools/bin/lex"
@ -79,7 +78,6 @@ case $AFS_SYSNAME in
hp_ux11*)
AR="/usr/bin/ar"
AS="/usr/ccs/bin/as"
CC="/opt/ansic/bin/cc"
DBM="/lib/libndbm.a"
LD="/bin/ld "
LEX="/opt/langtools/bin/lex"
@ -103,7 +101,6 @@ case $AFS_SYSNAME in
ia64_hpux*)
AR="/usr/bin/ar"
AS="/usr/ccs/bin/as"
CC="/opt/ansic/bin/cc"
DBM="/lib/hpux32/libndbm.so"
LD="/bin/ld "
LEX="/opt/langtools/bin/lex"
@ -233,7 +230,6 @@ case $AFS_SYSNAME in
;;
ppc_darwin_70)
CC="cc"
AFSD_LDFLAGS="-F/System/Library/PrivateFrameworks -framework DiskArbitration -framework SystemConfiguration -framework IOKit -framework CoreFoundation"
MT_CFLAGS='-D_REENTRANT'
KROOT=
@ -248,7 +244,6 @@ case $AFS_SYSNAME in
;;
*_darwin_80)
CC="cc"
AFSD_LDFLAGS="-F/System/Library/PrivateFrameworks -framework DiskArbitration -framework SystemConfiguration -framework IOKit -framework CoreFoundation"
MT_CFLAGS="-D_REENTRANT"
KROOT=
@ -349,7 +344,6 @@ case $AFS_SYSNAME in
;;
rs_aix42)
CC="cc"
DBG=""
LIBSYS_AIX_EXP="afsl.exp"
MT_CC="xlc_r"
@ -364,7 +358,6 @@ case $AFS_SYSNAME in
;;
rs_aix51 | rs_aix52 | rs_aix53)
CC="cc"
DBG="-g"
LIBSYS_AIX_EXP="afsl.exp"
MT_CC="xlc_r"
@ -380,7 +373,6 @@ case $AFS_SYSNAME in
;;
rs_aix61 | rs_aix71)
CC="cc"
DBG="-g"
LIBSYS_AIX_EXP="afsl.exp"
MT_CC="xlc_r"
@ -396,10 +388,6 @@ case $AFS_SYSNAME in
;;
rs_aix7*)
# Prefer 'ibm-clang' for CC, otherwise use 'cc'
CC=
AC_PROG_CC([ibm-clang cc])
# Are we using the newer ibm-clang compiler, or the older xlc?
AC_MSG_CHECKING([AIX compiler type])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
@ -457,7 +445,6 @@ case $AFS_SYSNAME in
sgi_65)
AFSD_LIBS="/usr/lib32/libdwarf.a /usr/lib32/libelf.a"
CC="/usr/bin/cc"
FSINCLUDES="-I/usr/include/sys/fs"
LD="/usr/bin/ld"
MT_CFLAGS='-D_SGI_MP_SOURCE'
@ -480,7 +467,6 @@ case $AFS_SYSNAME in
;;
sun4x_5*)
CC=$SOLARISCC
LD="/usr/ccs/bin/ld"
MT_CFLAGS='-mt'
PAM_CFLAGS="-KPIC"
@ -514,7 +500,6 @@ case $AFS_SYSNAME in
;;
esac
CC=$SOLARISCC
CFLAGS="$CFLAGS ${XARCHFLAGS}"
LD="/usr/ccs/bin/ld"
MT_CFLAGS='-mt'

View File

@ -1,16 +0,0 @@
AC_DEFUN([SOLARIS_PATH_CC], [
AC_PATH_PROG([SOLARISCC], [cc], [],
[m4_join([:],
[/opt/SUNWspro/bin],
[/opt/SunStudioExpress/bin],
[/opt/developerstudio12.6/bin],
[/opt/developerstudio12.5/bin],
[/opt/solarisstudio12.4/bin],
[/opt/solarisstudio12.3/bin],
[/opt/solstudio12.2/bin],
[/opt/sunstudio12.1/bin])])
AS_IF([test "x$SOLARISCC" = "x"],
[AC_MSG_FAILURE([m4_join([ ],
[Could not find the solaris cc program.],
[Please define the environment variable SOLARISCC to specify the path.])])])
])