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
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
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 btrfsck.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 # 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)
82 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $<
86 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
88 all: version.h $(progs) manpages
91 # NOTE: For static compiles, you need to have all the required libs
92 # static equivalent available
94 static: version.h btrfs.static mkfs.btrfs.static btrfs-find-root.static
100 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
102 $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(lib_LIBS) \
103 -shared -Wl,-soname,libbtrfs.so -o libbtrfs.so.0.1
105 $(libs_static): $(libbtrfs_objects)
107 $(Q)$(AR) cru libbtrfs.a $(libbtrfs_objects)
111 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so.0
112 $(Q)$(LN) -sf libbtrfs.so.0.1 libbtrfs.so
114 # keep intermediate files from the below implicit rules around
115 .PRECIOUS: $(addsuffix .o,$(progs))
117 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
118 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
119 # turns them into a list of libraries to link against if they exist
121 # For static variants, use an extra $(subst) to get rid of the ".static"
122 # from the target name before translating to list of libs
124 btrfs-%.static: version.h $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
126 $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
127 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS) \
128 $($(subst -,_,$(subst .static,,$@)-libs))
130 btrfs-%: version.h $(objects) $(libs) btrfs-%.o
132 $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
134 btrfs: $(objects) btrfs.o help.o $(cmds_objects) $(libs)
136 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
137 $(objects) $(LDFLAGS) $(LIBS) -lpthread
139 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
141 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
142 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
144 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
147 $(Q)$(LN) -f btrfs btrfsck
149 mkfs.btrfs: $(objects) $(libs) mkfs.o
151 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS)
153 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
155 $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
156 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
158 btrfstune: $(objects) $(libs) btrfstune.o
160 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
162 dir-test: $(objects) $(libs) dir-test.o
164 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
166 quick-test: $(objects) $(libs) quick-test.o
168 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
170 ioctl-test: $(objects) $(libs) ioctl-test.o
172 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
174 send-test: $(objects) $(libs) send-test.o
176 $(Q)$(CC) $(CFLAGS) -o send-test $(objects) send-test.o $(LDFLAGS) $(LIBS) -lpthread
179 $(Q)$(MAKE) $(MAKEOPTS) -C man
182 cd man; $(MAKE) install
186 $(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \
187 btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
188 btrfs.static mkfs.btrfs.static btrfs-calc-size \
191 $(Q)$(MAKE) $(MAKEOPTS) -C man $@
193 install: $(libs) $(progs) install-man
194 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
195 $(INSTALL) $(progs) $(DESTDIR)$(bindir)
196 # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
197 $(LN) -f $(DESTDIR)$(bindir)/btrfs $(DESTDIR)$(bindir)/btrfsck
198 $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
199 $(INSTALL) $(libs) $(DESTDIR)$(libdir)
200 cp -a $(lib_links) $(DESTDIR)$(libdir)
201 $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
202 $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)