1 # Export all variables to sub-makes by default
10 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
12 # Non-static compilation flags
14 -include config.h -Wall \
15 -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES \
17 -fno-strict-aliasing -fPIC \
22 LIBS = @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@ -L. -pthread
23 LIBBTRFS_LIBS = $(LIBS)
25 # Static compilation flags
26 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
27 STATIC_LDFLAGS = -static -Wl,--gc-sections
28 STATIC_LIBS = @UUID_LIBS_STATIC@ @BLKID_LIBS_STATIC@ \
29 @ZLIB_LIBS_STATIC@ @LZO2_LIBS_STATIC@ -L. -pthread
31 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
32 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
33 extent-cache.o extent_io.o volumes.o utils.o repair.o \
34 qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
35 ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
37 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
38 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
39 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
40 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
41 cmds-property.o cmds-fi-disk_usage.o
42 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
43 uuid-tree.o utils-lib.o rbtree-utils.o
44 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
45 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
46 extent_io.h ioctl.h ctree.h btrfsck.h version.h
47 TESTS = fsck-tests.sh convert-tests.sh
52 incdir = @includedir@/btrfs
54 ifeq ("$(origin V)", "command line")
61 ifeq ($(BUILD_VERBOSE),1)
67 MAKEOPTS = --no-print-directory Q=$(Q)
69 progs = mkfs.btrfs btrfs-debug-tree btrfsck \
70 btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
71 btrfs-find-root btrfstune btrfs-show-super \
72 btrfs-corrupt-block btrfs-select-super btrfs-calc-size
74 progs_extra = btrfs-fragments
76 progs_static = $(foreach p,$(progs),$(p).static)
78 # external libs required by various binaries; for btrfs-foo,
79 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
80 btrfs_convert_libs = -lext2fs -lcom_err
81 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
84 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
85 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
86 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
88 ifneq ($(DISABLE_DOCUMENTATION),1)
89 BUILDDIRS += build-Documentation
90 INSTALLDIRS += install-Documentation
95 .PHONY: $(INSTALLDIRS)
98 .PHONY: all install clean
100 # Create all the static targets
101 static_objects = $(patsubst %.o, %.static.o, $(objects))
102 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
103 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
105 libs_shared = libbtrfs.so.0.1
106 libs_static = libbtrfs.a
107 libs = $(libs_shared) $(libs_static)
108 lib_links = libbtrfs.so.0 libbtrfs.so
109 headers = $(libbtrfs_headers)
111 # make C=1 to enable sparse
112 check_defs := .cc-defines.h
115 # We're trying to use sparse against glibc headers which go wild
116 # trying to use internal compiler macros to test features. We
117 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
118 # 'cause sparse defines that one.
120 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
121 grep -v __SIZE_TYPE__ > $(check_defs))
122 check = sparse -include $(check_defs) -D__CHECKER__ \
123 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef
125 # don't use FORTIFY with sparse because glibc with FORTIFY can
126 # generate so many sparse errors that sparse stops parsing,
127 # which masks real errors that we want to see.
131 CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
135 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
138 @$(check_echo) " [SP] $<"
139 $(Q)$(check) $(CFLAGS) $<
141 $(Q)$(CC) $(CFLAGS) -c $<
145 $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
147 all: $(progs) $(BUILDDIRS)
148 $(SUBDIRS): $(BUILDDIRS)
150 @echo "Making all in $(patsubst build-%,%,$@)"
151 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
153 test: btrfs btrfs-convert btrfs-image btrfs-corrupt-block
154 $(Q)for t in $(TESTS); do \
155 echo " [TEST] $$t"; \
156 bash tests/$$t || exit 1; \
160 # NOTE: For static compiles, you need to have all the required libs
161 # static equivalent available
163 static: $(progs_static)
165 version.h: version.sh version.h.in configure.ac
167 $(Q)bash ./config.status --silent $@
169 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
171 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
172 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
174 $(libs_static): $(libbtrfs_objects)
176 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
180 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so.0
181 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so
183 # keep intermediate files from the below implicit rules around
184 .PRECIOUS: $(addsuffix .o,$(progs))
186 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
187 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
188 # turns them into a list of libraries to link against if they exist
190 # For static variants, use an extra $(subst) to get rid of the ".static"
191 # from the target name before translating to list of libs
193 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
195 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
196 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
197 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
199 btrfs-%: $(objects) $(libs) btrfs-%.o
201 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(libs) \
202 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
204 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
206 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
207 $(objects) $(libs) $(LDFLAGS) $(LIBS)
209 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
211 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
212 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
214 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
217 $(Q)$(LN_S) -f btrfs btrfsck
219 btrfsck.static: btrfs.static
223 mkfs.btrfs: $(objects) $(libs) mkfs.o
225 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) $(libs) mkfs.o $(LDFLAGS) $(LIBS)
227 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
229 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
230 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
232 btrfstune: $(objects) $(libs) btrfstune.o
234 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) $(libs) btrfstune.o $(LDFLAGS) $(LIBS)
236 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
238 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
239 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
241 dir-test: $(objects) $(libs) dir-test.o
243 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
245 quick-test: $(objects) $(libs) quick-test.o
247 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
249 ioctl-test: $(objects) $(libs) ioctl-test.o
251 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
253 send-test: $(objects) $(libs) send-test.o
255 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
257 library-test: $(libs_shared) library-test.o
259 $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
261 library-test.static: $(libs_static) library-test.o
263 $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
265 test-build: test-build-pre test-build-real
274 -$(MAKE) library-test.static
277 $(MAKE) -j 8 $(progs_extra)
280 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
283 clean-all: clean clean-doc clean-gen
287 $(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
288 dir-test ioctl-test quick-test send-test library-test library-test-static \
289 btrfs.static mkfs.btrfs.static \
291 $(libs) $(lib_links) \
292 $(progs_static) $(progs_extra)
295 @echo "Cleaning Documentation"
296 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
299 @echo "Cleaning Generated Files"
300 $(Q)$(RM) -rf version.h config.status config.cache connfig.log \
301 configure.lineno config.status.lineno Makefile \
302 Documentation/Makefile \
303 config.log config.h config.h.in~ aclocal.m4 \
304 configure autom4te.cache/ config/
307 @echo "Cleaning $(patsubst clean-%,%,$@)"
308 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
310 install: $(libs) $(progs) $(INSTALLDIRS)
311 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
312 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
313 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
314 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
315 $(LN_S) -f $(DESTDIR)$(bindir)/btrfs $(DESTDIR)$(bindir)/btrfsck
316 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
317 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
318 cp -a $(lib_links) $(DESTDIR)$(libdir)
319 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
320 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
322 install-static: $(progs_static) $(INSTALLDIRS)
323 for p in $(progs_static) ; do \
324 $(INSTALL) -D -m755 $$p $(DESTDIR)$(bindir)/`basename $$p .static` ; \
328 @echo "Making install in $(patsubst install-%,%,$@)"
329 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
332 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
333 cd $(DESTDIR)$(incdir); $(RM) -f $(headers)
334 $(RMDIR) -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
335 cd $(DESTDIR)$(libdir); $(RM) -f $(lib_links) $(libs)
336 cd $(DESTDIR)$(bindir); $(RM) -f btrfsck fsck.btrfs $(progs)
338 ifneq ($(MAKECMDGOALS),clean)
339 -include $(objects:.o=.o.d) $(cmd-objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))