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 \
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
20 CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
21 -Wuninitialized -Wshadow -Wundef
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 # external libs required by various binaries; for btrfs-foo,
51 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
52 btrfs_convert_libs = -lext2fs -lcom_err
53 btrfs_image_libs = -lpthread
54 btrfs_fragment_libs = -lgd -lpng -ljpeg -lfreetype
56 # Create all the static targets
57 static_objects = $(patsubst %.o, %.static.o, $(objects))
58 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
59 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
61 # Define static compilation flags
62 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
63 STATIC_LDFLAGS = -static -Wl,--gc-sections
64 STATIC_LIBS = $(lib_LIBS) -lpthread
66 libs_shared = libbtrfs.so.0.1
67 libs_static = libbtrfs.a
68 libs = $(libs_shared) $(libs_static)
69 lib_links = libbtrfs.so.0 libbtrfs.so
70 headers = $(libbtrfs_headers)
72 # make C=1 to enable sparse
74 check = sparse $(CHECKFLAGS)
80 $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(AM_CFLAGS) $(CFLAGS) $<
85 $(Q)$(CC) $(AM_CFLAGS) $(CFLAGS) -c $<
89 $(Q)$(CC) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
91 all: $(progs) manpages
94 # NOTE: For static compiles, you need to have all the required libs
95 # static equivalent available
97 static: btrfs.static mkfs.btrfs.static btrfs-find-root.static
103 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
105 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(lib_LIBS) \
106 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
108 $(libs_static): $(libbtrfs_objects)
110 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
114 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
115 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
117 # keep intermediate files from the below implicit rules around
118 .PRECIOUS: $(addsuffix .o,$(progs))
120 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
121 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
122 # turns them into a list of libraries to link against if they exist
124 # For static variants, use an extra $(subst) to get rid of the ".static"
125 # from the target name before translating to list of libs
127 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
129 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
130 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS) \
131 $($(subst -,_,$(subst .static,,$@)-libs))
133 btrfs-%: $(objects) $(libs) btrfs-%.o
135 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
137 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
139 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
140 $(objects) $(LDFLAGS) $(LIBS) -lpthread
142 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
144 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
145 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
147 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
150 $(Q)$(LN) -f btrfs btrfsck
152 mkfs.btrfs: $(objects) $(libs) mkfs.o
154 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
156 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
158 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
159 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
161 btrfstune: $(objects) $(libs) btrfstune.o
163 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
165 dir-test: $(objects) $(libs) dir-test.o
167 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
169 quick-test: $(objects) $(libs) quick-test.o
171 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
173 ioctl-test: $(objects) $(libs) ioctl-test.o
175 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
177 send-test: $(objects) $(libs) send-test.o
179 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS) -lpthread
182 $(Q)$(MAKE) $(MAKEOPTS) -C man
185 cd man; $(MAKE) install
189 $(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \
190 btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
191 btrfs.static mkfs.btrfs.static btrfs-calc-size \
194 $(Q)$(MAKE) $(MAKEOPTS) -C man $@
196 install: $(libs) $(progs) install-man
197 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
198 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
199 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
200 $(LN) -f $(DESTDIR)$(bindir)/btrfs $(DESTDIR)$(bindir)/btrfsck
201 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
202 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
203 cp -a $(lib_links) $(DESTDIR)$(libdir)
204 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
205 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
207 ifneq ($(MAKECMDGOALS),clean)
208 -include $(objects:.o=.o.d) $(cmd-objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))