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
18 # Export all variables to sub-makes by default
21 include Makefile.extrawarn
29 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
30 DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
38 -DBTRFS_FLAT_INCLUDES \
40 -fno-strict-aliasing \
41 -fPIC $(KBUILD_CFLAGS) $(EXTRA_CFLAGS)
44 -rdynamic $(EXTRA_LDFLAGS)
46 LIBS = @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@ -L. -pthread
47 LIBBTRFS_LIBS = $(LIBS)
49 # Static compilation flags
50 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
51 STATIC_LDFLAGS = -static -Wl,--gc-sections
52 STATIC_LIBS = @UUID_LIBS_STATIC@ @BLKID_LIBS_STATIC@ \
53 @ZLIB_LIBS_STATIC@ @LZO2_LIBS_STATIC@ -L. -pthread
55 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
56 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
57 extent-cache.o extent_io.o volumes.o utils.o repair.o \
58 qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
59 ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
60 inode.o file.o find-root.o
61 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
62 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
63 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
64 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
65 cmds-property.o cmds-fi-usage.o
66 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
67 uuid-tree.o utils-lib.o rbtree-utils.o
68 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
69 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
70 extent_io.h ioctl.h ctree.h btrfsck.h version.h
71 TESTS = fsck-tests.sh convert-tests.sh
74 exec_prefix = @exec_prefix@
77 incdir = @includedir@/btrfs
79 ifeq ("$(origin V)", "command line")
86 ifeq ($(BUILD_VERBOSE),1)
92 MAKEOPTS = --no-print-directory Q=$(Q)
94 # build all by default
95 progs = $(progs_install) btrfsck btrfs-corrupt-block btrfs-calc-size
97 # install only selected
98 progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
99 btrfs-map-logical btrfs-image btrfs-zero-log \
100 btrfs-find-root btrfstune btrfs-show-super \
103 progs_extra = btrfs-fragments
105 progs_static = $(foreach p,$(progs),$(p).static)
107 ifneq ($(DISABLE_BTRFSCONVERT),1)
108 progs_install += btrfs-convert
111 # external libs required by various binaries; for btrfs-foo,
112 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
113 btrfs_convert_libs = @EXT2FS_LIBS@ @COM_ERR_LIBS@
114 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
117 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
118 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
119 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
121 ifneq ($(DISABLE_DOCUMENTATION),1)
122 BUILDDIRS += build-Documentation
123 INSTALLDIRS += install-Documentation
128 .PHONY: $(INSTALLDIRS)
131 .PHONY: all install clean
133 # Create all the static targets
134 static_objects = $(patsubst %.o, %.static.o, $(objects))
135 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
136 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
138 libs_shared = libbtrfs.so.0.1
139 libs_static = libbtrfs.a
140 libs = $(libs_shared) $(libs_static)
141 lib_links = libbtrfs.so.0 libbtrfs.so
142 headers = $(libbtrfs_headers)
144 # make C=1 to enable sparse
145 check_defs := .cc-defines.h
148 # We're trying to use sparse against glibc headers which go wild
149 # trying to use internal compiler macros to test features. We
150 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
151 # 'cause sparse defines that one.
153 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
154 grep -v __SIZE_TYPE__ > $(check_defs))
155 check = sparse -include $(check_defs) -D__CHECKER__ \
156 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef
158 # don't use FORTIFY with sparse because glibc with FORTIFY can
159 # generate so many sparse errors that sparse stops parsing,
160 # which masks real errors that we want to see.
161 CFLAGS += -U_FORTIFY_SOURCE
168 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
171 @$(check_echo) " [SP] $<"
172 $(Q)$(check) $(CFLAGS) $<
174 $(Q)$(CC) $(CFLAGS) -c $<
178 $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
180 all: $(progs) $(BUILDDIRS)
181 $(SUBDIRS): $(BUILDDIRS)
183 @echo "Making all in $(patsubst build-%,%,$@)"
184 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
186 test-convert: btrfs btrfs-convert
187 @echo " [TEST] convert-tests.sh"
188 $(Q)bash tests/convert-tests.sh
190 test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
191 @echo " [TEST] fsck-tests.sh"
192 $(Q)bash tests/fsck-tests.sh
194 test-misc: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
195 @echo " [TEST] misc-tests.sh"
196 $(Q)bash tests/misc-tests.sh
199 @echo "Cleaning tests"
200 $(Q)bash tests/clean-tests.sh
202 test: test-fsck test-convert test-misc
205 # NOTE: For static compiles, you need to have all the required libs
206 # static equivalent available
208 static: $(progs_static)
210 version.h: version.sh version.h.in configure.ac
212 $(Q)bash ./config.status --silent $@
214 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
216 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
217 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
219 $(libs_static): $(libbtrfs_objects)
221 $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
225 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so.0
226 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so
228 # keep intermediate files from the below implicit rules around
229 .PRECIOUS: $(addsuffix .o,$(progs))
231 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
232 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
233 # turns them into a list of libraries to link against if they exist
235 # For static variants, use an extra $(subst) to get rid of the ".static"
236 # from the target name before translating to list of libs
238 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
240 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
241 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
242 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
244 btrfs-%: $(objects) $(libs_static) btrfs-%.o
246 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(libs_static) \
247 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
249 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs_static)
251 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
252 $(objects) $(libs_static) $(LDFLAGS) $(LIBS)
254 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
256 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
257 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
259 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
262 $(Q)$(LN_S) -f btrfs btrfsck
264 btrfsck.static: btrfs.static
268 mkfs.btrfs: $(objects) $(libs_static) mkfs.o
270 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) $(libs_static) mkfs.o $(LDFLAGS) $(LIBS)
272 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
274 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
275 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
277 btrfstune: $(objects) $(libs_static) btrfstune.o
279 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(libs_static) $(LDFLAGS) $(LIBS)
281 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
283 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
284 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
286 dir-test: $(objects) $(libs) dir-test.o
288 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
290 quick-test: $(objects) $(libs) quick-test.o
292 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
294 ioctl-test: $(objects) $(libs) ioctl-test.o
296 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
298 send-test: $(objects) $(libs) send-test.o
300 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
302 library-test: $(libs_shared) library-test.o
304 $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
306 library-test.static: $(libs_static) library-test.o
308 $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
310 test-build: test-build-pre test-build-real
319 -$(MAKE) library-test.static
322 $(MAKE) -j 8 $(progs_extra)
325 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
328 clean-all: clean clean-doc clean-gen
332 $(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
333 dir-test ioctl-test quick-test send-test library-test library-test-static \
334 btrfs.static mkfs.btrfs.static \
336 $(libs) $(lib_links) \
337 $(progs_static) $(progs_extra)
340 @echo "Cleaning Documentation"
341 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
344 @echo "Cleaning Generated Files"
345 $(Q)$(RM) -rf version.h config.status config.cache connfig.log \
346 configure.lineno config.status.lineno Makefile \
347 Documentation/Makefile \
348 config.log config.h config.h.in~ aclocal.m4 \
349 configure autom4te.cache/ config/
352 @echo "Cleaning $(patsubst clean-%,%,$@)"
353 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
355 install: $(libs) $(progs_install) $(INSTALLDIRS)
356 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
357 $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
358 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
359 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
360 $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
361 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
362 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
363 cp -a $(lib_links) $(DESTDIR)$(libdir)
364 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
365 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
367 install-static: $(progs_static) $(INSTALLDIRS)
368 for p in $(progs_static) ; do \
369 $(INSTALL) -D -m755 $$p $(DESTDIR)$(bindir)/ ; \
371 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
372 $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
375 @echo "Making install in $(patsubst install-%,%,$@)"
376 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
379 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
380 cd $(DESTDIR)$(incdir); $(RM) -f $(headers)
381 $(RMDIR) -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
382 cd $(DESTDIR)$(libdir); $(RM) -f $(lib_links) $(libs)
383 cd $(DESTDIR)$(bindir); $(RM) -f btrfsck fsck.btrfs $(progs_install)
385 ifneq ($(MAKECMDGOALS),clean)
386 -include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))