+#
+# 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 \
+ $(EXTRAWARN_CFLAGS) \
+ $(DEBUG_CFLAGS_INTERNAL) \
+ $(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 \