4 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -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 \
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 \
14 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o
15 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
16 crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
17 extent_io.h ioctl.h ctree.h
19 CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
20 -Wuninitialized -Wshadow -Wundef
21 DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
25 bindir = $(prefix)/bin
26 lib_LIBS = -luuid -lblkid -lm -lz -llzo2 -L.
27 libdir ?= $(prefix)/lib
28 incdir = $(prefix)/include/btrfs
29 LIBS = $(lib_LIBS) $(libs_static)
31 ifeq ("$(origin V)", "command line")
38 ifeq ($(BUILD_VERBOSE),1)
44 MAKEOPTS = --no-print-directory Q=$(Q)
46 progs = mkfs.btrfs btrfs-debug-tree btrfsck \
47 btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
48 btrfs-find-root btrfstune btrfs-show-super
50 # Create all the static targets
51 static_objects = $(patsubst %.o, %.static.o, $(objects))
52 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
53 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
55 # Define static compilation flags
56 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
57 STATIC_LDFLAGS = -static -Wl,--gc-sections
58 STATIC_LIBS = $(lib_LIBS) -lpthread
60 libs_shared = libbtrfs.so.0.1
61 libs_static = libbtrfs.a
62 libs = $(libs_shared) $(libs_static)
63 lib_links = libbtrfs.so.0 libbtrfs.so
64 headers = $(libbtrfs_headers)
66 # make C=1 to enable sparse
68 check = sparse $(CHECKFLAGS)
76 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $<
80 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
82 all: version.h $(progs) manpages
85 # NOTE: For static compiles, you need to have all the required libs
86 # static equivalent available
88 static: version.h btrfs.static mkfs.btrfs.static btrfs-find-root.static
94 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
96 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(lib_LIBS) \
97 -shared -Wl,-soname,libbtrfs.so -o libbtrfs.so.0.1
99 $(libs_static): $(libbtrfs_objects)
101 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
105 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
106 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
108 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
110 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
111 $(objects) $(LDFLAGS) $(LIBS) -lpthread
113 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
115 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
116 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
118 calc-size: $(objects) $(libs) calc-size.o
120 $(Q)$(CC) $(CFLAGS) -o calc-size calc-size.o $(objects) $(LDFLAGS) $(LIBS)
122 btrfs-find-root: $(objects) $(libs) find-root.o
124 $(Q)$(CC) $(CFLAGS) -o btrfs-find-root find-root.o $(objects) $(LDFLAGS) $(LIBS)
126 btrfs-find-root.static: $(static_objects) find-root.static.o $(static_libbtrfs_objects)
128 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs-find-root.static find-root.static.o $(static_objects) \
129 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
131 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
134 $(Q)$(LN) -f btrfs btrfsck
136 mkfs.btrfs: $(objects) $(libs) mkfs.o
138 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
140 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
142 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
143 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
145 btrfs-debug-tree: $(objects) $(libs) debug-tree.o
147 $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS)
149 btrfs-zero-log: $(objects) $(libs) btrfs-zero-log.o
151 $(Q)$(CC) $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
153 btrfs-show-super: $(objects) $(libs) btrfs-show-super.o
155 $(Q)$(CC) $(CFLAGS) -o btrfs-show-super $(objects) btrfs-show-super.o $(LDFLAGS) $(LIBS)
157 btrfs-select-super: $(objects) $(libs) btrfs-select-super.o
159 $(Q)$(CC) $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
161 btrfstune: $(objects) $(libs) btrfstune.o
163 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
165 btrfs-map-logical: $(objects) $(libs) btrfs-map-logical.o
167 $(Q)$(CC) $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS)
169 btrfs-corrupt-block: $(objects) $(libs) btrfs-corrupt-block.o
171 $(Q)$(CC) $(CFLAGS) -o btrfs-corrupt-block $(objects) btrfs-corrupt-block.o $(LDFLAGS) $(LIBS)
173 btrfs-image: $(objects) $(libs) btrfs-image.o
175 $(Q)$(CC) $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS)
177 btrfs-crc: btrfs-crc.o $(libs)
179 $(Q)$(CC) $(CFLAGS) -o btrfs-crc btrfs-crc.o $(LDFLAGS) $(LIBS)
181 dir-test: $(objects) $(libs) dir-test.o
183 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
185 quick-test: $(objects) $(libs) quick-test.o
187 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
189 btrfs-convert: $(objects) $(libs) convert.o
191 $(Q)$(CC) $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
193 btrfs-fragments: $(objects) $(libs) fragments.o
195 $(Q)$(CC) $(CFLAGS) -o btrfs-fragments $(objects) fragments.o $(LDFLAGS) $(LIBS) -lgd -lpng -ljpeg -lfreetype
197 ioctl-test: $(objects) $(libs) ioctl-test.o
199 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
201 send-test: $(objects) send-test.o
203 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS) -lpthread
206 $(Q)$(MAKE) $(MAKEOPTS) -C man
209 cd man; $(MAKE) install
213 $(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \
214 btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
215 btrfs.static mkfs.btrfs.static \
218 $(Q)$(MAKE) $(MAKEOPTS) -C man $@
220 install: $(libs) $(progs) install-man
221 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
222 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
223 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
224 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
225 cp -a $(lib_links) $(DESTDIR)$(libdir)
226 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
227 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)