btrfs-progs: check: introduce function to check dir_item
[platform/upstream/btrfs-progs.git] / Makefile.in
index 1928a4e..5c4a995 100644 (file)
 #                  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
@@ -40,6 +48,7 @@ RMDIR = @RMDIR@
 INSTALL = @INSTALL@
 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
 DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
+BTRFSCONVERT_EXT2 = @BTRFSCONVERT_EXT2@
 
 EXTRA_CFLAGS :=
 EXTRA_LDFLAGS :=
@@ -48,6 +57,8 @@ DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
 DEBUG_CFLAGS_INTERNAL =
 DEBUG_CFLAGS :=
 
+TOPDIR := $(shell pwd)
+
 # Common build flags
 CFLAGS = @CFLAGS@ \
         -include config.h \
@@ -55,12 +66,14 @@ CFLAGS = @CFLAGS@ \
         -D_XOPEN_SOURCE=700  \
         -fno-strict-aliasing \
         -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)
@@ -80,10 +93,10 @@ CHECKER_FLAGS := -include $(check_defs) -D__CHECKER__ \
        -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 \
@@ -92,10 +105,12 @@ 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
 
@@ -144,18 +159,31 @@ ifneq (,$(findstring all,$(D)))
   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)
 
@@ -166,6 +194,7 @@ endif
 # 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
@@ -219,7 +248,7 @@ else
 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
@@ -228,7 +257,7 @@ endif
        @$(check_echo) "    [SP]     $<"
        $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
        @echo "    [CC]     $@"
-       $(Q)$(CC) $(CFLAGS) -c $< $($(subst -,_,$(@:%.o=%)-cflags))
+       $(Q)$(CC) $(CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.o=%)-cflags))
 
 %.static.o: %.c
        @echo "    [CC]     $@"
@@ -244,6 +273,7 @@ test-convert: btrfs btrfs-convert
        @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
@@ -274,7 +304,7 @@ test-inst: all
                $(MAKE) DESTDIR=$$tmpdest install && \
                $(RM) -rf -- $$tmpdest
 
-test: test-fsck test-mkfs test-convert test-misc test-fuzz
+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
@@ -360,6 +390,15 @@ btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects
        $(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)
@@ -368,21 +407,53 @@ quick-test: $(objects) $(libs) quick-test.o
        @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
 
@@ -406,8 +477,10 @@ clean-all: clean clean-doc clean-gen
 
 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) \
@@ -419,7 +492,7 @@ clean-doc:
 
 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 \
@@ -457,10 +530,10 @@ $(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)$(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)))