btrfs-progs: check: pass a template to add_extent_rec_nolookup
[btrfs-progs-unstable/devel.git] / Makefile.in
blob0a1aece70dab41dae278138dcc4cb19f36d03b29
1 # btrfs-progs
3 # Basic build targets:
4 # all all main tools
5 # static build static bnaries, requires static version of the libraries
6 # test run the full testsuite
7 # install install to default location (/usr/local)
8 # clean clean built binaries (not the documentation)
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 # W=123 build with warnings (default: off)
14 # EXTRA_CFLAGS additional compiler flags
15 # EXTRA_LDFLAGS additional linker flags
17 # Static checkers:
18 # CHECKER static checker binary to be called (default: sparse)
19 # CHECKER_FLAGS flags to pass to CHECKER, can override CFLAGS
22 # Export all variables to sub-makes by default
23 export
25 include Makefile.extrawarn
27 CC = @CC@
28 LN_S = @LN_S@
29 AR = @AR@
30 RM = @RM@
31 RMDIR = @RMDIR@
32 INSTALL = @INSTALL@
33 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
34 DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
36 EXTRA_CFLAGS :=
37 EXTRA_LDFLAGS :=
39 # Common build flags
40 CFLAGS = @CFLAGS@ \
41 -include config.h \
42 -DBTRFS_FLAT_INCLUDES \
43 -D_XOPEN_SOURCE=700 \
44 -fno-strict-aliasing \
45 -fPIC $(EXTRAWARN_CFLAGS) $(EXTRA_CFLAGS)
47 LDFLAGS = @LDFLAGS@ \
48 -rdynamic $(EXTRA_LDFLAGS)
50 LIBS = @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@ -L. -pthread
51 LIBBTRFS_LIBS = $(LIBS)
53 # Static compilation flags
54 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
55 STATIC_LDFLAGS = -static -Wl,--gc-sections
56 STATIC_LIBS = @UUID_LIBS_STATIC@ @BLKID_LIBS_STATIC@ \
57 @ZLIB_LIBS_STATIC@ @LZO2_LIBS_STATIC@ -L. -pthread
59 # don't use FORTIFY with sparse because glibc with FORTIFY can
60 # generate so many sparse errors that sparse stops parsing,
61 # which masks real errors that we want to see.
62 CHECKER := sparse
63 check_defs := .cc-defines.h
64 CHECKER_FLAGS := -include $(check_defs) -D__CHECKER__ \
65 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef \
66 -U_FORTIFY_SOURCE
68 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
69 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
70 extent-cache.o extent_io.o volumes.o utils.o repair.o \
71 qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
72 ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
73 inode.o file.o find-root.o free-space-tree.o help.o
74 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
75 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
76 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
77 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
78 cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
79 cmds-inspect-dump-super.o cmds-inspect-tree-stats.o cmds-fi-du.o
80 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
81 uuid-tree.o utils-lib.o rbtree-utils.o
82 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
83 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
84 extent_io.h ioctl.h ctree.h btrfsck.h version.h
85 TESTS = fsck-tests.sh convert-tests.sh
87 prefix ?= @prefix@
88 exec_prefix = @exec_prefix@
89 bindir = @bindir@
90 libdir ?= @libdir@
91 incdir = @includedir@/btrfs
93 ifeq ("$(origin V)", "command line")
94 BUILD_VERBOSE = $(V)
95 endif
96 ifndef BUILD_VERBOSE
97 BUILD_VERBOSE = 0
98 endif
100 ifeq ($(BUILD_VERBOSE),1)
102 else
103 Q = @
104 endif
106 MAKEOPTS = --no-print-directory Q=$(Q)
108 # build all by default
109 progs = $(progs_install) btrfsck btrfs-corrupt-block btrfs-calc-size
111 # install only selected
112 progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
113 btrfs-map-logical btrfs-image btrfs-zero-log \
114 btrfs-find-root btrfstune btrfs-show-super \
115 btrfs-select-super
117 progs_extra = btrfs-fragments
119 progs_static = $(foreach p,$(progs),$(p).static)
121 ifneq ($(DISABLE_BTRFSCONVERT),1)
122 progs_install += btrfs-convert
123 endif
125 # external libs required by various binaries; for btrfs-foo,
126 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
127 btrfs_convert_libs = @EXT2FS_LIBS@ @COM_ERR_LIBS@
128 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
129 btrfs_debug_tree_objects = cmds-inspect-dump-tree.o
130 btrfs_show_super_objects = cmds-inspect-dump-super.o
131 btrfs_calc_size_objects = cmds-inspect-tree-stats.o
133 # collect values of the variables above
134 standalone_deps = $(foreach dep,$(patsubst %,%_objects,$(subst -,_,$(filter btrfs-%, $(progs)))),$($(dep)))
136 SUBDIRS =
137 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
138 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
139 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
141 ifneq ($(DISABLE_DOCUMENTATION),1)
142 BUILDDIRS += build-Documentation
143 INSTALLDIRS += install-Documentation
144 endif
146 .PHONY: $(SUBDIRS)
147 .PHONY: $(BUILDDIRS)
148 .PHONY: $(INSTALLDIRS)
149 .PHONY: $(TESTDIRS)
150 .PHONY: $(CLEANDIRS)
151 .PHONY: all install clean
153 # Create all the static targets
154 static_objects = $(patsubst %.o, %.static.o, $(objects))
155 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
156 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
158 libs_shared = libbtrfs.so.0.1
159 libs_static = libbtrfs.a
160 libs = $(libs_shared) $(libs_static)
161 lib_links = libbtrfs.so.0 libbtrfs.so
162 headers = $(libbtrfs_headers)
164 # make C=1 to enable sparse
165 ifdef C
166 # We're trying to use sparse against glibc headers which go wild
167 # trying to use internal compiler macros to test features. We
168 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
169 # 'cause sparse defines that one.
171 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
172 grep -v __SIZE_TYPE__ > $(check_defs))
173 check = $(CHECKER)
174 check_echo = echo
175 else
176 check = true
177 check_echo = true
178 endif
180 %.o.d: %.c
181 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
183 .c.o:
184 @$(check_echo) " [SP] $<"
185 $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
186 @echo " [CC] $@"
187 $(Q)$(CC) $(CFLAGS) -c $<
189 %.static.o: %.c
190 @echo " [CC] $@"
191 $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
193 all: $(progs) $(BUILDDIRS)
194 $(SUBDIRS): $(BUILDDIRS)
195 $(BUILDDIRS):
196 @echo "Making all in $(patsubst build-%,%,$@)"
197 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
199 test-convert: btrfs btrfs-convert
200 @echo " [TEST] convert-tests.sh"
201 $(Q)bash tests/convert-tests.sh
203 test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
204 @echo " [TEST] fsck-tests.sh"
205 $(Q)bash tests/fsck-tests.sh
207 test-misc: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
208 @echo " [TEST] misc-tests.sh"
209 $(Q)bash tests/misc-tests.sh
211 test-mkfs: btrfs mkfs.btrfs
212 @echo " [TEST] mkfs-tests.sh"
213 $(Q)bash tests/mkfs-tests.sh
215 test-fuzz: btrfs
216 @echo " [TEST] fuzz-tests.sh"
217 $(Q)bash tests/fuzz-tests.sh
219 test-cli: btrfs
220 @echo " [TEST] cli-tests.sh"
221 $(Q)bash tests/cli-tests.sh
223 test-clean:
224 @echo "Cleaning tests"
225 $(Q)bash tests/clean-tests.sh
227 test: test-fsck test-mkfs test-convert test-misc test-fuzz
230 # NOTE: For static compiles, you need to have all the required libs
231 # static equivalent available
233 static: $(progs_static)
235 version.h: version.sh version.h.in configure.ac
236 @echo " [SH] $@"
237 $(Q)bash ./config.status --silent $@
239 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
240 @echo " [LD] $@"
241 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
242 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
244 $(libs_static): $(libbtrfs_objects)
245 @echo " [AR] $@"
246 $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
248 $(lib_links):
249 @echo " [LN] $@"
250 $(Q)$(LN_S) -f libbtrfs.so.0.1 $@
252 # keep intermediate files from the below implicit rules around
253 .PRECIOUS: $(addsuffix .o,$(progs))
255 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
256 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
257 # turns them into a list of libraries to link against if they exist
259 # For static variants, use an extra $(subst) to get rid of the ".static"
260 # from the target name before translating to list of libs
262 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects) $(patsubst %.o,%.static.o,$(standalone_deps))
263 @echo " [LD] $@"
264 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
265 $(patsubst %.o, %.static.o, $($(subst -,_,$(subst .static,,$@)-objects))) \
266 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
267 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
269 btrfs-%: $(objects) $(libs_static) btrfs-%.o $(standalone_deps)
270 @echo " [LD] $@"
271 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o \
272 $($(subst -,_,$@-objects)) \
273 $(libs_static) \
274 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
276 btrfs: $(objects) btrfs.o $(cmds_objects) $(libs_static)
277 @echo " [LD] $@"
278 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o $(cmds_objects) \
279 $(objects) $(libs_static) $(LDFLAGS) $(LIBS)
281 btrfs.static: $(static_objects) btrfs.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
282 @echo " [LD] $@"
283 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o $(static_cmds_objects) \
284 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
286 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
287 btrfsck: btrfs
288 @echo " [LN] $@"
289 $(Q)$(LN_S) -f btrfs btrfsck
291 btrfsck.static: btrfs.static
292 @echo " [LN] $@"
293 $(Q)$(LN_S) -f $^ $@
295 mkfs.btrfs: $(objects) $(libs_static) mkfs.o
296 @echo " [LD] $@"
297 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) $(libs_static) mkfs.o $(LDFLAGS) $(LIBS)
299 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
300 @echo " [LD] $@"
301 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
302 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
304 btrfstune: $(objects) $(libs_static) btrfstune.o
305 @echo " [LD] $@"
306 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(libs_static) $(LDFLAGS) $(LIBS)
308 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
309 @echo " [LD] $@"
310 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
311 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
313 dir-test: $(objects) $(libs) dir-test.o
314 @echo " [LD] $@"
315 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
317 quick-test: $(objects) $(libs) quick-test.o
318 @echo " [LD] $@"
319 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
321 ioctl-test: $(objects) $(libs) ioctl-test.o
322 @echo " [LD] $@"
323 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
325 send-test: $(objects) $(libs) send-test.o
326 @echo " [LD] $@"
327 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
329 library-test: $(libs_shared) library-test.o
330 @echo " [LD] $@"
331 $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
333 library-test.static: $(libs_static) library-test.o
334 @echo " [LD] $@"
335 $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
337 test-build: test-build-pre test-build-real
339 test-build-pre:
340 $(MAKE) clean-all
341 ./autogen.sh
342 ./configure
344 test-build-real:
345 $(MAKE) library-test
346 -$(MAKE) library-test.static
347 $(MAKE) -j 8 all
348 -$(MAKE) -j 8 static
349 $(MAKE) -j 8 $(progs_extra)
351 manpages:
352 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
355 clean-all: clean clean-doc clean-gen
357 clean: $(CLEANDIRS)
358 @echo "Cleaning"
359 $(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
360 dir-test ioctl-test quick-test send-test library-test library-test-static \
361 btrfs.static mkfs.btrfs.static \
362 $(check_defs) \
363 $(libs) $(lib_links) \
364 $(progs_static) $(progs_extra)
366 clean-doc:
367 @echo "Cleaning Documentation"
368 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
370 clean-gen:
371 @echo "Cleaning Generated Files"
372 $(Q)$(RM) -rf version.h config.status config.cache connfig.log \
373 configure.lineno config.status.lineno Makefile \
374 Documentation/Makefile \
375 config.log config.h config.h.in~ aclocal.m4 \
376 configure autom4te.cache/ config/
378 $(CLEANDIRS):
379 @echo "Cleaning $(patsubst clean-%,%,$@)"
380 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
382 install: $(libs) $(progs_install) $(INSTALLDIRS)
383 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
384 $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
385 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
386 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
387 $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
388 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
389 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
390 cp -a $(lib_links) $(DESTDIR)$(libdir)
391 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
392 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
394 install-static: $(progs_static) $(INSTALLDIRS)
395 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
396 $(INSTALL) $(progs_static) $(DESTDIR)$(bindir)
397 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
398 $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
400 $(INSTALLDIRS):
401 @echo "Making install in $(patsubst install-%,%,$@)"
402 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
404 uninstall:
405 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
406 cd $(DESTDIR)$(incdir); $(RM) -f $(headers)
407 $(RMDIR) -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
408 cd $(DESTDIR)$(libdir); $(RM) -f $(lib_links) $(libs)
409 cd $(DESTDIR)$(bindir); $(RM) -f btrfsck fsck.btrfs $(progs_install)
411 ifneq ($(MAKECMDGOALS),clean)
412 -include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
413 endif