dnl $Id: configure.in,v 1.1.1.1 2002/05/29 20:17:14 csieh Exp $

AC_INIT(insmod/insmod.c)
AC_PREFIX_DEFAULT(/usr)

# Canonical system uses HOST_CC while Linux may use HOSTCC
if test -z "$HOST_CC"; then
  HOST_CC="$HOSTCC"
  export HOST_CC
fi

AC_CANONICAL_SYSTEM

case "$target_cpu" in
  alpha*)  ARCH=alpha ;;
  i?86)    ARCH=i386  ;;
  ia64)    ARCH=ia64  ;;
  arm*)    ARCH=arm   ;;
  mips*)   ARCH=mips  ;;
  powerpc) ARCH=ppc   ;;
  *)       ARCH=$target_cpu ;;
esac

for i in rmmod modprobe lsmod ksyms kallsyms
do eval COMBINE_$i=$i
done
AC_ARG_ENABLE(combined,
[  --enable-combined            Create insmod and rmmod/modprobe/lsmod/ksyms/kallsyms
                               as one executable.  Default is one combined
                               module, if you --disable-combined you can still
                               combine individual modules into insmod with
                               --enable-combined-X.],
[if test "$enableval" = "no"; then
	for i in rmmod modprobe lsmod ksyms kallsyms
	do eval COMBINE_$i=""
	done
fi])

AC_ARG_ENABLE(combined-rmmod,
[  --enable-combined-rmmod      Create insmod and rmmod as one executable
                               (default)],
[if test "$enableval" = "yes"; then
  COMBINE_rmmod=rmmod
  else
  COMBINE_rmmod=""
fi])
AC_SUBST(COMBINE_rmmod)

AC_ARG_ENABLE(combined-modprobe,
[  --enable-combined-modprobe   Create insmod and modprobe as one executable
                               (default)],
[if test "$enableval" = "yes"; then
  COMBINE_modprobe=modprobe
  else
  COMBINE_modprobe=""
fi])
AC_SUBST(COMBINE_modprobe)

AC_ARG_ENABLE(combined-lsmod,
[  --enable-combined-lsmod      Create insmod and lsmod as one executable
                               (default)],
[if test "$enableval" = "yes"; then
  COMBINE_lsmod=lsmod
  else
  COMBINE_lsmod=""
fi])
AC_SUBST(COMBINE_lsmod)

AC_ARG_ENABLE(combined-ksyms,
[  --enable-combined-ksyms      Create insmod and ksyms as one executable
                               (default)],
[if test "$enableval" = "yes"; then
  COMBINE_ksyms=ksyms
  else
  COMBINE_ksyms=""
fi])
AC_SUBST(COMBINE_ksyms)

AC_ARG_ENABLE(combined-kallsyms,
[  --enable-combined-kallsyms   Create insmod and kallsyms as one executable
                               (default)],
[if test "$enableval" = "yes"; then
  COMBINE_kallsyms=kallsyms
  else
  COMBINE_kallsyms=""
fi])
AC_SUBST(COMBINE_kallsyms)

AC_ARG_ENABLE(compat-2-0,
[  --disable-compat-2-0         Do not create utilities that can run on a Linux
                               2.0 system (default)],
[if test "$enableval" = "yes"; then
  AC_DEFINE(COMPAT_2_0)
fi])

AC_ARG_ENABLE(kerneld,
[  --disable-kerneld            Do not create kerneld binary (default)],
[if test "$enableval" = "yes"; then
  kerneld_SUBDIR=kerneld
  kerneld_Makefiles="kerneld/Makefile man_kerneld/Makefile"
fi])
AC_SUBST(kerneld_SUBDIR)

AC_ARG_ENABLE(insmod-static,
[  --disable-insmod-static      Do not create insmod.static binary (default)],
[if test "$enableval" = "yes"; then
  insmod_static=yes
else
  insmod_static=no
fi],[insmod_static=no])
AC_SUBST(insmod_static)

COMMON_sparc=yes
AC_ARG_ENABLE(common-sparc,
[  --enable-common-sparc        Make all the utilities work on both sparc32 and
                               sparc64 as one executable (default on sparc is
                               yes, default on other architectures is no)],
[if test "$enableval" = "yes"; then
  COMMON_sparc=yes
  else
  COMMON_sparc=no
fi])
case "$ARCH" in
  sparc64) if test "$COMMON_sparc" = "yes"; then ARCH="sparc"; fi ;;
  sparc*) ;;
  *) COMMON_sparc=no ;;
esac
AC_SUBST(COMMON_sparc)

AC_SUBST(ARCH)

case "$ARCH" in
  ia64)	DEFAULT_STRIP=;;
  *)	DEFAULT_STRIP=-s ;;
esac
AC_ARG_ENABLE(strip,
[  --enable-strip               Strip binaries during install.   Default is no
                               on IA64 (ski does not like stripped binaries),
                               yes on other architectures],
[if test "$enableval" = "yes"; then
  STRIP=-s
else
  STRIP=
fi],[STRIP=$DEFAULT_STRIP])
AC_SUBST(STRIP)

