1 # Export all variables to sub-makes by default
10 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
11 DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
19 -DBTRFS_FLAT_INCLUDES \
21 -fno-strict-aliasing \
25 -rdynamic $(EXTRA_LDFLAGS)
27 LIBS = @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@ -L. -pthread
28 LIBBTRFS_LIBS = $(LIBS)
30 # Static compilation flags
31 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
32 STATIC_LDFLAGS = -static -Wl,--gc-sections
33 STATIC_LIBS = @UUID_LIBS_STATIC@ @BLKID_LIBS_STATIC@ \
34 @ZLIB_LIBS_STATIC@ @LZO2_LIBS_STATIC@ -L. -pthread
36 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
37 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
38 extent-cache.o extent_io.o volumes.o utils.o repair.o \
39 qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
40 ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
41 inode.o file.o find-root.o
42 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
43 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
44 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
45 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
46 cmds-property.o cmds-fi-usage.o
47 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
48 uuid-tree.o utils-lib.o rbtree-utils.o
49 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
50 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
51 extent_io.h ioctl.h ctree.h btrfsck.h version.h
52 TESTS = fsck-tests.sh convert-tests.sh
55 exec_prefix = @exec_prefix@
58 incdir = @includedir@/btrfs
60 ifeq ("$(origin V)", "command line")
67 ifeq ($(BUILD_VERBOSE),1)
73 MAKEOPTS = --no-print-directory Q=$(Q)
75 # build all by default
76 progs = $(progs_install) btrfsck btrfs-corrupt-block btrfs-calc-size
78 # install only selected
79 progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
80 btrfs-map-logical btrfs-image btrfs-zero-log \
81 btrfs-find-root btrfstune btrfs-show-super \
84 progs_extra = btrfs-fragments
86 progs_static = $(foreach p,$(progs),$(p).static)
88 ifneq ($(DISABLE_BTRFSCONVERT),1)
89 progs_install += btrfs-convert
92 # external libs required by various binaries; for btrfs-foo,
93 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
94 btrfs_convert_libs = @EXT2FS_LIBS@ @COM_ERR_LIBS@
95 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
98 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
99 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
100 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
102 ifneq ($(DISABLE_DOCUMENTATION),1)
103 BUILDDIRS += build-Documentation
104 INSTALLDIRS += install-Documentation
109 .PHONY: $(INSTALLDIRS)
112 .PHONY: all install clean
114 # Create all the static targets
115 static_objects = $(patsubst %.o, %.static.o, $(objects))
116 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
117 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
119 libs_shared = libbtrfs.so.0.1
120 libs_static = libbtrfs.a
121 libs = $(libs_shared) $(libs_static)
122 lib_links = libbtrfs.so.0 libbtrfs.so
123 headers = $(libbtrfs_headers)
125 # make C=1 to enable sparse
126 check_defs := .cc-defines.h
129 # We're trying to use sparse against glibc headers which go wild
130 # trying to use internal compiler macros to test features. We
131 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
132 # 'cause sparse defines that one.
134 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
135 grep -v __SIZE_TYPE__ > $(check_defs))
136 check = sparse -include $(check_defs) -D__CHECKER__ \
137 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef
139 # don't use FORTIFY with sparse because glibc with FORTIFY can
140 # generate so many sparse errors that sparse stops parsing,
141 # which masks real errors that we want to see.
142 CFLAGS += -U_FORTIFY_SOURCE
149 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
152 @$(check_echo) " [SP] $<"
153 $(Q)$(check) $(CFLAGS) $<
155 $(Q)$(CC) $(CFLAGS) -c $<
159 $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
161 all: $(progs) $(BUILDDIRS)
162 $(SUBDIRS): $(BUILDDIRS)
164 @echo "Making all in $(patsubst build-%,%,$@)"
165 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
167 test-convert: btrfs btrfs-convert
168 @echo " [TEST] convert-tests.sh"
169 $(Q)bash tests/convert-tests.sh
171 test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
172 @echo " [TEST] fsck-tests.sh"
173 $(Q)bash tests/fsck-tests.sh
175 test-misc: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
176 @echo " [TEST] misc-tests.sh"
177 $(Q)bash tests/misc-tests.sh
180 @echo "Cleaning tests"
181 $(Q)bash tests/clean-tests.sh
183 test: test-fsck test-convert test-misc
186 # NOTE: For static compiles, you need to have all the required libs
187 # static equivalent available
189 static: $(progs_static)
191 version.h: version.sh version.h.in configure.ac
193 $(Q)bash ./config.status --silent $@
195 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
197 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
198 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
200 $(libs_static): $(libbtrfs_objects)
202 $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
206 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so.0
207 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so
209 # keep intermediate files from the below implicit rules around
210 .PRECIOUS: $(addsuffix .o,$(progs))
212 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
213 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
214 # turns them into a list of libraries to link against if they exist
216 # For static variants, use an extra $(subst) to get rid of the ".static"
217 # from the target name before translating to list of libs
219 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
221 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
222 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
223 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
225 btrfs-%: $(objects) $(libs_static) btrfs-%.o
227 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(libs_static) \
228 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
230 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs_static)
232 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
233 $(objects) $(libs_static) $(LDFLAGS) $(LIBS)
235 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
237 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
238 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
240 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
243 $(Q)$(LN_S) -f btrfs btrfsck
245 btrfsck.static: btrfs.static
249 mkfs.btrfs: $(objects) $(libs_static) mkfs.o
251 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) $(libs_static) mkfs.o $(LDFLAGS) $(LIBS)
253 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
255 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
256 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
258 btrfstune: $(objects) $(libs_static) btrfstune.o
260 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(libs_static) $(LDFLAGS) $(LIBS)
262 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
264 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
265 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
267 dir-test: $(objects) $(libs) dir-test.o
269 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
271 quick-test: $(objects) $(libs) quick-test.o
273 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
275 ioctl-test: $(objects) $(libs) ioctl-test.o
277 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
279 send-test: $(objects) $(libs) send-test.o
281 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
283 library-test: $(libs_shared) library-test.o
285 $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
287 library-test.static: $(libs_static) library-test.o
289 $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
291 test-build: test-build-pre test-build-real
300 -$(MAKE) library-test.static
303 $(MAKE) -j 8 $(progs_extra)
306 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
309 clean-all: clean clean-doc clean-gen
313 $(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
314 dir-test ioctl-test quick-test send-test library-test library-test-static \
315 btrfs.static mkfs.btrfs.static \
317 $(libs) $(lib_links) \
318 $(progs_static) $(progs_extra)
321 @echo "Cleaning Documentation"
322 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
325 @echo "Cleaning Generated Files"
326 $(Q)$(RM) -rf version.h config.status config.cache connfig.log \
327 configure.lineno config.status.lineno Makefile \
328 Documentation/Makefile \
329 config.log config.h config.h.in~ aclocal.m4 \
330 configure autom4te.cache/ config/
333 @echo "Cleaning $(patsubst clean-%,%,$@)"
334 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
336 install: $(libs) $(progs_install) $(INSTALLDIRS)
337 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
338 $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
339 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
340 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
341 $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
342 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
343 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
344 cp -a $(lib_links) $(DESTDIR)$(libdir)
345 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
346 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
348 install-static: $(progs_static) $(INSTALLDIRS)
349 for p in $(progs_static) ; do \
350 $(INSTALL) -D -m755 $$p $(DESTDIR)$(bindir)/ ; \
352 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
353 $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
356 @echo "Making install in $(patsubst install-%,%,$@)"
357 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
360 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
361 cd $(DESTDIR)$(incdir); $(RM) -f $(headers)
362 $(RMDIR) -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
363 cd $(DESTDIR)$(libdir); $(RM) -f $(lib_links) $(libs)
364 cd $(DESTDIR)$(bindir); $(RM) -f btrfsck fsck.btrfs $(progs_install)
366 ifneq ($(MAKECMDGOALS),clean)
367 -include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))