summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2018-02-15 11:04:47 -0800
committerDavid Sterba <dsterba@suse.com>2018-02-24 01:37:16 +0100
commit502e2a3510c5db03335c0df8abc7f9804a65207b (patch)
tree09aa390489e91d46aa92ac2bd49528cb7ad8304a /Makefile
parent510bb4ccc4258567e731b81c4722a6adc7faec8b (diff)
Add libbtrfsutil
Currently, users wishing to manage Btrfs filesystems programatically have to shell out to btrfs-progs and parse the output. This isn't ideal. The goal of libbtrfsutil is to provide a library version of as many of the operations of btrfs-progs as possible and to migrate btrfs-progs to use it. Rather than simply refactoring the existing btrfs-progs code, the code has to be written from scratch for a couple of reasons: * A lot of the btrfs-progs code was not designed with a nice library API in mind in terms of reusability, naming, and error reporting. * libbtrfsutil is licensed under the LGPL, whereas btrfs-progs is under the GPL, which makes it dubious to directly copy or move the code. Eventually, most of the low-level btrfs-progs code should either live in libbtrfsutil or the shared kernel/userspace filesystem code, and btrfs-progs will just be the CLI wrapper. This first commit just includes the build system changes, license, README, and error reporting helper. Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile72
1 files changed, 52 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 92cfe7b..7c88460 100644
--- a/Makefile
+++ b/Makefile
@@ -73,10 +73,20 @@ CFLAGS = $(SUBST_CFLAGS) \
-fPIC \
-I$(TOPDIR) \
-I$(TOPDIR)/kernel-lib \
+ -I$(TOPDIR)/libbtrfsutil \
$(EXTRAWARN_CFLAGS) \
$(DEBUG_CFLAGS_INTERNAL) \
$(EXTRA_CFLAGS)
+LIBBTRFSUTIL_CFLAGS = $(SUBST_CFLAGS) \
+ $(CSTD) \
+ -D_GNU_SOURCE \
+ -fPIC \
+ -fvisibility=hidden \
+ -I$(TOPDIR)/libbtrfsutil \
+ $(EXTRAWARN_CFLAGS) \
+ $(EXTRA_CFLAGS)
+
LDFLAGS = $(SUBST_LDFLAGS) \
-rdynamic -L$(TOPDIR) \
$(DEBUG_LDFLAGS_INTERNAL) \
@@ -121,12 +131,17 @@ libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-l
kernel-lib/crc32c.h kernel-lib/list.h kerncompat.h \
kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
extent-cache.h extent_io.h ioctl.h ctree.h btrfsck.h version.h
+libbtrfsutil_major := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MAJOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
+libbtrfsutil_minor := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MINOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
+libbtrfsutil_patch := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_PATCH ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
+libbtrfsutil_version := $(libbtrfsutil_major).$(libbtrfsutil_minor).$(libbtrfsutil_patch)
+libbtrfsutil_objects = libbtrfsutil/errors.o
convert_objects = convert/main.o convert/common.o convert/source-fs.o \
convert/source-ext2.o convert/source-reiserfs.o
mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
image_objects = image/main.o image/sanitize.o
all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \
- $(mkfs_objects) $(image_objects)
+ $(mkfs_objects) $(image_objects) $(libbtrfsutil_objects)
udev_rules = 64-btrfs-dm.rules
@@ -246,11 +261,10 @@ static_convert_objects = $(patsubst %.o, %.static.o, $(convert_objects))
static_mkfs_objects = $(patsubst %.o, %.static.o, $(mkfs_objects))
static_image_objects = $(patsubst %.o, %.static.o, $(image_objects))
-libs_shared = libbtrfs.so.0.1
-libs_static = libbtrfs.a
+libs_shared = libbtrfs.so.0.1 libbtrfsutil.so.$(libbtrfsutil_version)
+libs_static = libbtrfs.a libbtrfsutil.a
libs = $(libs_shared) $(libs_static)
-lib_links = libbtrfs.so.0 libbtrfs.so
-headers = $(libbtrfs_headers)
+lib_links = libbtrfs.so.0 libbtrfs.so libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so
# make C=1 to enable sparse
ifdef C
@@ -287,7 +301,7 @@ endif
$(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.static.o=%)-cflags)) \
$($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
-all: $(progs) libbtrfs $(BUILDDIRS)
+all: $(progs) $(libs) $(lib_links) $(BUILDDIRS)
$(SUBDIRS): $(BUILDDIRS)
$(BUILDDIRS):
@echo "Making all in $(patsubst build-%,%,$@)"
@@ -355,20 +369,35 @@ kernel-lib/tables.c:
@echo " [TABLE] $@"
$(Q)./mktables > $@ || ($(RM) -f $@ && exit 1)
-libbtrfs: $(libs_shared) $(lib_links)
+libbtrfs.so.0.1: $(libbtrfs_objects)
+ @echo " [LD] $@"
+ $(Q)$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LIBBTRFS_LIBS) \
+ -shared -Wl,-soname,libbtrfs.so.0 -o $@
+
+libbtrfs.a: $(libbtrfs_objects)
+ @echo " [AR] $@"
+ $(Q)$(AR) cr $@ $^
+
+libbtrfs.so.0 libbtrfs.so: libbtrfs.so.0.1
+ @echo " [LN] $@"
+ $(Q)$(LN_S) -f $< $@
+
+libbtrfsutil/%.o: libbtrfsutil/%.c
+ @echo " [CC] $@"
+ $(Q)$(CC) $(LIBBTRFSUTIL_CFLAGS) -o $@ -c $< -o $@
-$(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
+libbtrfsutil.so.$(libbtrfsutil_version): $(libbtrfsutil_objects)
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
- -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
+ $(Q)$(CC) $(LIBBTRFSUTIL_CFLAGS) $(libbtrfsutil_objects) \
+ -shared -Wl,-soname,libbtrfsutil.so.$(libbtrfsutil_major) -o $@
-$(libs_static): $(libbtrfs_objects)
+libbtrfsutil.a: $(libbtrfsutil_objects)
@echo " [AR] $@"
- $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
+ $(Q)$(AR) cr $@ $^
-$(lib_links):
+libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so: libbtrfsutil.so.$(libbtrfsutil_version)
@echo " [LN] $@"
- $(Q)$(LN_S) -f libbtrfs.so.0.1 $@
+ $(Q)$(LN_S) -f $< $@
# keep intermediate files from the below implicit rules around
.PRECIOUS: $(addsuffix .o,$(progs))
@@ -487,7 +516,7 @@ test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64
$(Q)./ioctl-test-32 > ioctl-test-32.log
$(Q)./ioctl-test-64 > ioctl-test-64.log
-library-test: library-test.c $(libs_shared)
+library-test: library-test.c libbtrfs.so
@echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d))
$(Q)mkdir -p $(TMPD)/include/btrfs && \
cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
@@ -551,7 +580,8 @@ clean: $(CLEANDIRS)
mktables btrfs.static mkfs.btrfs.static fssum \
$(check_defs) \
$(libs) $(lib_links) \
- $(progs_static) $(progs_extra)
+ $(progs_static) $(progs_extra) \
+ libbtrfsutil/*.o libbtrfsutil/*.o.d
clean-doc:
@echo "Cleaning Documentation"
@@ -579,8 +609,9 @@ install: $(libs) $(progs_install) $(INSTALLDIRS)
$(INSTALL) -m755 -d $(DESTDIR)$(libdir)
$(INSTALL) $(libs) $(DESTDIR)$(libdir)
cp -a $(lib_links) $(DESTDIR)$(libdir)
- $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
- $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
+ $(INSTALL) -m755 -d $(DESTDIR)$(incdir)/btrfs
+ $(INSTALL) -m644 $(libbtrfs_headers) $(DESTDIR)$(incdir)/btrfs
+ $(INSTALL) -m644 libbtrfsutil/btrfsutil.h $(DESTDIR)$(incdir)
ifneq ($(udevdir),)
$(INSTALL) -m755 -d $(DESTDIR)$(udevruledir)
$(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
@@ -598,8 +629,9 @@ $(INSTALLDIRS):
uninstall:
$(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
- cd $(DESTDIR)$(incdir); $(RM) -f -- $(headers)
- $(RMDIR) -p --ignore-fail-on-non-empty -- $(DESTDIR)$(incdir)
+ cd $(DESTDIR)$(incdir)/btrfs; $(RM) -f -- $(libbtrfs_headers)
+ $(RMDIR) -p --ignore-fail-on-non-empty -- $(DESTDIR)$(incdir)/btrfs
+ cd $(DESTDIR)$(incdir); $(RM) -f -- btrfsutil.h
cd $(DESTDIR)$(libdir); $(RM) -f -- $(lib_links) $(libs)
cd $(DESTDIR)$(bindir); $(RM) -f -- btrfsck fsck.btrfs $(progs_install)