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