turn pcmcia support on or off by default depending on whether
[comedi.git] / m4 / as-linux.m4
1 dnl as-linux.m4 0.2.0
2
3 dnl autostars m4 macro for detecting a Linux source tree (or
4 dnl equivalent) for compiling modules.
5
6 dnl David Schleef <ds@schleef.org>
7 dnl Frank Mori Hess <fmhess@users.sourceforge.net>
8 dnl Thomas Vander Stichele <thomas@apestaart.org>
9
10 dnl $Id$
11
12 dnl AS_LINUX()
13 dnl
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
23
24 dnl this macro defines:
25 dnl LINUX_DIR
26 dnl   The directory where the Linux source resides.
27 dnl CONFIG_FILE
28 dnl   The Linux config file
29 dnl LINUX_ARCH
30 dnl   $(ARCH) in kernel Makefiles
31 dnl LINUX_AFLAGS
32 dnl   $(AFLAGS) in kernel Makefiles
33 dnl LINUX_LDFLAGS
34 dnl   Linker flags used by Linux
35 dnl LINUX_ARFLAGS
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
41 dnl   Linux Makefiles.
42 dnl LINUX_CFLAGS
43 dnl   CFLAGS used by Linux.  Includes both $CFLAGS and $MODFLAGS from
44 dnl   kernel Makefiles. Also includes warnings and optimization.
45 dnl LINUX_CC
46 dnl   Compiler used by Linux.
47 dnl LINUX_LD
48 dnl   Path to linker (possibly with options) used by Linux.
49 dnl LINUX_AS
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)
53 dnl LINUX_MODULE_EXT
54 dnl   Module extension (.o or .ko)
55 dnl LINUX_MODPOST
56 dnl   path to modpost script
57 dnl modulesdir
58 dnl   base install path for kernel modules
59 dnl modulesdeveldir
60 dnl   base install path for kernel module development files
61 dnl 
62 dnl End of search list.
63
64 dnl main entry point
65 dnl checks the version, and figures out all flags to use to make modules.
66 AC_DEFUN([AS_LINUX],
67 [
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
71         AS_LINUX_MACHINE()       
72         dnl check if the user supplied an rpm target arch
73         dnl override the LINUX_MACHINE value if he did
74         AS_LINUX_RPM_TARGET()    
75          
76         dnl find the kernel source tree for the given uname -r   
77         AS_LINUX_DIR()
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)
91
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
96                 2.6)
97                         AS_LINUX_2_6()
98                         ;;
99                 2.[[01234]])
100                         AS_LINUX_2_4()
101                         ;;
102                 *)
103                         AC_MSG_ERROR([Unknown Linux major.minor $LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR])
104                         ;;
105         esac
106 ])
107
108
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],
112 [
113         AC_ARG_WITH([linuxdir],
114                 [AC_HELP_STRING([--with-linuxdir=DIR],
115                         [specify path to Linux source directory])],
116                 [LINUX_DIR="${withval}"],
117                 [LINUX_DIR=default])
118
119         if test "${LINUX_DIR}" != "default" ; then
120                 AS_TRY_LINUX_DIR([${LINUX_DIR}], , AC_MSG_ERROR([Linux dir not found]) )
121         fi
122
123         if test "${LINUX_DIR}" = "default" ; then
124                 dir="/lib/modules/$LINUX_KERNEL_RELEASE/build";
125                 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
126         fi
127         if test "${LINUX_DIR}" = "default" ; then
128                 dir="../linux";
129                 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
130         fi
131         if test "${LINUX_DIR}" = "default" ; then
132                 dir="/usr/src/linux";
133                 AS_TRY_LINUX_DIR([${dir}], [LINUX_DIR=${dir}], )
134         fi
135
136         if test "${LINUX_DIR}" = "default" ; then
137                 AC_MSG_ERROR([Linux source directory not found])
138         fi
139
140         AC_SUBST(LINUX_DIR)
141 ])
142
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)
146
147         if test -f "$1/Makefile" ; then
148                 result=yes
149                 $2
150         else
151                 result="not found"
152                 $3
153         fi
154
155         AC_MSG_RESULT($result)
156 ])
157
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],
162 [
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";
169         then
170                 LINUX_KERNEL_RELEASE=`uname -r`
171         fi
172         AC_MSG_NOTICE([Using $LINUX_KERNEL_RELEASE as the uname -r value])
173 ])
174
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],
179 [
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";
186         then
187                 LINUX_MACHINE=`uname -r`
188         fi
189         AC_MSG_NOTICE([Using $LINUX_MACHINE as the uname -m value])
190 ])
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
197
198 dnl this macro possibly overrides LINUX_MACHINE
199
200 dnl first argument is the kernel release building for
201 AC_DEFUN([AS_LINUX_RPM_TARGET],
202 [
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}"],
208                 [LINUX_RPM_TARGET=])
209         if test "x$LINUX_RPM_TARGET" = "x"
210         then
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, yes, no)
214                 if test "x$RPM" != "xno" ; then
215                         AC_MSG_CHECKING([if rpm can be used to query packages])
216                         if rpm -qa >/dev/null 2>/dev/null ; then
217                           rpm_check=yes
218                         else
219                           rpm_check=no
220                         fi
221                         AC_MSG_RESULT($rpm_check)
222
223                         if test "x$rpm_check" = yes ; then
224                           if rpm -q kernel-$RELEASE > /dev/null
225                           then
226                             LINUX_RPM_TARGET=`rpm -q --queryformat %{arch} kernel-$RELEASE`
227                           else
228                             AC_MSG_NOTICE([Cannot guess target arch, consider setting it using --with-rpm-target])
229                           fi
230                         fi
231                 fi
232         fi
233
234         dnl now override LINUX_MACHINE if LINUX_RPM_TARGET is set
235         if test "x$LINUX_RPM_TARGET" != "x"
236         then
237                 dnl override LINUX_MACHINE based on this
238                 dnl FIXME: add other possible Red Hat/Fedora/rpm targets here
239                 LINUX_MACHINE=
240                 case "$LINUX_RPM_TARGET" in
241                         i?86) LINUX_MACHINE=i386;;
242                         athlon) LINUX_MACHINE=i386;;
243                         x86_64) LINUX_MACHINE=x86_64;;
244                 esac
245                 if test "x$LINUX_MACHINE" = "x"
246                 then
247                 AC_MSG_ERROR(Could not guess uname -m value from target $LINUX_RPM_TARGET)
248                 fi
249         fi
250 ])
251
252
253 dnl allow for specifying an override for EXTRAVERSION
254 dnl if none specified, make it from the passed-in KERNEL_RELEASE (uname -r)
255 dnl resulting value is stored in LINUX_EXTRAVERSION
256 dnl first argument is the uname -r string to use as a fallback
257 AC_DEFUN([AS_LINUX_EXTRAVERSION],
258 [
259         KERNEL_RELEASE=[$1]
260         dnl extract the default by getting everything after first -
261         LINUX_EXTRAVERSION="-`echo $KERNEL_RELEASE | cut -d- -f 2-`"
262         AC_ARG_WITH([extraversion],
263                 [AC_HELP_STRING([--with-extraversion=FILE],
264                         [specify override for kernel EXTRAVERSION])],
265                 [LINUX_EXTRAVERSION="${withval}"],)
266 ])
267
268
269 dnl check if we can find a config file for the Linux kernel
270 dnl defines LINUX_CONFIG to the absolute location of a usable
271 dnl kernel source config file
272
273 dnl for rpm distros, it can try and guess the correct config file by
274 dnl checking the global LINUX_RPM_TARGET variable set somewhere else
275 dnl (FIXME: move this to an argument instead ?)
276
277 dnl first argument is LINUX_DIR to check for possible configs
278 dnl second argument is kernel-release (uname -r)
279 dnl third argument is machine (uname -m)
280
281 AC_DEFUN([AS_LINUX_CONFIG],
282 [
283         LINUX_DIR=[$1]
284         KERNEL_RELEASE=[$2]
285         MACHINE=[$3]
286         AC_ARG_WITH([linuxconfig],
287                 [AC_HELP_STRING([--with-linuxconfig=FILE],
288                         [specify path to Linux configuration file])],
289                 [LINUX_CONFIG="${withval}"],
290                 [LINUX_CONFIG=default])
291
292         dnl if a file got specified, try it as a linux config file
293         if test "${LINUX_CONFIG}" != "default" ; then
294                 AS_TRY_LINUX_CONFIG($LINUX_CONFIG, $MACHINE,
295                                     ,, AC_MSG_ERROR([Linux config not found]) )
296         fi
297
298         dnl if no file specified, first check for the regular .config file
299         dnl in LINUX_DIR created by manual configuration
300         if test "${LINUX_CONFIG}" = "default" ; then
301                 file="$LINUX_DIR/.config";
302                 AS_TRY_LINUX_CONFIG($file, $MACHINE,
303                                     [LINUX_CONFIG=${file}], )
304         fi
305         dnl second, try to guess what config file to use for the current kernel
306         dnl FIXME: the possible arch is from rpmbuild --target, and is
307         dnl different from the value of ARCH (Makefile) or MACHINE (uname -m)
308         dnl so we should have a redhat flag to specify the target to find
309         dnl the correct config file
310         if test "${LINUX_CONFIG}" = "default" && test "x$LINUX_RPM_TARGET" != "x"; then
311                 dnl Red Hat stores configuration files for their built kernels
312                 dnl named kernel-(version)-(arch)(extra).config
313                 dnl where arch is athlon, i386, i586, i686, x86_64
314                 dnl and (extra) is empty or -smp, -BOOT, -bigmem
315                 dnl haven't seen combinations of extra yet as of FC1
316                 KVERSION=`echo $KERNEL_RELEASE | cut -d- -f1`
317                 extra=
318                 echo $KERNEL_RELEASE | grep smp && EXTRA="-smp"
319                 echo $KERNEL_RELEASE | grep bigmem && EXTRA="-bigmem"
320                 echo $KERNEL_RELEASE | grep BOOT && EXTRA="-BOOT"
321                 file="$LINUX_DIR/configs/kernel-$KVERSION-$LINUX_RPM_TARGET$EXTRA.config"
322                 AS_TRY_LINUX_CONFIG($file, $MACHINE,
323                                     [LINUX_CONFIG=${file}], )
324         fi
325         if test "${LINUX_CONFIG}" = "default" ; then
326                 AC_MSG_ERROR([
327 The kernel source tree at ${LINUX_DIR} is not configured,
328 and no configuration files in config/ matching your kernel were found.
329 Fix before continuing or specify a config file using --with-configfile.])
330         fi
331
332         AC_SUBST(LINUX_CONFIG)
333 ])
334
335 dnl check if the given candidate config file is usable
336 dnl FIXME: it would be nice if it could check if it matches the
337 dnl given machine (uname -m)
338 AC_DEFUN([AS_TRY_LINUX_CONFIG],
339 [
340         CFG=[$1]
341         MACHINE=[$2]
342         AC_MSG_CHECKING($CFG)
343
344         if test -f "$CFG" ; then
345                 result=yes
346                 ifelse([$3], , :, [$3])
347         else
348                 result="not found"
349                 ifelse([$4], , :, [$4])
350         fi
351         AC_MSG_RESULT($result)
352 ])
353
354 dnl check if RED_HAT_LINUX_KERNEL is defined
355 dnl pre-FC2 RH/Fedora defines this in linux/rhconfig.h
356 dnl included from linux/version.h
357 dnl if this is present, a few extra defines need to be present to make sure
358 dnl symbol versioning is correct
359 dnl uses LINUX_DIR to find rhconfig.h
360 AC_DEFUN([AS_CHECK_REDHAT_PRE_FC2],
361 [
362         AC_MSG_CHECKING(Pre-FC2 Red Hat/Fedora kernel)
363         HAVE_REDHAT_KERNEL=false
364         ac_save_CFLAGS="$CFLAGS"
365         CFLAGS="$CFLAGS -I${LINUX_DIR}/include/linux"
366         AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
367 #include "rhconfig.h"
368 int code = RED_HAT_LINUX_KERNEL;
369         ]),
370         AC_MSG_RESULT(found); HAVE_REDHAT_KERNEL=true,
371         AC_MSG_RESULT(not found))
372         dnl restore CFLAGS
373         CFLAGS="$ac_save_CFLAGS"
374
375         dnl check for Red Hat define flags to use - see /sbin/mkkerneldoth
376
377         dnl initialize the booleans we want to detect
378         ENTERPRISE='0'
379         SMP='0'
380         UP='0'
381         BIGMEM='0'
382         HUGEMEM='0'
383
384         dnl get variables from the currently running kernel as default 
385         KERNEL_TYPE=`uname -r | sed 's_^.*\(smp\|enterprise\|bigmem\|hugemem\)$_\1_;t;s_.*__;'`
386         KERNEL_RELEASE=`uname -r | sed 's|smp\|enterprise\|bigmem\|hugemem||g'`
387         KERNEL_ARCH=`uname -m`
388
389         dnl check the config file and override KERNEL_ARCH
390         AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M386, KERNEL_ARCH=i386)
391         AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M586, KERNEL_ARCH=i586)
392         AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_M686, KERNEL_ARCH=i686)
393         dnl for some reason the i686 bigmem config file has PENTIUM
394         AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MPENTIUMIII, KERNEL_ARCH=i686)
395         AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_MK7, KERNEL_ARCH=athlon)
396
397         dnl check the config file and override KERNEL_TYPE
398         AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_SMP, KERNEL_TYPE=smp)
399         dnl bigmem is also smp, so this check is done after smp to override
400         AS_CHECK_LINUX_CONFIG_OPTION(CONFIG_HIGHMEM64G, KERNEL_TYPE=bigmem)
401
402         dnl FIXME: need to check hugemem and enterprise config files, which
403         dnl aren't provided in Fedora Core 1 !
404
405         case "$KERNEL_TYPE" in
406                 smp) SMP='1';;
407                 enterprise) ENTERPRISE='1';;
408                 bigmem) BIGMEM='1';;
409                 hugemem) HUGEMEM='1';;
410                 *) UP='1';;
411         esac
412         REDHAT_CFLAGS="-D__MODULE_KERNEL_$KERNEL_ARCH=1"
413         REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_ENTERPRISE=$ENTERPRISE"
414         REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_UP=$UP"
415         REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_SMP=$SMP"
416         REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_BIGMEM=$BIGMEM"
417         REDHAT_CFLAGS="$REDHAT_CFLAGS -D__BOOT_KERNEL_HUGEMEM=$HUGEMEM"
418
419         LINUX_REDHAT_CFLAGS="$REDHAT_CFLAGS"
420
421         AC_SUBST(LINUX_KERNEL_TYPE, "$KERNEL_TYPE")
422 ])
423
424 dnl add an argument to specify/override the module install path
425 dnl if nothing specified, it will be /lib/modules/(kernelrel)
426 AC_DEFUN([AS_LINUX_MODULESDIR],
427 [
428         KERNEL_RELEASE=[$1]
429         AC_ARG_WITH([modulesdir],
430                 [AC_HELP_STRING([--with-modulesdir=DIR],
431                         [specify path to kernel-specific modules install directory])],
432                 [MODULESDIR="${withval}"],
433                 [MODULESDIR=default])
434
435         if test "${MODULESDIR}" = "default" ; then
436                 MODULESDIR="/lib/modules/${KERNEL_RELEASE}"
437         fi
438         dnl make it available to Makefiles so it can be used in ...dir
439         AC_SUBST(modulesdir, $MODULESDIR)
440         AC_MSG_NOTICE([Putting kernel modules under ${MODULESDIR}])
441 ])
442
443 dnl add an argument to specify/override the module devel install path
444 dnl if nothing specified, it will be the passed in LINUXDIR)
445 AC_DEFUN([AS_LINUX_MODULESDEVELDIR],
446 [
447         LINUXDIR=[$1]
448         AC_ARG_WITH([modulesdeveldir],
449                 [AC_HELP_STRING([--with-modulesdeveldir=DIR],
450                         [specify path to kernel-specific module development install directory])],
451                 [MODULESDEVELDIR="${withval}"],
452                 [MODULESDEVELDIR=default])
453
454         if test "${MODULESDEVELDIR}" = "default" ; then
455                 MODULESDEVELDIR="${LINUXDIR}"
456         fi
457         dnl make it available to Makefiles so it can be used in ...dir
458         AC_SUBST(modulesdeveldir, $MODULESDEVELDIR)
459         AC_MSG_NOTICE([Putting kernel module development files under ${MODULESDEVELDIR}])
460 ])
461
462 AC_DEFUN([AS_LINUX_2_6],
463 [
464         AC_MSG_CHECKING(for Linux CFLAGS)
465
466         {
467           tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
468           test -n "$tmpdir" && test -d "$tmpdir"
469         } ||
470         {
471           tmpdir=./confstat$$-$RANDOM
472           (umask 077 && mkdir $tmpdir)
473         } ||
474         {
475           echo "$me: cannot create a temporary directory in ." >&2
476           { (exit 1); exit 1; }
477         }
478
479         tmpdir=`pwd`/$tmpdir
480
481         cat >${tmpdir}/Makefile <<EOF
482 obj-m += fake.o
483
484 \$(obj)/fake.c: flags
485         touch \$(obj)/fake.c
486
487 .PHONY: flags
488 flags:
489         echo LINUX_ARCH=\"\$(ARCH)\" >>\$(obj)/flags
490         echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's,include,"\$(LINUXDIR)/include",g'>>\$(obj)/flags
491         echo LINUX_LDFLAGS=\"\" >>\$(obj)/flags
492         echo LINUX_ARFLAGS=\"\$(ARFLAGS)\" >>\$(obj)/flags
493         echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\" >>\$(obj)/flags
494         echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\" >>\$(obj)/flags
495         echo LINUX_CFLAGS=\"\$(CFLAGS) \$(CPPFLAGS)\" \
496                 | sed -e 's,-Iinclude,-I\$(LINUXDIR)/include,g' -e 's,-include include,-include \$(LINUXDIR)/include,g' >>\$(obj)/flags
497         echo LINUX_CFLAGS_MODULE=\"\$(CFLAGS_MODULE)\" >>\$(obj)/flags
498         echo LINUX_CC=\"\$(CC)\" >>\$(obj)/flags
499         echo LINUX_LD=\"\$(LD) \$(LDFLAGS) \$(LDFLAGS_MODULE)\" >>\$(obj)/flags
500         echo LINUX_AS=\"\$(AS)\" >>\$(obj)/flags
501 EOF
502
503         echo ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
504         ${MAKE-make} -C ${LINUX_DIR} V=1 SUBDIRS=${tmpdir} LINUXDIR=${LINUX_DIR} modules >&5 2>&5
505         . ${tmpdir}/flags
506         rm -rf ${tmpdir}
507
508         LINUX_MODULE_EXT=".ko"
509         LINUX_MODULE_STYLE="2.6.6"
510
511         LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_CFLAGS_MODULE"
512
513         AC_SUBST(LINUX_ARCH)
514         AC_SUBST(LINUX_AFLAGS)
515         AC_SUBST(LINUX_LDFLAGS)
516         AC_SUBST(LINUX_ARFLAGS)
517         AC_SUBST(LINUX_CROSS_COMPILE)
518         AC_SUBST(LINUX_KERNELRELEASE)
519         AC_SUBST(LINUX_CFLAGS)
520         AC_SUBST(LINUX_CC)
521         AC_SUBST(LINUX_LD)
522         AC_SUBST(LINUX_AS)
523         AC_SUBST(LINUX_MODULE_EXT)
524         AC_SUBST(LINUX_MODULE_STYLE)
525         AC_SUBST(LINUX_MODPOST)
526
527         AC_MSG_RESULT([$LINUX_CFLAGS])
528         
529         AC_PATH_PROG([LINUX_MODPOST], ["modpost"], ["no"], ["$LINUX_DIR/scripts:$LINUX_DIR/scripts/mod"])
530 ])
531
532
533 AC_DEFUN([AS_LINUX_2_4],
534 [
535         AC_MSG_CHECKING(for Linux 2.4 make flags)
536         dnl we try to figure out the CFLAGS by invoking the Makefile on
537         dnl a test dir
538         dnl we use the correct config file by substituting the MAKEFILES
539         dnl Makefile variable, which originally points to .config
540
541         if [[ ! -e "${LINUX_DIR}/.hdepend" ]];then
542                 AC_MSG_WARN([
543 No .hdepend file found, you may need to run 'make dep' on the kernel source before continuing.])
544         fi
545
546         {
547           tmpdir=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
548           test -n "$tmpdir" && test -d "$tmpdir"
549         } ||
550         {
551           tmpdir=./confstat$$-$RANDOM
552           (umask 077 && mkdir $tmpdir)
553         } ||
554         {
555           echo "$me: cannot create a temporary directory in ." >&2
556           { (exit 1); exit 1; }
557         }
558         tmpdir=`pwd`/$tmpdir
559
560         #sed "s|\.config|${CONFIG_FILE}|g" ${LINUX_DIR}/Makefile >$tmpdir/Makefile
561         cat >$tmpdir/Makefile <<EOF
562 modules:
563         @echo LINUX_ARCH=\"\$(ARCH)\"
564         @echo LINUX_AFLAGS=\"\$(AFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
565         @echo LINUX_LDFLAGS=\"\"
566         @echo LINUX_ARFLAGS=\"\$(ARFLAGS)\"
567         @echo LINUX_CROSS_COMPILE=\"\$(CROSS_COMPILE)\"
568         @echo LINUX_KERNELRELEASE=\"\$(KERNELRELEASE)\"
569         @echo LINUX_CFLAGS=\"\$(CFLAGS)\" | sed 's_Iinclude_I\"\$(LINUXDIR)/include\"_g'
570         @echo LINUX_MODFLAGS=\"\$(MODFLAGS)\"
571         @echo LINUX_CC=\"\$(CC)\"
572         @echo LINUX_LD=\"\$(LD) \$(LDFLAGS)\"
573         @echo LINUX_AS=\"\$(AS)\"
574 EOF
575         make -C ${LINUX_DIR} SUBDIRS=${tmpdir} modules | grep ^LINUX_ >${tmpdir}/ack
576         if (($?)); then
577                 echo make modules with LINUX_DIR=$(LINUX_DIR) failed.
578                 exit 1
579         fi
580         . ${tmpdir}/ack
581         rm -rf ${tmpdir}
582
583         LINUX_MODULE_EXT=".o"
584         LINUX_MODULE_STYLE="2.4.0"
585
586         LINUX_CFLAGS="$LINUX_CFLAGS $LINUX_MODFLAGS"
587
588         dnl if we have REDHAT_CFLAGS, put them in LINUX_CFLAGS
589         if test "x$REDHAT_CFLAGS" != "x";
590         then
591                 LINUX_CFLAGS="$LINUX_CFLAGS $REDHAT_CFLAGS"
592         fi
593         AC_SUBST(LINUX_ARCH)
594         AC_SUBST(LINUX_AFLAGS)
595         AC_SUBST(LINUX_LDFLAGS)
596         AC_SUBST(LINUX_ARFLAGS)
597         AC_SUBST(LINUX_CROSS_COMPILE)
598         AC_SUBST(LINUX_KERNELRELEASE)
599         AC_SUBST(LINUX_CFLAGS)
600         AC_SUBST(LINUX_CC)
601         AC_SUBST(LINUX_LD)
602         AC_SUBST(LINUX_AS)
603         AC_SUBST(LINUX_MODULE_EXT)
604         AC_SUBST(LINUX_MODULE_STYLE)
605
606         AC_MSG_RESULT([ok])
607
608         AC_MSG_CHECKING(for Linux 2.4 CFLAGS)
609         AC_MSG_RESULT($LINUX_CFLAGS)
610         AC_MSG_CHECKING(for Linux 2.4 LDFLAGS)
611         AC_MSG_RESULT($LINUX_LDFLAGS)
612 ])
613
614 AC_DEFUN([AS_CHECK_LINUX_CONFIG_OPTION],
615 [
616         AC_MSG_CHECKING([Linux config option $1])
617
618         if grep '^$1=y$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
619                 result=yes
620                 $2
621         else if grep '^$1=m$' ${LINUX_CONFIG} >/dev/null 2>/dev/null; then
622                 result=module
623                 $3
624         else
625                 result=no
626                 $4
627         fi
628         fi
629
630         AC_MSG_RESULT([$result])
631 ])
632
633 AC_DEFUN([AS_LINUX_CONFIG_OPTION],
634 [
635         AS_CHECK_LINUX_CONFIG_OPTION([$1],
636                 [$1=yes],
637                 [$1=module],
638                 [$1=no])
639
640         AM_CONDITIONAL([$1],[test "${$1}" = yes])
641 ])
642
643 AC_DEFUN([AS_LINUX_CONFIG_OPTION_MODULE],
644 [
645         AS_CHECK_LINUX_CONFIG_OPTION([$1],
646                 [$1=yes],
647                 [$1=module],
648                 [$1=no])
649
650         AM_CONDITIONAL([$1],[test "${$1}" = yes -o "${$1}" = module])
651 ])
652
653 dnl check for the major/minor version of the Linux source by checking
654 dnl the Makefile
655 dnl first argument is the linux directory
656 dnl sets LINUX_VERSION_MAJOR and LINUX_VERSION_MINOR
657 AC_DEFUN([AS_LINUX_VERSION_MAJOR_MINOR],
658 [
659         LINUX_DIR=[$1]
660         AC_MSG_CHECKING([Linux major/minor version])
661
662         if [[ ! -f "${LINUX_DIR}/Makefile" ]];then
663                 AC_MSG_ERROR([The Linux kernel Makefile does not exist.])
664         fi
665         dnl the next set of tests is for figuring out version major/minor
666         dnl use VERSION and PATCHLEVEL in the kernel Makefile
667         LINUX_VERSION_MAJOR=`sed -n 's/^VERSION = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
668         LINUX_VERSION_MINOR=`sed -n 's/^PATCHLEVEL = \([[0-9]]*\)/\1/p' "${LINUX_DIR}/Makefile"`
669         if [[ -z "$LINUX_VERSION_MAJOR" -o -z "$LINUX_VERSION_MINOR" ]]; then
670                 AC_MSG_ERROR([No major/minor version information found in Linux kernel Makefile.])
671         fi
672         AC_MSG_RESULT($LINUX_VERSION_MAJOR.$LINUX_VERSION_MINOR)
673 ])
674
675 # COMEDI_CHECK_LINUX_KBUILD([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
676 # -------------------------------------------------------------
677 #
678 # Check if kernel source tree is recent enough to support "Kbuild" files.
679 AC_DEFUN([COMEDI_CHECK_LINUX_KBUILD],
680 [
681         AC_MSG_CHECKING([for Kbuild support in $1])
682         dnl For combined kernel source and build directory,
683         dnl if $1/scripts/Makefile.build refers to $(<something>)/Kbuild
684         dnl then we support Kbuild (2.6.10 onwards).
685         dnl For separate kernel source and build directory, if $1/Makefile
686         dnl contains KERNELOUTPUT variable then this is from a separate
687         dnl kernel build directory, so Kbuild is required
688         dnl (but it will not work prior to 2.6.10).
689         if grep -q '/Kbuild' "$1/scripts/Makefile.build" 2>/dev/null; then
690                 AC_MSG_RESULT([yes])
691                 $2
692         else if grep -q '^KERNELOUTPUT *:=' "$1/Makefile" 2>/dev/null; then
693                 AC_MSG_RESULT([yes])
694                 $2
695         else
696                 AC_MSG_RESULT([no])
697                 $3
698         fi
699         fi
700 ])
701
702 # COMEDI_CHECK_PCMCIA_PROBE([LINUX_SOURCE_PATH], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
703 # -------------------------------------------------------------
704 #
705 # Check if kernel pcmcia support is new enough to have a probe member in the pcmcia_driver
706 # struct.
707 AC_DEFUN([COMEDI_CHECK_PCMCIA_PROBE],
708 [
709         AC_REQUIRE([AC_PROG_EGREP])
710         AC_MSG_CHECKING([$1 for probe in pcmcia_driver struct])
711         cat "$1/include/pcmcia/ds.h" | tr \\n ' ' | [$EGREP "struct[[:space:]]+pcmcia_driver[[:space:]]*[{][^}]*probe"] > /dev/null
712         if (($?)); then
713                 AC_MSG_RESULT([no])
714                 $3
715         else
716                 AC_MSG_RESULT([yes])
717                 $2
718         fi
719 ])