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