4 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES -fPIC
6 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
7 root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
8 extent-cache.o extent_io.o volumes.o utils.o repair.o \
9 qgroup.o raid6.o free-space-cache.o uuid-tree.o
10 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
11 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
12 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
13 cmds-restore.o cmds-chunk.o
14 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
16 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
17 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
18 extent_io.h ioctl.h ctree.h btrfsck.h
22 bindir = $(prefix)/bin
23 lib_LIBS = -luuid -lblkid -lm -lz -llzo2 -L.
24 libdir ?= $(prefix)/lib
25 incdir = $(prefix)/include/btrfs
26 LIBS = $(lib_LIBS) $(libs_static)
28 ifeq ("$(origin V)", "command line")
35 ifeq ($(BUILD_VERBOSE),1)
41 MAKEOPTS = --no-print-directory Q=$(Q)
43 progs = mkfs.btrfs btrfs-debug-tree btrfsck \
44 btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
45 btrfs-find-root btrfstune btrfs-show-super
47 # external libs required by various binaries; for btrfs-foo,
48 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
49 btrfs_convert_libs = -lext2fs -lcom_err
50 btrfs_image_libs = -lpthread
51 btrfs_fragment_libs = -lgd -lpng -ljpeg -lfreetype
53 # Create all the static targets
54 static_objects = $(patsubst %.o, %.static.o, $(objects))
55 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
56 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
58 # Define static compilation flags
59 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
60 STATIC_LDFLAGS = -static -Wl,--gc-sections
61 STATIC_LIBS = $(lib_LIBS) -lpthread
63 libs_shared = libbtrfs.so.0.1
64 libs_static = libbtrfs.a
65 libs = $(libs_shared) $(libs_static)
66 lib_links = libbtrfs.so.0 libbtrfs.so
67 headers = $(libbtrfs_headers)
69 # make C=1 to enable sparse
70 check_defs := .cc-defines.h
73 # We're trying to use sparse against glibc headers which go wild
74 # trying to use internal compiler macros to test features. We
75 # copy gcc's and give them to sparse. But not __SIZE_TYPE__
76 # 'cause sparse defines that one.
78 dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
79 grep -v __SIZE_TYPE__ > $(check_defs))
80 check = sparse -include $(check_defs) -D__CHECKER__ \
81 -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef
83 # don't use FORTIFY with sparse because glibc with FORTIFY can
84 # generate so many sparse errors that sparse stops parsing,
85 # which masks real errors that we want to see.
89 AM_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
93 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(AM_CFLAGS) $(CFLAGS) $<
96 @$(check_echo) " [SP] $<"
97 $(Q)$(check) $(AM_CFLAGS) $(CFLAGS) $<
99 $(Q)$(CC) $(AM_CFLAGS) $(CFLAGS) -c $<
103 $(Q)$(CC) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
105 all: $(progs) manpages
108 # NOTE: For static compiles, you need to have all the required libs
109 # static equivalent available
111 static: btrfs.static mkfs.btrfs.static btrfs-find-root.static
117 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
119 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(lib_LIBS) \
120 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
122 $(libs_static): $(libbtrfs_objects)
124 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
128 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
129 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
131 # keep intermediate files from the below implicit rules around
132 .PRECIOUS: $(addsuffix .o,$(progs))
134 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
135 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
136 # turns them into a list of libraries to link against if they exist
138 # For static variants, use an extra $(subst) to get rid of the ".static"
139 # from the target name before translating to list of libs
141 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
143 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
144 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS) \
145 $($(subst -,_,$(subst .static,,$@)-libs))
147 btrfs-%: $(objects) $(libs) btrfs-%.o
149 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
151 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
153 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
154 $(objects) $(LDFLAGS) $(LIBS) -lpthread
156 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
158 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
159 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
161 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
164 $(Q)$(LN) -f btrfs btrfsck
166 mkfs.btrfs: $(objects) $(libs) mkfs.o
168 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
170 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
172 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
173 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
175 btrfstune: $(objects) $(libs) btrfstune.o
177 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
179 dir-test: $(objects) $(libs) dir-test.o
181 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
183 quick-test: $(objects) $(libs) quick-test.o
185 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
187 ioctl-test: $(objects) $(libs) ioctl-test.o
189 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
191 send-test: $(objects) $(libs) send-test.o
193 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS) -lpthread
196 $(Q)$(MAKE) $(MAKEOPTS) -C man
199 cd man; $(MAKE) install
203 $(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \
204 btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
205 btrfs.static mkfs.btrfs.static btrfs-calc-size \
206 version.h $(check_defs) \
208 $(Q)$(MAKE) $(MAKEOPTS) -C man $@
210 install: $(libs) $(progs) install-man
211 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
212 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
213 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
214 $(LN) -f $(DESTDIR)$(bindir)/btrfs $(DESTDIR)$(bindir)/btrfsck
215 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
216 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
217 cp -a $(lib_links) $(DESTDIR)$(libdir)
218 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
219 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
221 ifneq ($(MAKECMDGOALS),clean)
222 -include $(objects:.o=.o.d) $(cmd-objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))