1 # Export all variables to sub-makes by default
7 AM_CFLAGS = -include config.h -Wall \
8 -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES \
10 -fno-strict-aliasing -fPIC
11 CFLAGS = -g -O1 -fno-strict-aliasing -rdynamic
12 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
13 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
14 extent-cache.o extent_io.o volumes.o utils.o repair.o \
15 qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
16 ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
18 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
19 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
20 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
21 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
22 cmds-property.o cmds-fi-disk_usage.o
23 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
24 uuid-tree.o utils-lib.o rbtree-utils.o
25 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
26 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
27 extent_io.h ioctl.h ctree.h btrfsck.h version.h
28 TESTS = fsck-tests.sh convert-tests.sh
32 lib_LIBS = @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@ -L. -pthread
34 incdir = @includedir@/btrfs
35 LIBS = $(lib_LIBS) $(libs_static)
37 ifeq ("$(origin V)", "command line")
44 ifeq ($(BUILD_VERBOSE),1)
50 MAKEOPTS = --no-print-directory Q=$(Q)
52 progs = mkfs.btrfs btrfs-debug-tree btrfsck \
53 btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
54 btrfs-find-root btrfstune btrfs-show-super
56 progs_extra = btrfs-corrupt-block btrfs-fragments btrfs-calc-size \
59 progs_static = $(foreach p,$(progs),$(p).static)
61 # external libs required by various binaries; for btrfs-foo,
62 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
63 btrfs_convert_libs = -lext2fs -lcom_err
64 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
67 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
68 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
69 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
71 ifeq ($(DISABLE_BACKTRACE),1)
72 AM_CFLAGS += -DBTRFS_DISABLE_BACKTRACE
75 ifneq ($(DISABLE_DOCUMENTATION),1)
76 BUILDDIRS += build-Documentation
77 INSTALLDIRS += install-Documentation
82 .PHONY: $(INSTALLDIRS)
85 .PHONY: all install clean
87 # Create all the static targets
88 static_objects = $(patsubst %.o, %.static.o, $(objects))
89 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
90 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
92 # Define static compilation flags
93 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
94 STATIC_LDFLAGS = -static -Wl,--gc-sections
95 STATIC_LIBS = $(lib_LIBS)
97 libs_shared = libbtrfs.so.0.1
98 libs_static = libbtrfs.a
99 libs = $(libs_shared) $(libs_static)
100 lib_links = libbtrfs.so.0 libbtrfs.so
101 headers = $(libbtrfs_headers)
103 # make C=1 to enable sparse
104 check_defs := .cc-defines.h
107 # We're trying to use sparse against glibc headers which go wild
108 # trying to use internal compiler macros to test features. We
109 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
110 # 'cause sparse defines that one.
112 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
113 grep -v __SIZE_TYPE__ > $(check_defs))
114 check = sparse -include $(check_defs) -D__CHECKER__ \
115 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef
117 # don't use FORTIFY with sparse because glibc with FORTIFY can
118 # generate so many sparse errors that sparse stops parsing,
119 # which masks real errors that we want to see.
123 AM_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
127 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(AM_CFLAGS) $(CFLAGS) $<
130 @$(check_echo) " [SP] $<"
131 $(Q)$(check) $(AM_CFLAGS) $(CFLAGS) $<
133 $(Q)$(CC) $(AM_CFLAGS) $(CFLAGS) -c $<
137 $(Q)$(CC) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
139 all: $(progs) $(BUILDDIRS)
140 $(SUBDIRS): $(BUILDDIRS)
142 @echo "Making all in $(patsubst build-%,%,$@)"
143 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
145 test: btrfs btrfs-convert btrfs-image btrfs-corrupt-block
146 $(Q)for t in $(TESTS); do \
147 echo " [TEST] $$t"; \
148 bash tests/$$t || exit 1; \
152 # NOTE: For static compiles, you need to have all the required libs
153 # static equivalent available
155 static: $(progs_static)
157 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
159 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(lib_LIBS) \
160 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
162 $(libs_static): $(libbtrfs_objects)
164 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
168 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so.0
169 $(Q)$(LN_S) -f libbtrfs.so.0.1 libbtrfs.so
171 # keep intermediate files from the below implicit rules around
172 .PRECIOUS: $(addsuffix .o,$(progs))
174 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
175 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
176 # turns them into a list of libraries to link against if they exist
178 # For static variants, use an extra $(subst) to get rid of the ".static"
179 # from the target name before translating to list of libs
181 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
183 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
184 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
185 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
187 btrfs-%: $(objects) $(libs) btrfs-%.o
189 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
191 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
193 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
194 $(objects) $(LDFLAGS) $(LIBS)
196 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
198 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
199 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
201 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
204 $(Q)$(LN) -f btrfs btrfsck
206 btrfsck.static: btrfs.static
210 mkfs.btrfs: $(objects) $(libs) mkfs.o
212 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
214 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
216 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
217 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
219 btrfstune: $(objects) $(libs) btrfstune.o
221 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
223 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
225 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
226 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
228 dir-test: $(objects) $(libs) dir-test.o
230 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
232 quick-test: $(objects) $(libs) quick-test.o
234 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
236 ioctl-test: $(objects) $(libs) ioctl-test.o
238 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
240 send-test: $(objects) $(libs) send-test.o
242 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS)
244 library-test: $(libs_shared) library-test.o
246 $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
248 library-test.static: $(libs_static) library-test.o
250 $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
255 -$(MAKE) library-test.static
258 $(MAKE) -j 8 $(progs_extra)
261 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
263 clean-all: clean-doc clean
267 $(Q)rm -f $(progs) cscope.out *.o *.o.d \
268 dir-test ioctl-test quick-test send-test library-test library-test-static \
269 btrfs.static mkfs.btrfs.static \
270 version.h $(check_defs) \
271 $(libs) $(lib_links) \
272 $(progs_static) $(progs_extra)
275 @echo "Cleaning Documentation"
276 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
279 @echo "Cleaning $(patsubst clean-%,%,$@)"
280 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
282 install: $(libs) $(progs) $(INSTALLDIRS)
283 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
284 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
285 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
286 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
287 $(LN) -f $(DESTDIR)$(bindir)/btrfs $(DESTDIR)$(bindir)/btrfsck
288 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
289 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
290 cp -a $(lib_links) $(DESTDIR)$(libdir)
291 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
292 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
294 install-static: $(progs_static) $(INSTALLDIRS)
295 for p in $(progs_static) ; do \
296 $(INSTALL) -D -m755 $$p $(DESTDIR)$(bindir)/`basename $$p .static` ; \
300 @echo "Making install in $(patsubst install-%,%,$@)"
301 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
304 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
305 cd $(DESTDIR)$(incdir); rm -f $(headers)
306 rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
307 cd $(DESTDIR)$(libdir); rm -f $(lib_links) $(libs)
308 cd $(DESTDIR)$(bindir); rm -f btrfsck fsck.btrfs $(progs)
310 ifneq ($(MAKECMDGOALS),clean)
311 -include $(objects:.o=.o.d) $(cmd-objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))