btrfs-progs: build: add rule for building cscope index
[platform/upstream/btrfs-progs.git] / Makefile
1 #
2 # Basic build targets:
3 #   all         all main tools
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           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
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 libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
106                    kernel-lib/crc32c.o \
107                    uuid-tree.o utils-lib.o rbtree-utils.o
108 libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
109                kernel-lib/crc32c.h kernel-lib/list.h kerncompat.h \
110                kernel-lib/radix-tree.h extent-cache.h \
111                extent_io.h ioctl.h ctree.h btrfsck.h version.h
112 convert_objects = convert/main.o convert/common.o convert/source-fs.o \
113                   convert/source-ext2.o
114 mkfs_objects = mkfs/main.o mkfs/common.o
115
116 TESTS = fsck-tests.sh convert-tests.sh
117
118 udev_rules = 64-btrfs-dm.rules
119
120 ifeq ("$(origin V)", "command line")
121   BUILD_VERBOSE = $(V)
122 endif
123 ifndef BUILD_VERBOSE
124   BUILD_VERBOSE = 0
125 endif
126
127 ifeq ($(BUILD_VERBOSE),1)
128   Q =
129 else
130   Q = @
131 endif
132
133 ifeq ("$(origin D)", "command line")
134   DEBUG_CFLAGS_INTERNAL = $(DEBUG_CFLAGS_DEFAULT) $(DEBUG_CFLAGS)
135 endif
136
137 ifneq (,$(findstring verbose,$(D)))
138   DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
139 endif
140
141 ifneq (,$(findstring trace,$(D)))
142   DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
143 endif
144
145 ifneq (,$(findstring abort,$(D)))
146   DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
147 endif
148
149 ifneq (,$(findstring all,$(D)))
150   DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
151   DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
152   DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
153 endif
154
155 ifneq (,$(findstring asan,$(D)))
156   DEBUG_CFLAGS_INTERNAL += -fsanitize=address
157 endif
158
159 ifneq (,$(findstring ubsan,$(D)))
160   DEBUG_CFLAGS_INTERNAL += -fsanitize=undefined
161 endif
162
163 ifneq (,$(findstring bcheck,$(D)))
164   DEBUG_CFLAGS_INTERNAL += -DDEBUG_BUILD_CHECKS
165 endif
166
167 MAKEOPTS = --no-print-directory Q=$(Q)
168
169 # build all by default
170 progs = $(progs_install) btrfsck btrfs-corrupt-block
171
172 # install only selected
173 progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
174         btrfs-map-logical btrfs-image btrfs-zero-log \
175         btrfs-find-root btrfstune \
176         btrfs-select-super
177
178 # other tools, not built by default
179 progs_extra = btrfs-fragments btrfs-calc-size btrfs-show-super
180
181 progs_static = $(foreach p,$(progs),$(p).static)
182
183 ifneq ($(DISABLE_BTRFSCONVERT),1)
184 progs_install += btrfs-convert
185 endif
186
187 # external libs required by various binaries; for btrfs-foo,
188 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
189 btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2)
190 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
191 btrfs_debug_tree_objects = cmds-inspect-dump-tree.o
192 btrfs_show_super_objects = cmds-inspect-dump-super.o
193 btrfs_calc_size_objects = cmds-inspect-tree-stats.o
194
195 # collect values of the variables above
196 standalone_deps = $(foreach dep,$(patsubst %,%_objects,$(subst -,_,$(filter btrfs-%, $(progs)))),$($(dep)))
197
198 SUBDIRS =
199 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
200 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
201 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
202
203 ifneq ($(DISABLE_DOCUMENTATION),1)
204 BUILDDIRS += build-Documentation
205 INSTALLDIRS += install-Documentation
206 endif
207
208 .PHONY: $(SUBDIRS)
209 .PHONY: $(BUILDDIRS)
210 .PHONY: $(INSTALLDIRS)
211 .PHONY: $(TESTDIRS)
212 .PHONY: $(CLEANDIRS)
213 .PHONY: all install clean
214 .PHONY: FORCE
215
216 # Create all the static targets
217 static_objects = $(patsubst %.o, %.static.o, $(objects))
218 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
219 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
220 static_convert_objects = $(patsubst %.o, %.static.o, $(convert_objects))
221 static_mkfs_objects = $(patsubst %.o, %.static.o, $(mkfs_objects))
222
223 libs_shared = libbtrfs.so.0.1
224 libs_static = libbtrfs.a
225 libs = $(libs_shared) $(libs_static)
226 lib_links = libbtrfs.so.0 libbtrfs.so
227 headers = $(libbtrfs_headers)
228
229 # make C=1 to enable sparse
230 ifdef C
231         # We're trying to use sparse against glibc headers which go wild
232         # trying to use internal compiler macros to test features.  We
233         # copy gcc's and give them to sparse.  But not __SIZE_TYPE__
234         # 'cause sparse defines that one.
235         #
236         dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
237                         grep -v __SIZE_TYPE__ > $(check_defs))
238         check = $(CHECKER)
239         check_echo = echo
240 else
241         check = true
242         check_echo = true
243 endif
244
245 %.o.d: %.c
246         $(Q)$(CC) -MD -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
247
248 #
249 # Pick from per-file variables, btrfs_*_cflags
250 #
251 .c.o:
252         @$(check_echo) "    [SP]     $<"
253         $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
254         @echo "    [CC]     $@"
255         $(Q)$(CC) $(CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.o=%)-cflags)) \
256                 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
257
258 %.static.o: %.c
259         @echo "    [CC]     $@"
260         $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.static.o=%)-cflags)) \
261                 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
262
263 all: $(progs) $(BUILDDIRS)
264 $(SUBDIRS): $(BUILDDIRS)
265 $(BUILDDIRS):
266         @echo "Making all in $(patsubst build-%,%,$@)"
267         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
268
269 test-convert: btrfs btrfs-convert
270         @echo "    [TEST]   convert-tests.sh"
271         $(Q)bash tests/convert-tests.sh
272
273 test-check: test-fsck
274 test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
275         @echo "    [TEST]   fsck-tests.sh"
276         $(Q)bash tests/fsck-tests.sh
277
278 test-misc: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
279         @echo "    [TEST]   misc-tests.sh"
280         $(Q)bash tests/misc-tests.sh
281
282 test-mkfs: btrfs mkfs.btrfs
283         @echo "    [TEST]   mkfs-tests.sh"
284         $(Q)bash tests/mkfs-tests.sh
285
286 test-fuzz: btrfs
287         @echo "    [TEST]   fuzz-tests.sh"
288         $(Q)bash tests/fuzz-tests.sh
289
290 test-cli: btrfs
291         @echo "    [TEST]   cli-tests.sh"
292         $(Q)bash tests/cli-tests.sh
293
294 test-clean:
295         @echo "Cleaning tests"
296         $(Q)bash tests/clean-tests.sh
297
298 test-inst: all
299         @tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
300                 echo "Test installation to $$tmpdest" && \
301                 $(MAKE) DESTDIR=$$tmpdest install && \
302                 $(RM) -rf -- $$tmpdest
303
304 test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli
305
306 #
307 # NOTE: For static compiles, you need to have all the required libs
308 #       static equivalent available
309 #
310 static: $(progs_static)
311
312 version.h: version.sh version.h.in configure.ac
313         @echo "    [SH]     $@"
314         $(Q)bash ./config.status --silent $@
315
316 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
317         @echo "    [LD]     $@"
318         $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
319                 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
320
321 $(libs_static): $(libbtrfs_objects)
322         @echo "    [AR]     $@"
323         $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
324
325 $(lib_links):
326         @echo "    [LN]     $@"
327         $(Q)$(LN_S) -f libbtrfs.so.0.1 $@
328
329 # keep intermediate files from the below implicit rules around
330 .PRECIOUS: $(addsuffix .o,$(progs))
331
332 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
333 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
334 # turns them into a list of libraries to link against if they exist
335 #
336 # For static variants, use an extra $(subst) to get rid of the ".static"
337 # from the target name before translating to list of libs
338
339 btrfs-%.static: btrfs-%.static.o $(static_objects) $(patsubst %.o,%.static.o,$(standalone_deps)) $(static_libbtrfs_objects)
340         @echo "    [LD]     $@"
341         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
342                 $(patsubst %.o, %.static.o, $($(subst -,_,$(subst .static,,$@)-objects))) \
343                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
344                 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
345
346 btrfs-%: btrfs-%.o $(objects) $(standalone_deps) $(libs_static)
347         @echo "    [LD]     $@"
348         $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o \
349                 $($(subst -,_,$@-objects)) \
350                 $(libs_static) \
351                 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
352
353 btrfs: btrfs.o $(objects) $(cmds_objects) $(libs_static)
354         @echo "    [LD]     $@"
355         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
356
357 btrfs.static: btrfs.static.o $(static_objects) $(static_cmds_objects) $(static_libbtrfs_objects)
358         @echo "    [LD]     $@"
359         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
360
361 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
362 btrfsck: btrfs
363         @echo "    [LN]     $@"
364         $(Q)$(LN_S) -f btrfs btrfsck
365
366 btrfsck.static: btrfs.static
367         @echo "    [LN]     $@"
368         $(Q)$(LN_S) -f $^ $@
369
370 mkfs.btrfs: $(mkfs_objects) $(objects) $(libs_static)
371         @echo "    [LD]     $@"
372         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
373
374 mkfs.btrfs.static: $(static_mkfs_objects) $(static_objects) $(static_libbtrfs_objects)
375         @echo "    [LD]     $@"
376         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
377
378 btrfstune: btrfstune.o $(objects) $(libs_static)
379         @echo "    [LD]     $@"
380         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
381
382 btrfstune.static: btrfstune.static.o $(static_objects) $(static_libbtrfs_objects)
383         @echo "    [LD]     $@"
384         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
385
386 btrfs-image: image/main.o $(objects) $(libs_static)
387         @echo "    [LD]     $@"
388         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
389
390 btrfs-image.static: image/main.static.o $(static_objects) $(static_libbtrfs_objects)
391         @echo "    [LD]     $@"
392         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
393
394 btrfs-convert: $(convert_objects) $(objects) $(libs_static)
395         @echo "    [LD]     $@"
396         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(btrfs_convert_libs) $(LIBS)
397
398 btrfs-convert.static: $(static_convert_objects) $(static_objects) $(static_libbtrfs_objects)
399         @echo "    [LD]     $@"
400         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(STATIC_LDFLAGS) $(btrfs_convert_libs) $(STATIC_LIBS)
401
402 dir-test: dir-test.o $(objects) $(libs)
403         @echo "    [LD]     $@"
404         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
405
406 quick-test: quick-test.o $(objects) $(libs)
407         @echo "    [LD]     $@"
408         $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
409
410 ioctl-test.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
411         @echo "    [CC]   $@"
412         $(Q)$(CC) $(CFLAGS) -c $< -o $@
413
414 ioctl-test-32.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
415         @echo "    [CC32]   $@"
416         $(Q)$(CC) $(CFLAGS) -m32 -c $< -o $@
417
418 ioctl-test-64.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
419         @echo "    [CC64]   $@"
420         $(Q)$(CC) $(CFLAGS) -m64 -c $< -o $@
421
422 ioctl-test: ioctl-test.o
423         @echo "    [LD]   $@"
424         $(Q)$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
425         @echo "   ?[PAHOLE] $@.pahole"
426         -$(Q)pahole $@ > $@.pahole
427
428 ioctl-test-32: ioctl-test-32.o
429         @echo "    [LD32]   $@"
430         $(Q)$(CC) $(CFLAGS) -m32 -o $@ $< $(LDFLAGS)
431         @echo "   ?[PAHOLE] $@.pahole"
432         -$(Q)pahole $@ > $@.pahole
433
434 ioctl-test-64: ioctl-test-64.o
435         @echo "    [LD64]   $@"
436         $(Q)$(CC) $(CFLAGS) -m64 -o $@ $< $(LDFLAGS)
437         @echo "   ?[PAHOLE] $@.pahole"
438         -$(Q)pahole $@ > $@.pahole
439
440 test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64
441         @echo "    [TEST/ioctl]"
442         $(Q)./ioctl-test > ioctl-test.log
443         $(Q)./ioctl-test-32 > ioctl-test-32.log
444         $(Q)./ioctl-test-64 > ioctl-test-64.log
445
446 library-test: library-test.o $(libs_shared)
447         @echo "    [LD]     $@"
448         $(Q)$(CC) $(CFLAGS) -o $@ library-test.o $(LDFLAGS) -Wl,-rpath=$(TOPDIR) -lbtrfs
449         @echo "    [TEST]   $@"
450         $(Q)./$@
451
452 library-test.static: library-test.static.o $(libs_static)
453         @echo "    [LD]     $@"
454         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ library-test.static.o $(STATIC_LDFLAGS) $(libs_static) $(STATIC_LIBS)
455         @echo "    [TEST]   $@"
456         $(Q)./$@
457
458 test-build: test-build-pre test-build-real
459
460 test-build-pre:
461         $(MAKE) clean-all
462         ./autogen.sh
463         ./configure
464
465 test-build-real:
466         $(MAKE) library-test
467         -$(MAKE) library-test.static
468         $(MAKE) -j 8 all
469         -$(MAKE) -j 8 static
470         $(MAKE) -j 8 $(progs_extra)
471
472 manpages:
473         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
474
475 tags: FORCE
476         @echo "    [TAGS]   $(TAGS_CMD)"
477         $(Q)$(TAGS_CMD) *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch]
478
479 cscope: FORCE
480         @echo "    [CSCOPE] $(CSCOPE_CMD)"
481         $(Q)ls -1 *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] > cscope.files
482         $(Q)$(CSCOPE_CMD)
483
484 clean-all: clean clean-doc clean-gen
485
486 clean: $(CLEANDIRS)
487         @echo "Cleaning"
488         $(Q)$(RM) -f -- $(progs) *.o *.o.d \
489                 kernel-lib/*.o kernel-lib/*.o.d \
490                 image/*.o image/*.o.d \
491                 convert/*.o convert/*.o.d \
492                 mkfs/*.o mkfs/*.o.d \
493               dir-test ioctl-test quick-test library-test library-test-static \
494               btrfs.static mkfs.btrfs.static \
495               $(check_defs) \
496               $(libs) $(lib_links) \
497               $(progs_static) $(progs_extra)
498
499 clean-doc:
500         @echo "Cleaning Documentation"
501         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
502
503 clean-gen:
504         @echo "Cleaning Generated Files"
505         $(Q)$(RM) -rf -- version.h config.status config.cache connfig.log \
506                 configure.lineno config.status.lineno Makefile.inc \
507                 Documentation/Makefile tags \
508                 cscope.files cscope.out cscope.in.out cscope.po.out \
509                 config.log config.h config.h.in~ aclocal.m4 \
510                 configure autom4te.cache/ config/
511
512 $(CLEANDIRS):
513         @echo "Cleaning $(patsubst clean-%,%,$@)"
514         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
515
516 install: $(libs) $(progs_install) $(INSTALLDIRS)
517         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
518         $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
519         $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
520         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
521         $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
522         $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
523         $(INSTALL) $(libs) $(DESTDIR)$(libdir)
524         cp -a $(lib_links) $(DESTDIR)$(libdir)
525         $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
526         $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
527 ifneq ($(udevdir),)
528         $(INSTALL) -m755 -d $(DESTDIR)$(udevruledir)
529         $(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
530 endif
531
532 install-static: $(progs_static) $(INSTALLDIRS)
533         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
534         $(INSTALL) $(progs_static) $(DESTDIR)$(bindir)
535         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
536         $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
537
538 $(INSTALLDIRS):
539         @echo "Making install in $(patsubst install-%,%,$@)"
540         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
541
542 uninstall:
543         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
544         cd $(DESTDIR)$(incdir); $(RM) -f -- $(headers)
545         $(RMDIR) -p --ignore-fail-on-non-empty -- $(DESTDIR)$(incdir)
546         cd $(DESTDIR)$(libdir); $(RM) -f -- $(lib_links) $(libs)
547         cd $(DESTDIR)$(bindir); $(RM) -f -- btrfsck fsck.btrfs $(progs_install)
548
549 ifneq ($(MAKECMDGOALS),clean)
550 -include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
551 endif