#
# Basic build targets:
-# all all main tools
+# all all main tools and the shared library
# static build static bnaries, requires static version of the libraries
# test run the full testsuite
# install install to default location (/usr/local)
# abort - call abort() on first error (dumps core)
# all - shortcut for all of the above
# asan - enable address sanitizer compiler feature
+# tsan - enable thread sanitizer compiler feature
# ubsan - undefined behaviour sanitizer compiler feature
# bcheck - extended build checks
# W=123 build with warnings (default: off)
endif
TAGS_CMD := ctags
+CSCOPE_CMD := cscope -u -b -c -q
include Makefile.extrawarn
# Common build flags
CFLAGS = $(SUBST_CFLAGS) \
+ -std=gnu90 \
-include config.h \
-DBTRFS_FLAT_INCLUDES \
-D_XOPEN_SOURCE=700 \
objects = ctree.o disk-io.o kernel-lib/radix-tree.o extent-tree.o print-tree.o \
root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
extent-cache.o extent_io.o volumes.o utils.o repair.o \
- qgroup.o raid56.o free-space-cache.o kernel-lib/list_sort.o props.o \
- ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
+ qgroup.o free-space-cache.o kernel-lib/list_sort.o props.o \
+ kernel-shared/ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
inode.o file.o find-root.o free-space-tree.o help.o send-dump.o \
- fsfeatures.o
+ fsfeatures.o kernel-lib/tables.o kernel-lib/raid56.o
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
- cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o
+ cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \
+ mkfs/common.o
libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
- kernel-lib/crc32c.o \
+ kernel-lib/crc32c.o messages.o \
uuid-tree.o utils-lib.o rbtree-utils.o
libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
kernel-lib/crc32c.h kernel-lib/list.h kerncompat.h \
- kernel-lib/radix-tree.h extent-cache.h \
- extent_io.h ioctl.h ctree.h btrfsck.h version.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
convert_objects = convert/main.o convert/common.o convert/source-fs.o \
convert/source-ext2.o
mkfs_objects = mkfs/main.o mkfs/common.o
DEBUG_CFLAGS_INTERNAL += -fsanitize=address
endif
+ifneq (,$(findstring tsan,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -fsanitize=thread -fPIE
+ LD_FLAGS += -fsanitize=thread -ltsan -pie
+endif
+
ifneq (,$(findstring ubsan,$(D)))
DEBUG_CFLAGS_INTERNAL += -fsanitize=undefined
endif
$(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.static.o=%)-cflags)) \
$($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
-all: $(progs) $(BUILDDIRS)
+all: $(progs) libbtrfs $(BUILDDIRS)
$(SUBDIRS): $(BUILDDIRS)
$(BUILDDIRS):
@echo "Making all in $(patsubst build-%,%,$@)"
$(Q)bash tests/convert-tests.sh
test-check: test-fsck
-test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
+test-fsck: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune
@echo " [TEST] fsck-tests.sh"
$(Q)bash tests/fsck-tests.sh
-test-misc: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
+test-misc: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune fssum \
+ btrfs-zero-log btrfs-find-root btrfs-select-super
@echo " [TEST] misc-tests.sh"
$(Q)bash tests/misc-tests.sh
test-inst: all
@tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
echo "Test installation to $$tmpdest" && \
- $(MAKE) DESTDIR=$$tmpdest install && \
+ $(MAKE) $(MAKEOPTS) DESTDIR=$$tmpdest install && \
$(RM) -rf -- $$tmpdest
test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli
@echo " [SH] $@"
$(Q)bash ./config.status --silent $@
+mktables: kernel-lib/mktables.c
+ @echo " [CC] $@"
+ $(Q)$(CC) $(CFLAGS) $< -o $@
+
+# the target can be regenerated manually using mktables, but a local copy is
+# kept so the build process is simpler
+kernel-lib/tables.c:
+ @echo " [TABLE] $@"
+ $(Q)./mktables > $@ || ($(RM) -f $@ && exit 1)
+
+libbtrfs: $(libs_shared) $(lib_links)
+
$(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
$(Q)./ioctl-test-32 > ioctl-test-32.log
$(Q)./ioctl-test-64 > ioctl-test-64.log
-library-test: library-test.o $(libs_shared)
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o $@ library-test.o $(LDFLAGS) -Wl,-rpath=$(TOPDIR) -lbtrfs
- @echo " [TEST] $@"
- $(Q)./$@
-
-library-test.static: library-test.static.o $(libs_static)
- @echo " [LD] $@"
- $(Q)$(CC) $(STATIC_CFLAGS) -o $@ library-test.static.o $(STATIC_LDFLAGS) $(libs_static) $(STATIC_LIBS)
- @echo " [TEST] $@"
- $(Q)./$@
+library-test: library-test.c $(libs_shared)
+ @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d))
+ $(Q)mkdir -p $(TMPD)/include/btrfs && \
+ cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
+ cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(TOPDIR)/,$^) -Wl,-rpath=$(TOPDIR) -lbtrfs
+ @echo " [TEST RUN] $@"
+ $(Q)cd $(TMPD) && ./$@
+ @echo " [TEST CLEAN] $@"
+ $(Q)$(RM) -rf -- $(TMPD)
+
+library-test.static: library-test.c $(libs_static)
+ @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d))
+ $(Q)mkdir -p $(TMPD)/include/btrfs && \
+ cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
+ cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(TOPDIR)/,$^) $(STATIC_LDFLAGS) $(STATIC_LIBS)
+ @echo " [TEST RUN] $@"
+ $(Q)cd $(TMPD) && ./$@
+ @echo " [TEST CLEAN] $@"
+ $(Q)$(RM) -rf -- $(TMPD)
+
+fssum: tests/fssum.c tests/sha224-256.c
+ @echo " [LD] $@"
+ $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
test-build: test-build-pre test-build-real
test-build-pre:
- $(MAKE) clean-all
+ $(MAKE) $(MAKEOPTS) clean-all
./autogen.sh
./configure
test-build-real:
- $(MAKE) library-test
- -$(MAKE) library-test.static
- $(MAKE) -j 8 all
- -$(MAKE) -j 8 static
- $(MAKE) -j 8 $(progs_extra)
+ $(MAKE) $(MAKEOPTS) library-test
+ -$(MAKE) $(MAKEOPTS) library-test.static
+ $(MAKE) $(MAKEOPTS) -j 8 all
+ -$(MAKE) $(MAKEOPTS) -j 8 static
+ $(MAKE) $(MAKEOPTS) -j 8 $(progs_extra)
manpages:
$(Q)$(MAKE) $(MAKEOPTS) -C Documentation
@echo " [TAGS] $(TAGS_CMD)"
$(Q)$(TAGS_CMD) *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch]
+cscope: FORCE
+ @echo " [CSCOPE] $(CSCOPE_CMD)"
+ $(Q)ls -1 *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] > cscope.files
+ $(Q)$(CSCOPE_CMD)
+
clean-all: clean clean-doc clean-gen
clean: $(CLEANDIRS)
@echo "Cleaning"
- $(Q)$(RM) -f -- $(progs) cscope.out *.o *.o.d \
+ $(Q)$(RM) -f -- $(progs) *.o *.o.d \
kernel-lib/*.o kernel-lib/*.o.d \
+ kernel-shared/*.o kernel-shared/*.o.d \
image/*.o image/*.o.d \
convert/*.o convert/*.o.d \
mkfs/*.o mkfs/*.o.d \
dir-test ioctl-test quick-test library-test library-test-static \
- btrfs.static mkfs.btrfs.static \
+ mktables btrfs.static mkfs.btrfs.static fssum \
$(check_defs) \
$(libs) $(lib_links) \
$(progs_static) $(progs_extra)
$(Q)$(RM) -rf -- version.h config.status config.cache connfig.log \
configure.lineno config.status.lineno Makefile.inc \
Documentation/Makefile tags \
+ cscope.files cscope.out cscope.in.out cscope.po.out \
config.log config.h config.h.in~ aclocal.m4 \
configure autom4te.cache/ config/