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
191 AS_TRY_LINUX_SRC_DIR([${dir}], [LINUX_SRC_DIR=${dir}], )
195 if test "${LINUX_SRC_DIR}" = "default" ; then
196 AC_MSG_ERROR([Linux source directory not found])
199 AC_SUBST(LINUX_SRC_DIR)
202 dnl check if the given candidate path for a linux source tree is usable
203 AC_DEFUN([AS_TRY_LINUX_SRC_DIR],
204 [AC_MSG_CHECKING(for Linux source in $1)
206 if test -f "$1/Makefile" ; then
214 AC_MSG_RESULT($result)
217 dnl allow for specifying a kernel release (uname -r) to build for
218 dnl use uname -r of running one if not specified
219 dnl store result in LINUX_KERNEL_RELEASE
220 AC_DEFUN([AS_LINUX_KERNEL_RELEASE],
222 AC_ARG_WITH([kernel-release],
223 [AC_HELP_STRING([--with-kernel-release=RELEASE],
224 [specify the "uname -r"-value to build for])],
225 [LINUX_KERNEL_RELEASE="${withval}"],
226 [LINUX_KERNEL_RELEASE=`uname -r`])
227 if test "x$LINUX_KERNEL_RELEASE" = "xyes";
229 LINUX_KERNEL_RELEASE=`uname -r`
231 AC_MSG_NOTICE([Using $LINUX_KERNEL_RELEASE as the uname -r value])
234 dnl replaces LINUX_KERNEL_RELEASE once the Linux build directory is known
235 dnl first argument is the Linux build directory
236 AC_DEFUN([AS_LINUX_OVERRIDE_KERNEL_RELEASE],
239 UTSINC="${INCDIR}/linux/utsrelease.h"
240 if ! test -f "${UTSINC}"; then
241 UTSINC="${INCDIR}/linux/version.h"
243 if test -f "${UTSINC}"; then
244 RELEASE=`echo UTS_RELEASE | cat "${UTSINC}" - |
245 /lib/cpp -I "${INCDIR}" | tail -n 1 |
246 sed 's/^"\(.*\)"$/\1/'`
247 if test "${RELEASE}" != "UTS_RELEASE" -a "${RELEASE}" != "" \
248 -a "${RELEASE}" != "${LINUX_KERNEL_RELEASE}"; then
249 AC_MSG_NOTICE([Overriding uname -r value with ${RELEASE}])
250 LINUX_KERNEL_RELEASE="${RELEASE}"
256 dnl allow for specifying a machine (uname -m) to build for
257 dnl use uname -m, of running one if not specified
258 dnl store result in LINUX_MACHINE
259 AC_DEFUN([AS_LINUX_MACHINE],
261 AC_ARG_WITH([machine],
262 [AC_HELP_STRING([--with-machine=MACHINE],
263 [specify the "uname -m"-value to build for])],
264 [LINUX_MACHINE="${withval}"],
265 [LINUX_MACHINE=`uname -m`])
266 if test "x$LINUX_MACHINE" = "xyes";
268 LINUX_MACHINE=`uname -r`
270 AC_MSG_NOTICE([Using $LINUX_MACHINE as the uname -m value])
272 dnl allow for specifying an rpm target arch
273 dnl if none specified, try to guess one from running rpm querying for
274 dnl the kernel with the uname -r
275 dnl this is so configure without arguments works out of the box
276 dnl FIXME: investigate if uname -p is a correct guess for this, and if
277 dnl we should have a flag for specifying it instead
279 dnl this macro possibly overrides LINUX_MACHINE
281 dnl first argument is the kernel release building for
282 AC_DEFUN([AS_LINUX_RPM_TARGET],
284 RELEASE=$LINUX_KERNEL_RELEASE
285 AC_ARG_WITH([rpm-target],
286 [AC_HELP_STRING([--with-rpm-target=TARGET],
287 [specify the target arch to build for])],
288 [LINUX_RPM_TARGET="${withval}"],
290 if test "x$LINUX_RPM_TARGET" = "x"
292 dnl if we have rpm, try to guess the target of the kernel
293 dnl we want to build for using rpm
294 AC_PATH_PROG([RPM], [rpm], [no])
295 if test "x$RPM" != "xno" ; then
296 if $RPM -q kernel-$RELEASE > /dev/null
298 LINUX_RPM_TARGET=`$RPM -q --queryformat %{arch} kernel-$RELEASE`
300 AC_MSG_NOTICE([Cannot guess target arch, consider setting it using --with-rpm-target])
305 dnl now override LINUX_MACHINE if LINUX_RPM_TARGET is set
306 if test "x$LINUX_RPM_TARGET" != "x"
308 dnl override LINUX_MACHINE based on this
309 dnl FIXME: add other possible Red Hat/Fedora/rpm targets here
311 case "$LINUX_RPM_TARGET" in
312 i?86) LINUX_MACHINE=i386;;
313 athlon) LINUX_MACHINE=i386;;
314 x86_64) LINUX_MACHINE=x86_64;;
316 if test "x$LINUX_MACHINE" = "x"
318 AC_MSG_ERROR(Could not guess uname -m value from target $LINUX_RPM_TARGET)
324 dnl allow for specifying an override for EXTRAVERSION
325 dnl if none specified, make it from the passed-in KERNEL_RELEASE (uname -r)
326 dnl resulting value is stored in LINUX_EXTRAVERSION
327 dnl first argument is the uname -r string to use as a fallback
328 AC_DEFUN([AS_LINUX_EXTRAVERSION],
331 dnl extract the default by getting everything after first -
332 LINUX_EXTRAVERSION="-`echo $KERNEL_RELEASE | cut -d- -f 2-`"
333 AC_ARG_WITH([extraversion],
334 [AC_HELP_STRING([--with-extraversion=FILE],
335 [specify override for kernel EXTRAVERSION])],
336 [LINUX_EXTRAVERSION="${withval}"],)
340 dnl check if we can find a config file for the Linux kernel
341 dnl defines LINUX_CONFIG to the absolute location of a usable
342 dnl kernel source config file
344 dnl for rpm distros, it can try and guess the correct config file by
345 dnl checking the global LINUX_RPM_TARGET variable set somewhere else
346 dnl (FIXME: move this to an argument instead ?)
348 dnl first argument is LINUX_DIR to check for possible configs
349 dnl second argument is kernel-release (uname -r)
350 dnl third argument is machine (uname -m)
352 AC_DEFUN([AS_LINUX_CONFIG],
357 AC_ARG_WITH([linuxconfig],
358 [AC_HELP_STRING([--with-linuxconfig=FILE],
359 [specify path to Linux configuration file])],
360 [LINUX_CONFIG="${withval}"],
361 [LINUX_CONFIG=default])
363 dnl if a file got specified, try it as a linux config file
364 if test "${LINUX_CONFIG}" != "default" ; then
365 AS_TRY_LINUX_CONFIG($LINUX_CONFIG, $MACHINE,
366 ,, AC_MSG_ERROR([Linux config not found]) )
369 dnl if no file specified, first check for the regular .config file
370 dnl in LINUX_DIR created by manual configuration
371 if test "${LINUX_CONFIG}" = "default" ; then
372 file="$LINUX_DIR/.config";
373 AS_TRY_LINUX_CONFIG($file, $MACHINE,
374 [LINUX_CONFIG=${file}], )
376 dnl second, try to guess what config file to use for the current kernel
377 dnl FIXME: the possible arch is from rpmbuild --target, and is
378 dnl different from the value of ARCH (Makefile) or MACHINE (uname -m)
379 dnl so we should have a redhat flag to specify the target to find
380 dnl the correct config file
381 if test "${LINUX_CONFIG}" = "default" && test "x$LINUX_RPM_TARGET" != "x"; then
382 dnl Red Hat stores configuration files for their built kernels
383 dnl named kernel-(version)-(arch)(extra).config
384 dnl where arch is athlon, i386, i586, i686, x86_64
385 dnl and (extra) is empty or -smp, -BOOT, -bigmem
386 dnl haven't seen combinations of extra yet as of FC1
387 KVERSION=`echo $KERNEL_RELEASE | cut -d- -f1`
389 echo $KERNEL_RELEASE | grep smp && EXTRA="-smp"
390 echo $KERNEL_RELEASE | grep bigmem && EXTRA="-bigmem"
391 echo $KERNEL_RELEASE | grep BOOT && EXTRA="-BOOT"
392 file="$LINUX_DIR/configs/kernel-$KVERSION-$LINUX_RPM_TARGET$EXTRA.config"
393 AS_TRY_LINUX_CONFIG($file, $MACHINE,
394 [LINUX_CONFIG=${file}], )
396 if test "${LINUX_CONFIG}" = "default" ; then
398 The kernel source tree at ${LINUX_DIR} is not configured,
399 and no configuration files in config/ matching your kernel were found.
400 Fix before continuing or specify a config file using --with-configfile.])
403 AC_SUBST(LINUX_CONFIG)
406 dnl check if the given candidate config file is usable
407 dnl FIXME: it would be nice if it could check if it matches the
408 dnl given machine (uname -m)
409 AC_DEFUN([AS_TRY_LINUX_CONFIG],
413 AC_MSG_CHECKING($CFG)
415 if test -f "$CFG" ; then
417 ifelse([$3], , :, [$3])
420 ifelse([$4], , :, [$4])
422 AC_MSG_RESULT($result)
425 dnl check if RED_HAT_LINUX_KERNEL is defined
426 dnl pre-FC2 RH/Fedora defines this in linux/rhconfig.h
427 dnl included from linux/version.h
428 dnl if this is present, a few extra defines need to be present to make sure
429 dnl symbol versioning is correct
430 dnl uses LINUX_DIR to find rhconfig.h
431 AC_DEFUN([AS_CHECK_REDHAT_PRE_FC2],
433 AC_MSG_CHECKING(Pre-FC2 Red Hat/Fedora kernel)
434 HAVE_REDHAT_KERNEL=false
435 ac_save_CFLAGS="$CFLAGS"
436 CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux"
437 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
438 #include "rhconfig.h"
439 int code = RED_HAT_LINUX_KERNEL;
441 AC_MSG_RESULT(found); HAVE_REDHAT_KERNEL=true,
442 AC_MSG_RESULT(not found))
444 CFLAGS="$ac_save_CFLAGS"
446 dnl check for Red Hat define flags to use - see /sbin/mkkerneldoth
448 dnl initialize the booleans we want to detect
455 dnl get variables from the currently running kernel as default
456 KERNEL_TYPE=`uname -r | sed 's_^.*\(smp\|enterprise\|bigmem\|hugemem\)$_\1_;t;s_.*__;'`
457 KERNEL_RELEASE=`uname -r | sed 's|smp\|enterprise\|bigmem\|hugemem||g'`
458 KERNEL_ARCH=`uname -m`
460 dnl check the config file and override KERNEL_ARCH
461 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M386, KERNEL_ARCH=i386)
462 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M586, KERNEL_ARCH=i586)
463 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M686, KERNEL_ARCH=i686)
464 dnl for some reason the i686 bigmem config file has PENTIUM
465 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MPENTIUMIII, KERNEL_ARCH=i686)
466 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MK7, KERNEL_ARCH=athlon)
468 dnl check the config file and override KERNEL_TYPE
469 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_SMP, KERNEL_TYPE=smp)
470 dnl bigmem is also smp, so this check is done after smp to override
471 AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_HIGHMEM64G, KERNEL_TYPE=bigmem)
473 dnl FIXME: need to check hugemem and enterprise config files, which
474 dnl aren't provided in Fedora Core 1 !
476 case "$KERNEL_TYPE" in
478 enterprise) ENTERPRISE='1';;
480 hugemem) HUGEMEM='1';;
483 REDHAT_CFLAGS="-D__MODULE_KERNEL_$KERNEL_ARCH=1"
484 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_ENTERPRISE=$ENTERPRISE"
485 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_UP=$UP"
486 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_SMP=$SMP"
487 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_BIGMEM=$BIGMEM"
488 REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_HUGEMEM=$HUGEMEM"
490 LINUX_REDHAT_CFLAGS="$REDHAT_CFLAGS"
492 AC_SUBST(LINUX_KERNEL_TYPE, "$KERNEL_TYPE")
495 dnl add an argument to specify/override the module install path
496 dnl if nothing specified, it will be /lib/modules/(kernelrel)
497 AC_DEFUN([AS_LINUX_MODULESDIR],
500 AC_ARG_WITH([modulesdir],
501 [AC_HELP_STRING([--with-modulesdir=DIR],
502 [specify path to kernel-specific modules install directory])],
503 [MODULESDIR="${withval}"],
504 [MODULESDIR=default])
506 if test "${MODULESDIR}" = "default" ; then
507 MODULESDIR="/lib/modules/${KERNEL_RELEASE}"
509 dnl make it available to Makefiles so it can be used in ...dir
510 AC_SUBST(modulesdir, $MODULESDIR)
511 AC_MSG_NOTICE([Putting kernel modules under ${MODULESDIR}])
514 dnl add an argument to specify/override the module devel install path
515 dnl if nothing specified, it will be the passed in LINUXDIR)
516 AC_DEFUN([AS_LINUX_MODULESDEVELDIR],
519 AC_ARG_WITH([modulesdeveldir],
520 [AC_HELP_STRING([--with-modulesdeveldir=DIR],
521 [specify path to kernel-specific module development install directory])],
522 [MODULESDEVELDIR="${withval}"],
523 [MODULESDEVELDIR=default])
525 if test "${MODULESDEVELDIR}" = "default" ; then
526 MODULESDEVELDIR="${LINUXDIR}"
528 dnl make it available to Makefiles so it can be used in ...dir
529 AC_SUBST(modulesdeveldir, $MODULESDEVELDIR)
530 AC_MSG_NOTICE([Putting kernel module development files under ${MODULESDEVELDIR}])
533 AC_DEFUN([AS_LINUX_2_6],
535 AC_MSG_CHECKING(for Linux CFLAGS)
538 tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
539 test -n "$tmpdir" && test -d "$tmpdir"
542 tmpdir=./confstat$$-$RANDOM
543 (umask 077 && mkdir $tmpdir)
546 echo "$me: cannot create a temporary directory in ." >&2
547 { (exit 1); exit 1; }
552 cat >${tmpdir}/Makefile <<EOF
555 \$(obj)/fake.c: flags
560 echo LINUX_ARCH=\"\$(ARCH)\" >>\$(obj)/flags
561 echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's,include,"\$(LINUXDIR)/include",g'>>\$(obj)/flags
562 echo LINUX_LDFLAGS=\"\" >>\$(obj)/flags
563 echo LINUX_ARFLAGS=\"\$(ARFLAGS)\" >>\$(obj)/flags
564 echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\" >>\$(obj)/flags
565 echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\" >>\$(obj)/flags
566 echo LINUX_CFLAGS=\"\$(CFLAGS) \$(CPPFLAGS)\" \
567 | sed -e 's,-Iinclude,-I\$(LINUXDIR)/include,g' -e 's,-include include,-include \$(LINUXDIR)/include,g' >>\$(obj)/flags
568 echo LINUX_CFLAGS_MODULE=\"\$(CFLAGS_MODULE)\" >>\$(obj)/flags
569 echo LINUX_CC=\"\$(CC)\" >>\$(obj)/flags
570 echo LINUX_LD=\"\$(LD) \$(LDFLAGS) \$(LDFLAGS_MODULE)\" >>\$(obj)/flags
571 echo LINUX_AS=\"\$(AS)\" >>\$(obj)/flags
572 echo LINUX_MODLIB=\"\$(MODLIB)\" >>\$(obj)/flags
575 echo ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
576 ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
580 LINUX_MODULE_EXT=".ko"
581 LINUX_MODULE_STYLE="2.6.6"
583 LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_CFLAGS_MODULE"
586 AC_SUBST(LINUX_AFLAGS)
587 AC_SUBST(LINUX_LDFLAGS)
588 AC_SUBST(LINUX_ARFLAGS)
589 AC_SUBST(LINUX_CROSS_COMPILE)
590 AC_SUBST(LINUX_KERNELRELEASE)
591 AC_SUBST(LINUX_CFLAGS)
595 AC_SUBST(LINUX_MODULE_EXT)
596 AC_SUBST(LINUX_MODULE_STYLE)
597 AC_SUBST(LINUX_MODPOST)
598 AC_SUBST(LINUX_MODLIB)
600 AC_MSG_RESULT([$LINUX_CFLAGS])
602 AC_PATH_PROG([LINUX_MODPOST], ["modpost"], ["no"], ["$LINUX_DIR/scripts:$LINUX_DIR/scripts/mod"])
606 AC_DEFUN([AS_LINUX_2_4],
608 AC_MSG_CHECKING(for Linux 2.4 make flags)
609 dnl we try to figure out the CFLAGS by invoking the Makefile on
611 dnl we use the correct config file by substituting the MAKEFILES
612 dnl Makefile variable, which originally points to .config
614 if [[ ! -e "${LINUX_DIR}/.hdepend" ]];then
616 No .hdepend file found, you may need to run 'make dep' on the kernel source before continuing.])
620 tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
621 test -n "$tmpdir" && test -d "$tmpdir"
624 tmpdir=./confstat$$-$RANDOM
625 (umask 077 && mkdir $tmpdir)
628 echo "$me: cannot create a temporary directory in ." >&2
629 { (exit 1); exit 1; }
633 #sed "s|\.config|${CONFIG_FILE}|g" ${LINUX_DIR}/Makefile >$tmpdir/Makefile
634 cat >$tmpdir/Makefile <<EOF
636 @echo LINUX_ARCH=\"\$(ARCH)\"
637 @echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
638 @echo LINUX_LDFLAGS=\"\"
639 @echo LINUX_ARFLAGS=\"\$(ARFLAGS)\"
640 @echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\"
641 @echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\"
642 @echo LINUX_CFLAGS=\"\$(CFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
643 @echo LINUX_MODFLAGS=\"\$(MODFLAGS)\"
644 @echo LINUX_CC=\"\$(CC)\"
645 @echo LINUX_LD=\"\$(LD) \$(LDFLAGS)\"
646 @echo LINUX_AS=\"\$(AS)\"
648 make -C ${LINUX_DIR} SUBDIRS=${tmpdir} modules | grep ^LINUX_ >${tmpdir}/ack
650 echo make modules with LINUX_DIR=$(LINUX_DIR) failed.
656 LINUX_MODULE_EXT=".o"
657 LINUX_MODULE_STYLE="2.4.0"
659 LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_MODFLAGS"
661 dnl if we have REDHAT_CFLAGS, put them in LINUX_CFLAGS
662 if test "x$REDHAT_CFLAGS" != "x";
664 LINUX_CFLAGS="$LINUX_CFLAGS $REDHAT_CFLAGS"
667 AC_SUBST(LINUX_AFLAGS)
668 AC_SUBST(LINUX_LDFLAGS)
669 AC_SUBST(LINUX_ARFLAGS)
670 AC_SUBST(LINUX_CROSS_COMPILE)
671 AC_SUBST(LINUX_KERNELRELEASE)
672 AC_SUBST(LINUX_CFLAGS)
676 AC_SUBST(LINUX_MODULE_EXT)
677 AC_SUBST(LINUX_MODULE_STYLE)
681 AC_MSG_CHECKING(for Linux 2.4 CFLAGS)
682 AC_MSG_RESULT($LINUX_CFLAGS)
683 AC_MSG_CHECKING(for Linux 2.4 LDFLAGS)
684 AC_MSG_RESULT($LINUX_LDFLAGS)
687 AC_DEFUN([AS_CHECK_LINUX_CONFIG_OPTION],
689 AC_MSG_CHECKING([Linux config option $1])
691 if grep '^$1=y$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
694 else if grep '^$1=m$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
703 AC_MSG_RESULT([$result])
706 AC_DEFUN([AS_LINUX_CONFIG_OPTION],
708 AS_CHECK_LINUX_CONFIG_OPTION([$1],
713 AM_CONDITIONAL([$1],[test "${$1}" = yes])
716 AC_DEFUN([AS_LINUX_CONFIG_OPTION_MODULE],
718 AS_CHECK_LINUX_CONFIG_OPTION([$1],
723 AM_CONDITIONAL([$1],[test "${$1}" = yes -o "${$1}" = module])
726 dnl check for the major/minor version of the Linux source by checking
728 dnl first argument is the linux directory
729 dnl sets LINUX_VERSION_MAJOR and LINUX_VERSION_MINOR
730 AC_DEFUN([AS_LINUX_VERSION_MAJOR_MINOR],
733 AC_MSG_CHECKING([Linux major/minor version])
735 if [[ ! -f "${LINUX_DIR}/Makefile" ]];then
736 AC_MSG_ERROR([The Linux kernel Makefile does not exist.])
738 dnl the next set of tests is for figuring out version major/minor
739 dnl use VERSION and PATCHLEVEL in the kernel Makefile
740 LINUX_VERSION_MAJOR=`sed -n 's/^VERSION = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
741 LINUX_VERSION_MINOR=`sed -n 's/^PATCHLEVEL = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
742 if [[ -z "$LINUX_VERSION_MAJOR" -o -z "$LINUX_VERSION_MINOR" ]]; then
743 AC_MSG_ERROR([No major/minor version information found in Linux kernel Makefile.])
745 AC_MSG_RESULT($LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR)
748 # COMEDI_CHECK_LINUX_KBUILD([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
749 # -------------------------------------------------------------
751 # Check if kernel source tree is recent enough to support "Kbuild" files.
752 AC_DEFUN([COMEDI_CHECK_LINUX_KBUILD],
754 AC_MSG_CHECKING([for Kbuild support in $1])
755 dnl If $1/scripts/Makefile.build refers to $(<something>)/Kbuild
756 dnl then we support Kbuild (2.6.10 onwards).
757 if grep -q '/Kbuild' "$1/scripts/Makefile.build" 2>/dev/null; then
766 # COMEDI_CHECK_PCMCIA_PROBE([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
767 # -------------------------------------------------------------
769 # Check if kernel pcmcia support is new enough to have a probe member in the pcmcia_driver
771 AC_DEFUN([COMEDI_CHECK_PCMCIA_PROBE],
773 AC_REQUIRE([AC_PROG_EGREP])
774 AC_MSG_CHECKING([$1 for probe in pcmcia_driver struct])
775 cat "$1/include/pcmcia/ds.h" | tr \\n ' ' | [$EGREP "struct[[:space:]]+pcmcia_driver[[:space:]]*[{][^}]*probe"] > /dev/null
785 # COMEDI_CHECK_HAVE_MUTEX_H([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
786 # -------------------------------------------------------------
788 # Check if kernel has <linux/mutex.h> file.
789 AC_DEFUN([COMEDI_CHECK_HAVE_MUTEX_H],
791 AC_MSG_CHECKING([$1 for include/linux/mutex.h])
792 if test -f "$1/include/linux/mutex.h"; then