3 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DBTRFS_FLAT_INCLUDES -fPIC
5 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
6 root-tree.o dir-item.o file-item.o inode-item.o \
7 inode-map.o extent-cache.o extent_io.o \
8 volumes.o utils.o btrfs-list.o repair.o \
9 send-stream.o send-utils.o qgroup.o raid6.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 -L.
27 libdir ?= $(prefix)/lib
28 incdir = $(prefix)/include/btrfs
29 LIBS = $(lib_LIBS) -lbtrfs
31 ifeq ("$(origin V)", "command line")
38 ifeq ($(BUILD_VERBOSE),1)
44 MAKEOPTS = --no-print-directory Q=$(Q)
46 progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol 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_progs = $(patsubst %.o, %.static.o, $(progs))
55 # Define static compilation flags
56 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
57 STATIC_LDFLAGS = -static -Wl,--gc-sections
58 STATIC_LIBS = $(LIBS) -lpthread
60 libs = libbtrfs.so.0.1
61 lib_links = libbtrfs.so.0 libbtrfs.so
62 headers = $(libbtrfs_headers)
64 # make C=1 to enable sparse
66 check = sparse $(CHECKFLAGS)
74 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $<
78 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
80 all: version.h $(progs) manpages
83 # NOTE: For static compiles, you need to have all the required libs
84 # static equivalent available
86 static: version.h $(libs) btrfs.static
91 $(libs): $(libbtrfs_objects) $(lib_links) send.h
93 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(lib_LIBS) -shared -Wl,-soname,libbtrfs.so -o libbtrfs.so.0.1
97 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
98 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
100 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
102 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
103 $(objects) $(LDFLAGS) $(LIBS) -lpthread
105 btrfs.static: $(static_objects) $(libs) btrfs.static.o help.static.o $(static_cmds_objects)
107 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
108 $(static_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
110 calc-size: $(objects) $(libs) calc-size.o
112 $(Q)$(CC) $(CFLAGS) -o calc-size calc-size.o $(objects) $(LDFLAGS) $(LIBS)
114 btrfs-find-root: $(objects) $(libs) find-root.o
116 $(Q)$(CC) $(CFLAGS) -o btrfs-find-root find-root.o $(objects) $(LDFLAGS) $(LIBS)
118 btrfsctl: $(objects) $(libs) btrfsctl.o
120 $(Q)$(CC) $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)
122 btrfs-vol: $(objects) $(libs) btrfs-vol.o
124 $(Q)$(CC) $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS)
126 btrfs-show: $(objects) $(libs) btrfs-show.o
128 $(Q)$(CC) $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS)
130 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
133 $(Q)$(LN) -f btrfs btrfsck
135 mkfs.btrfs: $(objects) $(libs) mkfs.o
137 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) -lblkid
139 btrfs-debug-tree: $(objects) $(libs) debug-tree.o
141 $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS)
143 btrfs-zero-log: $(objects) $(libs) btrfs-zero-log.o
145 $(Q)$(CC) $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
147 btrfs-show-super: $(objects) $(libs) btrfs-show-super.o
149 $(Q)$(CC) $(CFLAGS) -o btrfs-show-super $(objects) btrfs-show-super.o $(LDFLAGS) $(LIBS)
151 btrfs-select-super: $(objects) $(libs) btrfs-select-super.o
153 $(Q)$(CC) $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
155 btrfstune: $(objects) $(libs) btrfstune.o
157 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
159 btrfs-map-logical: $(objects) $(libs) btrfs-map-logical.o
161 $(Q)$(CC) $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS)
163 btrfs-corrupt-block: $(objects) $(libs) btrfs-corrupt-block.o
165 $(Q)$(CC) $(CFLAGS) -o btrfs-corrupt-block $(objects) btrfs-corrupt-block.o $(LDFLAGS) $(LIBS)
167 btrfs-image: $(objects) $(libs) btrfs-image.o
169 $(Q)$(CC) $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS)
171 dir-test: $(objects) $(libs) dir-test.o
173 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
175 quick-test: $(objects) $(libs) quick-test.o
177 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
179 btrfs-convert: $(objects) $(libs) convert.o
181 $(Q)$(CC) $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
183 ioctl-test: $(objects) $(libs) ioctl-test.o
185 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
187 send-test: $(objects) send-test.o
189 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS) -lpthread
192 $(Q)$(MAKE) $(MAKEOPTS) -C man
195 cd man; $(MAKE) install
199 $(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \
200 btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfs.static btrfsck \
203 $(Q)$(MAKE) $(MAKEOPTS) -C man $@
205 install: $(libs) $(progs) install-man
206 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
207 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
208 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
209 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
210 cp -a $(lib_links) $(DESTDIR)$(libdir)
211 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
212 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)