]> git.proxmox.com Git - mirror_zfs-debian.git/blob - config/zfs-build.m4
Restructure autoconf around ./config directory
[mirror_zfs-debian.git] / config / zfs-build.m4
1 AC_DEFUN([ZFS_AC_CONFIG], [
2
3 AC_ARG_WITH([zfs-config],
4 AS_HELP_STRING([--with-config=CONFIG],
5 [Config file 'kernel|user|lustre']),
6 [zfsconfig="$withval"])
7
8 AC_MSG_CHECKING([zfs config file])
9 if test -z "$zfsconfig" || test ! -r config/$zfsconfig; then
10 AC_MSG_RESULT([no])
11 AC_MSG_ERROR([
12 *** Please specify one of the valid config files located
13 *** in ./config/ with the '--with-zfs-config=CONFIG' option])
14 fi
15
16 AC_MSG_RESULT([$zfsconfig]);
17 . ./config/$zfsconfig
18
19 TOPDIR=`/bin/pwd`
20 ZFSDIR=${TOPDIR}/$BUILDDIR
21 LIBDIR=$ZFSDIR/lib
22 CMDDIR=$ZFSDIR/zcmd
23
24 AC_SUBST(TOPDIR)
25 AC_SUBST(ZFSDIR)
26 AC_SUBST(LIBDIR)
27 AC_SUBST(CMDDIR)
28 ])
29
30 AC_DEFUN([ZFS_AC_KERNEL], [
31 ver=`uname -r`
32
33 AC_ARG_WITH([linux],
34 AS_HELP_STRING([--with-linux=PATH],
35 [Path to kernel source]),
36 [kernelsrc="$withval"; kernelbuild="$withval"])
37
38 AC_ARG_WITH(linux-obj,
39 AS_HELP_STRING([--with-linux-obj=PATH],
40 [Path to kernel build objects]),
41 [kernelbuild="$withval"])
42
43 AC_MSG_CHECKING([kernel source directory])
44 if test -z "$kernelsrc"; then
45 kernelbuild=
46 sourcelink=/lib/modules/${ver}/source
47 buildlink=/lib/modules/${ver}/build
48
49 if test -e $sourcelink; then
50 kernelsrc=`(cd $sourcelink; /bin/pwd)`
51 fi
52 if test -e $buildlink; then
53 kernelbuild=`(cd $buildlink; /bin/pwd)`
54 fi
55 if test -z "$kernelsrc"; then
56 kernelsrc=$kernelbuild
57 fi
58 if test -z "$kernelsrc" -o -z "$kernelbuild"; then
59 AC_MSG_RESULT([Not found])
60 AC_MSG_ERROR([
61 *** Please specify the location of the kernel source
62 *** with the '--with-linux=PATH' option])
63 fi
64 fi
65
66 AC_MSG_RESULT([$kernelsrc])
67 AC_MSG_CHECKING([kernel build directory])
68 AC_MSG_RESULT([$kernelbuild])
69
70 AC_MSG_CHECKING([kernel source version])
71 if test -r $kernelbuild/include/linux/version.h &&
72 fgrep -q UTS_RELEASE $kernelbuild/include/linux/version.h; then
73
74 kernsrcver=`(echo "#include <linux/version.h>";
75 echo "kernsrcver=UTS_RELEASE") |
76 cpp -I $kernelbuild/include |
77 grep "^kernsrcver=" | cut -d \" -f 2`
78
79 elif test -r $kernelbuild/include/linux/utsrelease.h &&
80 fgrep -q UTS_RELEASE $kernelbuild/include/linux/utsrelease.h; then
81
82 kernsrcver=`(echo "#include <linux/utsrelease.h>";
83 echo "kernsrcver=UTS_RELEASE") |
84 cpp -I $kernelbuild/include |
85 grep "^kernsrcver=" | cut -d \" -f 2`
86 fi
87
88 if test -z "$kernsrcver"; then
89 AC_MSG_RESULT([Not found])
90 AC_MSG_ERROR([
91 *** Cannot determine the version of the linux kernel source.
92 *** Please prepare the kernel before running this script])
93 fi
94
95 AC_MSG_RESULT([$kernsrcver])
96
97 kmoduledir=${INSTALL_MOD_PATH}/lib/modules/$kernsrcver
98 LINUX=${kernelsrc}
99 LINUX_OBJ=${kernelbuild}
100
101 AC_SUBST(LINUX)
102 AC_SUBST(LINUX_OBJ)
103 AC_SUBST(kmoduledir)
104 ])
105
106 AC_DEFUN([ZFS_AC_SPL], [
107
108 AC_ARG_WITH([spl],
109 AS_HELP_STRING([--with-spl=PATH],
110 [Path to spl source]),
111 [splsrc="$withval"; splbuild="$withval"])
112
113 AC_ARG_WITH([spl-obj],
114 AS_HELP_STRING([--with-spl-obj=PATH],
115 [Path to spl build objects]),
116 [splbuild="$withval"])
117
118
119 AC_MSG_CHECKING([spl source directory])
120 if test -z "$splsrc"; then
121 splbuild=
122 sourcelink=/tmp/`whoami`/spl
123 buildlink=/tmp/`whoami`/spl
124
125 if test -e $sourcelink; then
126 splsrc=`(cd $sourcelink; /bin/pwd)`
127 fi
128 if test -e $buildlink; then
129 splbuild=`(cd $buildlink; /bin/pwd)`
130 fi
131 if test -z "$splsrc"; then
132 splsrc=$splbuild
133 fi
134 fi
135
136 if test -z "$splsrc" -o -z "$splbuild"; then
137 sourcelink=/lib/modules/${ver}/source
138 buildlink=/lib/modules/${ver}/build
139
140 if test -e $sourcelink; then
141 splsrc=`(cd $sourcelink; /bin/pwd)`
142 fi
143 if test -e $buildlink; then
144 splbuild=`(cd $buildlink; /bin/pwd)`
145 fi
146 if test -z "$splsrc"; then
147 splsrc=$splbuild
148 fi
149 if test -z "$splsrc" -o -z "$splbuild"; then
150 AC_MSG_RESULT([Not found])
151 AC_MSG_ERROR([
152 *** Please specify the location of the spl source
153 *** with the '--with-spl=PATH' option])
154 fi
155 fi
156
157 AC_MSG_RESULT([$splsrc])
158 AC_MSG_CHECKING([spl build directory])
159 AC_MSG_RESULT([$splbuild])
160
161 AC_MSG_CHECKING([spl source version])
162 if test -r $splbuild/spl_config.h &&
163 fgrep -q VERSION $splbuild/spl_config.h; then
164
165 splsrcver=`(echo "#include <spl_config.h>";
166 echo "splsrcver=VERSION") |
167 cpp -I $splbuild |
168 grep "^splsrcver=" | cut -d \" -f 2`
169 fi
170
171 if test -z "$splsrcver"; then
172 AC_MSG_RESULT([Not found])
173 AC_MSG_ERROR([
174 *** Cannot determine the version of the spl source.
175 *** Please prepare the spl source before running this script])
176 fi
177
178 AC_MSG_RESULT([$splsrcver])
179
180 AC_MSG_CHECKING([spl Module.symvers])
181 if test -r $splbuild/modules/Module.symvers; then
182 splsymvers=$splbuild/modules/Module.symvers
183 elif test -r $kernelbuild/Module.symvers; then
184 splsymvers=$kernelbuild/Module.symvers
185 fi
186
187 if test -z "$splsymvers"; then
188 AC_MSG_RESULT([Not found])
189 AC_MSG_ERROR([
190 *** Cannot find extra Module.symvers in the spl source.
191 *** Please prepare the spl source before running this script])
192 fi
193
194 AC_MSG_RESULT([$splsymvers])
195 AC_SUBST(splsrc)
196 AC_SUBST(splsymvers)
197 ])
198
199 AC_DEFUN([ZFS_AC_LICENSE], [
200 AC_MSG_CHECKING([license])
201 AC_MSG_RESULT([CDDL])
202 dnl # AC_DEFINE([HAVE_GPL_ONLY_SYMBOLS], [1],
203 dnl # [Define to 1 if module is licensed under the GPL])
204 ])
205
206 AC_DEFUN([ZFS_AC_DEBUG], [
207 AC_MSG_CHECKING([whether debugging is enabled])
208 AC_ARG_ENABLE( [debug],
209 AS_HELP_STRING([--enable-debug],
210 [Enable generic debug support (default off)]),
211 [ case "$enableval" in
212 yes) zfs_ac_debug=yes ;;
213 no) zfs_ac_debug=no ;;
214 *) AC_MSG_RESULT([Error!])
215 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug]) ;;
216 esac ]
217 )
218 if test "$zfs_ac_debug" = yes; then
219 AC_MSG_RESULT([yes])
220 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG "
221 HOSTCFLAGS="${HOSTCFLAGS} -DDEBUG "
222 else
223 AC_MSG_RESULT([no])
224 AC_DEFINE([NDEBUG], [1],
225 [Define to 1 to disable debug tracing])
226 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG "
227 HOSTCFLAGS="${HOSTCFLAGS} -DNDEBUG "
228 fi
229 ])
230
231 AC_DEFUN([ZFS_AC_SCRIPT_CONFIG], [
232 SCRIPT_CONFIG=.script-config
233 rm -f ${SCRIPT_CONFIG}
234 echo "KERNELSRC=${LINUX}" >>${SCRIPT_CONFIG}
235 echo "KERNELBUILD=${LINUX_OBJ}" >>${SCRIPT_CONFIG}
236 echo "KERNELSRCVER=$kernsrcver" >>${SCRIPT_CONFIG}
237 echo >>${SCRIPT_CONFIG}
238 echo "SPLSRC=$splsrc" >>${SCRIPT_CONFIG}
239 echo "SPLBUILD=$splbuild" >>${SCRIPT_CONFIG}
240 echo "SPLSRCVER=$splsrcver" >>${SCRIPT_CONFIG}
241 echo "SPLSYMVERS=$splsymvers" >>${SCRIPT_CONFIG}
242 echo >>${SCRIPT_CONFIG}
243 echo "ZFSSRC=${TOPDIR}/src" >>${SCRIPT_CONFIG}
244 echo "ZFSBUILD=${ZFSDIR}" >>${SCRIPT_CONFIG}
245 echo >>${SCRIPT_CONFIG}
246 echo "TOPDIR=${TOPDIR} >>${SCRIPT_CONFIG}
247 echo "LIBDIR=${LIBDIR} >>${SCRIPT_CONFIG}
248 echo "CMDDIR=${CMDDIR} >>${SCRIPT_CONFIG}
249 ])
250
251 dnl #
252 dnl # ZFS_LINUX_CONFTEST
253 dnl #
254 AC_DEFUN([ZFS_LINUX_CONFTEST], [
255 cat >conftest.c <<_ACEOF
256 $1
257 _ACEOF
258 ])
259
260 dnl #
261 dnl # ZFS_LANG_PROGRAM(C)([PROLOGUE], [BODY])
262 dnl #
263 m4_define([ZFS_LANG_PROGRAM], [
264 $1
265 int
266 main (void)
267 {
268 dnl Do *not* indent the following line: there may be CPP directives.
269 dnl Don't move the `;' right after for the same reason.
270 $2
271 ;
272 return 0;
273 }
274 ])
275
276 dnl #
277 dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
278 dnl #
279 AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
280 m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])dnl
281 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko build/Makefile
282 echo "obj-m := conftest.o" >build/Makefile
283 dnl AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" -f $PWD/build/Makefile LINUXINCLUDE="-Iinclude -include include/linux/autoconf.h" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM SUBDIRS=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
284 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" LINUXINCLUDE="-Iinclude -include include/linux/autoconf.h" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
285 [$4],
286 [_AC_MSG_LOG_CONFTEST
287 m4_ifvaln([$5],[$5])dnl])dnl
288 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
289 ])
290
291 dnl #
292 dnl # ZFS_LINUX_TRY_COMPILE like AC_TRY_COMPILE
293 dnl #
294 AC_DEFUN([ZFS_LINUX_TRY_COMPILE],
295 [ZFS_LINUX_COMPILE_IFELSE(
296 [AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
297 [modules],
298 [test -s build/conftest.o],
299 [$3], [$4])
300 ])
301
302 dnl #
303 dnl # ZFS_LINUX_CONFIG
304 dnl #
305 AC_DEFUN([ZFS_LINUX_CONFIG],
306 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
307 ZFS_LINUX_TRY_COMPILE([
308 #ifndef AUTOCONF_INCLUDED
309 #include <linux/config.h>
310 #endif
311 ],[
312 #ifndef CONFIG_$1
313 #error CONFIG_$1 not #defined
314 #endif
315 ],[
316 AC_MSG_RESULT([yes])
317 $2
318 ],[
319 AC_MSG_RESULT([no])
320 $3
321 ])
322 ])
323
324 dnl #
325 dnl # ZFS_CHECK_SYMBOL_EXPORT
326 dnl # check symbol exported or not
327 dnl #
328 AC_DEFUN([ZFS_CHECK_SYMBOL_EXPORT],
329 [AC_MSG_CHECKING([whether symbol $1 is exported])
330 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/Module.symvers 2>/dev/null
331 rc=$?
332 if test $rc -ne 0; then
333 export=0
334 for file in $2; do
335 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
336 rc=$?
337 if test $rc -eq 0; then
338 export=1
339 break;
340 fi
341 done
342 if test $export -eq 0; then
343 AC_MSG_RESULT([no])
344 $4
345 else
346 AC_MSG_RESULT([yes])
347 $3
348 fi
349 else
350 AC_MSG_RESULT([yes])
351 $3
352 fi
353 ])
354
355 dnl #
356 dnl # 2.6.x API change
357 dnl # bio_end_io_t uses 2 args (size was dropped from prototype)
358 dnl #
359 AC_DEFUN([ZFS_AC_2ARGS_BIO_END_IO_T],
360 [AC_MSG_CHECKING([whether bio_end_io_t wants 2 args])
361 tmp_flags="$EXTRA_KCFLAGS"
362 EXTRA_KCFLAGS="-Werror"
363 ZFS_LINUX_TRY_COMPILE([
364 #include <linux/bio.h>
365 ],[
366 void (*wanted_end_io)(struct bio *, int) = NULL;
367 bio_end_io_t *local_end_io;
368
369 local_end_io = wanted_end_io;
370 ],[
371 AC_MSG_RESULT(yes)
372 AC_DEFINE(HAVE_2ARGS_BIO_END_IO_T, 1,
373 [bio_end_io_t wants 2 args])
374 ],[
375 AC_MSG_RESULT(no)
376 ])
377 EXTRA_KCFLAGS="$tmp_flags"
378 ])