Btrfs progs v4.17.1
[btrfs-progs-unstable/devel.git] / Makefile
blobfcfc815a2a5b9992befdcf75d7a3d221a19efb0f
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 CFLAGS = $(SUBST_CFLAGS) \
67 $(CSTD) \
68 -include config.h \
69 -DBTRFS_FLAT_INCLUDES \
70 -D_XOPEN_SOURCE=700 \
71 -fno-strict-aliasing \
72 -fPIC \
73 -I$(TOPDIR) \
74 -I$(TOPDIR)/kernel-lib \
75 -I$(TOPDIR)/libbtrfsutil \
76 $(EXTRAWARN_CFLAGS) \
77 $(DEBUG_CFLAGS_INTERNAL) \
78 $(EXTRA_CFLAGS)
80 LIBBTRFSUTIL_CFLAGS = $(SUBST_CFLAGS) \
81 $(CSTD) \
82 -D_GNU_SOURCE \
83 -fPIC \
84 -fvisibility=hidden \
85 -I$(TOPDIR)/libbtrfsutil \
86 $(EXTRAWARN_CFLAGS) \
87 $(DEBUG_CFLAGS_INTERNAL) \
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)
210 # Programs to install.
211 progs_install = btrfs mkfs.btrfs btrfs-map-logical btrfs-image \
212 btrfs-find-root btrfstune btrfs-select-super
214 # Programs to build.
215 progs_build = $(progs_install) btrfsck btrfs-corrupt-block
217 # All programs. Use := instead of = so that this is expanded before we reassign
218 # progs_build below.
219 progs := $(progs_build) btrfs-convert btrfs-fragments
221 ifneq ($(DISABLE_BTRFSCONVERT),1)
222 progs_install += btrfs-convert
223 endif
225 # Static programs to build. Use := instead of = because `make static` should
226 # still build everything even if --disable-programs was passed to ./configure.
227 progs_static := $(foreach p,$(progs_build),$(p).static)
229 ifneq ($(BUILD_PROGRAMS),1)
230 progs_install =
231 progs_build =
232 endif
234 # external libs required by various binaries; for btrfs-foo,
235 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
236 btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2)
237 btrfs_convert_cflags += -DBTRFSCONVERT_REISERFS=$(BTRFSCONVERT_REISERFS)
238 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
239 cmds_restore_cflags = -DBTRFSRESTORE_ZSTD=$(BTRFSRESTORE_ZSTD)
241 CHECKER_FLAGS += $(btrfs_convert_cflags)
243 # collect values of the variables above
244 standalone_deps = $(foreach dep,$(patsubst %,%_objects,$(subst -,_,$(filter btrfs-%, $(progs)))),$($(dep)))
246 SUBDIRS =
247 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
248 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
249 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
251 ifneq ($(DISABLE_DOCUMENTATION),1)
252 BUILDDIRS += build-Documentation
253 INSTALLDIRS += install-Documentation
254 endif
256 .PHONY: $(SUBDIRS)
257 .PHONY: $(BUILDDIRS)
258 .PHONY: $(INSTALLDIRS)
259 .PHONY: $(TESTDIRS)
260 .PHONY: $(CLEANDIRS)
261 .PHONY: all install clean
262 .PHONY: FORCE
264 # Create all the static targets
265 static_objects = $(patsubst %.o, %.static.o, $(objects))
266 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
267 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
268 static_libbtrfsutil_objects = $(patsubst %.o, %.static.o, $(libbtrfsutil_objects))
269 static_convert_objects = $(patsubst %.o, %.static.o, $(convert_objects))
270 static_mkfs_objects = $(patsubst %.o, %.static.o, $(mkfs_objects))
271 static_image_objects = $(patsubst %.o, %.static.o, $(image_objects))
273 libs_shared = libbtrfs.so.0.1 libbtrfsutil.so.$(libbtrfsutil_version)
274 libs_static = libbtrfs.a libbtrfsutil.a
275 libs = $(libs_shared) $(libs_static)
276 lib_links = libbtrfs.so.0 libbtrfs.so libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so
277 libs_build =
278 ifeq ($(BUILD_SHARED_LIBRARIES),1)
279 libs_build += $(libs_shared) $(lib_links)
280 endif
281 ifeq ($(BUILD_STATIC_LIBRARIES),1)
282 libs_build += $(libs_static)
283 endif
285 # make C=1 to enable sparse
286 ifdef C
287 # We're trying to use sparse against glibc headers which go wild
288 # trying to use internal compiler macros to test features. We
289 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
290 # 'cause sparse defines that one.
292 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
293 grep -v __SIZE_TYPE__ > $(check_defs))
294 check = $(CHECKER)
295 check_echo = echo
296 CSTD = -std=gnu89
297 else
298 check = true
299 check_echo = true
300 endif
302 %.o.d: %.c
303 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
306 # Pick from per-file variables, btrfs_*_cflags
308 .c.o:
309 @$(check_echo) " [SP] $<"
310 $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
311 @echo " [CC] $@"
312 $(Q)$(CC) $(CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.o=%)-cflags)) \
313 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
315 %.static.o: %.c
316 @echo " [CC] $@"
317 $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@ $($(subst -,_,$(@:%.static.o=%)-cflags)) \
318 $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags))
320 all: $(progs_build) $(libs_build) $(BUILDDIRS)
321 ifeq ($(PYTHON_BINDINGS),1)
322 all: libbtrfsutil_python
323 endif
324 $(SUBDIRS): $(BUILDDIRS)
325 $(BUILDDIRS):
326 @echo "Making all in $(patsubst build-%,%,$@)"
327 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
329 test-convert: btrfs btrfs-convert
330 @echo " [TEST] convert-tests.sh"
331 $(Q)bash tests/convert-tests.sh
333 test-check: test-fsck
334 test-fsck: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune
335 @echo " [TEST] fsck-tests.sh"
336 $(Q)bash tests/fsck-tests.sh
338 test-misc: btrfs btrfs-image btrfs-corrupt-block mkfs.btrfs btrfstune fssum \
339 btrfs-find-root btrfs-select-super btrfs-convert
340 @echo " [TEST] misc-tests.sh"
341 $(Q)bash tests/misc-tests.sh
343 test-mkfs: btrfs mkfs.btrfs
344 @echo " [TEST] mkfs-tests.sh"
345 $(Q)bash tests/mkfs-tests.sh
347 test-fuzz: btrfs btrfs-image
348 @echo " [TEST] fuzz-tests.sh"
349 $(Q)bash tests/fuzz-tests.sh
351 test-cli: btrfs mkfs.btrfs
352 @echo " [TEST] cli-tests.sh"
353 $(Q)bash tests/cli-tests.sh
355 test-clean:
356 @echo "Cleaning tests"
357 $(Q)bash tests/clean-tests.sh
359 test-inst: all
360 @tmpdest=`mktemp --tmpdir -d btrfs-inst.XXXXXX` && \
361 echo "Test installation to $$tmpdest" && \
362 $(MAKE) $(MAKEOPTS) DESTDIR=$$tmpdest install && \
363 $(RM) -rf -- $$tmpdest
365 test: test-fsck test-mkfs test-misc test-cli test-convert test-fuzz
367 testsuite: btrfs-corrupt-block fssum
368 @echo "Export tests as a package"
369 $(Q)cd tests && ./export-testsuite.sh
371 ifeq ($(PYTHON_BINDINGS),1)
372 test-libbtrfsutil: libbtrfsutil_python mkfs.btrfs
373 $(Q)cd libbtrfsutil/python; \
374 LD_LIBRARY_PATH=../.. $(PYTHON) -m unittest discover -v tests
376 .PHONY: test-libbtrfsutil
378 test: test-libbtrfsutil
379 endif
382 # NOTE: For static compiles, you need to have all the required libs
383 # static equivalent available
385 static: $(progs_static)
387 version.h: version.h.in configure.ac
388 @echo " [SH] $@"
389 $(Q)bash ./config.status --silent $@
391 mktables: kernel-lib/mktables.c
392 @echo " [CC] $@"
393 $(Q)$(CC) $(CFLAGS) $< -o $@
395 # the target can be regenerated manually using mktables, but a local copy is
396 # kept so the build process is simpler
397 kernel-lib/tables.c:
398 @echo " [TABLE] $@"
399 $(Q)./mktables > $@ || ($(RM) -f $@ && exit 1)
401 libbtrfs.so.0.1: $(libbtrfs_objects)
402 @echo " [LD] $@"
403 $(Q)$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LIBBTRFS_LIBS) \
404 -shared -Wl,-soname,libbtrfs.so.0 -o $@
406 libbtrfs.a: $(libbtrfs_objects)
407 @echo " [AR] $@"
408 $(Q)$(AR) cr $@ $^
410 libbtrfs.so.0 libbtrfs.so: libbtrfs.so.0.1
411 @echo " [LN] $@"
412 $(Q)$(LN_S) -f $< $@
414 libbtrfsutil/%.o: libbtrfsutil/%.c
415 @echo " [CC] $@"
416 $(Q)$(CC) $(LIBBTRFSUTIL_CFLAGS) -o $@ -c $< -o $@
418 libbtrfsutil.so.$(libbtrfsutil_version): $(libbtrfsutil_objects)
419 @echo " [LD] $@"
420 $(Q)$(CC) $(LIBBTRFSUTIL_CFLAGS) $(libbtrfsutil_objects) \
421 -shared -Wl,-soname,libbtrfsutil.so.$(libbtrfsutil_major) -o $@
423 libbtrfsutil.a: $(libbtrfsutil_objects)
424 @echo " [AR] $@"
425 $(Q)$(AR) cr $@ $^
427 libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so: libbtrfsutil.so.$(libbtrfsutil_version)
428 @echo " [LN] $@"
429 $(Q)$(LN_S) -f $< $@
431 ifeq ($(PYTHON_BINDINGS),1)
432 libbtrfsutil_python: libbtrfsutil.so.$(libbtrfsutil_major) libbtrfsutil.so libbtrfsutil/btrfsutil.h
433 @echo " [PY] libbtrfsutil"
434 $(Q)cd libbtrfsutil/python; \
435 CFLAGS= LDFLAGS= $(PYTHON) setup.py $(SETUP_PY_Q) build_ext -i build
437 .PHONY: libbtrfsutil_python
438 endif
440 # keep intermediate files from the below implicit rules around
441 .PRECIOUS: $(addsuffix .o,$(progs))
443 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
444 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
445 # turns them into a list of libraries to link against if they exist
447 # For static variants, use an extra $(subst) to get rid of the ".static"
448 # from the target name before translating to list of libs
450 btrfs-%.static: btrfs-%.static.o $(static_objects) $(patsubst %.o,%.static.o,$(standalone_deps)) $(static_libbtrfs_objects)
451 @echo " [LD] $@"
452 $(Q)$(CC) -o $@ $@.o $(static_objects) \
453 $(patsubst %.o, %.static.o, $($(subst -,_,$(subst .static,,$@)-objects))) \
454 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
455 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
457 btrfs-%: btrfs-%.o $(objects) $(standalone_deps) $(libs_static)
458 @echo " [LD] $@"
459 $(Q)$(CC) -o $@ $(objects) $@.o \
460 $($(subst -,_,$@-objects)) \
461 $(libs_static) \
462 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
464 btrfs: btrfs.o $(objects) $(cmds_objects) $(libs_static)
465 @echo " [LD] $@"
466 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
468 btrfs.static: btrfs.static.o $(static_objects) $(static_cmds_objects) $(static_libbtrfs_objects) $(static_libbtrfsutil_objects)
469 @echo " [LD] $@"
470 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
472 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
473 btrfsck: btrfs
474 @echo " [LN] $@"
475 $(Q)$(LN_S) -f btrfs btrfsck
477 btrfsck.static: btrfs.static
478 @echo " [LN] $@"
479 $(Q)$(LN_S) -f $^ $@
481 mkfs.btrfs: $(mkfs_objects) $(objects) $(libs_static)
482 @echo " [LD] $@"
483 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
485 mkfs.btrfs.static: $(static_mkfs_objects) $(static_objects) $(static_libbtrfs_objects)
486 @echo " [LD] $@"
487 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
489 btrfstune: btrfstune.o $(objects) $(libs_static)
490 @echo " [LD] $@"
491 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
493 btrfstune.static: btrfstune.static.o $(static_objects) $(static_libbtrfs_objects)
494 @echo " [LD] $@"
495 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
497 btrfs-image: $(image_objects) $(objects) $(libs_static)
498 @echo " [LD] $@"
499 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)
501 btrfs-image.static: $(static_image_objects) $(static_objects) $(static_libbtrfs_objects)
502 @echo " [LD] $@"
503 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
505 btrfs-convert: $(convert_objects) $(objects) $(libs_static)
506 @echo " [LD] $@"
507 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(btrfs_convert_libs) $(LIBS)
509 btrfs-convert.static: $(static_convert_objects) $(static_objects) $(static_libbtrfs_objects)
510 @echo " [LD] $@"
511 $(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(btrfs_convert_libs) $(STATIC_LIBS)
513 quick-test: quick-test.o $(objects) $(libs)
514 @echo " [LD] $@"
515 $(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
517 ioctl-test.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
518 @echo " [CC] $@"
519 $(Q)$(CC) $(CFLAGS) -c $< -o $@
521 ioctl-test-32.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
522 @echo " [CC32] $@"
523 $(Q)$(CC) $(CFLAGS) -m32 -c $< -o $@
525 ioctl-test-64.o: ioctl-test.c ioctl.h kerncompat.h ctree.h
526 @echo " [CC64] $@"
527 $(Q)$(CC) $(CFLAGS) -m64 -c $< -o $@
529 ioctl-test: ioctl-test.o
530 @echo " [LD] $@"
531 $(Q)$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
532 @echo " ?[PAHOLE] $@.pahole"
533 -$(Q)pahole $@ > $@.pahole
535 ioctl-test-32: ioctl-test-32.o
536 @echo " [LD32] $@"
537 $(Q)$(CC) -m32 -o $@ $< $(LDFLAGS)
538 @echo " ?[PAHOLE] $@.pahole"
539 -$(Q)pahole $@ > $@.pahole
541 ioctl-test-64: ioctl-test-64.o
542 @echo " [LD64] $@"
543 $(Q)$(CC) -m64 -o $@ $< $(LDFLAGS)
544 @echo " ?[PAHOLE] $@.pahole"
545 -$(Q)pahole $@ > $@.pahole
547 test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64
548 @echo " [TEST/ioctl]"
549 $(Q)./ioctl-test > ioctl-test.log
550 $(Q)./ioctl-test-32 > ioctl-test-32.log
551 $(Q)./ioctl-test-64 > ioctl-test-64.log
553 library-test: library-test.c libbtrfs.so
554 @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d))
555 $(Q)mkdir -p $(TMPD)/include/btrfs && \
556 cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
557 cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(ABSTOPDIR)/,$^) -Wl,-rpath=$(ABSTOPDIR) -lbtrfs
558 @echo " [TEST RUN] $@"
559 $(Q)cd $(TMPD) && ./$@
560 @echo " [TEST CLEAN] $@"
561 $(Q)$(RM) -rf -- $(TMPD)
563 library-test.static: library-test.c $(libs_static)
564 @echo " [TEST PREP] $@"$(eval TMPD=$(shell mktemp -d))
565 $(Q)mkdir -p $(TMPD)/include/btrfs && \
566 cp $(libbtrfs_headers) $(TMPD)/include/btrfs && \
567 cd $(TMPD) && $(CC) -I$(TMPD)/include -o $@ $(addprefix $(ABSTOPDIR)/,$^) $(STATIC_LDFLAGS) $(STATIC_LIBS)
568 @echo " [TEST RUN] $@"
569 $(Q)cd $(TMPD) && ./$@
570 @echo " [TEST CLEAN] $@"
571 $(Q)$(RM) -rf -- $(TMPD)
573 fssum: tests/fssum.c tests/sha224-256.c
574 @echo " [LD] $@"
575 $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
577 test-build: test-build-pre test-build-real
579 test-build-pre:
580 $(MAKE) $(MAKEOPTS) clean-all
581 ./autogen.sh
582 ./configure
584 test-build-real:
585 $(MAKE) $(MAKEOPTS) library-test
586 -$(MAKE) $(MAKEOPTS) library-test.static
587 $(MAKE) $(MAKEOPTS) -j 8 $(progs) $(libs) $(lib_links) $(BUILDDIRS)
588 -$(MAKE) $(MAKEOPTS) -j 8 static
590 manpages:
591 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
593 tags: FORCE
594 @echo " [TAGS] $(TAGS_CMD)"
595 $(Q)$(TAGS_CMD) *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] \
596 check/*.[ch] kernel-lib/*.[ch] kernel-shared/*.[ch] \
597 libbtrfsutil/*.[ch]
599 cscope: FORCE
600 @echo " [CSCOPE] $(CSCOPE_CMD)"
601 $(Q)ls -1 *.[ch] image/*.[ch] convert/*.[ch] mkfs/*.[ch] check/*.[ch] \
602 kernel-lib/*.[ch] kernel-shared/*.[ch] libbtrfsutil/*.[ch] \
603 > cscope.files
604 $(Q)$(CSCOPE_CMD)
606 clean-all: clean clean-doc clean-gen
608 clean: $(CLEANDIRS)
609 @echo "Cleaning"
610 $(Q)$(RM) -f -- $(progs) *.o *.o.d \
611 kernel-lib/*.o kernel-lib/*.o.d \
612 kernel-shared/*.o kernel-shared/*.o.d \
613 image/*.o image/*.o.d \
614 convert/*.o convert/*.o.d \
615 mkfs/*.o mkfs/*.o.d check/*.o check/*.o.d \
616 ioctl-test quick-test library-test library-test-static \
617 mktables btrfs.static mkfs.btrfs.static fssum \
618 $(check_defs) \
619 $(libs) $(lib_links) \
620 $(progs_static) \
621 libbtrfsutil/*.o libbtrfsutil/*.o.d
622 ifeq ($(PYTHON_BINDINGS),1)
623 $(Q)cd libbtrfsutil/python; \
624 $(PYTHON) setup.py $(SETUP_PY_Q) clean -a
625 endif
627 clean-doc:
628 @echo "Cleaning Documentation"
629 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
631 clean-gen:
632 @echo "Cleaning Generated Files"
633 $(Q)$(RM) -rf -- version.h config.status config.cache connfig.log \
634 configure.lineno config.status.lineno Makefile.inc \
635 Documentation/Makefile tags \
636 cscope.files cscope.out cscope.in.out cscope.po.out \
637 config.log config.h config.h.in~ aclocal.m4 \
638 configure autom4te.cache/ config/
640 $(CLEANDIRS):
641 @echo "Cleaning $(patsubst clean-%,%,$@)"
642 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
644 install: $(libs_build) $(progs_install) $(INSTALLDIRS)
645 ifeq ($(BUILD_PROGRAMS),1)
646 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
647 $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
648 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
649 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
650 $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
651 ifneq ($(udevdir),)
652 $(INSTALL) -m755 -d $(DESTDIR)$(udevruledir)
653 $(INSTALL) -m644 $(udev_rules) $(DESTDIR)$(udevruledir)
654 endif
655 endif
656 ifneq ($(libs_build),)
657 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
658 $(INSTALL) $(libs_build) $(DESTDIR)$(libdir)
659 ifeq ($(BUILD_SHARED_LIBRARIES),1)
660 cp -d $(lib_links) $(DESTDIR)$(libdir)
661 endif
662 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)/btrfs
663 $(INSTALL) -m644 $(libbtrfs_headers) $(DESTDIR)$(incdir)/btrfs
664 $(INSTALL) -m644 libbtrfsutil/btrfsutil.h $(DESTDIR)$(incdir)
665 endif
667 ifeq ($(PYTHON_BINDINGS),1)
668 install_python: libbtrfsutil_python
669 $(Q)cd libbtrfsutil/python; \
670 $(PYTHON) setup.py install --skip-build $(if $(DESTDIR),--root $(DESTDIR)) --prefix $(prefix)
672 .PHONY: install_python
673 endif
675 install-static: $(progs_static) $(INSTALLDIRS)
676 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
677 $(INSTALL) $(progs_static) $(DESTDIR)$(bindir)
678 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
679 $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
681 $(INSTALLDIRS):
682 @echo "Making install in $(patsubst install-%,%,$@)"
683 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
685 uninstall:
686 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
687 cd $(DESTDIR)$(incdir)/btrfs; $(RM) -f -- $(libbtrfs_headers)
688 $(RMDIR) -p --ignore-fail-on-non-empty -- $(DESTDIR)$(incdir)/btrfs
689 cd $(DESTDIR)$(incdir); $(RM) -f -- btrfsutil.h
690 cd $(DESTDIR)$(libdir); $(RM) -f -- $(lib_links) $(libs)
691 cd $(DESTDIR)$(bindir); $(RM) -f -- btrfsck fsck.btrfs $(progs_install)
693 ifneq ($(MAKECMDGOALS),clean)
694 -include $(all_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
695 endif