btrfs-progs: convert: Fix a bug leads to discontinuous extents
[btrfs-progs-unstable/devel.git] / Makefile.in
blobac6b353be8ace02c1ef597230d973010c6d6596c
1 # btrfs-progs
3 # Basic build targets:
4 # all all main tools
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
20 # Static checkers:
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
26 export
28 include Makefile.extrawarn
30 CC = @CC@
31 LN_S = @LN_S@
32 AR = @AR@
33 RM = @RM@
34 RMDIR = @RMDIR@
35 INSTALL = @INSTALL@
36 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
37 DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
39 EXTRA_CFLAGS :=
40 EXTRA_LDFLAGS :=
42 DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
43 DEBUG_CFLAGS_INTERNAL =
44 DEBUG_CFLAGS :=
46 # Common build flags
47 CFLAGS = @CFLAGS@ \
48 -include config.h \
49 -DBTRFS_FLAT_INCLUDES \
50 -D_XOPEN_SOURCE=700 \
51 -fno-strict-aliasing \
52 -fPIC \
53 $(EXTRAWARN_CFLAGS) \
54 $(DEBUG_CFLAGS_INTERNAL) \
55 $(EXTRA_CFLAGS)
57 LDFLAGS = @LDFLAGS@ \
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.
72 CHECKER := sparse
73 check_defs := .cc-defines.h
74 CHECKER_FLAGS := -include $(check_defs) -D__CHECKER__ \
75 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef \
76 -U_FORTIFY_SOURCE
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
99 prefix ?= @prefix@
100 exec_prefix = @exec_prefix@
101 bindir = @bindir@
102 libdir ?= @libdir@
103 incdir = @includedir@/btrfs
104 udevdir = @UDEVDIR@
105 udevruledir = ${udevdir}/rules.d
107 ifeq ("$(origin V)", "command line")
108 BUILD_VERBOSE = $(V)
109 endif
110 ifndef BUILD_VERBOSE
111 BUILD_VERBOSE = 0
112 endif
114 ifeq ($(BUILD_VERBOSE),1)
116 else
117 Q = @
118 endif
120 ifeq ("$(origin D)", "command line")
121 DEBUG_CFLAGS_INTERNAL = $(DEBUG_CFLAGS_DEFAULT) $(DEBUG_CFLAGS)
122 endif
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 \
133 btrfs-select-super
135 progs_extra = btrfs-fragments
137 progs_static = $(foreach p,$(progs),$(p).static)
139 ifneq ($(DISABLE_BTRFSCONVERT),1)
140 progs_install += btrfs-convert
141 endif
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)))
154 SUBDIRS =
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
162 endif
164 .PHONY: $(SUBDIRS)
165 .PHONY: $(BUILDDIRS)
166 .PHONY: $(INSTALLDIRS)
167 .PHONY: $(TESTDIRS)
168 .PHONY: $(CLEANDIRS)
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
183 ifdef C
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))
191 check = $(CHECKER)
192 check_echo = echo
193 else
194 check = true
195 check_echo = true
196 endif
198 %.o.d: %.c
199 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
201 .c.o:
202 @$(check_echo) " [SP] $<"
203 $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
204 @echo " [CC] $@"
205 $(Q)$(CC) $(CFLAGS) -c $<
207 %.static.o: %.c
208 @echo " [CC] $@"
209 $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
211 all: $(progs) $(BUILDDIRS)
212 $(SUBDIRS): $(BUILDDIRS)
213 $(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
233 test-fuzz: btrfs
234 @echo " [TEST] fuzz-tests.sh"
235 $(Q)bash tests/fuzz-tests.sh
237 test-cli: btrfs
238 @echo " [TEST] cli-tests.sh"
239 $(Q)bash tests/cli-tests.sh
241 test-clean:
242 @echo "Cleaning tests"
243 $(Q)bash tests/clean-tests.sh
245 test-inst: all
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
260 @echo " [SH] $@"
261 $(Q)bash ./config.status --silent $@
263 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
264 @echo " [LD] $@"
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)
269 @echo " [AR] $@"
270 $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
272 $(lib_links):
273 @echo " [LN] $@"
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))
287 @echo " [LD] $@"
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)
294 @echo " [LD] $@"
295 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o \
296 $($(subst -,_,$@-objects)) \
297 $(libs_static) \
298 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
300 btrfs: $(objects) btrfs.o $(cmds_objects) $(libs_static)
301 @echo " [LD] $@"
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)
306 @echo " [LD] $@"
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'
311 btrfsck: btrfs
312 @echo " [LN] $@"
313 $(Q)$(LN_S) -f btrfs btrfsck
315 btrfsck.static: btrfs.static
316 @echo " [LN] $@"
317 $(Q)$(LN_S) -f $^ $@
319 mkfs.btrfs: $(objects) $(libs_static) mkfs.o
320 @echo " [LD] $@"
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)
324 @echo " [LD] $@"
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
329 @echo " [LD] $@"
330 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(libs_static) $(LDFLAGS) $(LIBS)
332 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
333 @echo " [LD] $@"
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
338 @echo " [LD] $@"
339 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
341 quick-test: $(objects) $(libs) quick-test.o
342 @echo " [LD] $@"
343 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
345 ioctl-test: $(objects) $(libs) ioctl-test.o
346 @echo " [LD] $@"
347 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
349 send-test: $(objects) $(libs) send-test.o
350 @echo " [LD] $@"
351 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
353 library-test: $(libs_shared) library-test.o
354 @echo " [LD] $@"
355 $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
357 library-test.static: $(libs_static) library-test.o
358 @echo " [LD] $@"
359 $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
361 test-build: test-build-pre test-build-real
363 test-build-pre:
364 $(MAKE) clean-all
365 ./autogen.sh
366 ./configure
368 test-build-real:
369 $(MAKE) library-test
370 -$(MAKE) library-test.static
371 $(MAKE) -j 8 all
372 -$(MAKE) -j 8 static
373 $(MAKE) -j 8 $(progs_extra)
375 manpages:
376 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
379 clean-all: clean clean-doc clean-gen
381 clean: $(CLEANDIRS)
382 @echo "Cleaning"
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 \
386 $(check_defs) \
387 $(libs) $(lib_links) \
388 $(progs_static) $(progs_extra)
390 clean-doc:
391 @echo "Cleaning Documentation"
392 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
394 clean-gen:
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/
402 $(CLEANDIRS):
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)
417 ifneq ($(udevdir),)
418 $(INSTALL) -m755 -d $(DESTDIR)$(udevruledir)
419 $(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
420 endif
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
428 $(INSTALLDIRS):
429 @echo "Making install in $(patsubst install-%,%,$@)"
430 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
432 uninstall:
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)))
441 endif