+# Basic build targets:
+# 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)
+# 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
+# tsan - enable thread 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
+#
+
+# Export all variables to sub-makes by default
+export
+
+-include Makefile.inc
+ifneq ($(MAKEFILE_INC_INCLUDED),yes)
+$(error Makefile.inc not generated, please configure first)
+endif
+
+TAGS_CMD := ctags
+CSCOPE_CMD := cscope -u -b -c -q
+
+include Makefile.extrawarn
+
+EXTRA_CFLAGS :=
+EXTRA_LDFLAGS :=
+
+DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
+DEBUG_CFLAGS_INTERNAL =
+DEBUG_CFLAGS :=
+
+DEBUG_LDFLAGS_DEFAULT =
+DEBUG_LDFLAGS_INTERNAL =
+DEBUG_LDFLAGS :=
+
+ABSTOPDIR = $(shell pwd)
+TOPDIR := .
+
+# Common build flags
+CSTD = -std=gnu90
+CFLAGS = $(SUBST_CFLAGS) \
+ $(CSTD) \
+ -include config.h \
+ -DBTRFS_FLAT_INCLUDES \
+ -D_XOPEN_SOURCE=700 \
+ -fno-strict-aliasing \
+ -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) \
+ $(EXTRA_LDFLAGS)
+
+LIBS = $(LIBS_BASE)
+LIBBTRFS_LIBS = $(LIBS_BASE)
+
+# Static compilation flags
+STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
+STATIC_LDFLAGS = -static -Wl,--gc-sections
+STATIC_LIBS = $(STATIC_LIBS_BASE)
+
+# don't use FORTIFY with sparse because glibc with FORTIFY can
+# generate so many sparse errors that sparse stops parsing,
+# which masks real errors that we want to see.
+# Note: additional flags might get added per-target later
+CHECKER := sparse
+check_defs := .cc-defines.h
+CHECKER_FLAGS := -include $(check_defs) -D__CHECKER__ \
+ -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef \
+ -U_FORTIFY_SOURCE -Wdeclaration-after-statement -Wdefault-bitfield-sign
+
+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 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 kernel-lib/tables.o kernel-lib/raid56.o transaction.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 check/main.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 \
+ mkfs/common.o check/mode-common.o check/mode-lowmem.o
+libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.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 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 libbtrfsutil/filesystem.o \
+ libbtrfsutil/subvolume.o libbtrfsutil/qgroup.o \
+ libbtrfsutil/stubs.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) $(libbtrfsutil_objects)
+
+udev_rules = 64-btrfs-dm.rules
+
+ifeq ("$(origin V)", "command line")
+ BUILD_VERBOSE = $(V)
+endif
+ifndef BUILD_VERBOSE
+ BUILD_VERBOSE = 0
+endif
+
+ifeq ($(BUILD_VERBOSE),1)
+ Q =
+ SETUP_PY_Q =
+else
+ Q = @
+ SETUP_PY_Q = -q
+endif
+
+ifeq ("$(origin D)", "command line")
+ DEBUG_CFLAGS_INTERNAL = $(DEBUG_CFLAGS_DEFAULT) $(DEBUG_CFLAGS)
+ DEBUG_LDFLAGS_INTERNAL = $(DEBUG_LDFLAGS_DEFAULT) $(DEBUG_LDFLAGS)
+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
+ DEBUG_LDFLAGS_INTERNAL += -fsanitize=address -lasan
+endif
+
+ifneq (,$(findstring tsan,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -fsanitize=thread -fPIC
+ DEBUG_LDFLAGS_INTERNAL += -fsanitize=thread -ltsan -pie
+endif
+
+ifneq (,$(findstring ubsan,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -fsanitize=undefined
+ DEBUG_LDFLAGS_INTERNAL += -fsanitize=undefined -lubsan
+endif
+
+ifneq (,$(findstring bcheck,$(D)))
+ DEBUG_CFLAGS_INTERNAL += -DDEBUG_BUILD_CHECKS
+endif
+
+MAKEOPTS = --no-print-directory Q=$(Q)