From 74eba3d47b03ac97e9bc759f2d4eee44cea9a9c6 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Wed, 2 Jun 2004 19:00:58 +0000 Subject: [PATCH] Upgrade as-linux.m4 and as-modtool.m4. Fix build system to handle changes. --- comedi/Makefile.am | 2 +- comedi/drivers/Makefile.am | 51 ++-- comedi/kcomedilib/Makefile.am | 2 +- m4/as-linux.m4 | 435 +++++++++++++++++++++++++--------- m4/as-modtool.m4 | 79 +++++- 5 files changed, 439 insertions(+), 130 deletions(-) diff --git a/comedi/Makefile.am b/comedi/Makefile.am index 32390fd2..9464b678 100644 --- a/comedi/Makefile.am +++ b/comedi/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = kcomedilib drivers +SUBDIRS = . kcomedilib drivers module_PROGRAMS = comedi.ko diff --git a/comedi/drivers/Makefile.am b/comedi/drivers/Makefile.am index 36fb402e..8fb45cc0 100644 --- a/comedi/drivers/Makefile.am +++ b/comedi/drivers/Makefile.am @@ -2,7 +2,36 @@ #SUBDIRS = addi-data AM_CFLAGS = $(COMEDI_CFLAGS) $(LINUX_CFLAGS) $(RTAI_CFLAGS) $(RTLINUX_CFLAGS) -LINK = $(top_builddir)/modtool --link -o $@ +LINK = $(top_builddir)/modtool --link -o $@ \ + -i ../.mods/comedi.o.symvers \ + -i .mods/8255.o.symvers \ + -i .mods/amcc_s5933.o.symvers \ + -i .mods/comedi_fc.o.symvers \ + -i .mods/das08.o.symvers \ + -i .mods/mite.o.symvers \ + -i .mods/ni_labpc.o.symvers + +8255_ko_LINK = $(top_builddir)/modtool --link -o $@ \ + -i ../.mods/comedi.o.symvers +amcc_s5933_ko_LINK = $(top_builddir)/modtool --link -o $@ \ + -i ../.mods/comedi.o.symvers +comedi_fc_ko_LINK = $(top_builddir)/modtool --link -o $@ \ + -i ../.mods/comedi.o.symvers +das08_ko_CFLAGS = $(top_builddir)/modtool --link -o $@ \ + -i ../.mods/comedi.o.symvers +mite_ko_LINK = $(top_builddir)/modtool --link -o $@ \ + -i ../.mods/comedi.o.symvers +ni_labpc_ko_CFLAGS = $(top_builddir)/modtool --link -o $@ \ + -i ../.mods/comedi.o.symvers + +8255_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB +amcc_s5933_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB +comedi_fc_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB +das08_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB +mite_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB +ni_labpc_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB + + EXTRA_DIST = \ 8253.h \ @@ -48,11 +77,16 @@ else usb_modules= endif -module_PROGRAMS = 8255.ko \ +module_PROGRAMS = \ + 8255.ko \ + amcc_s5933.ko \ + comedi_fc.ko \ + das08.ko \ + mite.ko \ + ni_labpc.ko \ adl_pci9111.ko \ adl_pci9118.ko \ adv_pci1710.ko \ - amcc_s5933.ko \ adv_pci_dio.ko \ amplc_pci230.ko \ amplc_pc236.ko \ @@ -62,10 +96,8 @@ module_PROGRAMS = 8255.ko \ cb_pcidda.ko \ cb_pcimdas.ko \ cb_pcimdda.ko \ - comedi_fc.ko \ contec_pci_dio.ko \ daqboard2000.ko \ - das08.ko \ das16.ko \ das16m1.ko \ das6402.ko \ @@ -85,7 +117,6 @@ module_PROGRAMS = 8255.ko \ ke_counter.ko \ me_daq.ko \ me4000.ko \ - mite.ko \ multiq3.ko \ ni_660x.ko \ ni_670x.ko \ @@ -95,7 +126,6 @@ module_PROGRAMS = 8255.ko \ ni_6527.ko \ ni_atmio16d.ko \ ni_at_a2150.ko \ - ni_labpc.ko \ ni_at_ao.ko \ pcm3730.ko \ pcmad.ko \ @@ -193,10 +223,3 @@ ssv_dnp_ko_SOURCES = ssv_dnp.c comedi_test_ko_SOURCES = comedi_test.c usbdux_ko_SOURCES = usbdux.c -mite_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB -8255_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB -amcc_s5933_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB -comedi_fc_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB -ni_labpc_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB -das08_ko_CFLAGS = $(AM_CFLAGS) -DEXPORT_SYMTAB - diff --git a/comedi/kcomedilib/Makefile.am b/comedi/kcomedilib/Makefile.am index 7aeece01..108da7e2 100644 --- a/comedi/kcomedilib/Makefile.am +++ b/comedi/kcomedilib/Makefile.am @@ -3,7 +3,7 @@ module_PROGRAMS = kcomedilib.ko kcomedilib_ko_SOURCES = data.c ksyms.c dio.c kcomedilib_main.c get.c kcomedilib_ko_CFLAGS = $(COMEDI_CFLAGS) $(LINUX_CFLAGS) $(RTAI_CFLAGS) $(RTLINUX_CFLAGS) -kcomedilib_ko_LINK = $(top_builddir)/modtool --link -o $@ +kcomedilib_ko_LINK = $(top_builddir)/modtool --link -o $@ -i ../.mods/comedi.o.symvers #ksyms.o: ksyms.c # $(CC) -o $@ ksyms.c $(CFLAGS) $(COMEDI_CFLAGS) $(LINUX_CFLAGS) -DEXPORT_SYMTAB diff --git a/m4/as-linux.m4 b/m4/as-linux.m4 index f1543bfb..1e4a1f92 100644 --- a/m4/as-linux.m4 +++ b/m4/as-linux.m4 @@ -1,14 +1,26 @@ -dnl as-linux.m4 0.0.1 +dnl as-linux.m4 0.2.0 + dnl autostars m4 macro for detecting a Linux source tree (or dnl equivalent) for compiling modules. -dnl + dnl David Schleef dnl Frank Mori Hess -dnl thomas@apestaart.org -dnl +dnl Thomas Vander Stichele + +dnl $Id$ + dnl AS_LINUX() dnl -dnl this macro adds the options --with-linuxdir and --with-linux-config. +dnl this macro adds the options +dnl --with-linuxdir to specify a kernel build tree location +dnl --with-linuxconfig to specify a kernel .config file +dnl --with-kernel-release to specify an alternative uname -r +dnl --with-machine to specify an alternative uname -m +dnl --with-rpm-target to specify to match the given rpm --target option +dnl --with-extraversion to specify an EXTRAVERSION override +dnl --with-modulesdir to specify the base install location of modules +dnl --with-modulesdeveldir to specify the base install location of build stuff + dnl this macro defines: dnl LINUX_DIR dnl The directory where the Linux source resides. @@ -38,10 +50,58 @@ dnl LINUX_AS dnl Assembler used by Linux. dnl LINUX_MODULE_EXT dnl Module extension (.o or .ko) -dnl +dnl LINUX_MODPOST +dnl path to modpost script +dnl modulesdir +dnl base install path for kernel modules +dnl modulesdeveldir +dnl base install path for kernel module development files dnl dnl End of search list. +dnl main entry point +dnl checks the version, and figures out all flags to use to make modules. +AC_DEFUN([AS_LINUX], +[ + dnl check if user supplied a uname -r, and if not use the running one + AS_LINUX_KERNEL_RELEASE() + dnl check if user supplied a uname -m, and if not use the running one + AS_LINUX_MACHINE() + dnl check if the user supplied an rpm target arch + dnl override the LINUX_MACHINE value if he did + AS_LINUX_RPM_TARGET($LINUX_KERNEL_RELEASE) + + dnl find the kernel source tree for the given uname -r + AS_LINUX_DIR($LINUX_KERNEL_RELEASE) + dnl check if user supplied an EXTRAVERSION, and if not get from uname -r + AS_LINUX_EXTRAVERSION($LINUX_KERNEL_RELEASE) + dnl check if user supplied a config file; if not, guess a good one + AS_LINUX_CONFIG($LINUX_DIR, $LINUX_KERNEL_RELEASE, $LINUX_MACHINE) + dnl check if we're building on pre-FC2 Red Hat/Fedora, + dnl and add some flags if we are + AS_CHECK_REDHAT_PRE_FC2() + dnl check for where to install modules + AS_LINUX_MODULESDIR($LINUX_KERNEL_RELEASE) + dnl check for where to install module development files + AS_LINUX_MODULESDEVELDIR($LINUX_DIR) + dnl check for the MAJOR/MINOR version of Linux + AS_LINUX_VERSION_MAJOR_MINOR($LINUX_DIR) + + dnl now call the correct macro to get compiler flags + dnl the versioned AS_LINUX macros just use the global variables + dnl this could be cleaned up later on if we feel like it + case $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR in + 2.6) + AS_LINUX_2_6() + ;; + 2.[[01234]]) + AS_LINUX_2_4() + ;; + *) + AC_MSG_ERROR([Unknown Linux major.minor $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR]) + ;; + esac +]) dnl check if we can find a source dir for the Linux kernel @@ -93,76 +153,202 @@ AC_DEFUN([AS_TRY_LINUX_DIR], AC_MSG_RESULT($result) ]) +dnl allow for specifying a kernel release (uname -r) to build for +dnl use uname -r of running one if not specified +dnl store result in LINUX_KERNEL_RELEASE +AC_DEFUN([AS_LINUX_KERNEL_RELEASE], +[ + AC_ARG_WITH([kernel-release], + [AC_HELP_STRING([--with-kernel-release=RELEASE], + [specify the "uname -r"-value to build for])], + [LINUX_KERNEL_RELEASE="${withval}"], + [LINUX_KERNEL_RELEASE=`uname -r`]) + if test "x$LINUX_KERNEL_RELEASE" = "xyes"; + then + LINUX_KERNEL_RELEASE=`uname -r` + fi + AC_MSG_NOTICE([Using $LINUX_KERNEL_RELEASE as the uname -r value]) +]) + +dnl allow for specifying a machine (uname -m) to build for +dnl use uname -, of running one if not specified +dnl store result in LINUX_MACHINE +AC_DEFUN([AS_LINUX_MACHINE], +[ + AC_ARG_WITH([machine], + [AC_HELP_STRING([--with-machine=MACHINE], + [specify the "uname -m"-value to build for])], + [LINUX_MACHINE="${withval}"], + [LINUX_MACHINE=`uname -m`]) + if test "x$LINUX_MACHINE" = "xyes"; + then + LINUX_MACHINE=`uname -r` + fi + AC_MSG_NOTICE([Using $LINUX_MACHINE as the uname -m value]) +]) +dnl allow for specifying an rpm target arch +dnl if none specified, try to guess one from running rpm querying for +dnl the kernel with the uname -r +dnl this is so configure without arguments works out of the box +dnl FIXME: investigate if uname -p is a correct guess for this, and if +dnl we should have a flag for specifying it instead + +dnl this macro possibly overrides LINUX_MACHINE + +dnl first argument is the kernel release building for +AC_DEFUN([AS_LINUX_RPM_TARGET], +[ + RELEASE=$1 + AC_ARG_WITH([rpm-target], + [AC_HELP_STRING([--with-rpm-target=TARGET], + [specify the target arch to build for])], + [LINUX_RPM_TARGET="${withval}"], + [LINUX_RPM_TARGET=]) + if test "x$LINUX_RPM_TARGET" = "x" + then + dnl if we have rpm, try to guess the target of the kernel + dnl we want to build for using rpm + AC_PATH_PROG(RPM, rpm, yes, no) + if test "x$RPM" = "xyes" + then + if rpm -q kernel-$RELEASE > /dev/null + then + LINUX_RPM_TARGET=`rpm -q --queryformat %{arch} kernel-$RELEASE` + else + AC_MSG_NOTICE([Cannot guess target arch, consider setting it using --with-rpm-target]) + fi + fi + fi + + dnl now override LINUX_MACHINE if LINUX_RPM_TARGET is set + if test "x$LINUX_RPM_TARGET" != "x" + then + dnl override LINUX_MACHINE based on this + dnl FIXME: add other possible Red Hat/Fedora/rpm targets here + LINUX_MACHINE= + case "$LINUX_RPM_TARGET" in + i?86) LINUX_MACHINE=i386;; + athlon) LINUX_MACHINE=i386;; + x86_64) LINUX_MACHINE=x86_64;; + esac + if test "x$LINUX_MACHINE" = "x" + then + AC_MSG_ERROR(Could not guess uname -m value from target $LINUX_RPM_TARGET) + fi + fi +]) + + +dnl allow for specifying an override for EXTRAVERSION +dnl if none specified, make it from the passed-in KERNEL_RELEASE (uname -r) +dnl resulting value is stored in LINUX_EXTRAVERSION +dnl first argument is the uname -r string to use as a fallback +AC_DEFUN([AS_LINUX_EXTRAVERSION], +[ + KERNEL_RELEASE=[$1] + dnl extract the default by getting everything after first - + LINUX_EXTRAVERSION="-`echo $KERNEL_RELEASE | cut -d- -f 2-`" + AC_ARG_WITH([extraversion], + [AC_HELP_STRING([--with-extraversion=FILE], + [specify override for kernel EXTRAVERSION])], + [LINUX_EXTRAVERSION="${withval}"],) +]) + + dnl check if we can find a config file for the Linux kernel -dnl defines CONFIG_FILE to the absolute location of a usable kernel source tree -dnl uses LINUX_DIR to find either .config or decent configs in configs/ -AC_DEFUN([AS_CONFIG_FILE], +dnl defines LINUX_CONFIG to the absolute location of a usable +dnl kernel source config file + +dnl for rpm distros, it can try and guess the correct config file by +dnl checking the global LINUX_RPM_TARGET variable set somewhere else +dnl (FIXME: move this to an argument instead ?) + +dnl first argument is LINUX_DIR to check for possible configs +dnl second argument is kernel-release (uname -r) +dnl third argument is machine (uname -m) + +AC_DEFUN([AS_LINUX_CONFIG], [ - AC_ARG_WITH([linux-config], - [AC_HELP_STRING([--with-linux-config=FILE], + LINUX_DIR=[$1] + KERNEL_RELEASE=[$2] + MACHINE=[$3] + AC_ARG_WITH([linuxconfig], + [AC_HELP_STRING([--with-linuxconfig=FILE], [specify path to Linux configuration file])], - [CONFIG_FILE="${withval}"], - [CONFIG_FILE=default]) + [LINUX_CONFIG="${withval}"], + [LINUX_CONFIG=default]) - if test "${CONFIG_FILE}" != "default" ; then - AS_TRY_CONFIG_FILE([${CONFIG_FILE}], , AC_MSG_ERROR([Linux config not found]) ) + dnl if a file got specified, try it as a linux config file + if test "${LINUX_CONFIG}" != "default" ; then + AS_TRY_LINUX_CONFIG($LINUX_CONFIG, $MACHINE, + ,, AC_MSG_ERROR([Linux config not found]) ) fi - dnl if default specified, first check for the regular .config file + dnl if no file specified, first check for the regular .config file dnl in LINUX_DIR created by manual configuration - if test "${CONFIG_FILE}" = "default" ; then + if test "${LINUX_CONFIG}" = "default" ; then file="$LINUX_DIR/.config"; - AS_TRY_CONFIG_FILE([${file}], [CONFIG_FILE=${file}], ) + AS_TRY_LINUX_CONFIG($file, $MACHINE, + [LINUX_CONFIG=${file}], ) fi dnl second, try to guess what config file to use for the current kernel - if test "${CONFIG_FILE}" = "default" ; then + dnl FIXME: the possible arch is from rpmbuild --target, and is + dnl different from the value of ARCH (Makefile) or MACHINE (uname -m) + dnl so we should have a redhat flag to specify the target to find + dnl the correct config file + if test "${LINUX_CONFIG}" = "default" && test "x$LINUX_RPM_TARGET" != "x"; then dnl Red Hat stores configuration files for their built kernels dnl named kernel-(version)-(arch)(extra).config dnl where arch is athlon, i386, i586, i686, x86_64 dnl and (extra) is empty or -smp, -BOOT, -bigmem dnl haven't seen combinations of extra yet as of FC1 - version=`uname -r | cut -d- -f1` - machine=`uname -m` + KVERSION=`echo $KERNEL_RELEASE | cut -d- -f1` extra= - uname -r | grep smp && extra="-smp" - uname -r | grep bigmem && extra="-bigmem" - uname -r | grep BOOT && extra="-BOOT" - file="$LINUX_DIR/configs/kernel-$version-$machine$extra.config" - AS_TRY_CONFIG_FILE([${file}], [CONFIG_FILE=${file}], ) + echo $KERNEL_RELEASE | grep smp && EXTRA="-smp" + echo $KERNEL_RELEASE | grep bigmem && EXTRA="-bigmem" + echo $KERNEL_RELEASE | grep BOOT && EXTRA="-BOOT" + file="$LINUX_DIR/configs/kernel-$KVERSION-$LINUX_RPM_TARGET$EXTRA.config" + AS_TRY_LINUX_CONFIG($file, $MACHINE, + [LINUX_CONFIG=${file}], ) fi - if test "${CONFIG_FILE}" = "default" ; then + if test "${LINUX_CONFIG}" = "default" ; then AC_MSG_ERROR([ The kernel source tree at ${LINUX_DIR} is not configured, and no configuration files in config/ matching your kernel were found. -Fix before continuing or specify a config file using --with-linux-config.]) +Fix before continuing or specify a config file using --with-configfile.]) fi - AC_SUBST(CONFIG_FILE) + AC_SUBST(LINUX_CONFIG) ]) dnl check if the given candidate config file is usable -AC_DEFUN([AS_TRY_CONFIG_FILE], - [AC_MSG_CHECKING(for configuration in $1) +dnl FIXME: it would be nice if it could check if it matches the +dnl given machine (uname -m) +AC_DEFUN([AS_TRY_LINUX_CONFIG], +[ + CFG=[$1] + MACHINE=[$2] + AC_MSG_CHECKING($CFG) - if test -f "$1" ; then + if test -f "$CFG" ; then result=yes - $2 + ifelse([$3], , :, [$3]) else result="not found" - $3 + ifelse([$4], , :, [$4]) fi - AC_MSG_RESULT($result) ]) dnl check if RED_HAT_LINUX_KERNEL is defined -dnl RH/Fedora defines this in linux/rhconfig.h, included from linux/version.h +dnl pre-FC2 RH/Fedora defines this in linux/rhconfig.h +dnl included from linux/version.h dnl if this is present, a few extra defines need to be present to make sure dnl symbol versioning is correct dnl uses LINUX_DIR to find rhconfig.h -AC_DEFUN([AS_CHECK_REDHAT], +AC_DEFUN([AS_CHECK_REDHAT_PRE_FC2], [ - AC_MSG_CHECKING(Red Hat/Fedora kernel) + AC_MSG_CHECKING(Pre-FC2 Red Hat/Fedora kernel) HAVE_REDHAT_KERNEL=false ac_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux" @@ -185,7 +371,7 @@ int code = RED_HAT_LINUX_KERNEL; HUGEMEM='0' dnl get variables from the currently running kernel as default - KERNEL_TYPE=`uname -r | sed 's_^.*\(smp\|enterprise\|bigmem\|hugemem\)$_-\1_;t;s_.*__;'` + KERNEL_TYPE=`uname -r | sed 's_^.*\(smp\|enterprise\|bigmem\|hugemem\)$_\1_;t;s_.*__;'` KERNEL_RELEASE=`uname -r | sed 's|smp\|enterprise\|bigmem\|hugemem||g'` KERNEL_ARCH=`uname -m` @@ -198,18 +384,18 @@ int code = RED_HAT_LINUX_KERNEL; AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MK7, KERNEL_ARCH=athlon) dnl check the config file and override KERNEL_TYPE - AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_SMP, KERNEL_TYPE=-smp) + AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_SMP, KERNEL_TYPE=smp) dnl bigmem is also smp, so this check is done after smp to override - AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_HIGHMEM64G, KERNEL_TYPE=-bigmem) + AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_HIGHMEM64G, KERNEL_TYPE=bigmem) dnl FIXME: need to check hugemem and enterprise config files, which dnl aren't provided in Fedora Core 1 ! case "$KERNEL_TYPE" in - -smp) SMP='1';; - -enterprise) ENTERPRISE='1';; - -bigmem) BIGMEM='1';; - -hugemem) HUGEMEM='1';; + smp) SMP='1';; + enterprise) ENTERPRISE='1';; + bigmem) BIGMEM='1';; + hugemem) HUGEMEM='1';; *) UP='1';; esac REDHAT_CFLAGS="-D__MODULE_KERNEL_$KERNEL_ARCH=1" @@ -218,68 +404,48 @@ int code = RED_HAT_LINUX_KERNEL; REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_SMP=$SMP" REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_BIGMEM=$BIGMEM" REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_HUGEMEM=$HUGEMEM" -]) -dnl main entry point -dnl checks the version, and figures out all flags to use to make modules. -AC_DEFUN([AS_LINUX], -[ - AS_LINUX_DIR() - AS_CONFIG_FILE() - AS_CHECK_REDHAT() + LINUX_REDHAT_CFLAGS="$REDHAT_CFLAGS" - AC_MSG_CHECKING([Linux major/minor version]) + AC_SUBST(LINUX_KERNEL_TYPE, "$KERNEL_TYPE") +]) - if [[ ! -f "${LINUX_DIR}/include/linux/version.h" ]];then - AC_MSG_ERROR([The header file include/linux/version.h does not exist. -For 2.6 kernels, it can be generated by running 'make prepare' in -the kernel source directory.]) +dnl add an argument to specify/override the module install path +dnl if nothing specified, it will be /lib/modules/(kernelrel) +AC_DEFUN([AS_LINUX_MODULESDIR], +[ + KERNEL_RELEASE=[$1] + AC_ARG_WITH([modulesdir], + [AC_HELP_STRING([--with-modulesdir=DIR], + [specify path to kernel-specific modules install directory])], + [MODULESDIR="${withval}"], + [MODULESDIR=default]) + + if test "${MODULESDIR}" = "default" ; then + MODULESDIR="/lib/modules/${KERNEL_RELEASE}" fi - dnl the next set of tests is for figuring out version major/minor - dnl we make sure we have the right version.h by faking out CFLAGS - ac_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux" - dnl make sure we find version.h and it contains LINUX_VERSION_CODE - AC_COMPILE_IFELSE(AC_LANG_PROGRAM([ -#include "version.h" -int code = LINUX_VERSION_CODE; -]), - :, AC_MSG_ERROR([${LINUX_DIR}/include/linux/version.h does not contain LINUX_VERSION_CODE])) - - - dnl figure out the linux kernel version major and minor - dnl using the LINUX_VERSION_CODE defined in include/linux/version.h - AC_RUN_IFELSE(AC_LANG_PROGRAM([ -#include "version.h" -#define KERNEL_VERSION_MAJOR(code) ((code) >> 16) -],[ - return KERNEL_VERSION_MAJOR(LINUX_VERSION_CODE); -]), - LINUX_VERSION_MAJOR=0, - LINUX_VERSION_MAJOR=$?) - AC_RUN_IFELSE(AC_LANG_PROGRAM([ -#include "version.h" -#define KERNEL_VERSION_MINOR(code) (((code) >> 8) & 0xff) -],[ - return KERNEL_VERSION_MINOR(LINUX_VERSION_CODE); -]), - LINUX_VERSION_MINOR=0, - LINUX_VERSION_MINOR=$?) - AC_MSG_RESULT($LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR) - dnl restore CFLAGS - CFLAGS="$ac_save_CFLAGS" + dnl make it available to Makefiles so it can be used in ...dir + AC_SUBST(modulesdir, $MODULESDIR) + AC_MSG_NOTICE([Putting kernel modules under ${MODULESDIR}]) +]) - case $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR in - 2.6) - AS_LINUX_2_6() - ;; - 2.[[01234]]) - AS_LINUX_2_4() - ;; - *) - AC_MSG_ERROR([Unknown Linux major.minor $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR]) - ;; - esac +dnl add an argument to specify/override the module devel install path +dnl if nothing specified, it will be the passed in LINUXDIR) +AC_DEFUN([AS_LINUX_MODULESDEVELDIR], +[ + LINUXDIR=[$1] + AC_ARG_WITH([modulesdeveldir], + [AC_HELP_STRING([--with-modulesdeveldir=DIR], + [specify path to kernel-specific module development install directory])], + [MODULESDEVELDIR="${withval}"], + [MODULESDEVELDIR=default]) + + if test "${MODULESDEVELDIR}" = "default" ; then + MODULESDEVELDIR="${LINUXDIR}" + fi + dnl make it available to Makefiles so it can be used in ...dir + AC_SUBST(modulesdeveldir, $MODULESDEVELDIR) + AC_MSG_NOTICE([Putting kernel module development files under ${MODULESDEVELDIR}]) ]) AC_DEFUN([AS_LINUX_2_6], @@ -310,12 +476,12 @@ obj-m += fake.o .PHONY: flags flags: echo LINUX_ARCH=\"\$(ARCH)\" >>\$(obj)/flags - echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's_Iinclude_I"\$(LINUXDIR)/include"_g'>>\$(obj)/flags + echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's,include,"\$(LINUXDIR)/include",g'>>\$(obj)/flags echo LINUX_LDFLAGS=\"\" >>\$(obj)/flags echo LINUX_ARFLAGS=\"\$(ARFLAGS)\" >>\$(obj)/flags echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\" >>\$(obj)/flags echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\" >>\$(obj)/flags - echo LINUX_CFLAGS=\"\$(CFLAGS)\" | sed 's_Iinclude_I"\$(LINUXDIR)/include"_g'>>\$(obj)/flags + echo LINUX_CFLAGS=\"\$(CFLAGS) \$(CPPFLAGS)\" | sed 's,Iinclude,I\$(LINUXDIR)/include,g' >>\$(obj)/flags echo LINUX_CFLAGS_MODULE=\"\$(CFLAGS_MODULE)\" >>\$(obj)/flags echo LINUX_CC=\"\$(CC)\" >>\$(obj)/flags echo LINUX_LD=\"\$(LD) \$(LDFLAGS) \$(LDFLAGS_MODULE)\" >>\$(obj)/flags @@ -330,6 +496,7 @@ EOF LINUX_MODULE_EXT=".ko" LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_CFLAGS_MODULE" + LINUX_MODPOST="$LINUX_DIR/scripts/modpost" AC_SUBST(LINUX_ARCH) AC_SUBST(LINUX_AFLAGS) @@ -342,8 +509,9 @@ EOF AC_SUBST(LINUX_LD) AC_SUBST(LINUX_AS) AC_SUBST(LINUX_MODULE_EXT) + AC_SUBST(LINUX_MODPOST) - AC_MSG_RESULT([ok]) + AC_MSG_RESULT([$LINUX_CFLAGS]) ]) @@ -426,10 +594,10 @@ AC_DEFUN([AS_CHECK_LINUX_CONFIG_OPTION], [ AC_MSG_CHECKING([Linux config option $1]) - if grep '^$1=y$' ${CONFIG_FILE} >/dev/null 2>/dev/null; then + if grep '^$1=y$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then result=yes $2 - else if grep '^$1=m$' ${CONFIG_FILE} >/dev/null 2>/dev/null; then + else if grep '^$1=m$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then result=module $3 else @@ -461,3 +629,56 @@ AC_DEFUN([AS_LINUX_CONFIG_OPTION_MODULE], AM_CONDITIONAL([$1],[test "${$1}" = yes -o "${$1}" = module]) ]) +dnl check for the major/minor version of the Linux source by checking +dnl the headers +dnl first argument is the linux directory +dnl sets LINUX_VERSION_MAJOR and LINUX_VERSION_MINOR +AC_DEFUN([AS_LINUX_VERSION_MAJOR_MINOR], +[ + LINUX_DIR=[$1] + AC_MSG_CHECKING([Linux major/minor version]) + + if [[ ! -f "${LINUX_DIR}/include/linux/version.h" ]];then + AC_MSG_ERROR([The header file include/linux/version.h does not exist. +For 2.6 kernels, it can be generated by running 'make prepare' in +the kernel source directory.]) + fi + dnl the next set of tests is for figuring out version major/minor + dnl we make sure we have the right version.h by faking out CFLAGS + dnl since we want to avoid including linux/version.h and acidentally + dnl pick up /usr/include/linux + dnl we still add ${LINUX_DIR}/include so the Red Hat version can pick + dnl up linux/rhversion.h + ac_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux -I${LINUX_DIR}/include" + dnl make sure we find version.h and it contains LINUX_VERSION_CODE + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([ +#include "version.h" +int code = LINUX_VERSION_CODE; +]), + :, AC_MSG_ERROR([${LINUX_DIR}/include/linux/version.h does not contain LINUX_VERSION_CODE])) + + + dnl figure out the linux kernel version major and minor + dnl using the LINUX_VERSION_CODE defined in include/linux/version.h + AC_RUN_IFELSE(AC_LANG_PROGRAM([ +#include "version.h" +#define KERNEL_VERSION_MAJOR(code) ((code) >> 16) +],[ + return KERNEL_VERSION_MAJOR(LINUX_VERSION_CODE); +]), + LINUX_VERSION_MAJOR=0, + LINUX_VERSION_MAJOR=$?) + AC_RUN_IFELSE(AC_LANG_PROGRAM([ +#include "version.h" +#define KERNEL_VERSION_MINOR(code) (((code) >> 8) % (2 << 8)) +],[ + return KERNEL_VERSION_MINOR(LINUX_VERSION_CODE); +]), + LINUX_VERSION_MINOR=0, + LINUX_VERSION_MINOR=$?) + AC_MSG_RESULT($LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR) + dnl restore CFLAGS + CFLAGS="$ac_save_CFLAGS" +]) + diff --git a/m4/as-modtool.m4 b/m4/as-modtool.m4 index 8ea64558..9c417b49 100644 --- a/m4/as-modtool.m4 +++ b/m4/as-modtool.m4 @@ -1,11 +1,13 @@ dnl as-modtool.m4 0.0.1 dnl autostars m4 macro for building modtool, a linker for Linux kernel dnl modules -dnl + dnl David Schleef dnl Frank Mori Hess -dnl thomas@apestaart.org -dnl +dnl Thomas Vander Stichele + +dnl $Id$ + dnl AS_LINUX_MODTOOL() dnl dnl this macro defines: @@ -21,11 +23,18 @@ dnl How do you specify that the building of modtool should go to the dnl end of the configure script? dnl +dnl SYMVERS_INCLUDES can be used to add additional .symvers files to the +dnl modpost step + AC_DEFUN([AS_LINUX_MODTOOL], [ - #AS_LINUX() + AC_PATH_PROG(STRIP, strip) + AC_PATH_PROG([DEPMOD], [depmod], [no], [$PATH:/sbin:/usr/sbin:/usr/local/sbin]) - moduledir="\$(libdir)/modules/\$(LINUX_KERNELRELEASE)/comedi" + dnl this can be overridden in Makefile.am + dnl FIXME: it'd be nice if we could specify different target_PROGRAMS + dnl and different targetdir + moduledir="\$(modulesdir)/\$(PACKAGE)" modulePROGRAMS_INSTALL="\$(top_builddir)/modtool --install" modulePROGRAMS_UNINSTALL="\$(top_builddir)/modtool --uninstall" AC_SUBST(moduledir) @@ -35,19 +44,74 @@ AC_DEFUN([AS_LINUX_MODTOOL], cat >modtool <.mods/symvers.tmp" + cat \$LINUX_DIR/Module.symvers \$SYMVERS_INCLUDES >.mods/symvers.tmp + + echo "\$LINUX_MODPOST -o .mods/\$target.o.symvers.tmp -i .mods/symvers.tmp \$target.o" + \$LINUX_MODPOST -o .mods/\$target.o.symvers.tmp -i .mods/symvers.tmp .mods/\$target.o + + echo "grep .mods/\$target .mods/\$target.o.symvers.tmp >.mods/\$target.o.symvers || true" + grep .mods/\$target .mods/\$target.o.symvers.tmp >.mods/\$target.o.symvers || true + + echo "rm -f .mods/\$target.o.symvers.tmp .mods/symvers.tmp" + rm -f .mods/\$target.o.symvers.tmp .mods/symvers.tmp + + echo \$CC \$CFLAGS -DKBUILD_MODNAME=\$target -c -o .mods/\$target.mod.o .mods/\$target.mod.c + \$CC \$CFLAGS -DKBUILD_MODNAME=\$target -c -o .mods/\$target.mod.o .mods/\$target.mod.c + + echo \$LINUX_LD -r -o \$target.ko .mods/\$target.mod.o .mods/\$target.o + \$LINUX_LD -r -o \$target.ko .mods/\$target.mod.o .mods/\$target.o + set +x + else + echo \$LINUX_LD -r -o \$target.ko \$[*] + \$LINUX_LD -r -o \$target.ko \$[*] + fi + ;; --install) module_src=\$[1] @@ -70,6 +134,7 @@ esac EOF chmod +x modtool + ]) -- 2.26.2