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