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-linuxsrcdir to specify a kernel source tree location
17 dnl --with-linuxconfig to specify a kernel .config file
18 dnl --with-kernel-release to specify an alternative uname -r
19 dnl --with-machine to specify an alternative uname -m
20 dnl --with-rpm-target to specify to match the given rpm --target option
21 dnl --with-extraversion to specify an EXTRAVERSION override
22 dnl --with-modulesdir to specify the base install location of modules
23 dnl --with-modulesdeveldir to specify the base install location of build stuff
25 dnl this macro defines:
27 dnl The directory where the Linux build tree resides.
29 dnl The directory where the Linux source tree resides.
31 dnl The Linux config file
33 dnl $(ARCH) in kernel Makefiles
35 dnl $(AFLAGS) in kernel Makefiles
37 dnl Linker flags used by Linux
39 dnl Archiver flags used by Linux
40 dnl LINUX_CROSS_COMPILE
41 dnl Cross-compiler prefix, if any. (example: "powerpc-linux-")
42 dnl LINUX_KERNELRELEASE
43 dnl Kernel release name (2.4.5-pre4-ac5-rmk), $(KERNELRELEASE) in
46 dnl CFLAGS used by Linux. Includes both $CFLAGS and $MODFLAGS from
47 dnl kernel Makefiles. Also includes warnings and optimization.
49 dnl Compiler used by Linux.
51 dnl Path to linker (possibly with options) used by Linux.
53 dnl Assembler used by Linux.
54 dnl LINUX_MODULE_STYLE
55 dnl Style of module building (2.4.0, 2.6.0, 2.6.6)
57 dnl Module extension (.o or .ko)
59 dnl path to modpost script
61 dnl base install path for kernel modules
63 dnl base install path for kernel module development files
65 dnl End of search list.
68 dnl checks the version, and figures out all flags to use to make modules.
71 dnl check if user supplied a uname -r, and if not use the running one
72 AS_LINUX_KERNEL_RELEASE()
73 dnl check if user supplied a uname -m, and if not use the running one
75 dnl check if the user supplied an rpm target arch
76 dnl override the LINUX_MACHINE value if he did
79 dnl find the kernel build tree for the given uname -r
81 dnl override kernel release uname -r value with info from build tree
82 AS_LINUX_OVERRIDE_KERNEL_RELEASE($LINUX_DIR)
83 dnl find the kernel source tree from the build tree or --with-linuxsrcdir
84 AS_LINUX_SRC_DIR($LINUX_DIR)
85 dnl check if user supplied an EXTRAVERSION, and if not get from uname -r
86 AS_LINUX_EXTRAVERSION($LINUX_KERNEL_RELEASE)
87 dnl check if user supplied a config file; if not, guess a good one
88 AS_LINUX_CONFIG($LINUX_DIR, $LINUX_KERNEL_RELEASE, $LINUX_MACHINE)
89 dnl check if we're building on pre-FC2 Red Hat/Fedora,
90 dnl and add some flags if we are
91 AS_CHECK_REDHAT_PRE_FC2()
92 dnl check for where to install modules
93 AS_LINUX_MODULESDIR($LINUX_KERNEL_RELEASE)
94 dnl check for where to install module development files
95 AS_LINUX_MODULESDEVELDIR($LINUX_DIR)
96 dnl check for the MAJOR/MINOR version of Linux
97 AS_LINUX_VERSION_MAJOR_MINOR($LINUX_DIR)
99 dnl now call the correct macro to get compiler flags
100 dnl the versioned AS_LINUX macros just use the global variables
101 dnl this could be cleaned up later on if we feel like it
102 case $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR in
110 AC_MSG_ERROR([Unknown Linux major.minor $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR])
116 dnl check if we can find a build dir for the Linux kernel
117 dnl defines LINUX_DIR to the absolute location of a usable kernel build tree
118 AC_DEFUN([AS_LINUX_DIR],
120 AC_ARG_WITH([linuxdir],
121 [AC_HELP_STRING([--with-linuxdir=DIR],
122 [specify path to Linux build directory])],
123 [LINUX_DIR="${withval}"],
126 if test "${LINUX_DIR}" != "default" ; then
127 AS_TRY_LINUX_DIR([${LINUX_DIR}], , AC_MSG_ERROR([Linux build dir not found]) )
130 if test "${LINUX_DIR}" = "default" ; then
131 dir="/lib/modules/$LINUX_KERNEL_RELEASE/build";
132 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
134 if test "${LINUX_DIR}" = "default" ; then
136 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
138 if test "${LINUX_DIR}" = "default" ; then
139 dir="/usr/src/linux";
140 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
143 if test "${LINUX_DIR}" = "default" ; then
144 AC_MSG_ERROR([Linux build directory not found])
150 dnl check if the given candidate path for a linux build tree is usable
151 AC_DEFUN([AS_TRY_LINUX_DIR],
152 [AC_MSG_CHECKING(for Linux build in $1)
154 if test -f "$1/Makefile" ; then
162 AC_MSG_RESULT($result)
165 dnl get the kernel source directory
166 dnl $1 is the kernel build directory
167 dnl defines LINUX_SRC_DIR to the absolute location of kernel source tree
168 AC_DEFUN([AS_LINUX_SRC_DIR],
170 AC_ARG_WITH([linuxsrcdir],
171 [AC_HELP_STRING([--with-linuxsrcdir=DIR],
172 [specify path to Linux source directory])],
173 [LINUX_SRC_DIR="${withval}"],
174 [LINUX_SRC_DIR=default])
176 if test "${LINUX_SRC_DIR}" != "default" ; then
177 AS_TRY_LINUX_SRC_DIR([${LINUX_SRC_DIR}], , AC_MSG_ERROR([Linux source dir not found]) )
180 if test "${LINUX_SRC_DIR}" = "default" ; then
181 AC_MSG_CHECKING(for separate Linux source and build directory)
182 dir=`sed -n -e 's/^KERNELSRC *:= *\(.*\)/\1/p' "$1/Makefile"`
183 if test -z "$dir"; then
185 dir=`sed -n -e 's/^MAKEARGS *:= *-C *\([[^[:space:]]]*\).*/\1/p' "$1/Makefile"`
187 if test -z "$dir"; then
195 AS_TRY_LINUX_SRC_DIR([${dir}], [LINUX_SRC_DIR=${dir}], )
199 if test "${LINUX_SRC_DIR}" = "default" ; then
200 AC_MSG_ERROR([Linux source directory not found])
203 AC_SUBST(LINUX_SRC_DIR)
206 dnl check if the given candidate path for a linux source tree is usable
207 AC_DEFUN([AS_TRY_LINUX_SRC_DIR],
208 [AC_MSG_CHECKING(for Linux source in $1)
210 if test -f "$1/Makefile" ; then
218 AC_MSG_RESULT($result)
221 dnl allow for specifying a kernel release (uname -r) to build for
222 dnl use uname -r of running one if not specified
223 dnl store result in LINUX_KERNEL_RELEASE
224 AC_DEFUN([AS_LINUX_KERNEL_RELEASE],
226 AC_ARG_WITH([kernel-release],
227 [AC_HELP_STRING([--with-kernel-release=RELEASE],
228 [specify the "uname -r"-value to build for])],
229 [LINUX_KERNEL_RELEASE="${withval}"],
230 [LINUX_KERNEL_RELEASE=`uname -r`])
231 if test "x$LINUX_KERNEL_RELEASE" = "xyes";
233 LINUX_KERNEL_RELEASE=`uname -r`
235 AC_MSG_NOTICE([Using $LINUX_KERNEL_RELEASE as the uname -r value])
238 dnl replaces LINUX_KERNEL_RELEASE once the Linux build directory is known
239 dnl first argument is the Linux build directory
240 AC_DEFUN([AS_LINUX_OVERRIDE_KERNEL_RELEASE],
243 UTSINC="${INCDIR}/linux/utsrelease.h"
244 if ! test -f "${UTSINC}"; then
245 UTSINC="${INCDIR}/linux/version.h"
247 if test -f "${UTSINC}"; then
248 RELEASE=`echo UTS_RELEASE | cat "${UTSINC}" - |
249 /lib/cpp -I "${INCDIR}" | tail -n 1 |
250 sed 's/^"\(.*\)"$/\1/'`
251 if test "${RELEASE}" != "UTS_RELEASE" -a "${RELEASE}" != "" \
252 -a "${RELEASE}" != "${LINUX_KERNEL_RELEASE}"; then
253 AC_MSG_NOTICE([Overriding uname -r value with ${RELEASE}])
254 LINUX_KERNEL_RELEASE="${RELEASE}"
260 dnl allow for specifying a machine (uname -m) to build for
261 dnl use uname -m, of running one if not specified
262 dnl store result in LINUX_MACHINE
263 AC_DEFUN([AS_LINUX_MACHINE],
265 AC_ARG_WITH([machine],
266 [AC_HELP_STRING([--with-machine=MACHINE],
267 [specify the "uname -m"-value to build for])],
268 [LINUX_MACHINE="${withval}"],
269 [LINUX_MACHINE=`uname -m`])
270 if test "x$LINUX_MACHINE" = "xyes";
272 LINUX_MACHINE=`uname -m`
274 AC_MSG_NOTICE([Using $LINUX_MACHINE as the uname -m value])
276 dnl allow for specifying an rpm target arch
277 dnl if none specified, try to guess one from running rpm querying for
278 dnl the kernel with the uname -r
279 dnl this is so configure without arguments works out of the box
280 dnl FIXME: investigate if uname -p is a correct guess for this, and if
281 dnl we should have a flag for specifying it instead
283 dnl this macro possibly overrides LINUX_MACHINE
285 dnl first argument is the kernel release building for
286 AC_DEFUN([AS_LINUX_RPM_TARGET],
288 RELEASE=$LINUX_KERNEL_RELEASE
289 AC_ARG_WITH([rpm-target],
290 [AC_HELP_STRING([--with-rpm-target=TARGET],
291 [specify the target arch to build for])],
292 [LINUX_RPM_TARGET="${withval}"],
294 if test "x$LINUX_RPM_TARGET" = "x"
296 dnl if we have rpm, try to guess the target of the kernel
297 dnl we want to build for using rpm
298 AC_PATH_PROG([RPM], [rpm], [no])
299 if test "x$RPM" != "xno" ; then
300 if $RPM -q kernel-$RELEASE > /dev/null
302 LINUX_RPM_TARGET=`$RPM -q --queryformat %{arch} kernel-$RELEASE`
304 AC_MSG_NOTICE([Cannot guess target arch, consider setting it using --with-rpm-target])
309 dnl now override LINUX_MACHINE if LINUX_RPM_TARGET is set
310 if test "x$LINUX_RPM_TARGET" != "x"
312 dnl override LINUX_MACHINE based on this
313 dnl FIXME: add other possible Red Hat/Fedora/rpm targets here
315 case "$LINUX_RPM_TARGET" in
316 i?86) LINUX_MACHINE=i386;;
317 athlon) LINUX_MACHINE=i386;;
318 x86_64) LINUX_MACHINE=x86_64;;
320 if test "x$LINUX_MACHINE" = "x"
322 AC_MSG_ERROR(Could not guess uname -m value from target $LINUX_RPM_TARGET)
328 dnl allow for specifying an override for EXTRAVERSION
329 dnl if none specified, make it from the passed-in KERNEL_RELEASE (uname -r)
330 dnl resulting value is stored in LINUX_EXTRAVERSION
331 dnl first argument is the uname -r string to use as a fallback
332 AC_DEFUN([AS_LINUX_EXTRAVERSION],
335 dnl extract the default by getting everything after first -
336 LINUX_EXTRAVERSION="-`echo $KERNEL_RELEASE | cut -d- -f 2-`"
337 AC_ARG_WITH([extraversion],
338 [AC_HELP_STRING([--with-extraversion=FILE],
339 [specify override for kernel EXTRAVERSION])],
340 [LINUX_EXTRAVERSION="${withval}"],)
344 dnl check if we can find a config file for the Linux kernel
345 dnl defines LINUX_CONFIG to the absolute location of a usable
346 dnl kernel source config file
348 dnl for rpm distros, it can try and guess the correct config file by
349 dnl checking the global LINUX_RPM_TARGET variable set somewhere else
350 dnl (FIXME: move this to an argument instead ?)
352 dnl first argument is LINUX_DIR to check for possible configs
353 dnl second argument is kernel-release (uname -r)
354 dnl third argument is machine (uname -m)
356 AC_DEFUN([AS_LINUX_CONFIG],
361 AC_ARG_WITH([linuxconfig],
362 [AC_HELP_STRING([--with-linuxconfig=FILE],
363 [specify path to Linux configuration file])],
364 [LINUX_CONFIG="${withval}"],
365 [LINUX_CONFIG=default])
367 dnl if a file got specified, try it as a linux config file
368 if test "${LINUX_CONFIG}" != "default" ; then
369 AS_TRY_LINUX_CONFIG($LINUX_CONFIG, $MACHINE,
370 ,, AC_MSG_ERROR([Linux config not found]) )
373 dnl if no file specified, first check for the regular .config file
374 dnl in LINUX_DIR created by manual configuration
375 if test "${LINUX_CONFIG}" = "default" ; then
376 file="$LINUX_DIR/.config";
377 AS_TRY_LINUX_CONFIG($file, $MACHINE,
378 [LINUX_CONFIG=${file}], )
380 dnl second, try to guess what config file to use for the current kernel
381 dnl FIXME: the possible arch is from rpmbuild --target, and is
382 dnl different from the value of ARCH (Makefile) or MACHINE (uname -m)
383 dnl so we should have a redhat flag to specify the target to find
384 dnl the correct config file
385 if test "${LINUX_CONFIG}" = "default" && test "x$LINUX_RPM_TARGET" != "x"; then
386 dnl Red Hat stores configuration files for their built kernels
387 dnl named kernel-(version)-(arch)(extra).config
388 dnl where arch is athlon, i386, i586, i686, x86_64
389 dnl and (extra) is empty or -smp, -BOOT, -bigmem
390 dnl haven't seen combinations of extra yet as of FC1
391 KVERSION=`echo $KERNEL_RELEASE | cut -d- -f1`
393 echo $KERNEL_RELEASE | grep smp && EXTRA="-smp"
394 echo $KERNEL_RELEASE | grep bigmem && EXTRA="-bigmem"
395 echo $KERNEL_RELEASE | grep BOOT && EXTRA="-BOOT"
396 file="$LINUX_DIR/configs/kernel-$KVERSION-$LINUX_RPM_TARGET$EXTRA.config"
397 AS_TRY_LINUX_CONFIG($file, $MACHINE,
398 [LINUX_CONFIG=${file}], )
400 if test "${LINUX_CONFIG}" = "default" ; then
402 The kernel source tree at ${LINUX_DIR} is not configured,
403 and no configuration files in config/ matching your kernel were found.
404 Fix before continuing or specify a config file using --with-configfile.])
407 AC_SUBST(LINUX_CONFIG)
410 dnl check if the given candidate config file is usable
411 dnl FIXME: it would be nice if it could check if it matches the
412 dnl given machine (uname -m)
413 AC_DEFUN([AS_TRY_LINUX_CONFIG],
417 AC_MSG_CHECKING($CFG)
419 if test -f "$CFG" ; then
421 ifelse([$3], , :, [$3])
424 ifelse([$4], , :, [$4])
426 AC_MSG_RESULT($result)
429 dnl check if RED_HAT_LINUX_KERNEL is defined
430 dnl pre-FC2 RH/Fedora defines this in linux/rhconfig.h
431 dnl included from linux/version.h
432 dnl if this is present, a few extra defines need to be present to make sure
433 dnl symbol versioning is correct
434 dnl uses LINUX_DIR to find rhconfig.h
435 AC_DEFUN([AS_CHECK_REDHAT_PRE_FC2],
437 AC_MSG_CHECKING(Pre-FC2 Red Hat/Fedora kernel)
438 HAVE_REDHAT_KERNEL=false
439 ac_save_CFLAGS="$CFLAGS"
440 CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux"
441 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
442 #include "rhconfig.h"
443 int code = RED_HAT_LINUX_KERNEL;
445 AC_MSG_RESULT(found); HAVE_REDHAT_KERNEL=true,
446 AC_MSG_RESULT(not found))
448 CFLAGS="$ac_save_CFLAGS"
450 dnl check for Red Hat define flags to use - see /sbin/mkkerneldoth
452 dnl initialize the booleans we want to detect
459 dnl get variables from the currently running kernel as default
460 KERNEL_TYPE=`uname -r | sed 's_^.*\(smp\|enterprise\|bigmem\|hugemem\)$_\1_;t;s_.*__;'`
461 KERNEL_RELEASE=`uname -r | sed 's|smp\|enterprise\|bigmem\|hugemem||g'`
462 KERNEL_ARCH=`uname -m`
464 dnl check the config file and override KERNEL_ARCH
465 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M386, KERNEL_ARCH=i386)
466 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M586, KERNEL_ARCH=i586)
467 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M686, KERNEL_ARCH=i686)
468 dnl for some reason the i686 bigmem config file has PENTIUM
469 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MPENTIUMIII, KERNEL_ARCH=i686)
470 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MK7, KERNEL_ARCH=athlon)
472 dnl check the config file and override KERNEL_TYPE
473 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_SMP, KERNEL_TYPE=smp)
474 dnl bigmem is also smp, so this check is done after smp to override
475 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_HIGHMEM64G, KERNEL_TYPE=bigmem)
477 dnl FIXME: need to check hugemem and enterprise config files, which
478 dnl aren't provided in Fedora Core 1 !
480 case "$KERNEL_TYPE" in
482 enterprise) ENTERPRISE='1';;
484 hugemem) HUGEMEM='1';;
487 REDHAT_CFLAGS="-D__MODULE_KERNEL_$KERNEL_ARCH=1"
488 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_ENTERPRISE=$ENTERPRISE"
489 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_UP=$UP"
490 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_SMP=$SMP"
491 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_BIGMEM=$BIGMEM"
492 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_HUGEMEM=$HUGEMEM"
494 LINUX_REDHAT_CFLAGS="$REDHAT_CFLAGS"
496 AC_SUBST(LINUX_KERNEL_TYPE, "$KERNEL_TYPE")
499 dnl add an argument to specify/override the module install path
500 dnl if nothing specified, it will be /lib/modules/(kernelrel)
501 AC_DEFUN([AS_LINUX_MODULESDIR],
504 AC_ARG_WITH([modulesdir],
505 [AC_HELP_STRING([--with-modulesdir=DIR],
506 [specify path to kernel-specific modules install directory])],
507 [MODULESDIR="${withval}"],
508 [MODULESDIR=default])
510 if test "${MODULESDIR}" = "default" ; then
511 MODULESDIR="/lib/modules/${KERNEL_RELEASE}"
513 dnl make it available to Makefiles so it can be used in ...dir
514 AC_SUBST(modulesdir, $MODULESDIR)
515 AC_MSG_NOTICE([Putting kernel modules under ${MODULESDIR}])
518 dnl add an argument to specify/override the module devel install path
519 dnl if nothing specified, it will be the passed in LINUXDIR)
520 AC_DEFUN([AS_LINUX_MODULESDEVELDIR],
523 AC_ARG_WITH([modulesdeveldir],
524 [AC_HELP_STRING([--with-modulesdeveldir=DIR],
525 [specify path to kernel-specific module development install directory])],
526 [MODULESDEVELDIR="${withval}"],
527 [MODULESDEVELDIR=default])
529 if test "${MODULESDEVELDIR}" = "default" ; then
530 MODULESDEVELDIR="${LINUXDIR}"
532 dnl make it available to Makefiles so it can be used in ...dir
533 AC_SUBST(modulesdeveldir, $MODULESDEVELDIR)
534 AC_MSG_NOTICE([Putting kernel module development files under ${MODULESDEVELDIR}])
537 AC_DEFUN([AS_LINUX_2_6],
539 AC_MSG_CHECKING(for Linux CFLAGS)
542 tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
543 test -n "$tmpdir" && test -d "$tmpdir"
546 tmpdir=./confstat$$-$RANDOM
547 (umask 077 && mkdir $tmpdir)
550 echo "$me: cannot create a temporary directory in ." >&2
551 { (exit 1); exit 1; }
556 cat >${tmpdir}/Makefile <<EOF
559 \$(obj)/fake.c: flags
564 echo LINUX_ARCH=\"\$(ARCH)\" >>\$(obj)/flags
565 echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's,include,"\$(LINUXDIR)/include",g'>>\$(obj)/flags
566 echo LINUX_LDFLAGS=\"\" >>\$(obj)/flags
567 echo LINUX_ARFLAGS=\"\$(ARFLAGS)\" >>\$(obj)/flags
568 echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\" >>\$(obj)/flags
569 echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\" >>\$(obj)/flags
570 echo LINUX_CFLAGS=\"\$(CFLAGS) \$(CPPFLAGS)\" \
571 | sed -e 's,-Iinclude,-I\$(LINUXDIR)/include,g' -e 's,-include include,-include \$(LINUXDIR)/include,g' >>\$(obj)/flags
572 echo LINUX_CFLAGS_MODULE=\"\$(CFLAGS_MODULE)\" >>\$(obj)/flags
573 echo LINUX_CC=\"\$(CC)\" >>\$(obj)/flags
574 echo LINUX_LD=\"\$(LD) \$(LDFLAGS) \$(LDFLAGS_MODULE)\" >>\$(obj)/flags
575 echo LINUX_AS=\"\$(AS)\" >>\$(obj)/flags
576 echo LINUX_MODLIB=\"\$(MODLIB)\" >>\$(obj)/flags
579 echo ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
580 ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
584 LINUX_MODULE_EXT=".ko"
585 LINUX_MODULE_STYLE="2.6.6"
587 LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_CFLAGS_MODULE"
590 AC_SUBST(LINUX_AFLAGS)
591 AC_SUBST(LINUX_LDFLAGS)
592 AC_SUBST(LINUX_ARFLAGS)
593 AC_SUBST(LINUX_CROSS_COMPILE)
594 AC_SUBST(LINUX_KERNELRELEASE)
595 AC_SUBST(LINUX_CFLAGS)
599 AC_SUBST(LINUX_MODULE_EXT)
600 AC_SUBST(LINUX_MODULE_STYLE)
601 AC_SUBST(LINUX_MODPOST)
602 AC_SUBST(LINUX_MODLIB)
604 AC_MSG_RESULT([$LINUX_CFLAGS])
606 AC_PATH_PROG([LINUX_MODPOST], ["modpost"], ["no"], ["$LINUX_DIR/scripts:$LINUX_DIR/scripts/mod"])
610 AC_DEFUN([AS_LINUX_2_4],
612 AC_MSG_CHECKING(for Linux 2.4 make flags)
613 dnl we try to figure out the CFLAGS by invoking the Makefile on
615 dnl we use the correct config file by substituting the MAKEFILES
616 dnl Makefile variable, which originally points to .config
618 if [[ ! -e "${LINUX_DIR}/.hdepend" ]];then
620 No .hdepend file found, you may need to run 'make dep' on the kernel source before continuing.])
624 tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
625 test -n "$tmpdir" && test -d "$tmpdir"
628 tmpdir=./confstat$$-$RANDOM
629 (umask 077 && mkdir $tmpdir)
632 echo "$me: cannot create a temporary directory in ." >&2
633 { (exit 1); exit 1; }
637 #sed "s|\.config|${CONFIG_FILE}|g" ${LINUX_DIR}/Makefile >$tmpdir/Makefile
638 cat >$tmpdir/Makefile <<EOF
640 @echo LINUX_ARCH=\"\$(ARCH)\"
641 @echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
642 @echo LINUX_LDFLAGS=\"\"
643 @echo LINUX_ARFLAGS=\"\$(ARFLAGS)\"
644 @echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\"
645 @echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\"
646 @echo LINUX_CFLAGS=\"\$(CFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
647 @echo LINUX_MODFLAGS=\"\$(MODFLAGS)\"
648 @echo LINUX_CC=\"\$(CC)\"
649 @echo LINUX_LD=\"\$(LD) \$(LDFLAGS)\"
650 @echo LINUX_AS=\"\$(AS)\"
652 make -C ${LINUX_DIR} SUBDIRS=${tmpdir} modules | grep ^LINUX_ >${tmpdir}/ack
654 echo make modules with LINUX_DIR=$(LINUX_DIR) failed.
660 LINUX_MODULE_EXT=".o"
661 LINUX_MODULE_STYLE="2.4.0"
663 LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_MODFLAGS"
665 dnl if we have REDHAT_CFLAGS, put them in LINUX_CFLAGS
666 if test "x$REDHAT_CFLAGS" != "x";
668 LINUX_CFLAGS="$LINUX_CFLAGS $REDHAT_CFLAGS"
671 AC_SUBST(LINUX_AFLAGS)
672 AC_SUBST(LINUX_LDFLAGS)
673 AC_SUBST(LINUX_ARFLAGS)
674 AC_SUBST(LINUX_CROSS_COMPILE)
675 AC_SUBST(LINUX_KERNELRELEASE)
676 AC_SUBST(LINUX_CFLAGS)
680 AC_SUBST(LINUX_MODULE_EXT)
681 AC_SUBST(LINUX_MODULE_STYLE)
685 AC_MSG_CHECKING(for Linux 2.4 CFLAGS)
686 AC_MSG_RESULT($LINUX_CFLAGS)
687 AC_MSG_CHECKING(for Linux 2.4 LDFLAGS)
688 AC_MSG_RESULT($LINUX_LDFLAGS)
691 AC_DEFUN([AS_CHECK_LINUX_CONFIG_OPTION],
693 AC_MSG_CHECKING([Linux config option $1])
695 if grep '^$1=y$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
698 else if grep '^$1=m$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
707 AC_MSG_RESULT([$result])
710 AC_DEFUN([AS_LINUX_CONFIG_OPTION],
712 AS_CHECK_LINUX_CONFIG_OPTION([$1],
717 AM_CONDITIONAL([$1],[test "${$1}" = yes])
720 AC_DEFUN([AS_LINUX_CONFIG_OPTION_MODULE],
722 AS_CHECK_LINUX_CONFIG_OPTION([$1],
727 AM_CONDITIONAL([$1],[test "${$1}" = yes -o "${$1}" = module])
730 dnl check for the major/minor version of the Linux source by checking
732 dnl first argument is the linux directory
733 dnl sets LINUX_VERSION_MAJOR and LINUX_VERSION_MINOR
734 AC_DEFUN([AS_LINUX_VERSION_MAJOR_MINOR],
737 AC_MSG_CHECKING([Linux major/minor version])
739 if [[ ! -f "${LINUX_DIR}/Makefile" ]];then
740 AC_MSG_ERROR([The Linux kernel Makefile does not exist.])
742 dnl the next set of tests is for figuring out version major/minor
743 dnl use VERSION and PATCHLEVEL in the kernel Makefile
744 LINUX_VERSION_MAJOR=`sed -n 's/^VERSION = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
745 LINUX_VERSION_MINOR=`sed -n 's/^PATCHLEVEL = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
746 if [[ -z "$LINUX_VERSION_MAJOR" -o -z "$LINUX_VERSION_MINOR" ]]; then
747 AC_MSG_ERROR([No major/minor version information found in Linux kernel Makefile.])
749 AC_MSG_RESULT($LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR)
752 # COMEDI_CHECK_LINUX_KBUILD([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
753 # -------------------------------------------------------------
755 # Check if kernel source tree is recent enough to support "Kbuild" files.
756 AC_DEFUN([COMEDI_CHECK_LINUX_KBUILD],
758 AC_MSG_CHECKING([for Kbuild support in $1])
759 dnl If $1/scripts/Makefile.build refers to $(<something>)/Kbuild
760 dnl then we support Kbuild (2.6.10 onwards).
761 if grep -q '/Kbuild' "$1/scripts/Makefile.build" 2>/dev/null; then
770 # COMEDI_CHECK_PCMCIA_PROBE([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
771 # -------------------------------------------------------------
773 # Check if kernel pcmcia support is new enough to have a probe member in the pcmcia_driver
775 AC_DEFUN([COMEDI_CHECK_PCMCIA_DRIVER_PROBE],
777 AC_REQUIRE([AC_PROG_EGREP])
778 AC_MSG_CHECKING([$1 for probe in pcmcia_driver struct])
779 cat "$1/include/pcmcia/ds.h" | tr \\n ' ' | [$EGREP "struct[[:space:]]+pcmcia_driver[[:space:]]*[{][^}]*probe"] > /dev/null
789 # COMEDI_CHECK_PCMCIA_DRIVER_NAME([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
790 # -------------------------------------------------------------
792 # Check if kernel pcmcia support is new enough to have a name member in the pcmcia_driver
794 AC_DEFUN([COMEDI_CHECK_PCMCIA_DRIVER_NAME],
796 AC_REQUIRE([AC_PROG_EGREP])
797 AC_MSG_CHECKING([$1 for name in pcmcia_driver struct])
798 cat "$1/include/pcmcia/ds.h" | tr \\n ' ' | [$EGREP "struct[[:space:]]+pcmcia_driver[[:space:]]*[{][^}]*name"] > /dev/null
808 # COMEDI_CHECK_PCMCIA_LOOP_TUPLE([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
809 # -------------------------------------------------------------
811 # Check if kernel pcmcia support is new enough to have the pcmcia_loop_tuple
813 AC_DEFUN([COMEDI_CHECK_PCMCIA_LOOP_TUPLE],
815 AC_MSG_CHECKING([$1 for pcmcia_loop_tuple function])
816 if [grep -q 'int[[:space:]]\+pcmcia_loop_tuple[[:space:]]*(' "$1/include/pcmcia/ds.h"] 2>/dev/null ; then
825 # COMEDI_CHECK_DS_DEV_NODE_T([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
826 # -------------------------------------------------------------
828 # Check if kernel pcmcia support is old enough to have the dev_node_t type
830 AC_DEFUN([COMEDI_CHECK_DS_DEV_NODE_T],
832 AC_MSG_CHECKING([$1 for dev_node_t in pcmcia/ds.h (removed in 2.6.35)])
833 if [grep -q dev_node_t "$1/include/pcmcia/ds.h"] 2>/dev/null ; then
842 # COMEDI_CHECK_CS_IRQ_REQ_T([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
843 # -------------------------------------------------------------
845 # Check if kernel pcmcia support is old enough to have the irq_req_t type
847 AC_DEFUN([COMEDI_CHECK_CS_IRQ_REQ_T],
849 AC_MSG_CHECKING([$1 for irq_req_t in pcmcia/cs.h (removed in 2.6.35)])
850 if [grep -q irq_req_t "$1/include/pcmcia/cs.h"] 2>/dev/null ; then
859 # COMEDI_CHECK_CS_IO_REQ_T([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
860 # -------------------------------------------------------------
862 # Check if kernel pcmcia support is old enough to have the io_req_t type
864 AC_DEFUN([COMEDI_CHECK_CS_IO_REQ_T],
866 AC_MSG_CHECKING([$1 for io_req_t in pcmcia/cs.h (removed in 2.6.36)])
867 if [grep -q io_req_t "$1/include/pcmcia/cs.h"] 2>/dev/null ; then
876 # COMEDI_CHECK_CS_MEMREQ_T([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
877 # -------------------------------------------------------------
879 # Check if kernel pcmcia support is old enough to have the memreq_t type
881 AC_DEFUN([COMEDI_CHECK_CS_MEMREQ_T],
883 AC_MSG_CHECKING([$1 for memreq_t in pcmcia/cs.h (removed in 2.6.36)])
884 if [grep -q memreq_t "$1/include/pcmcia/cs.h"] 2>/dev/null ; then
893 # COMEDI_CHECK_HAVE_CS_TYPES_H([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
894 # -------------------------------------------------------------
896 # Check if kernel has <pcmcia/cs_types.h> file.
897 AC_DEFUN([COMEDI_CHECK_HAVE_CS_TYPES_H],
899 AC_MSG_CHECKING([$1 for include/pcmcia/cs_types.h (removed in 2.6.36)])
900 if test -f "$1/include/pcmcia/cs_types.h"; then
909 # COMEDI_CHECK_HAVE_CS_H([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
910 # -------------------------------------------------------------
912 # Check if kernel has <pcmcia/cs.h> file.
913 AC_DEFUN([COMEDI_CHECK_HAVE_CS_H],
915 AC_MSG_CHECKING([$1 for include/pcmcia/cs.h (removed in 2.6.37)])
916 if test -f "$1/include/pcmcia/cs.h"; then
925 # COMEDI_CHECK_HAVE_MUTEX_H([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
926 # -------------------------------------------------------------
928 # Check if kernel has <linux/mutex.h> file.
929 AC_DEFUN([COMEDI_CHECK_HAVE_MUTEX_H],
931 AC_MSG_CHECKING([$1 for include/linux/mutex.h])
932 if test -f "$1/include/linux/mutex.h"; then
941 # COMEDI_CHECK_HAVE_LINUX_SEMAPHORE_H([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
942 # -------------------------------------------------------------
944 # Check if kernel has <linux/semaphore.h> file.
945 AC_DEFUN([COMEDI_CHECK_HAVE_LINUX_SEMAPHORE_H],
947 AC_MSG_CHECKING([$1 for include/linux/semaphore.h])
948 if test -f "$1/include/linux/semaphore.h"; then