3 dnl autostars m4 macro for detecting a Linux source tree (or
4 dnl equivalent) for compiling modules.
6 dnl David Schleef <ds@schleef.org>
7 dnl Frank Mori Hess <fmhess@users.sourceforge.net>
8 dnl Thomas Vander Stichele <thomas@apestaart.org>
14 dnl this macro adds the options
15 dnl --with-linuxdir to specify a kernel build tree location
16 dnl --with-linuxconfig to specify a kernel .config file
17 dnl --with-kernel-release to specify an alternative uname -r
18 dnl --with-machine to specify an alternative uname -m
19 dnl --with-rpm-target to specify to match the given rpm --target option
20 dnl --with-extraversion to specify an EXTRAVERSION override
21 dnl --with-modulesdir to specify the base install location of modules
22 dnl --with-modulesdeveldir to specify the base install location of build stuff
24 dnl this macro defines:
26 dnl The directory where the Linux source resides.
28 dnl The Linux config file
30 dnl $(ARCH) in kernel Makefiles
32 dnl $(AFLAGS) in kernel Makefiles
34 dnl Linker flags used by Linux
36 dnl Archiver flags used by Linux
37 dnl LINUX_CROSS_COMPILE
38 dnl Cross-compiler prefix, if any. (example: "powerpc-linux-")
39 dnl LINUX_KERNELRELEASE
40 dnl Kernel release name (2.4.5-pre4-ac5-rmk), $(KERNELRELEASE) in
43 dnl CFLAGS used by Linux. Includes both $CFLAGS and $MODFLAGS from
44 dnl kernel Makefiles. Also includes warnings and optimization.
46 dnl Compiler used by Linux.
48 dnl Path to linker (possibly with options) used by Linux.
50 dnl Assembler used by Linux.
51 dnl LINUX_MODULE_STYLE
52 dnl Style of module building (2.4.0, 2.6.0, 2.6.6)
54 dnl Module extension (.o or .ko)
56 dnl path to modpost script
58 dnl base install path for kernel modules
60 dnl base install path for kernel module development files
62 dnl End of search list.
65 dnl checks the version, and figures out all flags to use to make modules.
68 dnl check if user supplied a uname -r, and if not use the running one
69 AS_LINUX_KERNEL_RELEASE()
70 dnl check if user supplied a uname -m, and if not use the running one
72 dnl check if the user supplied an rpm target arch
73 dnl override the LINUX_MACHINE value if he did
76 dnl find the kernel source tree for the given uname -r
78 dnl check if user supplied an EXTRAVERSION, and if not get from uname -r
79 AS_LINUX_EXTRAVERSION($LINUX_KERNEL_RELEASE)
80 dnl check if user supplied a config file; if not, guess a good one
81 AS_LINUX_CONFIG($LINUX_DIR, $LINUX_KERNEL_RELEASE, $LINUX_MACHINE)
82 dnl check if we're building on pre-FC2 Red Hat/Fedora,
83 dnl and add some flags if we are
84 AS_CHECK_REDHAT_PRE_FC2()
85 dnl check for where to install modules
86 AS_LINUX_MODULESDIR($LINUX_KERNEL_RELEASE)
87 dnl check for where to install module development files
88 AS_LINUX_MODULESDEVELDIR($LINUX_DIR)
89 dnl check for the MAJOR/MINOR version of Linux
90 AS_LINUX_VERSION_MAJOR_MINOR($LINUX_DIR)
92 dnl now call the correct macro to get compiler flags
93 dnl the versioned AS_LINUX macros just use the global variables
94 dnl this could be cleaned up later on if we feel like it
95 case $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR in
103 AC_MSG_ERROR([Unknown Linux major.minor $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR])
109 dnl check if we can find a source dir for the Linux kernel
110 dnl defines LINUX_DIR to the absolute location of a usable kernel source tree
111 AC_DEFUN([AS_LINUX_DIR],
113 AC_ARG_WITH([linuxdir],
114 [AC_HELP_STRING([--with-linuxdir=DIR],
115 [specify path to Linux source directory])],
116 [LINUX_DIR="${withval}"],
119 if test "${LINUX_DIR}" != "default" ; then
120 AS_TRY_LINUX_DIR([${LINUX_DIR}], , AC_MSG_ERROR([Linux dir not found]) )
123 if test "${LINUX_DIR}" = "default" ; then
124 dir="/lib/modules/$LINUX_KERNEL_RELEASE/build";
125 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
127 if test "${LINUX_DIR}" = "default" ; then
129 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
131 if test "${LINUX_DIR}" = "default" ; then
132 dir="/usr/src/linux";
133 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
136 if test "${LINUX_DIR}" = "default" ; then
137 AC_MSG_ERROR([Linux source directory not found])
143 dnl check if the given candidate path for a linux source tree is usable
144 AC_DEFUN([AS_TRY_LINUX_DIR],
145 [AC_MSG_CHECKING(for Linux in $1)
147 if test -f "$1/Makefile" ; then
155 AC_MSG_RESULT($result)
158 dnl allow for specifying a kernel release (uname -r) to build for
159 dnl use uname -r of running one if not specified
160 dnl store result in LINUX_KERNEL_RELEASE
161 AC_DEFUN([AS_LINUX_KERNEL_RELEASE],
163 AC_ARG_WITH([kernel-release],
164 [AC_HELP_STRING([--with-kernel-release=RELEASE],
165 [specify the "uname -r"-value to build for])],
166 [LINUX_KERNEL_RELEASE="${withval}"],
167 [LINUX_KERNEL_RELEASE=`uname -r`])
168 if test "x$LINUX_KERNEL_RELEASE" = "xyes";
170 LINUX_KERNEL_RELEASE=`uname -r`
172 AC_MSG_NOTICE([Using $LINUX_KERNEL_RELEASE as the uname -r value])
175 dnl allow for specifying a machine (uname -m) to build for
176 dnl use uname -, of running one if not specified
177 dnl store result in LINUX_MACHINE
178 AC_DEFUN([AS_LINUX_MACHINE],
180 AC_ARG_WITH([machine],
181 [AC_HELP_STRING([--with-machine=MACHINE],
182 [specify the "uname -m"-value to build for])],
183 [LINUX_MACHINE="${withval}"],
184 [LINUX_MACHINE=`uname -m`])
185 if test "x$LINUX_MACHINE" = "xyes";
187 LINUX_MACHINE=`uname -r`
189 AC_MSG_NOTICE([Using $LINUX_MACHINE as the uname -m value])
191 dnl allow for specifying an rpm target arch
192 dnl if none specified, try to guess one from running rpm querying for
193 dnl the kernel with the uname -r
194 dnl this is so configure without arguments works out of the box
195 dnl FIXME: investigate if uname -p is a correct guess for this, and if
196 dnl we should have a flag for specifying it instead
198 dnl this macro possibly overrides LINUX_MACHINE
200 dnl first argument is the kernel release building for
201 AC_DEFUN([AS_LINUX_RPM_TARGET],
203 RELEASE=$LINUX_KERNEL_RELEASE
204 AC_ARG_WITH([rpm-target],
205 [AC_HELP_STRING([--with-rpm-target=TARGET],
206 [specify the target arch to build for])],
207 [LINUX_RPM_TARGET="${withval}"],
209 if test "x$LINUX_RPM_TARGET" = "x"
211 dnl if we have rpm, try to guess the target of the kernel
212 dnl we want to build for using rpm
213 AC_PATH_PROG([RPM], [rpm], [no])
214 if test "x$RPM" != "xno" ; then
215 if $RPM -q kernel-$RELEASE > /dev/null
217 LINUX_RPM_TARGET=`$RPM -q --queryformat %{arch} kernel-$RELEASE`
219 AC_MSG_NOTICE([Cannot guess target arch, consider setting it using --with-rpm-target])
224 dnl now override LINUX_MACHINE if LINUX_RPM_TARGET is set
225 if test "x$LINUX_RPM_TARGET" != "x"
227 dnl override LINUX_MACHINE based on this
228 dnl FIXME: add other possible Red Hat/Fedora/rpm targets here
230 case "$LINUX_RPM_TARGET" in
231 i?86) LINUX_MACHINE=i386;;
232 athlon) LINUX_MACHINE=i386;;
233 x86_64) LINUX_MACHINE=x86_64;;
235 if test "x$LINUX_MACHINE" = "x"
237 AC_MSG_ERROR(Could not guess uname -m value from target $LINUX_RPM_TARGET)
243 dnl allow for specifying an override for EXTRAVERSION
244 dnl if none specified, make it from the passed-in KERNEL_RELEASE (uname -r)
245 dnl resulting value is stored in LINUX_EXTRAVERSION
246 dnl first argument is the uname -r string to use as a fallback
247 AC_DEFUN([AS_LINUX_EXTRAVERSION],
250 dnl extract the default by getting everything after first -
251 LINUX_EXTRAVERSION="-`echo $KERNEL_RELEASE | cut -d- -f 2-`"
252 AC_ARG_WITH([extraversion],
253 [AC_HELP_STRING([--with-extraversion=FILE],
254 [specify override for kernel EXTRAVERSION])],
255 [LINUX_EXTRAVERSION="${withval}"],)
259 dnl check if we can find a config file for the Linux kernel
260 dnl defines LINUX_CONFIG to the absolute location of a usable
261 dnl kernel source config file
263 dnl for rpm distros, it can try and guess the correct config file by
264 dnl checking the global LINUX_RPM_TARGET variable set somewhere else
265 dnl (FIXME: move this to an argument instead ?)
267 dnl first argument is LINUX_DIR to check for possible configs
268 dnl second argument is kernel-release (uname -r)
269 dnl third argument is machine (uname -m)
271 AC_DEFUN([AS_LINUX_CONFIG],
276 AC_ARG_WITH([linuxconfig],
277 [AC_HELP_STRING([--with-linuxconfig=FILE],
278 [specify path to Linux configuration file])],
279 [LINUX_CONFIG="${withval}"],
280 [LINUX_CONFIG=default])
282 dnl if a file got specified, try it as a linux config file
283 if test "${LINUX_CONFIG}" != "default" ; then
284 AS_TRY_LINUX_CONFIG($LINUX_CONFIG, $MACHINE,
285 ,, AC_MSG_ERROR([Linux config not found]) )
288 dnl if no file specified, first check for the regular .config file
289 dnl in LINUX_DIR created by manual configuration
290 if test "${LINUX_CONFIG}" = "default" ; then
291 file="$LINUX_DIR/.config";
292 AS_TRY_LINUX_CONFIG($file, $MACHINE,
293 [LINUX_CONFIG=${file}], )
295 dnl second, try to guess what config file to use for the current kernel
296 dnl FIXME: the possible arch is from rpmbuild --target, and is
297 dnl different from the value of ARCH (Makefile) or MACHINE (uname -m)
298 dnl so we should have a redhat flag to specify the target to find
299 dnl the correct config file
300 if test "${LINUX_CONFIG}" = "default" && test "x$LINUX_RPM_TARGET" != "x"; then
301 dnl Red Hat stores configuration files for their built kernels
302 dnl named kernel-(version)-(arch)(extra).config
303 dnl where arch is athlon, i386, i586, i686, x86_64
304 dnl and (extra) is empty or -smp, -BOOT, -bigmem
305 dnl haven't seen combinations of extra yet as of FC1
306 KVERSION=`echo $KERNEL_RELEASE | cut -d- -f1`
308 echo $KERNEL_RELEASE | grep smp && EXTRA="-smp"
309 echo $KERNEL_RELEASE | grep bigmem && EXTRA="-bigmem"
310 echo $KERNEL_RELEASE | grep BOOT && EXTRA="-BOOT"
311 file="$LINUX_DIR/configs/kernel-$KVERSION-$LINUX_RPM_TARGET$EXTRA.config"
312 AS_TRY_LINUX_CONFIG($file, $MACHINE,
313 [LINUX_CONFIG=${file}], )
315 if test "${LINUX_CONFIG}" = "default" ; then
317 The kernel source tree at ${LINUX_DIR} is not configured,
318 and no configuration files in config/ matching your kernel were found.
319 Fix before continuing or specify a config file using --with-configfile.])
322 AC_SUBST(LINUX_CONFIG)
325 dnl check if the given candidate config file is usable
326 dnl FIXME: it would be nice if it could check if it matches the
327 dnl given machine (uname -m)
328 AC_DEFUN([AS_TRY_LINUX_CONFIG],
332 AC_MSG_CHECKING($CFG)
334 if test -f "$CFG" ; then
336 ifelse([$3], , :, [$3])
339 ifelse([$4], , :, [$4])
341 AC_MSG_RESULT($result)
344 dnl check if RED_HAT_LINUX_KERNEL is defined
345 dnl pre-FC2 RH/Fedora defines this in linux/rhconfig.h
346 dnl included from linux/version.h
347 dnl if this is present, a few extra defines need to be present to make sure
348 dnl symbol versioning is correct
349 dnl uses LINUX_DIR to find rhconfig.h
350 AC_DEFUN([AS_CHECK_REDHAT_PRE_FC2],
352 AC_MSG_CHECKING(Pre-FC2 Red Hat/Fedora kernel)
353 HAVE_REDHAT_KERNEL=false
354 ac_save_CFLAGS="$CFLAGS"
355 CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux"
356 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
357 #include "rhconfig.h"
358 int code = RED_HAT_LINUX_KERNEL;
360 AC_MSG_RESULT(found); HAVE_REDHAT_KERNEL=true,
361 AC_MSG_RESULT(not found))
363 CFLAGS="$ac_save_CFLAGS"
365 dnl check for Red Hat define flags to use - see /sbin/mkkerneldoth
367 dnl initialize the booleans we want to detect
374 dnl get variables from the currently running kernel as default
375 KERNEL_TYPE=`uname -r | sed 's_^.*\(smp\|enterprise\|bigmem\|hugemem\)$_\1_;t;s_.*__;'`
376 KERNEL_RELEASE=`uname -r | sed 's|smp\|enterprise\|bigmem\|hugemem||g'`
377 KERNEL_ARCH=`uname -m`
379 dnl check the config file and override KERNEL_ARCH
380 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M386, KERNEL_ARCH=i386)
381 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M586, KERNEL_ARCH=i586)
382 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M686, KERNEL_ARCH=i686)
383 dnl for some reason the i686 bigmem config file has PENTIUM
384 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MPENTIUMIII, KERNEL_ARCH=i686)
385 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MK7, KERNEL_ARCH=athlon)
387 dnl check the config file and override KERNEL_TYPE
388 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_SMP, KERNEL_TYPE=smp)
389 dnl bigmem is also smp, so this check is done after smp to override
390 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_HIGHMEM64G, KERNEL_TYPE=bigmem)
392 dnl FIXME: need to check hugemem and enterprise config files, which
393 dnl aren't provided in Fedora Core 1 !
395 case "$KERNEL_TYPE" in
397 enterprise) ENTERPRISE='1';;
399 hugemem) HUGEMEM='1';;
402 REDHAT_CFLAGS="-D__MODULE_KERNEL_$KERNEL_ARCH=1"
403 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_ENTERPRISE=$ENTERPRISE"
404 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_UP=$UP"
405 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_SMP=$SMP"
406 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_BIGMEM=$BIGMEM"
407 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_HUGEMEM=$HUGEMEM"
409 LINUX_REDHAT_CFLAGS="$REDHAT_CFLAGS"
411 AC_SUBST(LINUX_KERNEL_TYPE, "$KERNEL_TYPE")
414 dnl add an argument to specify/override the module install path
415 dnl if nothing specified, it will be /lib/modules/(kernelrel)
416 AC_DEFUN([AS_LINUX_MODULESDIR],
419 AC_ARG_WITH([modulesdir],
420 [AC_HELP_STRING([--with-modulesdir=DIR],
421 [specify path to kernel-specific modules install directory])],
422 [MODULESDIR="${withval}"],
423 [MODULESDIR=default])
425 if test "${MODULESDIR}" = "default" ; then
426 MODULESDIR="/lib/modules/${KERNEL_RELEASE}"
428 dnl make it available to Makefiles so it can be used in ...dir
429 AC_SUBST(modulesdir, $MODULESDIR)
430 AC_MSG_NOTICE([Putting kernel modules under ${MODULESDIR}])
433 dnl add an argument to specify/override the module devel install path
434 dnl if nothing specified, it will be the passed in LINUXDIR)
435 AC_DEFUN([AS_LINUX_MODULESDEVELDIR],
438 AC_ARG_WITH([modulesdeveldir],
439 [AC_HELP_STRING([--with-modulesdeveldir=DIR],
440 [specify path to kernel-specific module development install directory])],
441 [MODULESDEVELDIR="${withval}"],
442 [MODULESDEVELDIR=default])
444 if test "${MODULESDEVELDIR}" = "default" ; then
445 MODULESDEVELDIR="${LINUXDIR}"
447 dnl make it available to Makefiles so it can be used in ...dir
448 AC_SUBST(modulesdeveldir, $MODULESDEVELDIR)
449 AC_MSG_NOTICE([Putting kernel module development files under ${MODULESDEVELDIR}])
452 AC_DEFUN([AS_LINUX_2_6],
454 AC_MSG_CHECKING(for Linux CFLAGS)
457 tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
458 test -n "$tmpdir" && test -d "$tmpdir"
461 tmpdir=./confstat$$-$RANDOM
462 (umask 077 && mkdir $tmpdir)
465 echo "$me: cannot create a temporary directory in ." >&2
466 { (exit 1); exit 1; }
471 cat >${tmpdir}/Makefile <<EOF
474 \$(obj)/fake.c: flags
479 echo LINUX_ARCH=\"\$(ARCH)\" >>\$(obj)/flags
480 echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's,include,"\$(LINUXDIR)/include",g'>>\$(obj)/flags
481 echo LINUX_LDFLAGS=\"\" >>\$(obj)/flags
482 echo LINUX_ARFLAGS=\"\$(ARFLAGS)\" >>\$(obj)/flags
483 echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\" >>\$(obj)/flags
484 echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\" >>\$(obj)/flags
485 echo LINUX_CFLAGS=\"\$(CFLAGS) \$(CPPFLAGS)\" \
486 | sed -e 's,-Iinclude,-I\$(LINUXDIR)/include,g' -e 's,-include include,-include \$(LINUXDIR)/include,g' >>\$(obj)/flags
487 echo LINUX_CFLAGS_MODULE=\"\$(CFLAGS_MODULE)\" >>\$(obj)/flags
488 echo LINUX_CC=\"\$(CC)\" >>\$(obj)/flags
489 echo LINUX_LD=\"\$(LD) \$(LDFLAGS) \$(LDFLAGS_MODULE)\" >>\$(obj)/flags
490 echo LINUX_AS=\"\$(AS)\" >>\$(obj)/flags
493 echo ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
494 ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
498 LINUX_MODULE_EXT=".ko"
499 LINUX_MODULE_STYLE="2.6.6"
501 LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_CFLAGS_MODULE"
504 AC_SUBST(LINUX_AFLAGS)
505 AC_SUBST(LINUX_LDFLAGS)
506 AC_SUBST(LINUX_ARFLAGS)
507 AC_SUBST(LINUX_CROSS_COMPILE)
508 AC_SUBST(LINUX_KERNELRELEASE)
509 AC_SUBST(LINUX_CFLAGS)
513 AC_SUBST(LINUX_MODULE_EXT)
514 AC_SUBST(LINUX_MODULE_STYLE)
515 AC_SUBST(LINUX_MODPOST)
517 AC_MSG_RESULT([$LINUX_CFLAGS])
519 AC_PATH_PROG([LINUX_MODPOST], ["modpost"], ["no"], ["$LINUX_DIR/scripts:$LINUX_DIR/scripts/mod"])
523 AC_DEFUN([AS_LINUX_2_4],
525 AC_MSG_CHECKING(for Linux 2.4 make flags)
526 dnl we try to figure out the CFLAGS by invoking the Makefile on
528 dnl we use the correct config file by substituting the MAKEFILES
529 dnl Makefile variable, which originally points to .config
531 if [[ ! -e "${LINUX_DIR}/.hdepend" ]];then
533 No .hdepend file found, you may need to run 'make dep' on the kernel source before continuing.])
537 tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
538 test -n "$tmpdir" && test -d "$tmpdir"
541 tmpdir=./confstat$$-$RANDOM
542 (umask 077 && mkdir $tmpdir)
545 echo "$me: cannot create a temporary directory in ." >&2
546 { (exit 1); exit 1; }
550 #sed "s|\.config|${CONFIG_FILE}|g" ${LINUX_DIR}/Makefile >$tmpdir/Makefile
551 cat >$tmpdir/Makefile <<EOF
553 @echo LINUX_ARCH=\"\$(ARCH)\"
554 @echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
555 @echo LINUX_LDFLAGS=\"\"
556 @echo LINUX_ARFLAGS=\"\$(ARFLAGS)\"
557 @echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\"
558 @echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\"
559 @echo LINUX_CFLAGS=\"\$(CFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
560 @echo LINUX_MODFLAGS=\"\$(MODFLAGS)\"
561 @echo LINUX_CC=\"\$(CC)\"
562 @echo LINUX_LD=\"\$(LD) \$(LDFLAGS)\"
563 @echo LINUX_AS=\"\$(AS)\"
565 make -C ${LINUX_DIR} SUBDIRS=${tmpdir} modules | grep ^LINUX_ >${tmpdir}/ack
567 echo make modules with LINUX_DIR=$(LINUX_DIR) failed.
573 LINUX_MODULE_EXT=".o"
574 LINUX_MODULE_STYLE="2.4.0"
576 LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_MODFLAGS"
578 dnl if we have REDHAT_CFLAGS, put them in LINUX_CFLAGS
579 if test "x$REDHAT_CFLAGS" != "x";
581 LINUX_CFLAGS="$LINUX_CFLAGS $REDHAT_CFLAGS"
584 AC_SUBST(LINUX_AFLAGS)
585 AC_SUBST(LINUX_LDFLAGS)
586 AC_SUBST(LINUX_ARFLAGS)
587 AC_SUBST(LINUX_CROSS_COMPILE)
588 AC_SUBST(LINUX_KERNELRELEASE)
589 AC_SUBST(LINUX_CFLAGS)
593 AC_SUBST(LINUX_MODULE_EXT)
594 AC_SUBST(LINUX_MODULE_STYLE)
598 AC_MSG_CHECKING(for Linux 2.4 CFLAGS)
599 AC_MSG_RESULT($LINUX_CFLAGS)
600 AC_MSG_CHECKING(for Linux 2.4 LDFLAGS)
601 AC_MSG_RESULT($LINUX_LDFLAGS)
604 AC_DEFUN([AS_CHECK_LINUX_CONFIG_OPTION],
606 AC_MSG_CHECKING([Linux config option $1])
608 if grep '^$1=y$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
611 else if grep '^$1=m$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
620 AC_MSG_RESULT([$result])
623 AC_DEFUN([AS_LINUX_CONFIG_OPTION],
625 AS_CHECK_LINUX_CONFIG_OPTION([$1],
630 AM_CONDITIONAL([$1],[test "${$1}" = yes])
633 AC_DEFUN([AS_LINUX_CONFIG_OPTION_MODULE],
635 AS_CHECK_LINUX_CONFIG_OPTION([$1],
640 AM_CONDITIONAL([$1],[test "${$1}" = yes -o "${$1}" = module])
643 dnl check for the major/minor version of the Linux source by checking
645 dnl first argument is the linux directory
646 dnl sets LINUX_VERSION_MAJOR and LINUX_VERSION_MINOR
647 AC_DEFUN([AS_LINUX_VERSION_MAJOR_MINOR],
650 AC_MSG_CHECKING([Linux major/minor version])
652 if [[ ! -f "${LINUX_DIR}/Makefile" ]];then
653 AC_MSG_ERROR([The Linux kernel Makefile does not exist.])
655 dnl the next set of tests is for figuring out version major/minor
656 dnl use VERSION and PATCHLEVEL in the kernel Makefile
657 LINUX_VERSION_MAJOR=`sed -n 's/^VERSION = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
658 LINUX_VERSION_MINOR=`sed -n 's/^PATCHLEVEL = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
659 if [[ -z "$LINUX_VERSION_MAJOR" -o -z "$LINUX_VERSION_MINOR" ]]; then
660 AC_MSG_ERROR([No major/minor version information found in Linux kernel Makefile.])
662 AC_MSG_RESULT($LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR)
665 # COMEDI_CHECK_LINUX_KBUILD([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
666 # -------------------------------------------------------------
668 # Check if kernel source tree is recent enough to support "Kbuild" files.
669 AC_DEFUN([COMEDI_CHECK_LINUX_KBUILD],
671 AC_MSG_CHECKING([for Kbuild support in $1])
672 dnl For combined kernel source and build directory,
673 dnl if $1/scripts/Makefile.build refers to $(<something>)/Kbuild
674 dnl then we support Kbuild (2.6.10 onwards).
675 dnl For separate kernel source and build directory, if $1/Makefile
676 dnl contains KERNELOUTPUT variable then this is from a separate
677 dnl kernel build directory, so Kbuild is required
678 dnl (but it will not work prior to 2.6.10).
679 if grep -q '/Kbuild' "$1/scripts/Makefile.build" 2>/dev/null; then
682 else if grep -q '^KERNELOUTPUT *:=' "$1/Makefile" 2>/dev/null; then
692 # COMEDI_CHECK_PCMCIA_PROBE([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
693 # -------------------------------------------------------------
695 # Check if kernel pcmcia support is new enough to have a probe member in the pcmcia_driver
697 AC_DEFUN([COMEDI_CHECK_PCMCIA_PROBE],
699 AC_REQUIRE([AC_PROG_EGREP])
700 AC_MSG_CHECKING([$1 for probe in pcmcia_driver struct])
701 cat "$1/include/pcmcia/ds.h" | tr \\n ' ' | [$EGREP "struct[[:space:]]+pcmcia_driver[[:space:]]*[{][^}]*probe"] > /dev/null