295ba1ab83f5704884c8311f321edb45626feb33
[~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 if test -e $CONFIG_INCLUDE; then
257         CONFIG_INCLUDE_FLAG="-include $CONFIG_INCLUDE"
258 fi
259
260 # ------------ rhconfig.h includes runtime-generated bits --
261 # red hat kernel-source checks
262
263 # we know this exists after the check above.  if the user
264 # tarred up the tree and ran make dep etc. in it, then
265 # version.h gets overwritten with a standard linux one.
266 #
267 if (grep -q rhconfig $LINUX_OBJ/include/linux/version.h 2>/dev/null) ||
268    (grep -q rhconfig $LINUX_OBJ/include/generated/uapi/linux/version.h 2>/dev/null) ; then
269         # This is a clean kernel-source tree, we need to
270         # enable extensive workarounds to get this to build
271         # modules
272         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
273                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
274                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
275                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
276                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
277                 fi],
278                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
279         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
280 fi
281
282 # this is needed before we can build modules
283 SET_BUILD_ARCH
284 LB_LINUX_CROSS
285 LB_LINUX_VERSION
286
287 # --- check that we can build modules at all
288 AC_MSG_CHECKING([that modules can be built at all])
289 LB_LINUX_TRY_COMPILE([],[],[
290         AC_MSG_RESULT([yes])
291 ],[
292         AC_MSG_RESULT([no])
293         AC_MSG_WARN([Consult config.log for details.])
294         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
295         AC_MSG_ERROR([Kernel modules cannot be built.])
296 ])
297
298 LB_LINUX_RELEASE
299 ]) # end of LB_LINUX_PATH
300
301 # LB_LINUX_SYMVERFILE
302 # SLES 9 uses a different name for this file - unsure about vanilla kernels
303 # around this version, but it matters for servers only.
304 AC_DEFUN([LB_LINUX_SYMVERFILE],
305         [AC_MSG_CHECKING([name of module symbol version file])
306         if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
307                 SYMVERFILE=Modules.symvers
308         else
309                 SYMVERFILE=Module.symvers
310         fi
311         AC_MSG_RESULT($SYMVERFILE)
312         AC_SUBST(SYMVERFILE)
313 ])
314
315 #
316 # LB_LINUX_CROSS
317 #
318 # check for cross compilation
319 #
320 AC_DEFUN([LB_LINUX_CROSS],
321         [AC_MSG_CHECKING([for cross compilation])
322 CROSS_VARS=
323 case $target_vendor in
324         # The K1OM architecture is an extension of the x86 architecture.
325         # So, the $target_arch is x86_64.
326         k1om)
327                 AC_MSG_RESULT([Intel(R) Xeon Phi(TM)])
328                 CC_TARGET_ARCH=`$CC -v 2>&1 | grep Target: | sed -e 's/Target: //'`
329                 if test $CC_TARGET_ARCH != x86_64-$target_vendor-linux ; then
330                         AC_MSG_ERROR([Cross compiler not found in PATH.])
331                 fi
332                 CROSS_VARS="ARCH=$target_vendor CROSS_COMPILE=x86_64-$target_vendor-linux-"
333                 CCAS=$CC
334                 if test x$enable_server = xyes ; then
335                         AC_MSG_WARN([Disabling server (not supported for x86_64-$target_vendor-linux).])
336                         enable_server='no'
337                 fi
338                 ;;
339         *)
340                 CROSS_VARS="CROSS_COMPILE=$CROSS_COMPILE"
341                 AC_MSG_RESULT([no])
342                 ;;
343 esac
344 AC_SUBST(CROSS_VARS)
345 ])
346
347 # these are like AC_TRY_COMPILE, but try to build modules against the
348 # kernel, inside the build directory
349
350 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
351 # --------------------------------------
352 m4_define([LB_LANG_PROGRAM],
353 [
354 #include <linux/kernel.h>
355 $1
356 int
357 main (void)
358 {
359 dnl Do *not* indent the following line: there may be CPP directives.
360 dnl Don't move the `;' right after for the same reason.
361 $2
362   ;
363   return 0;
364 }])
365
366 #
367 # LB_LINUX_COMPILE_IFELSE
368 #
369 # like AC_COMPILE_IFELSE
370 #
371 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
372 [m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
373 MAKE=${MAKE:-make}
374 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko build/output.log
375 AS_IF([AC_TRY_COMMAND(cp conftest.c build && env $CROSS_VARS $MAKE -d [$2] ${LD:+"LD=$CROSS_COMPILE$LD"} CC="$CROSS_COMPILE$CC" -f $PWD/build/Makefile OFA_LINUX_CONFIG=$LINUX_CONFIG CONFIG_CC_STACKPROTECTOR_STRONG= 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/$SRCARCH/include -I$LINUX/arch/$SRCARCH/include/generated -I$LINUX_OBJ/include -I$LINUX/include -I$LINUX_OBJ/include2 $CONFIG_INCLUDE_FLAG" -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 2>build/output.log; [[[ $? -ne 0 ]]] && cat build/output.log 1>&2 && false || config/warning_filter.sh build/output.log) >/dev/null && AC_TRY_COMMAND([$3])],
376         [$4],
377         [_AC_MSG_LOG_CONFTEST
378 m4_ifvaln([$5],[$5])dnl])
379 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
380 ])
381
382 #
383 # LB_LINUX_ARCH
384 #
385 # Determine the kernel's idea of the current architecture
386 #
387 AC_DEFUN([LB_LINUX_ARCH],
388          [AC_MSG_CHECKING([Linux kernel architecture])
389           AS_IF([rm -f $PWD/build/arch
390                  make -s --no-print-directory echoarch -f $PWD/build/Makefile \
391                      OFA_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX $CROSS_VARS  \
392                      ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
393                 [AC_MSG_RESULT([$LINUX_ARCH])],
394                 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
395           rm -f build/arch])
396
397 #
398 # LB_LINUX_TRY_COMPILE
399 #
400 # like AC_TRY_COMPILE
401 #
402 AC_DEFUN([LB_LINUX_TRY_COMPILE],
403 [LB_LINUX_COMPILE_IFELSE(
404         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
405         [modules],
406         [test -s build/conftest.o],
407         [$3], [$4])])
408
409 #
410 # LB_LINUX_CONFIG
411 #
412 # check if a given config option is defined
413 #
414 AC_DEFUN([LB_LINUX_CONFIG],[
415         AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
416         LB_LINUX_TRY_COMPILE([
417                 #include <$AUTOCONF_HDIR/autoconf.h>
418         ],[
419                 #ifndef CONFIG_$1
420                 #error CONFIG_$1 not #defined
421                 #endif
422         ],[
423                 AC_MSG_RESULT([yes])
424                 $2
425         ],[
426                 AC_MSG_RESULT([no])
427                 $3
428         ])
429 ])
430
431 #
432 # LB_LINUX_CONFIG_IM
433 #
434 # check if a given config option is builtin or as module
435 #
436 AC_DEFUN([LB_LINUX_CONFIG_IM],[
437         AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
438         LB_LINUX_TRY_COMPILE([
439                 #include <$AUTOCONF_HDIR/autoconf.h>
440         ],[
441                 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
442                 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
443                 #endif
444         ],[
445                 AC_MSG_RESULT([yes])
446                 $2
447         ],[
448                 AC_MSG_RESULT([no])
449                 $3
450         ])
451 ])
452
453 #
454 # LB_LINUX_TRY_MAKE
455 #
456 # like LB_LINUX_TRY_COMPILE, but with different arguments
457 #
458 AC_DEFUN([LB_LINUX_TRY_MAKE],
459         [LB_LINUX_COMPILE_IFELSE(
460                 [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
461                 [$3], [$4], [$5], [$6]
462         )]
463 )
464
465 #
466 # LB_CONFIG_COMPAT_RDMA
467 #
468 AC_DEFUN([LB_CONFIG_COMPAT_RDMA],
469 [AC_MSG_CHECKING([whether to use Compat RDMA])
470 # set default
471 AC_ARG_WITH([o2ib],
472         AC_HELP_STRING([--with-o2ib=path],
473                        [build o2iblnd against path]),
474         [
475                 case $with_o2ib in
476                 yes)    O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
477                         ENABLEO2IB=2
478                         ;;
479                 no)     ENABLEO2IB=0
480                         ;;
481                 *)      O2IBPATHS=$with_o2ib
482                         ENABLEO2IB=3
483                         ;;
484                 esac
485         ],[
486                 O2IBPATHS="$LINUX $LINUX/drivers/infiniband"
487                 ENABLEO2IB=1
488         ])
489 if test $ENABLEO2IB -eq 0; then
490         AC_MSG_RESULT([no])
491 else
492         o2ib_found=false
493         for O2IBPATH in $O2IBPATHS; do
494                 if test \( -f ${O2IBPATH}/include/rdma/rdma_cm.h -a \
495                            -f ${O2IBPATH}/include/rdma/ib_cm.h -a \
496                            -f ${O2IBPATH}/include/rdma/ib_verbs.h -a \
497                            -f ${O2IBPATH}/include/rdma/ib_fmr_pool.h \); then
498                         o2ib_found=true
499                         break
500                 fi
501         done
502         compatrdma_found=false
503         if $o2ib_found; then
504                 if test \( -f ${O2IBPATH}/include/linux/compat-2.6.h \); then
505                         compatrdma_found=true
506                         AC_MSG_RESULT([yes])
507                         AC_DEFINE(HAVE_COMPAT_RDMA, 1, [compat rdma found])
508                 else
509                         AC_MSG_RESULT([no])
510                 fi
511         fi
512 fi
513 ])
514
515 #
516 # LB_CONFIG_OFED_BACKPORTS
517 #
518 # include any OFED backport headers in all compile commands
519 # NOTE: this does only include the backport paths, not the OFED headers
520 #       adding the OFED headers is done in the lnet portion
521 AC_DEFUN([LB_CONFIG_OFED_BACKPORTS],
522 [AC_MSG_CHECKING([whether to use any OFED backport headers])
523 if test $ENABLEO2IB -eq 0; then
524         AC_MSG_RESULT([no])
525 else
526         if ! $o2ib_found; then
527                 AC_MSG_RESULT([no])
528                 case $ENABLEO2IB in
529                         1) ;;
530                         2) AC_MSG_ERROR([kernel OpenIB gen2 headers not present]);;
531                         3) AC_MSG_ERROR([bad --with-o2ib path]);;
532                         *) AC_MSG_ERROR([internal error]);;
533                 esac
534         else
535                 if ! $compatrdma_found; then
536                         if test -f $O2IBPATH/config.mk; then
537                                 . $O2IBPATH/config.mk
538                         elif test -f $O2IBPATH/ofed_patch.mk; then
539                                 . $O2IBPATH/ofed_patch.mk
540                         fi
541                 fi
542                 if test -n "$BACKPORT_INCLUDES"; then
543                         OFED_BACKPORT_PATH="$O2IBPATH/${BACKPORT_INCLUDES/*\/kernel_addons/kernel_addons}/"
544                         EXTRA_LNET_INCLUDE="-I$OFED_BACKPORT_PATH $EXTRA_LNET_INCLUDE"
545                         AC_MSG_RESULT([yes])
546                 else
547                         AC_MSG_RESULT([no])
548                 fi
549         fi
550 fi
551 ])
552
553 # LC_MODULE_LOADING
554 # after 2.6.28 CONFIG_KMOD is removed, and only CONFIG_MODULES remains
555 # so we test if request_module is implemented or not
556 AC_DEFUN([LC_MODULE_LOADING],
557 [AC_MSG_CHECKING([if kernel module loading is possible])
558 LB_LINUX_TRY_MAKE([
559         #include <linux/kmod.h>
560 ],[
561         int myretval=ENOSYS ;
562         return myretval;
563 ],[
564         $makerule OFA_KERNEL_TEST=conftest.i
565 ],[dnl
566         grep request_module build/conftest.i |dnl
567                 grep -v `grep "int myretval=" build/conftest.i |dnl
568                         cut -d= -f2 | cut -d" "  -f1`dnl
569                 >/dev/null dnl
570 ],[
571         AC_MSG_RESULT(yes)
572         AC_DEFINE(HAVE_MODULE_LOADING_SUPPORT, 1,
573                   [kernel module loading is possible])
574 ],[
575         AC_MSG_RESULT(no)
576         AC_MSG_WARN([])
577         AC_MSG_WARN([Kernel module loading support is highly recommended.])
578         AC_MSG_WARN([])
579 ])
580 ])
581
582 #
583 # LB_PROG_LINUX
584 #
585 # linux tests
586 #
587 AC_DEFUN([LB_PROG_LINUX],
588 [LB_LINUX_PATH
589 LB_LINUX_ARCH
590 LB_LINUX_SYMVERFILE
591
592
593 LB_LINUX_CONFIG([MODULES],[],[
594         AC_MSG_ERROR([module support is required to build OFA kernel modules.])
595 ])
596
597 LB_LINUX_CONFIG([MODVERSIONS])
598
599 LB_LINUX_CONFIG([KALLSYMS],[],[
600         AC_MSG_ERROR([compat_mlnx requires that CONFIG_KALLSYMS is enabled in your kernel.])
601 ])
602
603 # 2.6.28
604 LC_MODULE_LOADING
605
606 LB_CONFIG_COMPAT_RDMA
607
608 # it's ugly to be doing anything with OFED outside of the lnet module, but
609 # this has to be done here so that the backports path is set before all of
610 # the LN_PROG_LINUX checks are done
611 LB_CONFIG_OFED_BACKPORTS
612 ])
613
614 #
615 # LB_CHECK_SYMBOL_EXPORT
616 # check symbol exported or not
617 # $1 - symbol
618 # $2 - file(s) for find.
619 # $3 - do 'yes'
620 # $4 - do 'no'
621 #
622 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
623 # or check
624 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
625 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
626 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
627 rc=$?
628 if test $rc -ne 0; then
629         export=0
630         for file in $2; do
631                 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
632                 rc=$?
633                 if test $rc -eq 0; then
634                         export=1
635                         break;
636                 fi
637         done
638         if test $export -eq 0; then
639                 AC_MSG_RESULT([no])
640                 $4
641         else
642                 AC_MSG_RESULT([yes])
643                 $3
644         fi
645 else
646         AC_MSG_RESULT([yes])
647         $3
648 fi
649 ])
650
651 #
652 # Like AC_CHECK_HEADER but checks for a kernel-space header
653 #
654 m4_define([LB_CHECK_LINUX_HEADER],
655 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
656 AC_CACHE_CHECK([for $1], ac_Header,
657                [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
658                                   [modules],
659                                   [test -s build/conftest.o],
660                                   [AS_VAR_SET(ac_Header, [yes])],
661                                   [AS_VAR_SET(ac_Header, [no])])])
662 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
663 AS_VAR_POPDEF([ac_Header])dnl
664 ])
665
666 #
667 # LB_USES_DPKG
668 #
669 # Determine if the target is a dpkg system or rpm
670 #
671 AC_DEFUN([LB_USES_DPKG],
672 [
673 AC_MSG_CHECKING([if this distro uses dpkg])
674 case `lsb_release -i -s 2>/dev/null` in
675         Ubuntu | Debian)
676                 AC_MSG_RESULT([yes])
677                 uses_dpkg=yes
678                 ;;
679         *)
680                 AC_MSG_RESULT([no])
681                 uses_dpkg=no
682                 ;;
683 esac
684 ])
685
686 #
687 # LB_PROG_CC
688 #
689 # checks on the C compiler
690 #
691 AC_DEFUN([LB_PROG_CC],
692 [AC_PROG_RANLIB
693 AC_CHECK_TOOL(LD, ld, [no])
694 AC_CHECK_TOOL(OBJDUMP, objdump, [no])
695 AC_CHECK_TOOL(STRIP, strip, [no])
696
697 # ---------  unsigned long long sane? -------
698 AC_CHECK_SIZEOF(unsigned long long, 0)
699 echo "---> size SIZEOF $SIZEOF_unsigned_long_long"
700 echo "---> size SIZEOF $ac_cv_sizeof_unsigned_long_long"
701 if test $ac_cv_sizeof_unsigned_long_long != 8 ; then
702         AC_MSG_ERROR([** we assume that sizeof(long long) == 8.])
703 fi
704
705 if test $target_cpu == "powerpc64"; then
706         AC_MSG_WARN([set compiler with -m64])
707         CFLAGS="$CFLAGS -m64"
708         CC="$CC -m64"
709 fi
710 ])
711
712 # LB_CONTITIONALS
713 #
714 AC_DEFUN([LB_CONDITIONALS],
715 [
716 AM_CONDITIONAL(ARCH_x86, test x$target_cpu = "xx86_64" -o x$target_cpu = "xi686")
717
718 AC_OUTPUT
719
720 cat <<_ACEOF
721
722 CC:            $CC
723 LD:            $LD
724 CFLAGS:        $CFLAGS
725 EXTRA_KCFLAGS: $EXTRA_KCFLAGS
726
727 Type 'make' to build kernel modules.
728 _ACEOF
729 ])
730
731 #
732 # SET_BUILD_ARCH
733 #
734 AC_DEFUN([SET_BUILD_ARCH],
735 [
736 AC_MSG_CHECKING([for build ARCH])
737 SRCARCH=${ARCH:-$(uname -m)}
738 SRCARCH=$(echo $SRCARCH | sed -e s/i.86/x86/ \
739                         -e s/x86_64/x86/ \
740                         -e s/ppc.*/powerpc/ \
741                         -e 's/powerpc64/powerpc/' \
742                         -e s/aarch64.*/arm64/ \
743                         -e s/s390x/s390/)
744
745 # very old kernels had different strucure under arch dir
746 if [[ "X$SRCARCH" == "Xx86" ]] && ! [[ -d "$LINUX/arch/x86" ]]; then
747         SRCARCH=x86_64
748 fi
749
750 AC_MSG_RESULT([ARCH=$ARCH, SRCARCH=$SRCARCH])
751 ])
752
753 #
754 # LB_LINUX_CONFIG_VALUE
755 #
756 #  get a given config's option value
757 #
758 AC_DEFUN([LB_LINUX_CONFIG_VALUE],[
759         AC_MSG_CHECKING([get value of CONFIG_$1])
760         if (grep -q "^#define CONFIG_$1 " $LINUX_OBJ/include/$AUTOCONF_HDIR/autoconf.h 2>/dev/null); then
761                 res=$(grep "^#define CONFIG_$1 " $LINUX_OBJ/include/$AUTOCONF_HDIR/autoconf.h 2>/dev/null | cut -d' ' -f'3')
762                 AC_MSG_RESULT([$1 value is '$res'])
763                 $2
764         else
765                 AC_MSG_RESULT([$1 in not defined in autoconf.h])
766                 $3
767         fi
768 ])