AC_ARG_ENABLE(zlib,
[  --disable-zlib               Do not handle gzipped objects (default)],
[if test "$enableval" = "yes"; then
  AC_DEFINE(CONFIG_USE_ZLIB)
  LIBS="$LIBS -lz"
fi])

# Default for use-syscall depends on the presence of query_module in libc.
AC_CHECK_LIB(c, query_module, [default_syscall=n], [default_syscall=y])
AC_ARG_ENABLE(use-syscall,
[  --disable-use-syscall        Do not use _syscall(), use libc functions instead.
                               Default is disable the use of syscall but only if
                               libc supports query_module.],
[if test "$enableval" = "yes"; then
  USE_SYSCALL="y"
else
  USE_SYSCALL="n"
fi],[USE_SYSCALL="$default_syscall"])
if test "$USE_SYSCALL" = "y"; then
  AC_DEFINE(CONFIG_USE_SYSCALL)
fi
AC_SUBST(USE_SYSCALL)

AC_ARG_ENABLE(root-check,
[  --enable-root-check          Check that modules are owned by root before
                               loading (default)],
[if test "$enableval" = "yes"; then
  AC_DEFINE(CONFIG_ROOT_CHECK_OFF, 0) 
else
  AC_DEFINE(CONFIG_ROOT_CHECK_OFF, 1) 
fi],[AC_DEFINE(CONFIG_ROOT_CHECK_OFF, 0)])

# If the user did not specify CFLAGS, use suitable values for modutils
if test "$CFLAGS" = ""; then
  CFLAGS="-O2 -Wall"
fi

AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_LN_S

# AC_PROG_INSTALL is unsuitable for cross compilation.  It generates a
# hard coded pathname for INSTALL.  Even if we set our own value for
# INSTALL, acgeneral insists on preceding a relative INSTALL with
# "../".  Easiest solution is to use another variable inside autoconf
# and not use AC_PROG_INSTALL.
#
if test -z "$INSTALL"; then
  INSTALL_LOCAL=install
else
  INSTALL_LOCAL="$INSTALL"
fi
AC_SUBST(INSTALL_LOCAL)

# If the user did not specify HOSTCC, use CC
if test -z "$HOSTCC"; then
  HOSTCC=$CC
fi
AC_SUBST(HOSTCC)

# If the user did not specify HOSTCFLAGS, use CFLAGS
if test -z "$HOSTCFLAGS"; then
  HOSTCFLAGS=$CFLAGS
fi
AC_SUBST(HOSTCFLAGS)

# If the user did not specify AR, use ar
if test -z "$AR"; then
  AR=ar
fi
AC_SUBST(AR)

# If the user did not specify PARSECFLAGS, use -Wno-uninitialized.
# Yacc and Lex generated programs raise comments about uninitialized
# variables when -Wall is used so turn this warning off for the parse
# programs.
if test "$PARSERCFLAGS" = ""; then
  PARSERCFLAGS=-Wno-uninitialized
fi
AC_SUBST(PARSERCFLAGS)

# If the user did not specify MKDIR, use mkdir -p.
if test "$MKDIR" = ""; then
  MKDIR="mkdir -p"
fi
AC_SUBST(MKDIR)

AC_CHECK_FUNC(wordexp, HAVE_WORDEXP="-DHAVE_WORDEXP=1", HAVE_WORDEXP="")
AC_SUBST(HAVE_WORDEXP)

AC_CHECK_FUNC(glob, HAVE_GLOB="-DHAVE_GLOB=1", HAVE_GLOB="")
AC_SUBST(HAVE_GLOB)

if test "$ARCH" = "alpha"; then
  AC_MSG_CHECKING(for broken alpha assembler)
  cat > conftest.c <<EOF
[#]line __oline__ "configure"
static int x, y;
int main() { return y; }
EOF
  if AC_TRY_EVAL(ac_compile); then
    ac_broken_gas=no
    if objdump -r conftest.o | grep 'LITERAL.*y.*4$' > /dev/null; then
      AC_DEFINE(AXP_BROKEN_GAS)
      ac_broken_gas=yes
    fi
    rm -rf conftest*
  else
    AC_MSG_ERROR([what, we can't build a simple proggie?])
  fi
  AC_MSG_RESULT($ac_broken_gas)
fi

# If the user did not specify a prefix, then change exec_prefix
# to be '' so that binaries go into /sbin.
if test "x$prefix" = "xNONE"; then
  if test "x$exec_prefix" = "xNONE"; then
    exec_prefix=""
  fi
fi

AC_OUTPUT(Makefile Makefile.common depmod/Makefile genksyms/Makefile
	  insmod/Makefile $kerneld_Makefiles obj/Makefile util/Makefile
	  man/Makefile)
