5 # static build static bnaries, requires static version of the libraries
6 # test run the full testsuite
7 # install install to default location (/usr/local)
8 # clean clean built binaries (not the documentation)
9 # clean-all clean as above, clean docs and generated files
11 # Tuning by variables (environment or make arguments):
12 # V=1 verbose, print command lines (default: quiet)
13 # C=1 run checker before compilation (default checker: sparse)
14 # D=1 debugging build, turn off optimizations
15 # W=123 build with warnings (default: off)
16 # DEBUG_CFLAGS additional compiler flags for debugging build
17 # EXTRA_CFLAGS additional compiler flags
18 # EXTRA_LDFLAGS additional linker flags
21 # CHECKER static checker binary to be called (default: sparse)
22 # CHECKER_FLAGS flags to pass to CHECKER, can override CFLAGS
25 # Export all variables to sub-makes by default
28 include Makefile.extrawarn
36 DISABLE_DOCUMENTATION
= @DISABLE_DOCUMENTATION@
37 DISABLE_BTRFSCONVERT
= @DISABLE_BTRFSCONVERT@
42 DEBUG_CFLAGS_DEFAULT
= -O0
-U_FORTIFY_SOURCE
-ggdb3
43 DEBUG_CFLAGS_INTERNAL
=
49 -DBTRFS_FLAT_INCLUDES \
51 -fno-strict-aliasing \
54 $(DEBUG_CFLAGS_INTERNAL
) \
58 -rdynamic
$(EXTRA_LDFLAGS
)
60 LIBS
= @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@
-L.
-pthread
61 LIBBTRFS_LIBS
= $(LIBS
)
63 # Static compilation flags
64 STATIC_CFLAGS
= $(CFLAGS
) -ffunction-sections
-fdata-sections
65 STATIC_LDFLAGS
= -static
-Wl
,--gc-sections
66 STATIC_LIBS
= @UUID_LIBS_STATIC@ @BLKID_LIBS_STATIC@ \
67 @ZLIB_LIBS_STATIC@ @LZO2_LIBS_STATIC@
-L.
-pthread
69 # don't use FORTIFY with sparse because glibc with FORTIFY can
70 # generate so many sparse errors that sparse stops parsing,
71 # which masks real errors that we want to see.
73 check_defs
:= .cc-defines.h
74 CHECKER_FLAGS
:= -include $(check_defs
) -D__CHECKER__ \
75 -D__CHECK_ENDIAN__
-Wbitwise
-Wuninitialized
-Wshadow
-Wundef \
78 objects
= ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
79 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
80 extent-cache.o extent_io.o volumes.o utils.o repair.o \
81 qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
82 ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
83 inode.o file.o find-root.o free-space-tree.o help.o
84 cmds_objects
= cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
85 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
86 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
87 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
88 cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
89 cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o
90 libbtrfs_objects
= send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
91 uuid-tree.o utils-lib.o rbtree-utils.o
92 libbtrfs_headers
= send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
93 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
94 extent_io.h ioctl.h ctree.h btrfsck.h version.h
95 TESTS
= fsck-tests.sh convert-tests.sh
97 udev_rules
= 64-btrfs-dm.rules
100 exec_prefix = @
exec_prefix@
103 incdir
= @
includedir@
/btrfs
105 udevruledir
= ${udevdir}/rules.d
107 ifeq ("$(origin V)", "command line")
114 ifeq ($(BUILD_VERBOSE
),1)
120 ifeq ("$(origin D)", "command line")
121 DEBUG_CFLAGS_INTERNAL
= $(DEBUG_CFLAGS_DEFAULT
) $(DEBUG_CFLAGS
)
124 MAKEOPTS
= --no-print-directory Q
=$(Q
)
126 # build all by default
127 progs
= $(progs_install
) btrfsck btrfs-corrupt-block btrfs-calc-size
129 # install only selected
130 progs_install
= btrfs mkfs.btrfs btrfs-debug-tree \
131 btrfs-map-logical btrfs-image btrfs-zero-log \
132 btrfs-find-root btrfstune btrfs-show-super \
135 progs_extra
= btrfs-fragments
137 progs_static
= $(foreach p
,$(progs
),$(p
).static
)
139 ifneq ($(DISABLE_BTRFSCONVERT
),1)
140 progs_install
+= btrfs-convert
143 # external libs required by various binaries; for btrfs-foo,
144 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
145 btrfs_convert_libs
= @EXT2FS_LIBS@ @COM_ERR_LIBS@
146 btrfs_fragments_libs
= -lgd
-lpng
-ljpeg
-lfreetype
147 btrfs_debug_tree_objects
= cmds-inspect-dump-tree.o
148 btrfs_show_super_objects
= cmds-inspect-dump-super.o
149 btrfs_calc_size_objects
= cmds-inspect-tree-stats.o
151 # collect values of the variables above
152 standalone_deps
= $(foreach dep
,$(patsubst %,%_objects
,$(subst -,_
,$(filter btrfs-
%, $(progs
)))),$($(dep
)))
155 BUILDDIRS
= $(patsubst %,build-
%,$(SUBDIRS
))
156 INSTALLDIRS
= $(patsubst %,install-
%,$(SUBDIRS
))
157 CLEANDIRS
= $(patsubst %,clean-
%,$(SUBDIRS
))
159 ifneq ($(DISABLE_DOCUMENTATION
),1)
160 BUILDDIRS
+= build-Documentation
161 INSTALLDIRS
+= install-Documentation
166 .PHONY
: $(INSTALLDIRS
)
169 .PHONY
: all install clean
171 # Create all the static targets
172 static_objects
= $(patsubst %.o
, %.static.o
, $(objects
))
173 static_cmds_objects
= $(patsubst %.o
, %.static.o
, $(cmds_objects
))
174 static_libbtrfs_objects
= $(patsubst %.o
, %.static.o
, $(libbtrfs_objects
))
176 libs_shared
= libbtrfs.so
.0.1
177 libs_static
= libbtrfs.a
178 libs
= $(libs_shared
) $(libs_static
)
179 lib_links
= libbtrfs.so
.0 libbtrfs.so
180 headers
= $(libbtrfs_headers
)
182 # make C=1 to enable sparse
184 # We're trying to use sparse against glibc headers which go wild
185 # trying to use internal compiler macros to test features. We
186 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
187 # 'cause sparse defines that one.
189 dummy
:= $(shell $(CC
) -dM
-E
-x c
- < /dev
/null | \
190 grep
-v __SIZE_TYPE__
> $(check_defs
))
199 $(Q
)$(CC
) -MM
-MG
-MF
$@
-MT
$(@
:.o.d
=.o
) -MT
$(@
:.o.d
=.static.o
) -MT
$@
$(CFLAGS
) $<
202 @
$(check_echo
) " [SP] $<"
203 $(Q
)$(check) $(CFLAGS
) $(CHECKER_FLAGS
) $<
205 $(Q
)$(CC
) $(CFLAGS
) -c
$<
209 $(Q
)$(CC
) $(STATIC_CFLAGS
) -c
$< -o
$@
211 all: $(progs
) $(BUILDDIRS
)
212 $(SUBDIRS
): $(BUILDDIRS
)
214 @echo
"Making all in $(patsubst build-%,%,$@)"
215 $(Q
)$(MAKE
) $(MAKEOPTS
) -C
$(patsubst build-
%,%,$@
)
217 test-convert
: btrfs btrfs-convert
218 @echo
" [TEST] convert-tests.sh"
219 $(Q
)bash tests
/convert-tests.sh
221 test-fsck
: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
222 @echo
" [TEST] fsck-tests.sh"
223 $(Q
)bash tests
/fsck-tests.sh
225 test-misc
: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
226 @echo
" [TEST] misc-tests.sh"
227 $(Q
)bash tests
/misc-tests.sh
229 test-mkfs
: btrfs mkfs.btrfs
230 @echo
" [TEST] mkfs-tests.sh"
231 $(Q
)bash tests
/mkfs-tests.sh
234 @echo
" [TEST] fuzz-tests.sh"
235 $(Q
)bash tests
/fuzz-tests.sh
238 @echo
" [TEST] cli-tests.sh"
239 $(Q
)bash tests
/cli-tests.sh
242 @echo
"Cleaning tests"
243 $(Q
)bash tests
/clean-tests.sh
246 @tmpdest
=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
247 echo
"Test installation to $$tmpdest" && \
248 $(MAKE
) DESTDIR
=$$tmpdest install && \
249 $(RM
) -rf
-- $$tmpdest
251 test: test-fsck test-mkfs test-convert test-misc test-fuzz
254 # NOTE: For static compiles, you need to have all the required libs
255 # static equivalent available
257 static
: $(progs_static
)
259 version.h
: version.sh version.h.in configure.ac
261 $(Q
)bash .
/config.status
--silent
$@
263 $(libs_shared
): $(libbtrfs_objects
) $(lib_links
) send.h
265 $(Q
)$(CC
) $(CFLAGS
) $(libbtrfs_objects
) $(LDFLAGS
) $(LIBBTRFS_LIBS
) \
266 -shared
-Wl
,-soname
,libbtrfs.so
.0 -o libbtrfs.so
.0.1
268 $(libs_static
): $(libbtrfs_objects
)
270 $(Q
)$(AR
) cr libbtrfs.a
$(libbtrfs_objects
)
274 $(Q
)$(LN_S
) -f libbtrfs.so
.0.1 $@
276 # keep intermediate files from the below implicit rules around
277 .PRECIOUS
: $(addsuffix .o
,$(progs
))
279 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
280 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
281 # turns them into a list of libraries to link against if they exist
283 # For static variants, use an extra $(subst) to get rid of the ".static"
284 # from the target name before translating to list of libs
286 btrfs-
%.static
: $(static_objects
) btrfs-
%.static.o
$(static_libbtrfs_objects
) $(patsubst %.o
,%.static.o
,$(standalone_deps
))
288 $(Q
)$(CC
) $(STATIC_CFLAGS
) -o
$@
$@.o
$(static_objects
) \
289 $(patsubst %.o
, %.static.o
, $($(subst -,_
,$(subst .static
,,$@
)-objects
))) \
290 $(static_libbtrfs_objects
) $(STATIC_LDFLAGS
) \
291 $($(subst -,_
,$(subst .static
,,$@
)-libs
)) $(STATIC_LIBS
)
293 btrfs-
%: $(objects
) $(libs_static
) btrfs-
%.o
$(standalone_deps
)
295 $(Q
)$(CC
) $(CFLAGS
) -o
$@
$(objects
) $@.o \
296 $($(subst -,_
,$@
-objects
)) \
298 $(LDFLAGS
) $(LIBS
) $($(subst -,_
,$@
-libs
))
300 btrfs
: $(objects
) btrfs.o
$(cmds_objects
) $(libs_static
)
302 $(Q
)$(CC
) $(CFLAGS
) -o btrfs btrfs.o
$(cmds_objects
) \
303 $(objects
) $(libs_static
) $(LDFLAGS
) $(LIBS
)
305 btrfs.static
: $(static_objects
) btrfs.static.o
$(static_cmds_objects
) $(static_libbtrfs_objects
)
307 $(Q
)$(CC
) $(STATIC_CFLAGS
) -o btrfs.static btrfs.static.o
$(static_cmds_objects
) \
308 $(static_objects
) $(static_libbtrfs_objects
) $(STATIC_LDFLAGS
) $(STATIC_LIBS
)
310 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
313 $(Q
)$(LN_S
) -f btrfs btrfsck
315 btrfsck.static
: btrfs.static
319 mkfs.btrfs
: $(objects
) $(libs_static
) mkfs.o
321 $(Q
)$(CC
) $(CFLAGS
) -o mkfs.btrfs
$(objects
) $(libs_static
) mkfs.o
$(LDFLAGS
) $(LIBS
)
323 mkfs.btrfs.static
: $(static_objects
) mkfs.static.o
$(static_libbtrfs_objects
)
325 $(Q
)$(CC
) $(STATIC_CFLAGS
) -o mkfs.btrfs.static mkfs.static.o
$(static_objects
) \
326 $(static_libbtrfs_objects
) $(STATIC_LDFLAGS
) $(STATIC_LIBS
)
328 btrfstune
: $(objects
) $(libs_static
) btrfstune.o
330 $(Q
)$(CC
) $(CFLAGS
) -o btrfstune
$(objects
) btrfstune.o
$(libs_static
) $(LDFLAGS
) $(LIBS
)
332 btrfstune.static
: $(static_objects
) btrfstune.static.o
$(static_libbtrfs_objects
)
334 $(Q
)$(CC
) $(STATIC_CFLAGS
) -o
$@ btrfstune.static.o
$(static_objects
) \
335 $(static_libbtrfs_objects
) $(STATIC_LDFLAGS
) $(STATIC_LIBS
)
337 dir-test
: $(objects
) $(libs
) dir-test.o
339 $(Q
)$(CC
) $(CFLAGS
) -o dir-test
$(objects
) $(libs
) dir-test.o
$(LDFLAGS
) $(LIBS
)
341 quick-test
: $(objects
) $(libs
) quick-test.o
343 $(Q
)$(CC
) $(CFLAGS
) -o quick-test
$(objects
) $(libs
) quick-test.o
$(LDFLAGS
) $(LIBS
)
345 ioctl-test
: $(objects
) $(libs
) ioctl-test.o
347 $(Q
)$(CC
) $(CFLAGS
) -o ioctl-test
$(objects
) $(libs
) ioctl-test.o
$(LDFLAGS
) $(LIBS
)
349 send-test
: $(objects
) $(libs
) send-test.o
351 $(Q
)$(CC
) $(CFLAGS
) -o send-test
$(objects
) $(libs
) send-test.o
$(LDFLAGS
) $(LIBS
)
353 library-test
: $(libs_shared
) library-test.o
355 $(Q
)$(CC
) $(CFLAGS
) -o library-test library-test.o
$(LDFLAGS
) -lbtrfs
357 library-test.static
: $(libs_static
) library-test.o
359 $(Q
)$(CC
) $(CFLAGS
) -o library-test-static library-test.o
$(LDFLAGS
) $(libs_static
)
361 test-build
: test-build-pre test-build-real
370 -$(MAKE
) library-test.static
373 $(MAKE
) -j
8 $(progs_extra
)
376 $(Q
)$(MAKE
) $(MAKEOPTS
) -C Documentation
379 clean-all
: clean clean-doc clean-gen
383 $(Q
)$(RM
) -f
$(progs
) cscope.out
*.o
*.o.d \
384 dir-test ioctl-test quick-test send-test library-test library-test-static \
385 btrfs.static mkfs.btrfs.static \
387 $(libs
) $(lib_links
) \
388 $(progs_static
) $(progs_extra
)
391 @echo
"Cleaning Documentation"
392 $(Q
)$(MAKE
) $(MAKEOPTS
) -C Documentation
clean
395 @echo
"Cleaning Generated Files"
396 $(Q
)$(RM
) -rf version.h config.status config.cache connfig.log \
397 configure.lineno config.status.lineno Makefile \
398 Documentation
/Makefile \
399 config.log config.h config.h.in~ aclocal.m4 \
400 configure autom4te.cache
/ config
/
403 @echo
"Cleaning $(patsubst clean-%,%,$@)"
404 $(Q
)$(MAKE
) $(MAKEOPTS
) -C
$(patsubst clean-
%,%,$@
) clean
406 install: $(libs
) $(progs_install
) $(INSTALLDIRS
)
407 $(INSTALL
) -m755
-d
$(DESTDIR
)$(bindir)
408 $(INSTALL
) $(progs_install
) $(DESTDIR
)$(bindir)
409 $(INSTALL
) fsck.btrfs
$(DESTDIR
)$(bindir)
410 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
411 $(LN_S
) -f btrfs
$(DESTDIR
)$(bindir)/btrfsck
412 $(INSTALL
) -m755
-d
$(DESTDIR
)$(libdir)
413 $(INSTALL
) $(libs
) $(DESTDIR
)$(libdir)
414 cp
-a
$(lib_links
) $(DESTDIR
)$(libdir)
415 $(INSTALL
) -m755
-d
$(DESTDIR
)$(incdir
)
416 $(INSTALL
) -m644
$(headers
) $(DESTDIR
)$(incdir
)
418 $(INSTALL
) -m755
-d
$(DESTDIR
)$(udevruledir
)
419 $(INSTALL
) -m644
$(udev_rules
) $(DESTDIR
)$(udevruledir
)
422 install-static
: $(progs_static
) $(INSTALLDIRS
)
423 $(INSTALL
) -m755
-d
$(DESTDIR
)$(bindir)
424 $(INSTALL
) $(progs_static
) $(DESTDIR
)$(bindir)
425 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
426 $(LN_S
) -f btrfs.static
$(DESTDIR
)$(bindir)/btrfsck.static
429 @echo
"Making install in $(patsubst install-%,%,$@)"
430 $(Q
)$(MAKE
) $(MAKEOPTS
) -C
$(patsubst install-
%,%,$@
) install
433 $(Q
)$(MAKE
) $(MAKEOPTS
) -C Documentation
uninstall
434 cd
$(DESTDIR
)$(incdir
); $(RM
) -f
$(headers
)
435 $(RMDIR
) -p
--ignore-fail-on-non-empty
$(DESTDIR
)$(incdir
)
436 cd
$(DESTDIR
)$(libdir); $(RM
) -f
$(lib_links
) $(libs
)
437 cd
$(DESTDIR
)$(bindir); $(RM
) -f btrfsck fsck.btrfs
$(progs_install
)
439 ifneq ($(MAKECMDGOALS
),clean)
440 -include $(objects
:.o
=.o.d
) $(cmds_objects
:.o
=.o.d
) $(subst .btrfs
,, $(filter-out btrfsck.o.d
, $(progs
:=.o.d
)))