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 \
8 inode-map.o extent-cache.o extent_io.o \
9 volumes.o utils.o btrfs-list.o repair.o \
10 send-stream.o send-utils.o qgroup.o raid6.o
11 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
12 cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
13 cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
15 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
20 CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
21 -Wuninitialized -Wshadow -Wundef
22 DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
26 bindir = $(prefix)/bin
27 lib_LIBS = -luuid -lblkid -lm -lz -llzo2 -L.
28 libdir ?= $(prefix)/lib
29 incdir = $(prefix)/include/btrfs
30 LIBS = $(lib_LIBS) $(libs_static)
32 ifeq ("$(origin V)", "command line")
39 ifeq ($(BUILD_VERBOSE),1)
45 MAKEOPTS = --no-print-directory Q=$(Q)
47 progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \
48 btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
49 btrfs-find-root btrfstune btrfs-show-super
51 # Create all the static targets
52 static_objects = $(patsubst %.o, %.static.o, $(objects))
53 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
54 static_progs = $(patsubst %.o, %.static.o, $(progs))
56 # Define static compilation flags
57 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
58 STATIC_LDFLAGS = -static -Wl,--gc-sections
59 STATIC_LIBS = $(LIBS) -lpthread
61 libs_shared = libbtrfs.so.0.1
62 libs_static = libbtrfs.a
63 libs = $(libs_shared) $(libs_static)
64 lib_links = libbtrfs.so.0 libbtrfs.so
65 headers = $(libbtrfs_headers)
67 # make C=1 to enable sparse
69 check = sparse $(CHECKFLAGS)
77 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $<
81 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
83 all: version.h $(progs) manpages
86 # NOTE: For static compiles, you need to have all the required libs
87 # static equivalent available
89 static: version.h $(libs) btrfs.static mkfs.btrfs.static btrfs-find-root.static
94 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
96 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(lib_LIBS) -shared -Wl,-soname,libbtrfs.so -o libbtrfs.so.0.1
98 $(libs_static): $(libbtrfs_objects)
100 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
104 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
105 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
107 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
109 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
110 $(objects) $(LDFLAGS) $(LIBS) -lpthread
112 btrfs.static: $(static_objects) $(libs) btrfs.static.o help.static.o $(static_cmds_objects)
114 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
115 $(static_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
117 calc-size: $(objects) $(libs) calc-size.o
119 $(Q)$(CC) $(CFLAGS) -o calc-size calc-size.o $(objects) $(LDFLAGS) $(LIBS)
121 btrfs-find-root: $(objects) $(libs) find-root.o
123 $(Q)$(CC) $(CFLAGS) -o btrfs-find-root find-root.o $(objects) $(LDFLAGS) $(LIBS)
125 btrfs-find-root.static: $(static_objects) find-root.static.o
127 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs-find-root.static find-root.static.o $(static_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
129 btrfsctl: $(objects) $(libs) btrfsctl.o
131 $(Q)$(CC) $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)
133 btrfs-vol: $(objects) $(libs) btrfs-vol.o
135 $(Q)$(CC) $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS)
137 btrfs-show: $(objects) $(libs) btrfs-show.o
139 $(Q)$(CC) $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS)
141 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
144 $(Q)$(LN) -f btrfs btrfsck
146 mkfs.btrfs: $(objects) $(libs) mkfs.o
148 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) -lblkid
150 mkfs.btrfs.static: $(static_objects) mkfs.static.o
152 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o \
153 $(static_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
155 btrfs-debug-tree: $(objects) $(libs) debug-tree.o
157 $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS)
159 btrfs-zero-log: $(objects) $(libs) btrfs-zero-log.o
161 $(Q)$(CC) $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
163 btrfs-show-super: $(objects) $(libs) btrfs-show-super.o
165 $(Q)$(CC) $(CFLAGS) -o btrfs-show-super $(objects) btrfs-show-super.o $(LDFLAGS) $(LIBS)
167 btrfs-select-super: $(objects) $(libs) btrfs-select-super.o
169 $(Q)$(CC) $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
171 btrfstune: $(objects) $(libs) btrfstune.o
173 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
175 btrfs-map-logical: $(objects) $(libs) btrfs-map-logical.o
177 $(Q)$(CC) $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS)
179 btrfs-corrupt-block: $(objects) $(libs) btrfs-corrupt-block.o
181 $(Q)$(CC) $(CFLAGS) -o btrfs-corrupt-block $(objects) btrfs-corrupt-block.o $(LDFLAGS) $(LIBS)
183 btrfs-image: $(objects) $(libs) btrfs-image.o
185 $(Q)$(CC) $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS)
187 dir-test: $(objects) $(libs) dir-test.o
189 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
191 quick-test: $(objects) $(libs) quick-test.o
193 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
195 btrfs-convert: $(objects) $(libs) convert.o
197 $(Q)$(CC) $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
199 ioctl-test: $(objects) $(libs) ioctl-test.o
201 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
203 send-test: $(objects) send-test.o
205 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS) -lpthread
208 $(Q)$(MAKE) $(MAKEOPTS) -C man
211 cd man; $(MAKE) install
215 $(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \
216 btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
217 btrfs.static mkfs.btrfs.static \
220 $(Q)$(MAKE) $(MAKEOPTS) -C man $@
222 install: $(libs) $(progs) install-man
223 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
224 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
225 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
226 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
227 cp -a $(lib_links) $(DESTDIR)$(libdir)
228 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
229 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)