+AC_ARG_ENABLE([convert],
+ AS_HELP_STRING([--disable-convert], [do not build btrfs-convert]),
+ [], [enable_convert=yes]
+)
+
+AS_IF([test "x$enable_convert" = xyes], [DISABLE_BTRFSCONVERT=0], [DISABLE_BTRFSCONVERT=1])
+AC_SUBST([DISABLE_BTRFSCONVERT])
+
+AC_ARG_WITH([convert],
+ AS_HELP_STRING([[[]--with-convert[[=auto]]]], [built-in filesystems for convert (default: auto)
+supported (comma separated list): ext2,reiserfs]),
+ [], [with_convert=auto]
+)
+
+if test "$with_convert" = "yes"; then
+ with_convert=auto
+fi
+
+if test "$with_convert" = "no"; then
+ with_convert=
+fi
+
+convertfs=
+BTRFSCONVERT_EXT2=0
+BTRFSCONVERT_REISERFS=0
+if test "x$enable_convert" = xyes; then
+ if test "x$with_convert" = "xauto" || echo "$with_convert" | grep -q "ext2"; then
+ PKG_CHECK_MODULES(EXT2FS, [ext2fs >= 1.42],,
+ [PKG_CHECK_MODULES(EXT2FS, [ext2fs],
+ [AC_DEFINE([HAVE_OLD_E2FSPROGS], [1],
+ [E2fsprogs does not support BIGALLOC])]
+ )])
+ PKG_CHECK_MODULES(COM_ERR, [com_err])
+ convertfs="${convertfs:+$convertfs,}ext2"
+ BTRFSCONVERT_EXT2=1
+ fi
+ if test "x$with_convert" = "xauto"; then
+ PKG_CHECK_MODULES(REISERFS, [reiserfscore >= 3.6.27],
+ [BTRFSCONVERT_REISERFS=1],
+ [BTRFSCONVERT_REISERFS=0])
+ elif echo "$with_convert" | grep -q "reiserfs"; then
+ PKG_CHECK_MODULES(REISERFS, [reiserfscore >= 3.6.27],
+ [BTRFSCONVERT_REISERFS=1],[])
+ fi
+ if test "$BTRFSCONVERT_REISERFS" = 1; then
+ convertfs="${convertfs:+$convertfs,}reiserfs"
+ fi
+fi
+AC_SUBST([BTRFSCONVERT_EXT2])
+AC_SUBST([BTRFSCONVERT_REISERFS])
+
+# catch typos
+tmp=$(echo "$with_convert" | sed -e 's/auto//' | sed -e 's/ext2//' | sed -e 's/reiserfs//' | sed -e 's/,\+//')
+if ! test "x$tmp" = "x"; then
+ AC_MSG_ERROR([unknown tokens for --with-convert: $tmp])
+fi
+
+if test "$DISABLE_BTRFSCONVERT" = 0 && test "x$convertfs" = "x"; then
+ AC_MSG_ERROR([no filesystems for convert, use --disable-convert instead])
+fi
+
+HAVE_OWN_FIEMAP_EXTENT_SHARED_DEFINE=0
+AX_CHECK_DEFINE([linux/fiemap.h], [FIEMAP_EXTENT_SHARED], [],
+ [HAVE_OWN_FIEMAP_EXTENT_SHARED_DEFINE=1
+ AC_MSG_WARN([no definition of FIEMAP_EXTENT_SHARED found, probably old kernel, will use own defintion, 'btrfs fi du' might report wrong numbers])])
+
+if test "x$HAVE_OWN_FIEMAP_EXTENT_SHARED_DEFINE" == "x1"; then
+AC_DEFINE([HAVE_OWN_FIEMAP_EXTENT_SHARED_DEFINE], [1], [We defined FIEMAP_EXTENT_SHARED])
+else
+AC_DEFINE([HAVE_OWN_FIEMAP_EXTENT_SHARED_DEFINE], [0], [We did not define FIEMAP_EXTENT_SHARED])
+fi