# test run the full testsuite
# install install to default location (/usr/local)
# clean clean built binaries (not the documentation)
+# clean-all clean as above, clean docs and generated files
#
# Tuning by variables (environment or make arguments):
# V=1 verbose, print command lines (default: quiet)
# C=1 run checker before compilation (default checker: sparse)
+# D=1 debugging build, turn off optimizations
+# D=dflags dtto, turn on additional debugging features:
+# verbose - print file:line along with error/warning messages
+# trace - print trace before the error/warning messages
+# abort - call abort() on first error (dumps core)
+# all - shortcut for all of the above
+# asan - enable address sanitizer compiler feature
+# ubsan - undefined behaviour sanitizer compiler feature
+# bcheck - extended build checks
# W=123 build with warnings (default: off)
+# DEBUG_CFLAGS additional compiler flags for debugging build
# EXTRA_CFLAGS additional compiler flags
# EXTRA_LDFLAGS additional linker flags
#
+# Testing-specific options (see also tests/README.md):
+# TEST=GLOB run test(s) from directories matching GLOB
+# TEST_LOG=tty print name of a command run via the execution helpers
+# TEST_LOG=dump dump testing log file when a test fails
+#
# Static checkers:
# CHECKER static checker binary to be called (default: sparse)
# CHECKER_FLAGS flags to pass to CHECKER, can override CFLAGS
INSTALL = @INSTALL@
DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
+BTRFSCONVERT_EXT2 = @BTRFSCONVERT_EXT2@
EXTRA_CFLAGS :=
EXTRA_LDFLAGS :=
+DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
+DEBUG_CFLAGS_INTERNAL =
+DEBUG_CFLAGS :=
+
+TOPDIR := $(shell pwd)
+
# Common build flags
CFLAGS = @CFLAGS@ \
-include config.h \
-DBTRFS_FLAT_INCLUDES \
-D_XOPEN_SOURCE=700 \
-fno-strict-aliasing \
- -fPIC $(EXTRAWARN_CFLAGS) $(EXTRA_CFLAGS)
+ -fPIC \
+ -I$(TOPDIR) \
+ -I$(TOPDIR)/kernel-lib \
+ $(EXTRAWARN_CFLAGS) \
+ $(DEBUG_CFLAGS_INTERNAL) \
+ $(EXTRA_CFLAGS)
LDFLAGS = @LDFLAGS@ \
- -rdynamic $(EXTRA_LDFLAGS)
+ -rdynamic -L$(TOPDIR) $(EXTRA_LDFLAGS)
LIBS = @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@ -L. -pthread
LIBBTRFS_LIBS = $(LIBS)
-D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef \
-U_FORTIFY_SOURCE
-objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
+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 raid6.o free-space-cache.o list_sort.o props.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 \
inode.o file.o find-root.o free-space-tree.o help.o
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.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
-libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
+libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
+ kernel-lib/crc32c.o \
uuid-tree.o utils-lib.o rbtree-utils.o
-libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
- crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
+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
TESTS = fsck-tests.sh convert-tests.sh
+udev_rules = 64-btrfs-dm.rules
+
prefix ?= @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir ?= @libdir@
incdir = @includedir@/btrfs
+udevdir = @UDEVDIR@
+udevruledir = ${udevdir}/rules.d
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
Q = @
endif
+ifeq ("$(origin D)", "command line")
+ DEBUG_CFLAGS_INTERNAL = $(DEBUG_CFLAGS_DEFAULT) $(DEBUG_CFLAGS)
+endif
+
+ifneq (,$(findstring verbose,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
+endif
+
+ifneq (,$(findstring trace,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
+endif
+
+ifneq (,$(findstring abort,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
+endif
+
+ifneq (,$(findstring all,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
+endif
+
+ifneq (,$(findstring asan,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -fsanitize=address
+endif
+
+ifneq (,$(findstring ubsan,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -fsanitize=undefined
+endif
+
+ifneq (,$(findstring bcheck,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_BUILD_CHECKS
+endif
+
MAKEOPTS = --no-print-directory Q=$(Q)
# build all by default
-progs = $(progs_install) btrfsck btrfs-corrupt-block btrfs-calc-size
+progs = $(progs_install) btrfsck btrfs-corrupt-block
# install only selected
progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
btrfs-map-logical btrfs-image btrfs-zero-log \
- btrfs-find-root btrfstune btrfs-show-super \
+ btrfs-find-root btrfstune \
btrfs-select-super
-progs_extra = btrfs-fragments
+# other tools, not built by default
+progs_extra = btrfs-fragments btrfs-calc-size btrfs-show-super
progs_static = $(foreach p,$(progs),$(p).static)
# external libs required by various binaries; for btrfs-foo,
# specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
btrfs_convert_libs = @EXT2FS_LIBS@ @COM_ERR_LIBS@
+btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2)
btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
btrfs_debug_tree_objects = cmds-inspect-dump-tree.o
btrfs_show_super_objects = cmds-inspect-dump-super.o
endif
%.o.d: %.c
- $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
+ $(Q)$(CC) -MD -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
+#
+# Pick from per-file variables, btrfs_*_cflags
+#
.c.o:
@$(check_echo) " [SP] $<"
$(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
@echo " [CC] $@"
- $(Q)$(CC) $(CFLAGS) -c $<
+ $(Q)$(CC) $(CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.o=%)-cflags))
%.static.o: %.c
@echo " [CC] $@"
- $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
+ $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.static.o=%)-cflags))
all: $(progs) $(BUILDDIRS)
$(SUBDIRS): $(BUILDDIRS)
@echo " [TEST] convert-tests.sh"
$(Q)bash tests/convert-tests.sh
+test-check: test-fsck
test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
@echo " [TEST] fsck-tests.sh"
$(Q)bash tests/fsck-tests.sh
@echo "Cleaning tests"
$(Q)bash tests/clean-tests.sh
-test: test-fsck test-mkfs test-convert test-misc test-fuzz
+test-inst: all
+ @tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
+ echo "Test installation to $$tmpdest" && \
+ $(MAKE) DESTDIR=$$tmpdest install && \
+ $(RM) -rf -- $$tmpdest
+
+test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli
#
# NOTE: For static compiles, you need to have all the required libs
$(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
$(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
+btrfs-image: $(objects) $(libs_static) image/main.o
+ @echo " [LD] $@"
+ $(Q)$(CC) $(CFLAGS) -I$(TOPDIR)/image -o btrfs-image $(objects) image/main.o $(libs_static) $(LDFLAGS) $(LIBS)
+
+btrfs-image.static: $(static_objects) image/main.static.o $(static_libbtrfs_objects)
+ @echo " [LD] $@"
+ $(Q)$(CC) $(STATIC_CFLAGS) -o $@ image/main.static.o $(static_objects) \
+ $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
+
dir-test: $(objects) $(libs) dir-test.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
-ioctl-test: $(objects) $(libs) ioctl-test.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
-
-send-test: $(objects) $(libs) send-test.o
- @echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
+ioctl-test.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
+ @echo " [CC] $@"
+ $(Q)$(CC) $(CFLAGS) -c $< -o $@
+
+ioctl-test-32.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
+ @echo " [CC32] $@"
+ $(Q)$(CC) $(CFLAGS) -m32 -c $< -o $@
+
+ioctl-test-64.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
+ @echo " [CC64] $@"
+ $(Q)$(CC) $(CFLAGS) -m64 -c $< -o $@
+
+ioctl-test: ioctl-test.o
+ @echo " [LD] $@"
+ $(Q)$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+ @echo " ?[PAHOLE] $@.pahole"
+ -$(Q)pahole $@ > $@.pahole
+
+ioctl-test-32: ioctl-test-32.o
+ @echo " [LD32] $@"
+ $(Q)$(CC) $(CFLAGS) -m32 -o $@ $< $(LDFLAGS)
+ @echo " ?[PAHOLE] $@.pahole"
+ -$(Q)pahole $@ > $@.pahole
+
+ioctl-test-64: ioctl-test-64.o
+ @echo " [LD64] $@"
+ $(Q)$(CC) $(CFLAGS) -m64 -o $@ $< $(LDFLAGS)
+ @echo " ?[PAHOLE] $@.pahole"
+ -$(Q)pahole $@ > $@.pahole
+
+test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64
+ @echo " [TEST/ioctl]"
+ $(Q)./ioctl-test > ioctl-test.log
+ $(Q)./ioctl-test-32 > ioctl-test-32.log
+ $(Q)./ioctl-test-64 > ioctl-test-64.log
library-test: $(libs_shared) library-test.o
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
+ $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -Wl,-rpath=$(TOPDIR) -lbtrfs
+ @echo " [TEST] $@"
+ $(Q)./$@
-library-test.static: $(libs_static) library-test.o
+library-test.static: $(libs_static) library-test.static.o
@echo " [LD] $@"
- $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
+ $(Q)$(CC) $(STATIC_CFLAGS) -o library-test.static library-test.static.o $(STATIC_LDFLAGS) $(libs_static) $(STATIC_LIBS)
+ @echo " [TEST] $@"
+ $(Q)./$@
test-build: test-build-pre test-build-real
clean: $(CLEANDIRS)
@echo "Cleaning"
- $(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
- dir-test ioctl-test quick-test send-test library-test library-test-static \
+ $(Q)$(RM) -f -- $(progs) cscope.out *.o *.o.d \
+ kernel-lib/*.o kernel-lib/*.o.d \
+ image/*.o image/*.o.d \
+ dir-test ioctl-test quick-test library-test library-test-static \
btrfs.static mkfs.btrfs.static \
$(check_defs) \
$(libs) $(lib_links) \
clean-gen:
@echo "Cleaning Generated Files"
- $(Q)$(RM) -rf version.h config.status config.cache connfig.log \
+ $(Q)$(RM) -rf -- version.h config.status config.cache connfig.log \
configure.lineno config.status.lineno Makefile \
Documentation/Makefile \
config.log config.h config.h.in~ aclocal.m4 \
cp -a $(lib_links) $(DESTDIR)$(libdir)
$(INSTALL) -m755 -d $(DESTDIR)$(incdir)
$(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
+ifneq ($(udevdir),)
+ $(INSTALL) -m755 -d $(DESTDIR)$(udevruledir)
+ $(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
+endif
install-static: $(progs_static) $(INSTALLDIRS)
$(INSTALL) -m755 -d $(DESTDIR)$(bindir)
uninstall:
$(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
- cd $(DESTDIR)$(incdir); $(RM) -f $(headers)
- $(RMDIR) -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
- cd $(DESTDIR)$(libdir); $(RM) -f $(lib_links) $(libs)
- cd $(DESTDIR)$(bindir); $(RM) -f btrfsck fsck.btrfs $(progs_install)
+ cd $(DESTDIR)$(incdir); $(RM) -f -- $(headers)
+ $(RMDIR) -p --ignore-fail-on-non-empty -- $(DESTDIR)$(incdir)
+ cd $(DESTDIR)$(libdir); $(RM) -f -- $(lib_links) $(libs)
+ cd $(DESTDIR)$(bindir); $(RM) -f -- btrfsck fsck.btrfs $(progs_install)
ifneq ($(MAKECMDGOALS),clean)
-include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))