Merge branch 'ofed' of git://flatbed.openfabrics.org/~tnikolova/compat/ into ofed
[~tnikolova/compat/.git] / config / build-linux.m4
1 # LB_CHECK_FILE
2 #
3 # Check for file existance even when cross compiling
4 #
5 AC_DEFUN([LB_CHECK_FILE],
6 [AS_VAR_PUSHDEF([lb_File], [lb_cv_file_$1])dnl
7 AC_CACHE_CHECK([for $1], lb_File,
8 [if test -r "$1"; then
9     AS_VAR_SET(lb_File, yes)
10 else
11     AS_VAR_SET(lb_File, no)
12 fi])
13 AS_IF([test AS_VAR_GET(lb_File) = yes], [$2], [$3])[]dnl
14 AS_VAR_POPDEF([lb_File])dnl
15 ])# LB_CHECK_FILE
16
17
18 #
19 # LB_LINUX_VERSION
20 #
21 # Set things accordingly for a linux kernel
22 #
23 AC_DEFUN([LB_LINUX_VERSION],[
24 KMODEXT=".ko"
25
26 MODULE_TARGET="SUBDIRS"
27 makerule="$PWD/build"
28 AC_MSG_CHECKING([for external module build support])
29 # Support XEN
30 XEN_INCLUDES=
31 LB_LINUX_CONFIG([XEN],[XEN_INCLUDES='-I$LINUX/arch/x86/include/mach-xen'],[])
32 LB_LINUX_CONFIG_VALUE([XEN_INTERFACE_VERSION],[XEN_INCLUDES="$XEN_INCLUDES -D__XEN_INTERFACE_VERSION__=$res"],[XEN_INCLUDES="$XEN_INCLUDES -D__XEN_INTERFACE_VERSION__=$res"])
33 #
34 rm -f build/conftest.i
35 LB_LINUX_TRY_MAKE([],[],
36         [$makerule OFA_KERNEL_TEST=conftest.i],
37         [test -s build/conftest.i],
38         [
39                 AC_MSG_RESULT([no])
40         ],[
41                 makerule="_module_$makerule"
42                 MODULE_TARGET="M"
43                 LB_LINUX_TRY_MAKE([],[],
44                         [$makerule OFA_KERNEL_TEST=conftest.i],
45                         [test -s build/conftest.i],
46                         [
47                                 AC_MSG_RESULT([yes])
48                         ],[
49                                 AC_MSG_ERROR([unknown; check config.log for details])
50                         ])
51         ])
52
53 AC_SUBST(MODULE_TARGET)
54 AC_SUBST(KMODEXT)
55 ])
56
57 #
58 # LB_LINUX_RELEASE
59 #
60 # get the release version of linux
61 #
62 AC_DEFUN([LB_LINUX_RELEASE],
63 [LINUXRELEASE=
64 rm -f build/conftest.i
65 AC_MSG_CHECKING([for Linux release])
66 if test -s $LINUX_OBJ/include/$AUTOCONF_HDIR/utsrelease.h ; then
67         LINUXRELEASEHEADER=$AUTOCONF_HDIR/utsrelease.h
68 else
69         LINUXRELEASEHEADER=linux/version.h
70 fi
71 LB_LINUX_TRY_MAKE([
72         #include <$LINUXRELEASEHEADER>
73 ],[
74         char *LINUXRELEASE;
75         LINUXRELEASE=UTS_RELEASE;
76 ],[
77         $makerule OFA_KERNEL_TEST=conftest.i
78 ],[
79         test -s build/conftest.i
80 ],[
81         # LINUXRELEASE="UTS_RELEASE"
82         eval $(grep "LINUXRELEASE=" build/conftest.i)
83 ],[
84         AC_MSG_RESULT([unknown])
85         AC_MSG_ERROR([Could not preprocess test program.  Consult config.log for details.])
86 ])
87 rm -f build/conftest.i
88 if test x$LINUXRELEASE = x ; then
89         AC_MSG_RESULT([unknown])
90         AC_MSG_ERROR([Could not determine Linux release version from linux/version.h.])
91 fi
92 AC_MSG_RESULT([$LINUXRELEASE])
93 AC_SUBST(LINUXRELEASE)
94
95 moduledir='/lib/modules/'$LINUXRELEASE/updates/kernel
96 AC_SUBST(moduledir)
97
98 modulefsdir='$(moduledir)/fs/$(PACKAGE)'
99 AC_SUBST(modulefsdir)
100
101 modulenetdir='$(moduledir)/net/$(PACKAGE)'
102 AC_SUBST(modulenetdir)
103
104 # ------------ RELEASE --------------------------------
105 AC_MSG_CHECKING([for OFA release])
106 AC_ARG_WITH([release],
107         AC_HELP_STRING([--with-release=string],
108                        [set the release string (default=$kvers_YYYYMMDDhhmm)]),
109         [RELEASE=$withval],
110         RELEASE=""
111         if test -n "$DOWNSTREAM_RELEASE"; then
112                 RELEASE="${DOWNSTREAM_RELEASE}_"
113         fi
114         RELEASE="$RELEASE`echo ${LINUXRELEASE} | tr '-' '_'`_$BUILDID")
115 AC_MSG_RESULT($RELEASE)
116 AC_SUBST(RELEASE)
117
118 # check is redhat/suse kernels
119 AC_MSG_CHECKING([that RedHat kernel])
120 LB_LINUX_TRY_COMPILE([
121                 #include <linux/version.h>
122         ],[
123                 #ifndef RHEL_RELEASE_CODE
124                 #error "not redhat kernel"
125                 #endif
126         ],[
127                 RHEL_KERNEL="yes"
128                 AC_MSG_RESULT([yes])
129         ],[
130                 AC_MSG_RESULT([no])
131 ])
132
133 LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
134
135 ])
136
137 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
138 AC_DEFUN([LB_ARG_REPLACE_PATH],[
139         new_configure_args=
140         eval "set x $ac_configure_args"
141         shift
142         for arg; do
143                 case $arg in
144                         --with-[$1]=*)
145                                 arg=--with-[$1]=[$2]
146                                 ;;
147                         *\'*)
148                                 arg=$(printf %s\n ["$arg"] | \
149                                       sed "s/'/'\\\\\\\\''/g")
150                                 ;;
151                 esac
152                 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
153                 new_configure_args="$new_configure_args \"$arg\""
154         done
155         ac_configure_args=$new_configure_args
156 ])
157
158 # this is the work-horse of the next function
159 AC_DEFUN([__LB_ARG_CANON_PATH], [
160         [$3]=$(readlink -f $with_$2)
161         LB_ARG_REPLACE_PATH([$1], $[$3])
162 ])
163
164 # a front-end for the above function that transforms - and . in the
165 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
166 AC_DEFUN([LB_ARG_CANON_PATH], [
167         __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
168 ])
169
170 #
171 #
172 # LB_LINUX_PATH
173 #
174 # Find paths for linux, handling kernel-source rpms
175 #
176 AC_DEFUN([LB_LINUX_PATH],
177 [# prep some default values
178 for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
179         if readlink -q -e $DEFAULT_LINUX; then
180                 break
181         fi
182 done
183 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
184         PATHS="/lib/modules/$(uname -r)/build"
185 fi
186 PATHS+=" $DEFAULT_LINUX"
187 for DEFAULT_LINUX_OBJ in $PATHS; do
188         if readlink -q -e $DEFAULT_LINUX_OBJ; then
189                 break
190         fi
191 done
192 AC_MSG_CHECKING([for Linux sources])
193 AC_ARG_WITH([linux],
194         AC_HELP_STRING([--with-linux=path],
195                        [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
196         [LB_ARG_CANON_PATH([linux], [LINUX])
197         DEFAULT_LINUX_OBJ=$LINUX],
198         [LINUX=$DEFAULT_LINUX])
199 AC_MSG_RESULT([$LINUX])
200 AC_SUBST(LINUX)
201
202 # -------- check for linux --------
203 LB_CHECK_FILE([$LINUX],[],
204         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
205
206 # -------- linux objects (for 2.6) --
207 AC_MSG_CHECKING([for Linux objects dir])
208 AC_ARG_WITH([linux-obj],
209         AC_HELP_STRING([--with-linux-obj=path],
210                         [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
211         [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
212         [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
213
214 AC_MSG_RESULT([$LINUX_OBJ])
215 AC_SUBST(LINUX_OBJ)
216
217 # -------- check for .config --------
218 AC_ARG_WITH([linux-config],
219         [AC_HELP_STRING([--with-linux-config=path],
220                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
221         [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
222         [LINUX_CONFIG=$LINUX_OBJ/.config])
223 AC_SUBST(LINUX_CONFIG)
224
225 LB_CHECK_FILE([/boot/kernel.h],
226         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
227         [LB_CHECK_FILE([/var/adm/running-kernel.h],
228                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
229
230 AC_ARG_WITH([kernel-source-header],
231         AC_HELP_STRING([--with-kernel-source-header=path],
232                         [Use a different kernel version header.  Consult build/README.kernel-source for details.]),
233         [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
234
235 # ------------ .config exists ----------------
236 LB_CHECK_FILE([$LINUX_CONFIG],[],
237         [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult build/README.kernel-source])])
238
239 # ----------- make dep run? ------------------
240 # at 2.6.19 # $LINUX/include/linux/config.h is removed
241 # and at more old has only one line
242 # include <autoconf.h>
243 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],[AUTOCONF_HDIR=generated],
244         [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[AUTOCONF_HDIR=linux],
245         [AC_MSG_ERROR([Run make config in $LINUX.])])])
246         AC_SUBST(AUTOCONF_HDIR)
247
248 # ----------- kconfig.h exists ---------------
249 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
250 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
251 LB_CHECK_FILE([$LINUX/include/linux/kconfig.h],
252               [CONFIG_INCLUDE=$LINUX/include/linux/kconfig.h],
253               [CONFIG_INCLUDE=$LINUX/include/$AUTOCONF_HDIR/kconfig.h])
254         AC_SUBST(CONFIG_INCLUDE)
255
256 # ------------ rhconfig.h includes runtime-generated bits --
257 # red hat kernel-source checks
258
259 # we know this exists after the check above.  if the user
260 # tarred up the tree and ran make dep etc. in it, then
261 # version.h gets overwritten with a standard linux one.
262 #
263 if (grep -q rhconfig $LINUX_OBJ/include/linux/version.h 2>/dev/null) ||
264    (grep -q rhconfig $LINUX_OBJ/include/generated/uapi/linux/version.h 2>/dev/null) ; then
265         # This is a clean kernel-source tree, we need to
266         # enable extensive workarounds to get this to build
267         # modules
268         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
269                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
270                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
271                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
272                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
273                 fi],
274                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
275         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
276 fi
277
278 # this is needed before we can build modules
279 LB_LINUX_CROSS
280 LB_LINUX_VERSION
281
282 # --- check that we can build modules at all
283 AC_MSG_CHECKING([that modules can be built at all])
284 LB_LINUX_TRY_COMPILE([],[],[
285         AC_MSG_RESULT([yes])
286 ],[
287         AC_MSG_RESULT([no])
288         AC_MSG_WARN([Consult config.log for details.])
289         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
290         AC_MSG_ERROR([Kernel modules cannot be built.])
291 ])
292
293 LB_LINUX_RELEASE
294 ]) # end of LB_LINUX_PATH
295
296 # LB_LINUX_SYMVERFILE
297 # SLES 9 uses a different name for this file - unsure about vanilla kernels
298 # around this version, but it matters for servers only.
299 AC_DEFUN([LB_LINUX_SYMVERFILE],
300         [AC_MSG_CHECKING([name of module symbol version file])
301         if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
302                 SYMVERFILE=Modules.symvers
303         else
304                 SYMVERFILE=Module.symvers
305         fi
306         AC_MSG_RESULT($SYMVERFILE)
307         AC_SUBST(SYMVERFILE)
308 ])
309
310 #
311 # LB_LINUX_CROSS
312 #
313 # check for cross compilation
314 #
315 AC_DEFUN([LB_LINUX_CROSS],
316         [AC_MSG_CHECKING([for cross compilation])
317 CROSS_VARS=
318 case $target_vendor in
319         # The K1OM architecture is an extension of the x86 architecture.
320         # So, the $target_arch is x86_64.
321         k1om)
322                 AC_MSG_RESULT([Intel(R) Xeon Phi(TM)])
323                 CC_TARGET_ARCH=`$CC -v 2>&1 | grep Target: | sed -e 's/Target: //'`
324                 if test $CC_TARGET_ARCH != x86_64-$target_vendor-linux ; then
325                         AC_MSG_ERROR([Cross compiler not found in PATH.])
326                 fi
327                 CROSS_VARS="ARCH=$target_vendor CROSS_COMPILE=x86_64-$target_vendor-linux-"
328                 CCAS=$CC
329                 if test x$enable_server = xyes ; then
330                         AC_MSG_WARN([Disabling server (not supported for x86_64-$target_vendor-linux).])
331                         enable_server='no'
332                 fi
333                 ;;
334         *)
335                 AC_MSG_RESULT([no])
336                 ;;
337 esac
338 AC_SUBST(CROSS_VARS)
339 ])
340
341 # these are like AC_TRY_COMPILE, but try to build modules against the
342 # kernel, inside the build directory
343
344 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
345 # --------------------------------------
346 m4_define([LB_LANG_PROGRAM],
347 [
348 #include <linux/kernel.h>
349 $1
350 int
351 main (void)
352 {
353 dnl Do *not* indent the following line: there may be CPP directives.
354 dnl Don't move the `;' right after for the same reason.
355 $2
356   ;
357   return 0;
358 }])
359
360 #
361 # LB_LINUX_COMPILE_IFELSE
362 #
363 # like AC_COMPILE_IFELSE
364 #
365 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
366 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
367 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
368 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] ${LD:+"LD=$LD"} CC="$CC" -f $PWD/build/Makefile OFA_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="-include $AUTOCONF_HDIR/autoconf.h $XEN_INCLUDES $EXTRA_OFA_INCLUDE -I$LINUX/arch/$SRCARCH/include -Iarch/$SRCARCH/include/generated -Iinclude -I$LINUX/arch/$SRCARCH/include/uapi -Iarch/$SRCARCH/include/generated/uapi -I$LINUX/include -I$LINUX/include/uapi -Iinclude/generated/uapi  -I$LINUX/arch/$SRCARCH/include -Iarch/$SRCARCH/include/generated -I$LINUX/arch/`echo $target_cpu|sed -e 's/powerpc64/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include -I$LINUX/arch/`echo $target_cpu|sed -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/'`/include/generated -I$LINUX_OBJ/include -I$LINUX/include -I$LINUX_OBJ/include2 -include $CONFIG_INCLUDE" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $CROSS_VARS $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
369         [$4],
370         [_AC_MSG_LOG_CONFTEST
371 m4_ifvaln([$5],[$5])dnl])
372 rm -f build/conftest.o build/conftest.mod.c build/conftest.mod.o build/conftest.ko m4_ifval([$1], [build/conftest.c conftest.c])[]dnl
373 ])
374
375 #
376 # LB_LINUX_ARCH
377 #
378 # Determine the kernel's idea of the current architecture
379 #
380 AC_DEFUN([LB_LINUX_ARCH],
381          [AC_MSG_CHECKING([Linux kernel architecture])
382           AS_IF([rm -f $PWD/build/arch
383                  make -s --no-print-directory echoarch -f $PWD/build/Makefile \
384                      OFA_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $CROSS_VARS  \
385                      ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
386                 [AC_MSG_RESULT([$LINUX_ARCH])],
387                 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
388           rm -f build/arch])
389
390 #
391 # LB_LINUX_TRY_COMPILE
392 #
393 # like AC_TRY_COMPILE
394 #
395 AC_DEFUN([LB_LINUX_TRY_COMPILE],
396 [LB_LINUX_COMPILE_IFELSE(
397         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
398         [modules],
399         [test -s build/conftest.o],
400         [$3], [$4])])
401
402 #
403 # LB_LINUX_CONFIG
404 #
405 # check if a given config option is defined
406 #
407 AC_DEFUN([LB_LINUX_CONFIG],[
408         AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
409         LB_LINUX_TRY_COMPILE([
410                 #include <$AUTOCONF_HDIR/autoconf.h>
411         ],[
412                 #ifndef CONFIG_$1
413                 #error CONFIG_$1 not #defined
414                 #endif
415         ],[
416                 AC_MSG_RESULT([yes])
417                 $2
418         ],[
419                 AC_MSG_RESULT([no])
420                 $3
421         ])
422 ])
423
424 #
425 # LB_LINUX_CONFIG_IM
426 #
427 # check if a given config option is builtin or as module
428 #
429 AC_DEFUN([LB_LINUX_CONFIG_IM],[
430         AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
431         LB_LINUX_TRY_COMPILE([
432                 #include <$AUTOCONF_HDIR/autoconf.h>
433         ],[
434                 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
435                 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
436                 #endif
437         ],[
438                 AC_MSG_RESULT([yes])
439                 $2
440         ],[
441                 AC_MSG_RESULT([no])
442                 $3
443         ])
444 ])
445
446 #
447 # LB_LINUX_TRY_MAKE
448 #
449 # like LB_LINUX_TRY_COMPILE, but with different arguments
450 #
451 AC_DEFUN([LB_LINUX_TRY_MAKE],
452         [LB_LINUX_COMPILE_IFELSE(
453                 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
454                 [$3], [$4], [$5], [$6]
455         )]
456 )
457
458 #
459 # LB_CONFIG_COMPAT_RDMA
460 #
461 AC_DEFUN([LB_CONFIG_COMPAT_RDMA],
462 [AC_MSG_CHECKING([whether to use Compat RDMA])
463 # set default
464 AC_ARG_WITH([o2ib],
465         AC_HELP_STRING([--with-o2ib=path],
466                        [build o2iblnd against path]),
467         [
468                 case $with_o2ib in
469                 yes)    O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
470                         ENABLEO2IB=2
471                         ;;
472                 no)     ENABLEO2IB=0
473                         ;;
474                 *)      O2IBPATHS=$with_o2ib
475                         ENABLEO2IB=3
476                         ;;
477                 esac
478         ],[
479                 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
480                 ENABLEO2IB=1
481         ])
482 if test $ENABLEO2IB -eq 0; then
483         AC_MSG_RESULT([no])
484 else
485         o2ib_found=false
486         for O2IBPATH in $O2IBPATHS; do
487                 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
488                            -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
489                            -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
490                            -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
491                         o2ib_found=true
492                         break
493                 fi
494         done
495         compatrdma_found=false
496         if $o2ib_found; then
497                 if test \( -f ${O2IBPATH}/include/linux/compat-2.6.h \); then
498                         compatrdma_found=true
499                         AC_MSG_RESULT([yes])
500                         AC_DEFINE(HAVE_COMPAT_RDMA, 1, [compat rdma found])
501                 else
502                         AC_MSG_RESULT([no])
503                 fi
504         fi
505 fi
506 ])
507
508 #
509 # LB_CONFIG_OFED_BACKPORTS
510 #
511 # include any OFED backport headers in all compile commands
512 # NOTE: this does only include the backport paths, not the OFED headers
513 #       adding the OFED headers is done in the lnet portion
514 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
515 [AC_MSG_CHECKING([whether to use any OFED backport headers])
516 if test $ENABLEO2IB -eq 0; then
517         AC_MSG_RESULT([no])
518 else
519         if ! $o2ib_found; then
520                 AC_MSG_RESULT([no])
521                 case $ENABLEO2IB in
522                         1) ;;
523                         2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
524                         3) AC_MSG_ERROR([bad --with-o2ib path]);;
525                         *) AC_MSG_ERROR([internal error]);;
526                 esac
527         else
528                 if ! $compatrdma_found; then
529                         if test -f $O2IBPATH/config.mk; then
530                                 . $O2IBPATH/config.mk
531                         elif test -f $O2IBPATH/ofed_patch.mk; then
532                                 . $O2IBPATH/ofed_patch.mk
533                         fi
534                 fi
535                 if test -n "$BACKPORT_INCLUDES"; then
536                         OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
537                         EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
538                         AC_MSG_RESULT([yes])
539                 else
540                         AC_MSG_RESULT([no])
541                 fi
542         fi
543 fi
544 ])
545
546 # LC_MODULE_LOADING
547 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
548 # so we test if request_module is implemented or not
549 AC_DEFUN([LC_MODULE_LOADING],
550 [AC_MSG_CHECKING([if kernel module loading is possible])
551 LB_LINUX_TRY_MAKE([
552         #include <linux/kmod.h>
553 ],[
554         int myretval=ENOSYS ;
555         return myretval;
556 ],[
557         $makerule OFA_KERNEL_TEST=conftest.i
558 ],[dnl
559         grep request_module build/conftest.i |dnl
560                 grep -v `grep "int myretval=" build/conftest.i |dnl
561                         cut -d= -f2 | cut -d" "  -f1`dnl
562                 >/dev/null dnl
563 ],[
564         AC_MSG_RESULT(yes)
565         AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
566                   [kernel module loading is possible])
567 ],[
568         AC_MSG_RESULT(no)
569         AC_MSG_WARN([])
570         AC_MSG_WARN([Kernel module loading support is highly recommended.])
571         AC_MSG_WARN([])
572 ])
573 ])
574
575 #
576 # LB_PROG_LINUX
577 #
578 # linux tests
579 #
580 AC_DEFUN([LB_PROG_LINUX],
581 [LB_LINUX_PATH
582 LB_LINUX_ARCH
583 LB_LINUX_SYMVERFILE
584
585
586 LB_LINUX_CONFIG([MODULES],[],[
587         AC_MSG_ERROR([module support is required to build OFA kernel modules.])
588 ])
589
590 LB_LINUX_CONFIG([MODVERSIONS])
591
592 LB_LINUX_CONFIG([KALLSYMS],[],[
593         AC_MSG_ERROR([compat_mlnx requires that CONFIG_KALLSYMS is enabled in your kernel.])
594 ])
595
596 # 2.6.28
597 LC_MODULE_LOADING
598
599 LB_CONFIG_COMPAT_RDMA
600
601 # it's ugly to be doing anything with OFED outside of the lnet module, but
602 # this has to be done here so that the backports path is set before all of
603 # the LN_PROG_LINUX checks are done
604 LB_CONFIG_OFED_BACKPORTS
605 ])
606
607 #
608 # LB_CHECK_SYMBOL_EXPORT
609 # check symbol exported or not
610 # $1 - symbol
611 # $2 - file(s) for find.
612 # $3 - do 'yes'
613 # $4 - do 'no'
614 #
615 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
616 # or check
617 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
618 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
619 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
620 rc=$?
621 if test $rc -ne 0; then
622         export=0
623         for file in $2; do
624                 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
625                 rc=$?
626                 if test $rc -eq 0; then
627                         export=1
628                         break;
629                 fi
630         done
631         if test $export -eq 0; then
632                 AC_MSG_RESULT([no])
633                 $4
634         else
635                 AC_MSG_RESULT([yes])
636                 $3
637         fi
638 else
639         AC_MSG_RESULT([yes])
640         $3
641 fi
642 ])
643
644 #
645 # Like AC_CHECK_HEADER but checks for a kernel-space header
646 #
647 m4_define([LB_CHECK_LINUX_HEADER],
648 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
649 AC_CACHE_CHECK([for $1], ac_Header,
650                [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
651                                   [modules],
652                                   [test -s build/conftest.o],
653                                   [AS_VAR_SET(ac_Header, [yes])],
654                                   [AS_VAR_SET(ac_Header, [no])])])
655 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
656 AS_VAR_POPDEF([ac_Header])dnl
657 ])
658
659 #
660 # LB_USES_DPKG
661 #
662 # Determine if the target is a dpkg system or rpm
663 #
664 AC_DEFUN([LB_USES_DPKG],
665 [
666 AC_MSG_CHECKING([if this distro uses dpkg])
667 case `lsb_release -i -s 2>/dev/null` in
668         Ubuntu | Debian)
669                 AC_MSG_RESULT([yes])
670                 uses_dpkg=yes
671                 ;;
672         *)
673                 AC_MSG_RESULT([no])
674                 uses_dpkg=no
675                 ;;
676 esac
677 ])
678
679 #
680 # LB_PROG_CC
681 #
682 # checks on the C compiler
683 #
684 AC_DEFUN([LB_PROG_CC],
685 [AC_PROG_RANLIB
686 AC_CHECK_TOOL(LD, ld, [no])
687 AC_CHECK_TOOL(OBJDUMP, objdump, [no])
688 AC_CHECK_TOOL(STRIP, strip, [no])
689
690 # ---------  unsigned long long sane? -------
691 AC_CHECK_SIZEOF(unsigned long long, 0)
692 echo "---> size SIZEOF $SIZEOF_unsigned_long_long"
693 echo "---> size SIZEOF $ac_cv_sizeof_unsigned_long_long"
694 if test $ac_cv_sizeof_unsigned_long_long != 8 ; then
695         AC_MSG_ERROR([** we assume that sizeof(long long) == 8.])
696 fi
697
698 if test $target_cpu == "powerpc64"; then
699         AC_MSG_WARN([set compiler with -m64])
700         CFLAGS="$CFLAGS -m64"
701         CC="$CC -m64"
702 fi
703 ])
704
705 # LB_CONTITIONALS
706 #
707 AC_DEFUN([LB_CONDITIONALS],
708 [
709 AM_CONDITIONAL(ARCH_x86, test x$target_cpu = "xx86_64" -o x$target_cpu = "xi686")
710
711 AC_OUTPUT
712
713 cat <<_ACEOF
714
715 CC:            $CC
716 LD:            $LD
717 CFLAGS:        $CFLAGS
718 EXTRA_KCFLAGS: $EXTRA_KCFLAGS
719
720 Type 'make' to build kernel modules.
721 _ACEOF
722 ])
723
724 #
725 # SET_BUILD_ARCH
726 #
727 AC_DEFUN([SET_BUILD_ARCH],
728 [ARCH=${ARCH:-$(uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
729                         -e s/sun4u/sparc64/ \
730                         -e s/arm.*/arm/ -e s/sa110/arm/ \
731                         -e s/s390x/s390/ -e s/parisc64/parisc/ \
732                         -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
733                         -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )}
734
735 SRCARCH=${SRCARCH:-$ARCH}
736
737 # Additional ARCH settings for x86
738 if [[ "$ARCH" == "i386" ]]; then
739         SRCARCH=x86
740 fi
741 if [[ "$ARCH" == "x86_64" ]]; then
742         SRCARCH=x86
743 fi
744
745 # Additional ARCH settings for sparc
746 if [[ "$ARCH" == "sparc32" ]]; then
747         SRCARCH=sparc
748 fi
749 if [[ "$ARCH" == "sparc64" ]]; then
750         SRCARCH=sparc
751 fi
752
753 # Additional ARCH settings for sh
754 if [[ "$ARCH" == "sh64" ]]; then
755         SRCARCH=sh
756 fi
757
758 # Additional ARCH settings for tile
759 if [[ "$ARCH" == "tilepro" ]]; then
760         SRCARCH=tile
761 fi
762 if [[ "$ARCH" == "tilegx" ]]; then
763         SRCARCH=tile
764 fi
765 ])
766
767 #
768 # LB_LINUX_CONFIG_VALUE
769 #
770 #  get a given config's option value
771 #
772 AC_DEFUN([LB_LINUX_CONFIG_VALUE],[
773         AC_MSG_CHECKING([get value of CONFIG_$1])
774         if (grep -q "^#define CONFIG_$1 " $LINUX_OBJ/include/$AUTOCONF_HDIR/autoconf.h 2>/dev/null); then
775                 res=$(grep "^#define CONFIG_$1 " $LINUX_OBJ/include/$AUTOCONF_HDIR/autoconf.h 2>/dev/null | cut -d' ' -f'3')
776                 AC_MSG_RESULT([$1 value is '$res'])
777                 $2
778         else
779                 AC_MSG_RESULT([$1 in not defined in autoconf.h])
780                 $3
781         fi
782 ])