From 0dc5776426d183cf2b8e82d024d0333e2adbeec8 Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Sat, 10 Jan 2009 20:46:00 -0500 Subject: [PATCH 1/2] Convert btrfs-progs to be built with autotools There's no real code changes here - all I've done is replace the existing Makefile with an autotools build system, and update the names of a couple version macros and a few includes in several source files. What ends up getting built is very different now - all of the common objects that had previously been statically compiled into each executable are now a (shared or static, configurable) library: libbtrfs. The quick-test and dir-test tools can be built by running 'make btrfs-quick-test' or 'make btrfs-dir-test' - they are not built by default. Signed-off-by: Calvin Walton --- .gitignore | 31 ++++++++++++++++ Makefile | 79 ------------------------------------------ Makefile.am | 85 +++++++++++++++++++++++++++++++++++++++++++++ autogen.sh | 3 ++ btrfs-image.c | 1 - btrfs-show.c | 2 +- btrfsck.c | 2 +- btrfsctl.c | 2 +- btrfstune.c | 1 - configure.ac | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ debug-tree.c | 2 +- m4/.gitignore | 5 +++ mkfs.c | 2 +- version.sh | 59 ------------------------------- 14 files changed, 236 insertions(+), 145 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 m4/.gitignore delete mode 100644 version.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3d0da7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +*.la +*.lo +*.o +.deps +.libs +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +config.guess +config.h* +config.log +config.status +config.sub +configure +depcomp +install-sh +libtool +ltmain.sh +missing +stamp-h1 + +btrfs-convert +btrfs-debug-tree +btrfs-image +btrfs-show +btrfs-vol +btrfsctl +btrfstune +fsck.btrfs +mkfs.btrfs diff --git a/Makefile b/Makefile deleted file mode 100644 index 3349079..0000000 --- a/Makefile +++ /dev/null @@ -1,79 +0,0 @@ -CC=gcc -AM_CFLAGS = -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -CFLAGS = -g -Werror -Os -objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ - root-tree.o dir-item.o file-item.o inode-item.o \ - inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ - volumes.o utils.o -# -CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ - -Wuninitialized -Wshadow -Wundef -DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ - -INSTALL= install -prefix ?= /usr/local -bindir = $(prefix)/bin -LIBS=-luuid - -progs = btrfsctl btrfsck mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol \ - btrfstune btrfs-image - -# make C=1 to enable sparse -ifdef C - check=sparse $(CHECKFLAGS) -else - check=ls -endif - -.c.o: - $(check) $< - $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< - - -all: version $(progs) - -version: - bash version.sh - -btrfsctl: $(objects) btrfsctl.o - gcc $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS) - -btrfs-vol: $(objects) btrfs-vol.o - gcc $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS) - -btrfs-show: $(objects) btrfs-show.o - gcc $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS) - -btrfsck: $(objects) btrfsck.o bit-radix.o - gcc $(CFLAGS) -o btrfsck btrfsck.o $(objects) bit-radix.o $(LDFLAGS) $(LIBS) - -mkfs.btrfs: $(objects) mkfs.o - gcc $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) - -btrfs-debug-tree: $(objects) debug-tree.o - gcc $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS) - -btrfstune: $(objects) btrfstune.o - gcc $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS) - -btrfs-image: $(objects) btrfs-image.o - gcc $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS) - -dir-test: $(objects) dir-test.o - gcc $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS) - -quick-test: $(objects) quick-test.o - gcc $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS) - -convert: $(objects) convert.o - gcc $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs $(LDFLAGS) $(LIBS) - -clean : - rm -f $(progs) cscope.out *.o .*.d btrfs-convert - -install: $(progs) - $(INSTALL) -m755 -d $(DESTDIR)$(bindir) - $(INSTALL) $(progs) $(DESTDIR)$(bindir) - if [ -e btrfs-convert ]; then $(INSTALL) btrfs-convert $(DESTDIR)$(bindir); fi - --include .*.d diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..64772a3 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,85 @@ +ACLOCAL_AMFLAGS = -I m4 + +sbin_PROGRAMS = btrfs-debug-tree \ + btrfs-image \ + btrfs-show \ + btrfs-vol \ + btrfsctl \ + btrfstune \ + fsck.btrfs \ + mkfs.btrfs \ + @EXTRA_PROGRAMS@ + +EXTRA_PROGRAMS = btrfs-dir-test btrfs-quick-test btrfs-convert +lib_LTLIBRARIES = libbtrfs.la + +btrfs_convert_SOURCES = convert.c +btrfs_convert_CPPFLAGS = @EXT2FS_CFLAGS@ +btrfs_convert_LDADD = -lbtrfs @EXT2FS_LIBS@ + +btrfs_debug_tree_SOURCES = debug-tree.c +btrfs_debug_tree_LDADD = -lbtrfs + +btrfs_dir_test_SOURCES = dir-test.c +btrfs_dir_test_LDADD = -lbtrfs + +btrfs_image_SOURCES = btrfs-image.c +btrfs_image_LDADD = -lbtrfs @PTHREAD_LIBS@ @ZLIB_LIBS@ + +btrfs_quick_test_SOURCES = quick-test.c +btrfs_quick_test_LDADD = -lbtrfs + +btrfs_show_SOURCES = btrfs-show.c +btrfs_show_LDADD = -lbtrfs + +btrfs_vol_SOURCES = btrfs-vol.c +btrfs_vol_LDADD = -lbtrfs + +btrfsctl_SOURCES = btrfsctl.c +btrfsctl_LDADD = -lbtrfs + +btrfstune_SOURCES = btrfstune.c +btrfstune_LDADD = -lbtrfs + +fsck_btrfs_SOURCES = btrfsck.c \ + bit-radix.c \ + bit-radix.h +fsck_btrfs_LDADD = -lbtrfs + +mkfs_btrfs_SOURCES = mkfs.c +mkfs_btrfs_LDADD = -lbtrfs + +libbtrfs_la_SOURCES = ctree.c \ + ctree.h \ + crc32c.c \ + crc32c.h \ + dir-item.c \ + disk-io.c \ + disk-io.h \ + extent-cache.c \ + extent-cache.h \ + extent_io.c \ + extent_io.h \ + extent-tree.c \ + file-item.c \ + hash.h \ + inode-item.c \ + inode-map.c \ + ioctl.h \ + kerncompat.h \ + list.h \ + print-tree.c \ + print-tree.h \ + radix-tree.c \ + radix-tree.h \ + rbtree.c \ + rbtree.h \ + root-tree.c \ + transaction.h \ + utils.c \ + utils.h \ + volumes.c \ + volumes.h +libbtrfs_la_LIBADD = @UUID_LIBS@ +libbtrfs_la_CPPFLAGS = @UUID_CFLAGS@ +libbtrfs_la_LDFLAGS = -version-info 0:0:0 diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..c70cbcb --- /dev/null +++ b/autogen.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +autoreconf -iv -Wall diff --git a/btrfs-image.c b/btrfs-image.c index 9925bdb..28fb276 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -33,7 +33,6 @@ #include "disk-io.h" #include "transaction.h" #include "utils.h" -#include "version.h" #define HEADER_MAGIC 0xbd5c25e27295668bULL diff --git a/btrfs-show.c b/btrfs-show.c index c49626c..3b2b74c 100644 --- a/btrfs-show.c +++ b/btrfs-show.c @@ -36,7 +36,7 @@ #include "transaction.h" #include "utils.h" #include "volumes.h" -#include "version.h" +#include "config.h" static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search) { diff --git a/btrfsck.c b/btrfsck.c index 4a41e6d..9a757a1 100644 --- a/btrfsck.c +++ b/btrfsck.c @@ -27,7 +27,7 @@ #include "print-tree.h" #include "transaction.h" #include "list.h" -#include "version.h" +#include "config.h" static u64 bytes_used = 0; static u64 total_csum_bytes = 0; diff --git a/btrfsctl.c b/btrfsctl.c index e049799..c0bfa24 100644 --- a/btrfsctl.c +++ b/btrfsctl.c @@ -33,7 +33,7 @@ #include "ctree.h" #include "transaction.h" #include "utils.h" -#include "version.h" +#include "config.h" #ifdef __CHECKER__ #define BLKGETSIZE64 0 diff --git a/btrfstune.c b/btrfstune.c index 47830c5..90209f1 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -30,7 +30,6 @@ #include "disk-io.h" #include "transaction.h" #include "utils.h" -#include "version.h" static char *device; diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..0339980 --- /dev/null +++ b/configure.ac @@ -0,0 +1,107 @@ +AC_INIT([btrfs-progs], [0.16], []) + +AC_CONFIG_SRCDIR([btrfs-vol.c]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_FILES([Makefile]) + +dnl Set the version string from git if available + +GIT_VERSION="v$PACKAGE_VERSION" +AC_CHECK_PROG([GIT], [git], [yes], [no]) +if test $GIT = yes ; then + AC_MSG_CHECKING([for git revision string]) + if git rev-parse --verify HEAD >&AS_MESSAGE_LOG_FD 2>&1 ; then + if tag=`git describe --tags 2>&AS_MESSAGE_LOG_FD` ; then + GIT_VERSION="$tag" + if ! git diff-index --quiet HEAD ; then + GIT_VERSION="$GIT_VERSION"-dirty + fi + AC_MSG_RESULT([$GIT_VERSION]) + else + AC_MSG_RESULT([error determining revision]) + fi + else + AC_MSG_RESULT([not a git repository]) + fi +fi +AC_DEFINE_UNQUOTED([BTRFS_BUILD_VERSION], + ["$PACKAGE_NAME $GIT_VERSION"], + ["Package version string"]) + +dnl Command-line options + +AC_ARG_ENABLE([convert], + [AS_HELP_STRING([--enable-convert], + [Build a tool which converts an ext* filesystem to btrfs @<:@default: auto@:>@])], + [], + [enable_convert=auto]) + +if test "x$enable_convert" = xyes || test "x$enable_convert" = xauto ; then + want_ext2fs=yes +fi + +dnl Checks that don't require a compiler (fail fast) + +PKG_CHECK_MODULES([UUID], [uuid]) + +if test "x$want_ext2fs" = xyes ; then + PKG_CHECK_MODULES([EXT2FS], [ext2fs], + [have_ext2fs=yes], [have_ext2fs=no]) +fi + +AC_MSG_CHECKING([whether to build btrfs-convert]) +if test "x$have_ext2fs" = xyes ; then + if test "x$enable_convert" = xauto ; then + enable_convert=yes + fi +else + if test "x$enable_convert" = xyes ; then + AC_MSG_FAILURE([convert was enabled, but libext2fs was not found]) + else + enable_convert=no + fi +fi +AC_MSG_RESULT([$enable_convert]) + +dnl Set up the compiler and build system + +AM_INIT_AUTOMAKE([dist-bzip2 dist-lzma foreign no-dist-gzip subdir-objects]) + +LT_INIT([disable-static]) + +dnl Checks that require a compiler + +AC_SEARCH_LIBS([pthread_create], + [pthread], + [PTHREAD_LIBS="$ac_cv_search_pthread_create"], + [AC_MSG_ERROR([could not find pthread library])]) +AC_SUBST([PTHREAD_LIBS]) + +AC_SEARCH_LIBS([compress2], + [z], + [ZLIB_LIBS="$ac_cv_search_compress2"], + [AC_MSG_ERROR([could not find zlib library])]) +AC_SUBST([ZLIB_LIBS]) + +dnl Reset LIBS variable from AC_SEARCH_LIBS +dnl If I don't, they'll get linked to everything... +LIBS= + +dnl Tell automake which extra programs to build + +EXTRA_PROGRAMS= +if test "x$enable_convert" = xyes ; then + EXTRA_PROGRAMS="$EXTRA_PROGRAMS btrfs-convert" +fi +AC_SUBST([EXTRA_PROGRAMS]) + +dnl It's all done! + +AC_OUTPUT + +echo +echo "=== $PACKAGE_NAME $GIT_VERSION configuration ===" +echo "Optional features:" +echo " btrfs-convert: $enable_convert" +echo diff --git a/debug-tree.c b/debug-tree.c index 53f8be4..ef98db9 100644 --- a/debug-tree.c +++ b/debug-tree.c @@ -26,7 +26,7 @@ #include "disk-io.h" #include "print-tree.h" #include "transaction.h" -#include "version.h" +#include "config.h" static int print_usage(void) { diff --git a/m4/.gitignore b/m4/.gitignore new file mode 100644 index 0000000..38066dd --- /dev/null +++ b/m4/.gitignore @@ -0,0 +1,5 @@ +libtool.m4 +ltoptions.m4 +ltsugar.m4 +ltversion.m4 +lt~obsolete.m4 diff --git a/mkfs.c b/mkfs.c index d664254..6b4bd01 100644 --- a/mkfs.c +++ b/mkfs.c @@ -41,7 +41,7 @@ #include "volumes.h" #include "transaction.h" #include "utils.h" -#include "version.h" +#include "config.h" static u64 parse_size(char *s) { diff --git a/version.sh b/version.sh deleted file mode 100644 index 209b7d1..0000000 --- a/version.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -# -# determine-version -- report a useful version for releases -# -# Copyright 2008, Aron Griffis -# Copyright 2008, Oracle -# Released under the GNU GPLv2 - -v="Btrfs v0.16" - -which git &> /dev/null -if [ $? == 0 -a -d .git ]; then - if head=`git rev-parse --verify HEAD 2>/dev/null`; then - if tag=`git describe --tags 2>/dev/null`; then - v="$tag" - fi - - # Are there uncommitted changes? - git update-index --refresh --unmerged > /dev/null - if git diff-index --name-only HEAD | grep -v "^scripts/package" \ - | read dummy; then - v="$v"-dirty - fi - fi -fi - -which hg &> /dev/null -if [ $? == 0 -a -d .hg ]; then - last=$(hg tags | grep -m1 -o '^v[0-9.]\+') - - # now check if the repo has commits since then... - if [[ $(hg id -t) == $last || \ - $(hg di -r "$last:." | awk '/^diff/{print $NF}' | sort -u) == .hgtags ]] - then - # check if it's dirty - if [[ $(hg id | cut -d' ' -f1) == *+ ]]; then - v=$last+ - else - v=$last - fi - else - # includes dirty flag - v=$last+$(hg id -i) - fi -fi - -echo "#ifndef __BUILD_VERSION" > .build-version.h -echo "#define __BUILD_VERSION" >> .build-version.h -echo "#define BTRFS_BUILD_VERSION \"Btrfs $v\"" >> .build-version.h -echo "#endif" >> .build-version.h - -diff -q version.h .build-version.h >& /dev/null - -if [ $? == 0 ]; then - rm .build-version.h - exit 0 -fi - -mv .build-version.h version.h -- 1.6.1