1 # Export all variables to sub-makes by default
7 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES -fno-strict-aliasing -fPIC
8 CFLAGS = -g -O1 -fno-strict-aliasing
9 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
10 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
11 extent-cache.o extent_io.o volumes.o utils.o repair.o \
12 qgroup.o raid6.o free-space-cache.o list_sort.o props.o
13 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
14 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
15 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
16 cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
18 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
20 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
21 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
22 extent_io.h ioctl.h ctree.h btrfsck.h
27 bindir = $(prefix)/bin
28 lib_LIBS = -luuid -lblkid -lm -lz -llzo2 -L.
29 libdir ?= $(prefix)/lib
30 incdir = $(prefix)/include/btrfs
31 LIBS = $(lib_LIBS) $(libs_static)
33 ifeq ("$(origin V)", "command line")
40 ifeq ($(BUILD_VERBOSE),1)
46 MAKEOPTS = --no-print-directory Q=$(Q)
48 progs = mkfs.btrfs btrfs-debug-tree btrfsck \
49 btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
50 btrfs-find-root btrfstune btrfs-show-super
52 # external libs required by various binaries; for btrfs-foo,
53 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
54 btrfs_convert_libs = -lext2fs -lcom_err
55 btrfs_image_libs = -lpthread
56 btrfs_fragment_libs = -lgd -lpng -ljpeg -lfreetype
58 SUBDIRS = Documentation
59 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
60 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
61 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
65 .PHONY: $(INSTALLDIRS)
68 .PHONY: all install clean
70 # Create all the static targets
71 static_objects = $(patsubst %.o, %.static.o, $(objects))
72 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
73 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
75 # Define static compilation flags
76 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
77 STATIC_LDFLAGS = -static -Wl,--gc-sections
78 STATIC_LIBS = $(lib_LIBS) -lpthread
80 libs_shared = libbtrfs.so.0.1
81 libs_static = libbtrfs.a
82 libs = $(libs_shared) $(libs_static)
83 lib_links = libbtrfs.so.0 libbtrfs.so
84 headers = $(libbtrfs_headers)
86 # make C=1 to enable sparse
87 check_defs := .cc-defines.h
90 # We're trying to use sparse against glibc headers which go wild
91 # trying to use internal compiler macros to test features. We
92 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
93 # 'cause sparse defines that one.
95 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
96 grep -v __SIZE_TYPE__ > $(check_defs))
97 check = sparse -include $(check_defs) -D__CHECKER__ \
98 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef
100 # don't use FORTIFY with sparse because glibc with FORTIFY can
101 # generate so many sparse errors that sparse stops parsing,
102 # which masks real errors that we want to see.
106 AM_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
110 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(AM_CFLAGS) $(CFLAGS) $<
113 @$(check_echo) " [SP] $<"
114 $(Q)$(check) $(AM_CFLAGS) $(CFLAGS) $<
116 $(Q)$(CC) $(AM_CFLAGS) $(CFLAGS) -c $<
120 $(Q)$(CC) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
122 all: $(progs) manpages $(BUILDDIRS)
123 $(SUBDIRS): $(BUILDDIRS)
125 @echo "Making all in $(patsubst build-%,%,$@)"
126 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
129 $(Q)for t in $(TESTS); do \
130 echo " [TEST] $$t"; \
131 bash tests/$$t || exit 1; \
135 # NOTE: For static compiles, you need to have all the required libs
136 # static equivalent available
138 static: btrfs.static mkfs.btrfs.static btrfs-find-root.static
144 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
146 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(lib_LIBS) \
147 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
149 $(libs_static): $(libbtrfs_objects)
151 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
155 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
156 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
158 # keep intermediate files from the below implicit rules around
159 .PRECIOUS: $(addsuffix .o,$(progs))
161 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
162 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
163 # turns them into a list of libraries to link against if they exist
165 # For static variants, use an extra $(subst) to get rid of the ".static"
166 # from the target name before translating to list of libs
168 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
170 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
171 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS) \
172 $($(subst -,_,$(subst .static,,$@)-libs))
174 btrfs-%: $(objects) $(libs) btrfs-%.o
176 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
178 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
180 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
181 $(objects) $(LDFLAGS) $(LIBS) -lpthread
183 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
185 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
186 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
188 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
191 $(Q)$(LN) -f btrfs btrfsck
193 mkfs.btrfs: $(objects) $(libs) mkfs.o
195 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
197 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
199 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
200 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
202 btrfstune: $(objects) $(libs) btrfstune.o
204 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
206 dir-test: $(objects) $(libs) dir-test.o
208 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
210 quick-test: $(objects) $(libs) quick-test.o
212 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
214 ioctl-test: $(objects) $(libs) ioctl-test.o
216 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
218 send-test: $(objects) $(libs) send-test.o
220 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS) -lpthread
223 $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
227 $(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \
228 btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
229 btrfs.static mkfs.btrfs.static btrfs-calc-size \
230 version.h $(check_defs) \
234 @echo "Cleaning $(patsubst clean-%,%,$@)"
235 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
237 install: $(libs) $(progs) $(INSTALLDIRS)
238 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
239 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
240 $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
241 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
242 $(LN) -f $(DESTDIR)$(bindir)/btrfs $(DESTDIR)$(bindir)/btrfsck
243 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
244 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
245 cp -a $(lib_links) $(DESTDIR)$(libdir)
246 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
247 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
250 @echo "Making install in $(patsubst install-%,%,$@)"
251 $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
253 ifneq ($(MAKECMDGOALS),clean)
254 -include $(objects:.o=.o.d) $(cmd-objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))