3 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
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 crc32c.o rbtree.o extent-cache.o extent_io.o \
8 volumes.o utils.o btrfs-list.o btrfslabel.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 CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
15 -Wuninitialized -Wshadow -Wundef
16 DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
20 bindir = $(prefix)/bin
24 ifeq ("$(origin V)", "command line")
31 ifeq ($(BUILD_VERBOSE),1)
37 MAKEOPTS = --no-print-directory Q=$(Q)
39 progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \
40 btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \
41 btrfs-find-root btrfs-restore btrfstune btrfs-show-super
43 # Create all the static targets
44 static_objects = $(patsubst %.o, %.static.o, $(objects))
45 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
46 static_progs = $(patsubst %.o, %.static.o, $(progs))
48 # Define static compilation flags
49 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
50 STATIC_LDFLAGS = -static -Wl,--gc-sections
51 STATIC_LIBS = $(LIBS) -lpthread
53 # make C=1 to enable sparse
55 check = sparse $(CHECKFLAGS)
63 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $<
67 $(Q)$(CC) $(DEPFLAGS) $(AM_CFLAGS) $(STATIC_CFLAGS) -c $< -o $@
69 all: version.h $(progs) manpages
72 # NOTE: For static compiles, you need to have all the required libs
73 # static equivalent available
75 static: version.h btrfs.static
80 btrfs: $(objects) btrfs.o help.o $(cmds_objects)
82 $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o help.o $(cmds_objects) \
83 $(objects) $(LDFLAGS) $(LIBS) -lpthread
85 btrfs.static: $(static_objects) btrfs.static.o help.static.o $(static_cmds_objects)
87 $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o help.static.o $(static_cmds_objects) \
88 $(static_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
90 calc-size: $(objects) calc-size.o
92 $(Q)$(CC) $(CFLAGS) -o calc-size calc-size.o $(objects) $(LDFLAGS) $(LIBS)
94 btrfs-find-root: $(objects) find-root.o
96 $(Q)$(CC) $(CFLAGS) -o btrfs-find-root find-root.o $(objects) $(LDFLAGS) $(LIBS)
98 btrfs-restore: $(objects) restore.o
100 $(Q)$(CC) $(CFLAGS) -o btrfs-restore restore.o $(objects) $(LDFLAGS) $(LIBS) $(RESTORE_LIBS)
102 btrfsctl: $(objects) btrfsctl.o
104 $(Q)$(CC) $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS)
106 btrfs-vol: $(objects) btrfs-vol.o
108 $(Q)$(CC) $(CFLAGS) -o btrfs-vol btrfs-vol.o $(objects) $(LDFLAGS) $(LIBS)
110 btrfs-show: $(objects) btrfs-show.o
112 $(Q)$(CC) $(CFLAGS) -o btrfs-show btrfs-show.o $(objects) $(LDFLAGS) $(LIBS)
114 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
117 $(Q)$(LN) -f btrfs btrfsck
119 mkfs.btrfs: $(objects) mkfs.o
121 $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) -lblkid
123 btrfs-debug-tree: $(objects) debug-tree.o
125 $(Q)$(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS)
127 btrfs-zero-log: $(objects) btrfs-zero-log.o
129 $(Q)$(CC) $(CFLAGS) -o btrfs-zero-log $(objects) btrfs-zero-log.o $(LDFLAGS) $(LIBS)
131 btrfs-show-super: $(objects) btrfs-show-super.o
133 $(Q)$(CC) $(CFLAGS) -o btrfs-show-super $(objects) btrfs-show-super.o $(LDFLAGS) $(LIBS)
135 btrfs-select-super: $(objects) btrfs-select-super.o
137 $(Q)$(CC) $(CFLAGS) -o btrfs-select-super $(objects) btrfs-select-super.o $(LDFLAGS) $(LIBS)
139 btrfstune: $(objects) btrfstune.o
141 $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS)
143 btrfs-map-logical: $(objects) btrfs-map-logical.o
145 $(Q)$(CC) $(CFLAGS) -o btrfs-map-logical $(objects) btrfs-map-logical.o $(LDFLAGS) $(LIBS)
147 btrfs-corrupt-block: $(objects) btrfs-corrupt-block.o
149 $(Q)$(CC) $(CFLAGS) -o btrfs-corrupt-block $(objects) btrfs-corrupt-block.o $(LDFLAGS) $(LIBS)
151 btrfs-image: $(objects) btrfs-image.o
153 $(Q)$(CC) $(CFLAGS) -o btrfs-image $(objects) btrfs-image.o -lpthread -lz $(LDFLAGS) $(LIBS)
155 dir-test: $(objects) dir-test.o
157 $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS)
159 quick-test: $(objects) quick-test.o
161 $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) quick-test.o $(LDFLAGS) $(LIBS)
163 btrfs-convert: $(objects) convert.o
165 $(Q)$(CC) $(CFLAGS) -o btrfs-convert $(objects) convert.o -lext2fs -lcom_err $(LDFLAGS) $(LIBS)
167 ioctl-test: $(objects) ioctl-test.o
169 $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS)
172 $(Q)$(MAKE) $(MAKEOPTS) -C man
175 cd man; $(MAKE) install
179 $(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \
180 btrfs-zero-log btrfstune dir-test ioctl-test quick-test btrfs.static btrfsck \
182 $(Q)$(MAKE) $(MAKEOPTS) -C man $@
184 install: $(progs) install-man
185 $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
186 $(INSTALL) $(progs) $(DESTDIR)$(bindir)