btrfs-progs: build: modify cscope/ctags rules to include directories such as check
[btrfs-progs-unstable/devel.git] / Makefile
blob8afc8f6ed6a33c11e2b895cf6f9f3a9dce9f1c39
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
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
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
33 # Static checkers:
34 # CHECKER static checker binary to be called (default: sparse)
35 # CHECKER_FLAGS flags to pass to CHECKER, can override CFLAGS
38 # Export all variables to sub-makes by default
39 export
41 -include Makefile.inc
42 ifneq ($(MAKEFILE_INC_INCLUDED),yes)
43 $(error Makefile.inc not generated, please configure first)
44 endif
46 TAGS_CMD := ctags
47 CSCOPE_CMD := cscope -u -b -c -q
49 include Makefile.extrawarn
51 EXTRA_CFLAGS :=
52 EXTRA_LDFLAGS :=
54 DEBUG_CFLAGS_DEFAULT = -O0 -U_FORTIFY_SOURCE -ggdb3
55 DEBUG_CFLAGS_INTERNAL =
56 DEBUG_CFLAGS :=
58 DEBUG_LDFLAGS_DEFAULT =
59 DEBUG_LDFLAGS_INTERNAL =
60 DEBUG_LDFLAGS :=
62 ABSTOPDIR = $(shell pwd)
63 TOPDIR := .
65 # Common build flags
66 CSTD = -std=gnu90
67 CFLAGS = $(SUBST_CFLAGS) \
68 $(CSTD) \
69 -include config.h \
70 -DBTRFS_FLAT_INCLUDES \
71 -D_XOPEN_SOURCE=700 \
72 -fno-strict-aliasing \
73 -fPIC \
74 -I$(TOPDIR) \
75 -I$(TOPDIR)/kernel-lib \
76 -I$(TOPDIR)/libbtrfsutil \
77 $(EXTRAWARN_CFLAGS) \
78 $(DEBUG_CFLAGS_INTERNAL) \
79 $(EXTRA_CFLAGS)
81 LIBBTRFSUTIL_CFLAGS = $(SUBST_CFLAGS) \
82 $(CSTD) \
83 -D_GNU_SOURCE \
84 -fPIC \
85 -fvisibility=hidden \
86 -I$(TOPDIR)/libbtrfsutil \
87 $(EXTRAWARN_CFLAGS) \
88 $(EXTRA_CFLAGS)
90 LDFLAGS = $(SUBST_LDFLAGS) \
91 -rdynamic -L$(TOPDIR) \
92 $(DEBUG_LDFLAGS_INTERNAL) \
93 $(EXTRA_LDFLAGS)
95 LIBS = $(LIBS_BASE)
96 LIBBTRFS_LIBS = $(LIBS_BASE)
98 # Static compilation flags
99 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
100 STATIC_LDFLAGS = -static -Wl,--gc-sections
101 STATIC_LIBS = $(STATIC_LIBS_BASE)
103 # don't use FORTIFY with sparse because glibc with FORTIFY can
104 # generate so many sparse errors that sparse stops parsing,
105 # which masks real errors that we want to see.
106 # Note: additional flags might get added per-target later
107 CHECKER := sparse
108 check_defs := .cc-defines.h
109 CHECKER_FLAGS := -include $(check_defs) -D__CHECKER__ \
110 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef \
111 -U_FORTIFY_SOURCE -Wdeclaration-after-statement -Wdefault-bitfield-sign
113 objects = ctree.o disk-io.o kernel-lib/radix-tree.o extent-tree.o print-tree.o \
114 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
115 extent-cache.o extent_io.o volumes.o utils.o repair.o \
116 qgroup.o free-space-cache.o kernel-lib/list_sort.o props.o \
117 kernel-shared/ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
118 inode.o file.o find-root.o free-space-tree.o help.o send-dump.o \
119 fsfeatures.o kernel-lib/tables.o kernel-lib/raid56.o transaction.o
120 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
121 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
122 cmds-quota.o cmds-qgroup.o cmds-replace.o check/main.o \
123 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
124 cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
125 cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o \
126 mkfs/common.o check/mode-common.o check/mode-lowmem.o
127 libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
128 kernel-lib/crc32c.o messages.o \
129 uuid-tree.o utils-lib.o rbtree-utils.o
130 libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
131 kernel-lib/crc32c.h kernel-lib/list.h kerncompat.h \
132 kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
133 extent-cache.h extent_io.h ioctl.h ctree.h btrfsck.h version.h
134 libbtrfsutil_major := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MAJOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
135 libbtrfsutil_minor := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MINOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
136 libbtrfsutil_patch := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_PATCH ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
137 libbtrfsutil_version := $(libbtrfsutil_major).$(libbtrfsutil_minor).$(libbtrfsutil_patch)
138 libbtrfsutil_objects = libbtrfsutil/errors.o libbtrfsutil/filesystem.o \
139 libbtrfsutil/subvolume.o libbtrfsutil/qgroup.o \
140 libbtrfsutil/stubs.o
141 convert_objects = convert/main.o convert/common.o convert/source-fs.o \
142 convert/source-ext2.o convert/source-reiserfs.o
143 mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
144 image_objects = image/main.o image/sanitize.o
145 all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \
146 $(mkfs_objects) $(image_objects) $(libbtrfsutil_objects)
148 udev_rules = 64-btrfs-dm.rules
150 ifeq ("$(origin V)", "command line")
151 BUILD_VERBOSE = $(V)
152 endif
153 ifndef BUILD_VERBOSE
154 BUILD_VERBOSE = 0
155 endif
157 ifeq ($(BUILD_VERBOSE),1)
159 SETUP_PY_Q =
160 else
161 Q = @
162 SETUP_PY_Q = -q
163 endif
165 ifeq ("$(origin D)", "command line")
166 DEBUG_CFLAGS_INTERNAL = $(DEBUG_CFLAGS_DEFAULT) $(DEBUG_CFLAGS)
167 DEBUG_LDFLAGS_INTERNAL = $(DEBUG_LDFLAGS_DEFAULT) $(DEBUG_LDFLAGS)
168 endif
170 ifneq (,$(findstring verbose,$(D)))
171 DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
172 endif
174 ifneq (,$(findstring trace,$(D)))
175 DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
176 endif
178 ifneq (,$(findstring abort,$(D)))
179 DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
180 endif
182 ifneq (,$(findstring all,$(D)))
183 DEBUG_CFLAGS_INTERNAL += -DDEBUG_VERBOSE_ERROR=1
184 DEBUG_CFLAGS_INTERNAL += -DDEBUG_TRACE_ON_ERROR=1
185 DEBUG_CFLAGS_INTERNAL += -DDEBUG_ABORT_ON_ERROR=1
186 endif
188 ifneq (,$(findstring asan,$(D)))
189 DEBUG_CFLAGS_INTERNAL += -fsanitize=address
190 DEBUG_LDFLAGS_INTERNAL += -fsanitize=address -lasan
191 endif
193 ifneq (,$(findstring tsan,$(D)))
194 DEBUG_CFLAGS_INTERNAL += -fsanitize=thread -fPIC
195 DEBUG_LDFLAGS_INTERNAL += -fsanitize=thread -ltsan -pie
196 endif
198 ifneq (,$(findstring ubsan,$(D)))
199 DEBUG_CFLAGS_INTERNAL += -fsanitize=undefined
200 DEBUG_LDFLAGS_INTERNAL += -fsanitize=undefined -lubsan
201 endif
203 ifneq (,$(findstring bcheck,$(D)))
204 DEBUG_CFLAGS_INTERNAL += -DDEBUG_BUILD_CHECKS
205 endif
207 MAKEOPTS = --no-print-directory Q=$(Q)
209 # build all by default
210 progs = $(progs_install) btrfsck btrfs-corrupt-block
212 # install only selected
213 progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
214 btrfs-map-logical btrfs-image btrfs-zero-log \
215 btrfs-find-root btrfstune \
216 btrfs-select-super
218 # other tools, not built by default
219 progs_extra = btrfs-fragments btrfs-calc-size btrfs-show-super
221 progs_static = $(foreach p,$(progs),$(p).static)
223 ifneq ($(DISABLE_BTRFSCONVERT),1)
224 progs_install += btrfs-convert
225 endif
227 # external libs required by various binaries; for btrfs-foo,
228 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
229 btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2)
230 btrfs_convert_cflags += -DBTRFSCONVERT_REISERFS=$(BTRFSCONVERT_REISERFS)
231 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
232 btrfs_debug_tree_objects = cmds-inspect-dump-tree.o
233 btrfs_show_super_objects = cmds-inspect-dump-super.o
234 btrfs_calc_size_objects = cmds-inspect-tree-stats.o
235 cmds_restore_cflags = -DBTRFSRESTORE_ZSTD=$(BTRFSRESTORE_ZSTD)
237 CHECKER_FLAGS += $(btrfs_convert_cflags)
239 # collect values of the variables above
240 standalone_deps = $(foreach dep,$(patsubst %,%_objects,$(subst -,_,$(filter btrfs-%, $(progs) $(progs_extra)))),$($(dep)))
242 SUBDIRS =
243 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
244 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
245 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
247 ifneq ($(DISABLE_DOCUMENTATION),1)
248 BUILDDIRS += build-Documentation
249 INSTALLDIRS += install-Documentation
250 endif
252 .PHONY: $(SUBDIRS)
253 .PHONY: $(BUILDDIRS)
254 .PHONY: $(INSTALLDIRS)
255 .PHONY: $(TESTDIRS)
256 .PHONY: $(CLEANDIRS)
257 .PHONY: all install clean
258 .PHONY: FORCE
260 # Create all the static targets
261 static_objects = $(patsubst %.o, %.static.o, $(objects))
262 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
263 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
264 static_convert_objects = $(patsubst %.o, %.static.o, $(convert_objects))
265 static_mkfs_objects = $(patsubst %.o, %.static.o, $(mkfs_objects))
266 static_image_objects = $(patsubst %.o, %.static.o, $(image_objects))
268 libs_shared = libbtrfs.so.0.1 libbtrfsutil.so.$(libbtrfsutil_version)
269 libs_static = libbtrfs.a libbtrfsutil.a
270 libs = $(libs_shared) $(libs_static)
271 lib_links = libbtrfs.so.0 libbtrfs.so libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so
273 # make C=1 to enable sparse
274 ifdef C
275 # We're trying to use sparse against glibc headers which go wild
276 # trying to use internal compiler macros to test features. We
277 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
278 # 'cause sparse defines that one.
280 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
281 grep -v __SIZE_TYPE__ > $(check_defs))
282 check = $(CHECKER)
283 check_echo = echo
284 CSTD = -std=gnu89
285 else
286 check = true
287 check_echo = true
288 endif
290 %.o.d: %.c
291 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
294 # Pick from per-file variables, btrfs_*_cflags
296 .c.o:
297 @$(check_echo) " [SP] $<"
298 $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
299 @echo " [CC] $@"
300 $(Q)$(CC) $(CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.o=%)-cflags)) \
301 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
303 %.static.o: %.c
304 @echo " [CC] $@"
305 $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.static.o=%)-cflags)) \
306 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
308 all: $(progs) $(libs) $(lib_links) $(BUILDDIRS)
309 ifeq ($(PYTHON_BINDINGS),1)
310 all: libbtrfsutil_python
311 endif
312 $(SUBDIRS): $(BUILDDIRS)
313 $(BUILDDIRS):
314 @echo "Making all in $(patsubst build-%,%,$@)"
315 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
317 test-convert: btrfs btrfs-convert
318 @echo " [TEST] convert-tests.sh"
319 $(Q)bash tests/convert-tests.sh
321 test-check: test-fsck
322 test-fsck: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune
323 @echo " [TEST] fsck-tests.sh"
324 $(Q)bash tests/fsck-tests.sh
326 test-misc: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune fssum \
327 btrfs-zero-log btrfs-find-root btrfs-select-super btrfs-convert
328 @echo " [TEST] misc-tests.sh"
329 $(Q)bash tests/misc-tests.sh
331 test-mkfs: btrfs mkfs.btrfs
332 @echo " [TEST] mkfs-tests.sh"
333 $(Q)bash tests/mkfs-tests.sh
335 test-fuzz: btrfs btrfs-image
336 @echo " [TEST] fuzz-tests.sh"
337 $(Q)bash tests/fuzz-tests.sh
339 test-cli: btrfs mkfs.btrfs
340 @echo " [TEST] cli-tests.sh"
341 $(Q)bash tests/cli-tests.sh
343 test-clean:
344 @echo "Cleaning tests"
345 $(Q)bash tests/clean-tests.sh
347 test-inst: all
348 @tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
349 echo "Test installation to $$tmpdest" && \
350 $(MAKE) $(MAKEOPTS) DESTDIR=$$tmpdest install && \
351 $(RM) -rf -- $$tmpdest
353 test: test-fsck test-mkfs test-misc test-cli test-convert test-fuzz
355 testsuite: btrfs-corrupt-block fssum
356 @echo "Export tests as a package"
357 $(Q)cd tests && ./export-testsuite.sh
359 ifeq ($(PYTHON_BINDINGS),1)
360 test-libbtrfsutil: libbtrfsutil_python
361 $(Q)cd libbtrfsutil/python; \
362 LD_LIBRARY_PATH=../.. $(PYTHON) -m unittest discover -v tests
364 .PHONY: test-libbtrfsutil
366 test: test-libbtrfsutil
367 endif
370 # NOTE: For static compiles, you need to have all the required libs
371 # static equivalent available
373 static: $(progs_static)
375 version.h: version.h.in configure.ac
376 @echo " [SH] $@"
377 $(Q)bash ./config.status --silent $@
379 mktables: kernel-lib/mktables.c
380 @echo " [CC] $@"
381 $(Q)$(CC) $(CFLAGS) $< -o $@
383 # the target can be regenerated manually using mktables, but a local copy is
384 # kept so the build process is simpler
385 kernel-lib/tables.c:
386 @echo " [TABLE] $@"
387 $(Q)./mktables > $@ || ($(RM) -f $@ && exit 1)
389 libbtrfs.so.0.1: $(libbtrfs_objects)
390 @echo " [LD] $@"
391 $(Q)$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LIBBTRFS_LIBS) \
392 -shared -Wl,-soname,libbtrfs.so.0 -o $@
394 libbtrfs.a: $(libbtrfs_objects)
395 @echo " [AR] $@"
396 $(Q)$(AR) cr $@ $^
398 libbtrfs.so.0 libbtrfs.so: libbtrfs.so.0.1
399 @echo " [LN] $@"
400 $(Q)$(LN_S) -f $< $@
402 libbtrfsutil/%.o: libbtrfsutil/%.c
403 @echo " [CC] $@"
404 $(Q)$(CC) $(LIBBTRFSUTIL_CFLAGS) -o $@ -c $< -o $@
406 libbtrfsutil.so.$(libbtrfsutil_version): $(libbtrfsutil_objects)
407 @echo " [LD] $@"
408 $(Q)$(CC) $(LIBBTRFSUTIL_CFLAGS) $(libbtrfsutil_objects) \
409 -shared -Wl,-soname,libbtrfsutil.so.$(libbtrfsutil_major) -o $@
411 libbtrfsutil.a: $(libbtrfsutil_objects)
412 @echo " [AR] $@"
413 $(Q)$(AR) cr $@ $^
415 libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so: libbtrfsutil.so.$(libbtrfsutil_version)
416 @echo " [LN] $@"
417 $(Q)$(LN_S) -f $< $@
419 ifeq ($(PYTHON_BINDINGS),1)
420 libbtrfsutil_python: libbtrfsutil.so libbtrfsutil/btrfsutil.h
421 @echo " [PY] libbtrfsutil"
422 $(Q)cd libbtrfsutil/python; \
423 CFLAGS= LDFLAGS= $(PYTHON) setup.py $(SETUP_PY_Q) build_ext -i build
425 .PHONY: libbtrfsutil_python
426 endif
428 # keep intermediate files from the below implicit rules around
429 .PRECIOUS: $(addsuffix .o,$(progs))
431 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
432 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
433 # turns them into a list of libraries to link against if they exist
435 # For static variants, use an extra $(subst) to get rid of the ".static"
436 # from the target name before translating to list of libs
438 btrfs-%.static: btrfs-%.static.o $(static_objects) $(patsubst %.o,%.static.o,$(standalone_deps)) $(static_libbtrfs_objects)
439 @echo " [LD] $@"
440 $(Q)$(CC) -o $@ $@.o $(static_objects) \
441 $(patsubst %.o, %.static.o, $($(subst -,_,$(subst .static,,$@)-objects))) \
442 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
443 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
445 btrfs-%: btrfs-%.o $(objects) $(standalone_deps) $(libs_static)
446 @echo " [LD] $@"
447 $(Q)$(CC) -o $@ $(objects) $@.o \
448 $($(subst -,_,$@-objects)) \
449 $(libs_static) \
450 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
452 btrfs: btrfs.o $(objects) $(cmds_objects) $(libs_static)
453 @echo " [LD] $@"
454 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
456 btrfs.static: btrfs.static.o $(static_objects) $(static_cmds_objects) $(static_libbtrfs_objects)
457 @echo " [LD] $@"
458 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
460 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
461 btrfsck: btrfs
462 @echo " [LN] $@"
463 $(Q)$(LN_S) -f btrfs btrfsck
465 btrfsck.static: btrfs.static
466 @echo " [LN] $@"
467 $(Q)$(LN_S) -f $^ $@
469 mkfs.btrfs: $(mkfs_objects) $(objects) $(libs_static)
470 @echo " [LD] $@"
471 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
473 mkfs.btrfs.static: $(static_mkfs_objects) $(static_objects) $(static_libbtrfs_objects)
474 @echo " [LD] $@"
475 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
477 btrfstune: btrfstune.o $(objects) $(libs_static)
478 @echo " [LD] $@"
479 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
481 btrfstune.static: btrfstune.static.o $(static_objects) $(static_libbtrfs_objects)
482 @echo " [LD] $@"
483 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
485 btrfs-image: $(image_objects) $(objects) $(libs_static)
486 @echo " [LD] $@"
487 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
489 btrfs-image.static: $(static_image_objects) $(static_objects) $(static_libbtrfs_objects)
490 @echo " [LD] $@"
491 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
493 btrfs-convert: $(convert_objects) $(objects) $(libs_static)
494 @echo " [LD] $@"
495 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(btrfs_convert_libs) $(LIBS)
497 btrfs-convert.static: $(static_convert_objects) $(static_objects) $(static_libbtrfs_objects)
498 @echo " [LD] $@"
499 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(btrfs_convert_libs) $(STATIC_LIBS)
501 dir-test: dir-test.o $(objects) $(libs)
502 @echo " [LD] $@"
503 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
505 quick-test: quick-test.o $(objects) $(libs)
506 @echo " [LD] $@"
507 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
509 ioctl-test.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
510 @echo " [CC] $@"
511 $(Q)$(CC) $(CFLAGS) -c $< -o $@
513 ioctl-test-32.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
514 @echo " [CC32] $@"
515 $(Q)$(CC) $(CFLAGS) -m32 -c $< -o $@
517 ioctl-test-64.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
518 @echo " [CC64] $@"
519 $(Q)$(CC) $(CFLAGS) -m64 -c $< -o $@
521 ioctl-test: ioctl-test.o
522 @echo " [LD] $@"
523 $(Q)$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
524 @echo " ?[PAHOLE] $@.pahole"
525 -$(Q)pahole $@ > $@.pahole
527 ioctl-test-32: ioctl-test-32.o
528 @echo " [LD32] $@"
529 $(Q)$(CC) -m32 -o $@ $< $(LDFLAGS)
530 @echo " ?[PAHOLE] $@.pahole"
531 -$(Q)pahole $@ > $@.pahole
533 ioctl-test-64: ioctl-test-64.o
534 @echo " [LD64] $@"
535 $(Q)$(CC) -m64 -o $@ $< $(LDFLAGS)
536 @echo " ?[PAHOLE] $@.pahole"
537 -$(Q)pahole $@ > $@.pahole
539 test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64
540 @echo " [TEST/ioctl]"
541 $(Q)./ioctl-test > ioctl-test.log
542 $(Q)./ioctl-test-32 > ioctl-test-32.log
543 $(Q)./ioctl-test-64 > ioctl-test-64.log
545 library-test: library-test.c libbtrfs.so
546 @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d))
547 $(Q)mkdir -p $(TMPD)/include/btrfs && \
548 cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
549 cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(ABSTOPDIR)/,$^) -Wl,-rpath=$(ABSTOPDIR) -lbtrfs
550 @echo " [TEST RUN] $@"
551 $(Q)cd $(TMPD) && ./$@
552 @echo " [TEST CLEAN] $@"
553 $(Q)$(RM) -rf -- $(TMPD)
555 library-test.static: library-test.c $(libs_static)
556 @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d))
557 $(Q)mkdir -p $(TMPD)/include/btrfs && \
558 cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
559 cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(ABSTOPDIR)/,$^) $(STATIC_LDFLAGS) $(STATIC_LIBS)
560 @echo " [TEST RUN] $@"
561 $(Q)cd $(TMPD) && ./$@
562 @echo " [TEST CLEAN] $@"
563 $(Q)$(RM) -rf -- $(TMPD)
565 fssum: tests/fssum.c tests/sha224-256.c
566 @echo " [LD] $@"
567 $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
569 test-build: test-build-pre test-build-real
571 test-build-pre:
572 $(MAKE) $(MAKEOPTS) clean-all
573 ./autogen.sh
574 ./configure
576 test-build-real:
577 $(MAKE) $(MAKEOPTS) library-test
578 -$(MAKE) $(MAKEOPTS) library-test.static
579 $(MAKE) $(MAKEOPTS) -j 8 all
580 -$(MAKE) $(MAKEOPTS) -j 8 static
581 $(MAKE) $(MAKEOPTS) -j 8 $(progs_extra)
583 manpages:
584 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
586 tags: FORCE
587 @echo " [TAGS] $(TAGS_CMD)"
588 $(Q)$(TAGS_CMD) *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] \
589 check/*.[ch] kernel-lib/*.[ch] kernel-shared/*.[ch] \
590 libbtrfsutil/*.[ch]
592 cscope: FORCE
593 @echo " [CSCOPE] $(CSCOPE_CMD)"
594 $(Q)ls -1 *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] check/*.[ch] \
595 kernel-lib/*.[ch] kernel-shared/*.[ch] libbtrfsutil/*.[ch] \
596 > cscope.files
597 $(Q)$(CSCOPE_CMD)
599 clean-all: clean clean-doc clean-gen
601 clean: $(CLEANDIRS)
602 @echo "Cleaning"
603 $(Q)$(RM) -f -- $(progs) *.o *.o.d \
604 kernel-lib/*.o kernel-lib/*.o.d \
605 kernel-shared/*.o kernel-shared/*.o.d \
606 image/*.o image/*.o.d \
607 convert/*.o convert/*.o.d \
608 mkfs/*.o mkfs/*.o.d check/*.o check/*.o.d \
609 dir-test ioctl-test quick-test library-test library-test-static \
610 mktables btrfs.static mkfs.btrfs.static fssum \
611 $(check_defs) \
612 $(libs) $(lib_links) \
613 $(progs_static) $(progs_extra) \
614 libbtrfsutil/*.o libbtrfsutil/*.o.d
615 ifeq ($(PYTHON_BINDINGS),1)
616 $(Q)cd libbtrfsutil/python; \
617 $(PYTHON) setup.py $(SETUP_PY_Q) clean -a
618 endif
620 clean-doc:
621 @echo "Cleaning Documentation"
622 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
624 clean-gen:
625 @echo "Cleaning Generated Files"
626 $(Q)$(RM) -rf -- version.h config.status config.cache connfig.log \
627 configure.lineno config.status.lineno Makefile.inc \
628 Documentation/Makefile tags \
629 cscope.files cscope.out cscope.in.out cscope.po.out \
630 config.log config.h config.h.in~ aclocal.m4 \
631 configure autom4te.cache/ config/
633 $(CLEANDIRS):
634 @echo "Cleaning $(patsubst clean-%,%,$@)"
635 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
637 install: $(libs) $(progs_install) $(INSTALLDIRS)
638 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
639 $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
640 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
641 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
642 $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
643 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
644 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
645 cp -a $(lib_links) $(DESTDIR)$(libdir)
646 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)/btrfs
647 $(INSTALL) -m644 $(libbtrfs_headers) $(DESTDIR)$(incdir)/btrfs
648 $(INSTALL) -m644 libbtrfsutil/btrfsutil.h $(DESTDIR)$(incdir)
649 ifneq ($(udevdir),)
650 $(INSTALL) -m755 -d $(DESTDIR)$(udevruledir)
651 $(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
652 endif
654 ifeq ($(PYTHON_BINDINGS),1)
655 install_python: libbtrfsutil_python
656 $(Q)cd libbtrfsutil/python; \
657 $(PYTHON) setup.py install --skip-build $(if $(DESTDIR),--root $(DESTDIR)) --prefix $(prefix)
659 .PHONY: install_python
660 endif
662 install-static: $(progs_static) $(INSTALLDIRS)
663 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
664 $(INSTALL) $(progs_static) $(DESTDIR)$(bindir)
665 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
666 $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
668 $(INSTALLDIRS):
669 @echo "Making install in $(patsubst install-%,%,$@)"
670 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
672 uninstall:
673 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
674 cd $(DESTDIR)$(incdir)/btrfs; $(RM) -f -- $(libbtrfs_headers)
675 $(RMDIR) -p --ignore-fail-on-non-empty -- $(DESTDIR)$(incdir)/btrfs
676 cd $(DESTDIR)$(incdir); $(RM) -f -- btrfsutil.h
677 cd $(DESTDIR)$(libdir); $(RM) -f -- $(lib_links) $(libs)
678 cd $(DESTDIR)$(bindir); $(RM) -f -- btrfsck fsck.btrfs $(progs_install)
680 ifneq ($(MAKECMDGOALS),clean)
681 -include $(all_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
682 endif