btrfs-progs: check: enhance return values of walk_down_tree_v2
[platform/upstream/btrfs-progs.git] / Makefile
1 #
2 # Basic build targets:
3 #   all         all main tools and the shared library
4 #   static      build static bnaries, requires static version of the libraries
5 #   test        run the full testsuite
6 #   install     install to default location (/usr/local)
7 #   clean       clean built binaries (not the documentation)
8 #   clean-all   clean as above, clean docs and generated files
9 #
10 # Tuning by variables (environment or make arguments):
11 #   V=1            verbose, print command lines (default: quiet)
12 #   C=1            run checker before compilation (default checker: sparse)
13 #   D=1            debugging build, turn off optimizations
14 #   D=dflags       dtto, turn on additional debugging features:
15 #                  verbose - print file:line along with error/warning messages
16 #                  trace   - print trace before the error/warning messages
17 #                  abort   - call abort() on first error (dumps core)
18 #                  all     - shortcut for all of the above
19 #                  asan    - enable address sanitizer compiler feature
20 #                  ubsan   - undefined behaviour sanitizer compiler feature
21 #                  bcheck  - extended build checks
22 #   W=123          build with warnings (default: off)
23 #   DEBUG_CFLAGS   additional compiler flags for debugging build
24 #   EXTRA_CFLAGS   additional compiler flags
25 #   EXTRA_LDFLAGS  additional linker flags
26 #
27 # Testing-specific options (see also tests/README.md):
28 #   TEST=GLOB      run test(s) from directories matching GLOB
29 #   TEST_LOG=tty   print name of a command run via the execution helpers
30 #   TEST_LOG=dump  dump testing log file when a test fails
31 #
32 # Static checkers:
33 #   CHECKER        static checker binary to be called (default: sparse)
34 #   CHECKER_FLAGS  flags to pass to CHECKER, can override CFLAGS
35 #
36
37 # Export all variables to sub-makes by default
38 export
39
40 -include Makefile.inc
41 ifneq ($(MAKEFILE_INC_INCLUDED),yes)
42 $(error Makefile.inc not generated, please configure first)
43 endif
44
45 TAGS_CMD := ctags
46 CSCOPE_CMD := cscope -u -b -c -q
47
48 include Makefile.extrawarn
49
50 EXTRA_CFLAGS :=
51 EXTRA_LDFLAGS :=
52
53 DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
54 DEBUG_CFLAGS_INTERNAL =
55 DEBUG_CFLAGS :=
56
57 TOPDIR := $(shell pwd)
58
59 # Common build flags
60 CFLAGS = $(SUBST_CFLAGS) \
61          -include config.h \
62          -DBTRFS_FLAT_INCLUDES \
63          -D_XOPEN_SOURCE=700  \
64          -fno-strict-aliasing \
65          -fPIC \
66          -I$(TOPDIR) \
67          -I$(TOPDIR)/kernel-lib \
68          $(EXTRAWARN_CFLAGS) \
69          $(DEBUG_CFLAGS_INTERNAL) \
70          $(EXTRA_CFLAGS)
71
72 LDFLAGS = $(SUBST_LDFLAGS) \
73           -rdynamic -L$(TOPDIR) $(EXTRA_LDFLAGS)
74
75 LIBS = $(LIBS_BASE)
76 LIBBTRFS_LIBS = $(LIBS_BASE)
77
78 # Static compilation flags
79 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
80 STATIC_LDFLAGS = -static -Wl,--gc-sections
81 STATIC_LIBS = $(STATIC_LIBS_BASE)
82
83 # don't use FORTIFY with sparse because glibc with FORTIFY can
84 # generate so many sparse errors that sparse stops parsing,
85 # which masks real errors that we want to see.
86 CHECKER := sparse
87 check_defs := .cc-defines.h
88 CHECKER_FLAGS := -include $(check_defs) -D__CHECKER__ \
89         -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef \
90         -U_FORTIFY_SOURCE
91
92 objects = ctree.o disk-io.o kernel-lib/radix-tree.o extent-tree.o print-tree.o \
93           root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
94           extent-cache.o extent_io.o volumes.o utils.o repair.o \
95           qgroup.o raid56.o free-space-cache.o kernel-lib/list_sort.o props.o \
96           kernel-shared/ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
97           inode.o file.o find-root.o free-space-tree.o help.o send-dump.o \
98           fsfeatures.o messages.o
99 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
100                cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
101                cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
102                cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
103                cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
104                cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \
105                mkfs/common.o
106 libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
107                    kernel-lib/crc32c.o \
108                    uuid-tree.o utils-lib.o rbtree-utils.o
109 libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
110                kernel-lib/crc32c.h kernel-lib/list.h kerncompat.h \
111                kernel-lib/radix-tree.h extent-cache.h \
112                extent_io.h ioctl.h ctree.h btrfsck.h version.h
113 convert_objects = convert/main.o convert/common.o convert/source-fs.o \
114                   convert/source-ext2.o
115 mkfs_objects = mkfs/main.o mkfs/common.o
116
117 TESTS = fsck-tests.sh convert-tests.sh
118
119 udev_rules = 64-btrfs-dm.rules
120
121 ifeq ("$(origin V)", "command line")
122   BUILD_VERBOSE = $(V)
123 endif
124 ifndef BUILD_VERBOSE
125   BUILD_VERBOSE = 0
126 endif
127
128 ifeq ($(BUILD_VERBOSE),1)
129   Q =
130 else
131   Q = @
132 endif
133
134 ifeq ("$(origin D)", "command line")
135   DEBUG_CFLAGS_INTERNAL = $(DEBUG_CFLAGS_DEFAULT) $(DEBUG_CFLAGS)
136 endif
137
138 ifneq (,$(findstring verbose,$(D)))
139   DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
140 endif
141
142 ifneq (,$(findstring trace,$(D)))
143   DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
144 endif
145
146 ifneq (,$(findstring abort,$(D)))
147   DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
148 endif
149
150 ifneq (,$(findstring all,$(D)))
151   DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
152   DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
153   DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
154 endif
155
156 ifneq (,$(findstring asan,$(D)))
157   DEBUG_CFLAGS_INTERNAL += -fsanitize=address
158 endif
159
160 ifneq (,$(findstring ubsan,$(D)))
161   DEBUG_CFLAGS_INTERNAL += -fsanitize=undefined
162 endif
163
164 ifneq (,$(findstring bcheck,$(D)))
165   DEBUG_CFLAGS_INTERNAL += -DDEBUG_BUILD_CHECKS
166 endif
167
168 MAKEOPTS = --no-print-directory Q=$(Q)
169
170 # build all by default
171 progs = $(progs_install) btrfsck btrfs-corrupt-block
172
173 # install only selected
174 progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
175         btrfs-map-logical btrfs-image btrfs-zero-log \
176         btrfs-find-root btrfstune \
177         btrfs-select-super
178
179 # other tools, not built by default
180 progs_extra = btrfs-fragments btrfs-calc-size btrfs-show-super
181
182 progs_static = $(foreach p,$(progs),$(p).static)
183
184 ifneq ($(DISABLE_BTRFSCONVERT),1)
185 progs_install += btrfs-convert
186 endif
187
188 # external libs required by various binaries; for btrfs-foo,
189 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
190 btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2)
191 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
192 btrfs_debug_tree_objects = cmds-inspect-dump-tree.o
193 btrfs_show_super_objects = cmds-inspect-dump-super.o
194 btrfs_calc_size_objects = cmds-inspect-tree-stats.o
195
196 # collect values of the variables above
197 standalone_deps = $(foreach dep,$(patsubst %,%_objects,$(subst -,_,$(filter btrfs-%, $(progs)))),$($(dep)))
198
199 SUBDIRS =
200 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
201 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
202 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
203
204 ifneq ($(DISABLE_DOCUMENTATION),1)
205 BUILDDIRS += build-Documentation
206 INSTALLDIRS += install-Documentation
207 endif
208
209 .PHONY: $(SUBDIRS)
210 .PHONY: $(BUILDDIRS)
211 .PHONY: $(INSTALLDIRS)
212 .PHONY: $(TESTDIRS)
213 .PHONY: $(CLEANDIRS)
214 .PHONY: all install clean
215 .PHONY: FORCE
216
217 # Create all the static targets
218 static_objects = $(patsubst %.o, %.static.o, $(objects))
219 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
220 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
221 static_convert_objects = $(patsubst %.o, %.static.o, $(convert_objects))
222 static_mkfs_objects = $(patsubst %.o, %.static.o, $(mkfs_objects))
223
224 libs_shared = libbtrfs.so.0.1
225 libs_static = libbtrfs.a
226 libs = $(libs_shared) $(libs_static)
227 lib_links = libbtrfs.so.0 libbtrfs.so
228 headers = $(libbtrfs_headers)
229
230 # make C=1 to enable sparse
231 ifdef C
232         # We're trying to use sparse against glibc headers which go wild
233         # trying to use internal compiler macros to test features.  We
234         # copy gcc's and give them to sparse.  But not __SIZE_TYPE__
235         # 'cause sparse defines that one.
236         #
237         dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
238                         grep -v __SIZE_TYPE__ > $(check_defs))
239         check = $(CHECKER)
240         check_echo = echo
241 else
242         check = true
243         check_echo = true
244 endif
245
246 %.o.d: %.c
247         $(Q)$(CC) -MD -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
248
249 #
250 # Pick from per-file variables, btrfs_*_cflags
251 #
252 .c.o:
253         @$(check_echo) "    [SP]     $<"
254         $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
255         @echo "    [CC]     $@"
256         $(Q)$(CC) $(CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.o=%)-cflags)) \
257                 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
258
259 %.static.o: %.c
260         @echo "    [CC]     $@"
261         $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.static.o=%)-cflags)) \
262                 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
263
264 all: $(progs) libbtrfs $(BUILDDIRS)
265 $(SUBDIRS): $(BUILDDIRS)
266 $(BUILDDIRS):
267         @echo "Making all in $(patsubst build-%,%,$@)"
268         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
269
270 test-convert: btrfs btrfs-convert
271         @echo "    [TEST]   convert-tests.sh"
272         $(Q)bash tests/convert-tests.sh
273
274 test-check: test-fsck
275 test-fsck: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs
276         @echo "    [TEST]   fsck-tests.sh"
277         $(Q)bash tests/fsck-tests.sh
278
279 test-misc: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune
280         @echo "    [TEST]   misc-tests.sh"
281         $(Q)bash tests/misc-tests.sh
282
283 test-mkfs: btrfs mkfs.btrfs
284         @echo "    [TEST]   mkfs-tests.sh"
285         $(Q)bash tests/mkfs-tests.sh
286
287 test-fuzz: btrfs
288         @echo "    [TEST]   fuzz-tests.sh"
289         $(Q)bash tests/fuzz-tests.sh
290
291 test-cli: btrfs
292         @echo "    [TEST]   cli-tests.sh"
293         $(Q)bash tests/cli-tests.sh
294
295 test-clean:
296         @echo "Cleaning tests"
297         $(Q)bash tests/clean-tests.sh
298
299 test-inst: all
300         @tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
301                 echo "Test installation to $$tmpdest" && \
302                 $(MAKE) $(MAKEOPTS) DESTDIR=$$tmpdest install && \
303                 $(RM) -rf -- $$tmpdest
304
305 test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli
306
307 #
308 # NOTE: For static compiles, you need to have all the required libs
309 #       static equivalent available
310 #
311 static: $(progs_static)
312
313 version.h: version.sh version.h.in configure.ac
314         @echo "    [SH]     $@"
315         $(Q)bash ./config.status --silent $@
316
317 libbtrfs: $(libs_shared) $(lib_links)
318
319 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
320         @echo "    [LD]     $@"
321         $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
322                 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
323
324 $(libs_static): $(libbtrfs_objects)
325         @echo "    [AR]     $@"
326         $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
327
328 $(lib_links):
329         @echo "    [LN]     $@"
330         $(Q)$(LN_S) -f libbtrfs.so.0.1 $@
331
332 # keep intermediate files from the below implicit rules around
333 .PRECIOUS: $(addsuffix .o,$(progs))
334
335 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
336 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
337 # turns them into a list of libraries to link against if they exist
338 #
339 # For static variants, use an extra $(subst) to get rid of the ".static"
340 # from the target name before translating to list of libs
341
342 btrfs-%.static: btrfs-%.static.o $(static_objects) $(patsubst %.o,%.static.o,$(standalone_deps)) $(static_libbtrfs_objects)
343         @echo "    [LD]     $@"
344         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
345                 $(patsubst %.o, %.static.o, $($(subst -,_,$(subst .static,,$@)-objects))) \
346                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
347                 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
348
349 btrfs-%: btrfs-%.o $(objects) $(standalone_deps) $(libs_static)
350         @echo "    [LD]     $@"
351         $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o \
352                 $($(subst -,_,$@-objects)) \
353                 $(libs_static) \
354                 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
355
356 btrfs: btrfs.o $(objects) $(cmds_objects) $(libs_static)
357         @echo "    [LD]     $@"
358         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
359
360 btrfs.static: btrfs.static.o $(static_objects) $(static_cmds_objects) $(static_libbtrfs_objects)
361         @echo "    [LD]     $@"
362         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
363
364 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
365 btrfsck: btrfs
366         @echo "    [LN]     $@"
367         $(Q)$(LN_S) -f btrfs btrfsck
368
369 btrfsck.static: btrfs.static
370         @echo "    [LN]     $@"
371         $(Q)$(LN_S) -f $^ $@
372
373 mkfs.btrfs: $(mkfs_objects) $(objects) $(libs_static)
374         @echo "    [LD]     $@"
375         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
376
377 mkfs.btrfs.static: $(static_mkfs_objects) $(static_objects) $(static_libbtrfs_objects)
378         @echo "    [LD]     $@"
379         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
380
381 btrfstune: btrfstune.o $(objects) $(libs_static)
382         @echo "    [LD]     $@"
383         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
384
385 btrfstune.static: btrfstune.static.o $(static_objects) $(static_libbtrfs_objects)
386         @echo "    [LD]     $@"
387         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
388
389 btrfs-image: image/main.o $(objects) $(libs_static)
390         @echo "    [LD]     $@"
391         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
392
393 btrfs-image.static: image/main.static.o $(static_objects) $(static_libbtrfs_objects)
394         @echo "    [LD]     $@"
395         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
396
397 btrfs-convert: $(convert_objects) $(objects) $(libs_static)
398         @echo "    [LD]     $@"
399         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(btrfs_convert_libs) $(LIBS)
400
401 btrfs-convert.static: $(static_convert_objects) $(static_objects) $(static_libbtrfs_objects)
402         @echo "    [LD]     $@"
403         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(btrfs_convert_libs) $(STATIC_LIBS)
404
405 dir-test: dir-test.o $(objects) $(libs)
406         @echo "    [LD]     $@"
407         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
408
409 quick-test: quick-test.o $(objects) $(libs)
410         @echo "    [LD]     $@"
411         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
412
413 ioctl-test.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
414         @echo "    [CC]   $@"
415         $(Q)$(CC) $(CFLAGS) -c $< -o $@
416
417 ioctl-test-32.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
418         @echo "    [CC32]   $@"
419         $(Q)$(CC) $(CFLAGS) -m32 -c $< -o $@
420
421 ioctl-test-64.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
422         @echo "    [CC64]   $@"
423         $(Q)$(CC) $(CFLAGS) -m64 -c $< -o $@
424
425 ioctl-test: ioctl-test.o
426         @echo "    [LD]   $@"
427         $(Q)$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
428         @echo "   ?[PAHOLE] $@.pahole"
429         -$(Q)pahole $@ > $@.pahole
430
431 ioctl-test-32: ioctl-test-32.o
432         @echo "    [LD32]   $@"
433         $(Q)$(CC) $(CFLAGS) -m32 -o $@ $< $(LDFLAGS)
434         @echo "   ?[PAHOLE] $@.pahole"
435         -$(Q)pahole $@ > $@.pahole
436
437 ioctl-test-64: ioctl-test-64.o
438         @echo "    [LD64]   $@"
439         $(Q)$(CC) $(CFLAGS) -m64 -o $@ $< $(LDFLAGS)
440         @echo "   ?[PAHOLE] $@.pahole"
441         -$(Q)pahole $@ > $@.pahole
442
443 test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64
444         @echo "    [TEST/ioctl]"
445         $(Q)./ioctl-test > ioctl-test.log
446         $(Q)./ioctl-test-32 > ioctl-test-32.log
447         $(Q)./ioctl-test-64 > ioctl-test-64.log
448
449 library-test: library-test.o messages.o $(libs_shared)
450         @echo "    [LD]     $@"
451         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -Wl,-rpath=$(TOPDIR) -lbtrfs
452         @echo "    [TEST]   $@"
453         $(Q)./$@
454
455 library-test.static: library-test.static.o messages.static.o $(libs_static)
456         @echo "    [LD]     $@"
457         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(libs_static) $(STATIC_LIBS)
458         @echo "    [TEST]   $@"
459         $(Q)./$@
460
461 test-build: test-build-pre test-build-real
462
463 test-build-pre:
464         $(MAKE) $(MAKEOPTS) clean-all
465         ./autogen.sh
466         ./configure
467
468 test-build-real:
469         $(MAKE) $(MAKEOPTS) library-test
470         -$(MAKE) $(MAKEOPTS) library-test.static
471         $(MAKE) $(MAKEOPTS) -j 8 all
472         -$(MAKE) $(MAKEOPTS) -j 8 static
473         $(MAKE) $(MAKEOPTS) -j 8 $(progs_extra)
474
475 manpages:
476         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
477
478 tags: FORCE
479         @echo "    [TAGS]   $(TAGS_CMD)"
480         $(Q)$(TAGS_CMD) *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch]
481
482 cscope: FORCE
483         @echo "    [CSCOPE] $(CSCOPE_CMD)"
484         $(Q)ls -1 *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] > cscope.files
485         $(Q)$(CSCOPE_CMD)
486
487 clean-all: clean clean-doc clean-gen
488
489 clean: $(CLEANDIRS)
490         @echo "Cleaning"
491         $(Q)$(RM) -f -- $(progs) *.o *.o.d \
492                 kernel-lib/*.o kernel-lib/*.o.d \
493                 image/*.o image/*.o.d \
494                 convert/*.o convert/*.o.d \
495                 mkfs/*.o mkfs/*.o.d \
496               dir-test ioctl-test quick-test library-test library-test-static \
497               btrfs.static mkfs.btrfs.static \
498               $(check_defs) \
499               $(libs) $(lib_links) \
500               $(progs_static) $(progs_extra)
501
502 clean-doc:
503         @echo "Cleaning Documentation"
504         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
505
506 clean-gen:
507         @echo "Cleaning Generated Files"
508         $(Q)$(RM) -rf -- version.h config.status config.cache connfig.log \
509                 configure.lineno config.status.lineno Makefile.inc \
510                 Documentation/Makefile tags \
511                 cscope.files cscope.out cscope.in.out cscope.po.out \
512                 config.log config.h config.h.in~ aclocal.m4 \
513                 configure autom4te.cache/ config/
514
515 $(CLEANDIRS):
516         @echo "Cleaning $(patsubst clean-%,%,$@)"
517         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
518
519 install: $(libs) $(progs_install) $(INSTALLDIRS)
520         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
521         $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
522         $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
523         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
524         $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
525         $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
526         $(INSTALL) $(libs) $(DESTDIR)$(libdir)
527         cp -a $(lib_links) $(DESTDIR)$(libdir)
528         $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
529         $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
530 ifneq ($(udevdir),)
531         $(INSTALL) -m755 -d $(DESTDIR)$(udevruledir)
532         $(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
533 endif
534
535 install-static: $(progs_static) $(INSTALLDIRS)
536         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
537         $(INSTALL) $(progs_static) $(DESTDIR)$(bindir)
538         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
539         $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
540
541 $(INSTALLDIRS):
542         @echo "Making install in $(patsubst install-%,%,$@)"
543         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
544
545 uninstall:
546         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
547         cd $(DESTDIR)$(incdir); $(RM) -f -- $(headers)
548         $(RMDIR) -p --ignore-fail-on-non-empty -- $(DESTDIR)$(incdir)
549         cd $(DESTDIR)$(libdir); $(RM) -f -- $(lib_links) $(libs)
550         cd $(DESTDIR)$(bindir); $(RM) -f -- btrfsck fsck.btrfs $(progs_install)
551
552 ifneq ($(MAKECMDGOALS),clean)
553 -include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
554 endif