btrfs-progs: filesystem: add 'du' command
[platform/upstream/btrfs-progs.git] / Makefile.in
1 # btrfs-progs
2 #
3 # Basic build targets:
4 #   all         all main tools
5 #   static      build static bnaries, requires static version of the libraries
6 #   test        run the full testsuite
7 #   install     install to default location (/usr/local)
8 #   clean       clean built binaries (not the documentation)
9 #
10 # Tuning by variables (environment or make arguments):
11 #   V=1            verbose, print command lines (default: quiet)
12 #   C=1            run checker before compilation (default checker: sparse)
13 #   W=123          build with warnings (default: off)
14 #   EXTRA_CFLAGS   additional compiler flags
15 #   EXTRA_LDFLAGS  additional linker flags
16 #
17 # Static checkers:
18 #   CHECKER        static checker binary to be called (default: sparse)
19 #   CHECKER_FLAGS  flags to pass to CHECKER, can override CFLAGS
20 #
21
22 # Export all variables to sub-makes by default
23 export
24
25 include Makefile.extrawarn
26
27 CC = @CC@
28 LN_S = @LN_S@
29 AR = @AR@
30 RM = @RM@
31 RMDIR = @RMDIR@
32 INSTALL = @INSTALL@
33 DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@
34 DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@
35
36 EXTRA_CFLAGS :=
37 EXTRA_LDFLAGS :=
38
39 # Common build flags
40 CFLAGS = @CFLAGS@ \
41          -include config.h \
42          -DBTRFS_FLAT_INCLUDES \
43          -D_XOPEN_SOURCE=700  \
44          -fno-strict-aliasing \
45          -fPIC $(EXTRAWARN_CFLAGS) $(EXTRA_CFLAGS)
46
47 LDFLAGS = @LDFLAGS@ \
48           -rdynamic $(EXTRA_LDFLAGS)
49
50 LIBS = @UUID_LIBS@ @BLKID_LIBS@ @ZLIB_LIBS@ @LZO2_LIBS@ -L. -pthread
51 LIBBTRFS_LIBS = $(LIBS)
52
53 # Static compilation flags
54 STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
55 STATIC_LDFLAGS = -static -Wl,--gc-sections
56 STATIC_LIBS = @UUID_LIBS_STATIC@ @BLKID_LIBS_STATIC@ \
57               @ZLIB_LIBS_STATIC@ @LZO2_LIBS_STATIC@ -L. -pthread
58
59 # don't use FORTIFY with sparse because glibc with FORTIFY can
60 # generate so many sparse errors that sparse stops parsing,
61 # which masks real errors that we want to see.
62 CHECKER := sparse
63 check_defs := .cc-defines.h
64 CHECKER_FLAGS := -include $(check_defs) -D__CHECKER__ \
65         -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef \
66         -U_FORTIFY_SOURCE
67
68 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
69           root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
70           extent-cache.o extent_io.o volumes.o utils.o repair.o \
71           qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
72           ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
73           inode.o file.o find-root.o free-space-tree.o help.o
74 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
75                cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
76                cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
77                cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
78                cmds-property.o cmds-fi-usage.o cmds-inspect-dump-tree.o \
79                cmds-inspect-dump-super.o cmds-fi-du.o
80 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
81                    uuid-tree.o utils-lib.o rbtree-utils.o
82 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
83                crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
84                extent_io.h ioctl.h ctree.h btrfsck.h version.h
85 TESTS = fsck-tests.sh convert-tests.sh
86
87 prefix ?= @prefix@
88 exec_prefix = @exec_prefix@
89 bindir = @bindir@
90 libdir ?= @libdir@
91 incdir = @includedir@/btrfs
92
93 ifeq ("$(origin V)", "command line")
94   BUILD_VERBOSE = $(V)
95 endif
96 ifndef BUILD_VERBOSE
97   BUILD_VERBOSE = 0
98 endif
99
100 ifeq ($(BUILD_VERBOSE),1)
101   Q =
102 else
103   Q = @
104 endif
105
106 MAKEOPTS = --no-print-directory Q=$(Q)
107
108 # build all by default
109 progs = $(progs_install) btrfsck btrfs-corrupt-block btrfs-calc-size
110
111 # install only selected
112 progs_install = btrfs mkfs.btrfs btrfs-debug-tree \
113         btrfs-map-logical btrfs-image btrfs-zero-log \
114         btrfs-find-root btrfstune btrfs-show-super \
115         btrfs-select-super
116
117 progs_extra = btrfs-fragments
118
119 progs_static = $(foreach p,$(progs),$(p).static)
120
121 ifneq ($(DISABLE_BTRFSCONVERT),1)
122 progs_install += btrfs-convert
123 endif
124
125 # external libs required by various binaries; for btrfs-foo,
126 # specify btrfs_foo_libs = <list of libs>; see $($(subst...)) rules below
127 btrfs_convert_libs = @EXT2FS_LIBS@ @COM_ERR_LIBS@
128 btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
129 btrfs_debug_tree_objects = cmds-inspect-dump-tree.o
130 btrfs_show_super_objects = cmds-inspect-dump-super.o
131
132 SUBDIRS =
133 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
134 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
135 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
136
137 ifneq ($(DISABLE_DOCUMENTATION),1)
138 BUILDDIRS += build-Documentation
139 INSTALLDIRS += install-Documentation
140 endif
141
142 .PHONY: $(SUBDIRS)
143 .PHONY: $(BUILDDIRS)
144 .PHONY: $(INSTALLDIRS)
145 .PHONY: $(TESTDIRS)
146 .PHONY: $(CLEANDIRS)
147 .PHONY: all install clean
148
149 # Create all the static targets
150 static_objects = $(patsubst %.o, %.static.o, $(objects))
151 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
152 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
153
154 libs_shared = libbtrfs.so.0.1
155 libs_static = libbtrfs.a
156 libs = $(libs_shared) $(libs_static)
157 lib_links = libbtrfs.so.0 libbtrfs.so
158 headers = $(libbtrfs_headers)
159
160 # make C=1 to enable sparse
161 ifdef C
162         # We're trying to use sparse against glibc headers which go wild
163         # trying to use internal compiler macros to test features.  We
164         # copy gcc's and give them to sparse.  But not __SIZE_TYPE__
165         # 'cause sparse defines that one.
166         #
167         dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
168                         grep -v __SIZE_TYPE__ > $(check_defs))
169         check = $(CHECKER)
170         check_echo = echo
171 else
172         check = true
173         check_echo = true
174 endif
175
176 %.o.d: %.c
177         $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
178
179 .c.o:
180         @$(check_echo) "    [SP]     $<"
181         $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
182         @echo "    [CC]     $@"
183         $(Q)$(CC) $(CFLAGS) -c $<
184
185 %.static.o: %.c
186         @echo "    [CC]     $@"
187         $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
188
189 all: $(progs) $(BUILDDIRS)
190 $(SUBDIRS): $(BUILDDIRS)
191 $(BUILDDIRS):
192         @echo "Making all in $(patsubst build-%,%,$@)"
193         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
194
195 test-convert: btrfs btrfs-convert
196         @echo "    [TEST]   convert-tests.sh"
197         $(Q)bash tests/convert-tests.sh
198
199 test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
200         @echo "    [TEST]   fsck-tests.sh"
201         $(Q)bash tests/fsck-tests.sh
202
203 test-misc: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
204         @echo "    [TEST]   misc-tests.sh"
205         $(Q)bash tests/misc-tests.sh
206
207 test-mkfs: btrfs mkfs.btrfs
208         @echo "    [TEST]   mkfs-tests.sh"
209         $(Q)bash tests/mkfs-tests.sh
210
211 test-fuzz: btrfs
212         @echo "    [TEST]   fuzz-tests.sh"
213         $(Q)bash tests/fuzz-tests.sh
214
215 test-clean:
216         @echo "Cleaning tests"
217         $(Q)bash tests/clean-tests.sh
218
219 test: test-fsck test-mkfs test-convert test-misc test-fuzz
220
221 #
222 # NOTE: For static compiles, you need to have all the required libs
223 #       static equivalent available
224 #
225 static: $(progs_static)
226
227 version.h: version.sh version.h.in configure.ac
228         @echo "    [SH]     $@"
229         $(Q)bash ./config.status --silent $@
230
231 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
232         @echo "    [LD]     $@"
233         $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
234                 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
235
236 $(libs_static): $(libbtrfs_objects)
237         @echo "    [AR]     $@"
238         $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
239
240 $(lib_links):
241         @echo "    [LN]     $@"
242         $(Q)$(LN_S) -f libbtrfs.so.0.1 $@
243
244 # keep intermediate files from the below implicit rules around
245 .PRECIOUS: $(addsuffix .o,$(progs))
246
247 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
248 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
249 # turns them into a list of libraries to link against if they exist
250 #
251 # For static variants, use an extra $(subst) to get rid of the ".static"
252 # from the target name before translating to list of libs
253
254 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
255         @echo "    [LD]     $@"
256         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
257                 $($(subst -,_,$(subst .static,,$@)-objects)) \
258                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
259                 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
260
261 btrfs-%: $(objects) $(libs_static) btrfs-%.o
262         @echo "    [LD]     $@"
263         $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o \
264                 $($(subst -,_,$@-objects)) \
265                 $(libs_static) \
266                 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
267
268 btrfs: $(objects) btrfs.o $(cmds_objects) $(libs_static)
269         @echo "    [LD]     $@"
270         $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o $(cmds_objects) \
271                 $(objects) $(libs_static) $(LDFLAGS) $(LIBS)
272
273 btrfs.static: $(static_objects) btrfs.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
274         @echo "    [LD]     $@"
275         $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o $(static_cmds_objects) \
276                 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
277
278 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
279 btrfsck: btrfs
280         @echo "    [LN]     $@"
281         $(Q)$(LN_S) -f btrfs btrfsck
282
283 btrfsck.static: btrfs.static
284         @echo "    [LN]     $@"
285         $(Q)$(LN_S) -f $^ $@
286
287 mkfs.btrfs: $(objects) $(libs_static) mkfs.o
288         @echo "    [LD]     $@"
289         $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) $(libs_static) mkfs.o $(LDFLAGS) $(LIBS)
290
291 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
292         @echo "    [LD]     $@"
293         $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
294                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
295
296 btrfstune: $(objects) $(libs_static) btrfstune.o
297         @echo "    [LD]     $@"
298         $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(libs_static) $(LDFLAGS) $(LIBS)
299
300 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
301         @echo "    [LD]     $@"
302         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
303                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
304
305 dir-test: $(objects) $(libs) dir-test.o
306         @echo "    [LD]     $@"
307         $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
308
309 quick-test: $(objects) $(libs) quick-test.o
310         @echo "    [LD]     $@"
311         $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
312
313 ioctl-test: $(objects) $(libs) ioctl-test.o
314         @echo "    [LD]     $@"
315         $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
316
317 send-test: $(objects) $(libs) send-test.o
318         @echo "    [LD]     $@"
319         $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
320
321 library-test: $(libs_shared) library-test.o
322         @echo "    [LD]     $@"
323         $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
324
325 library-test.static: $(libs_static) library-test.o
326         @echo "    [LD]     $@"
327         $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
328
329 test-build: test-build-pre test-build-real
330
331 test-build-pre:
332         $(MAKE) clean-all
333         ./autogen.sh
334         ./configure
335
336 test-build-real:
337         $(MAKE) library-test
338         -$(MAKE) library-test.static
339         $(MAKE) -j 8 all
340         -$(MAKE) -j 8 static
341         $(MAKE) -j 8 $(progs_extra)
342
343 manpages:
344         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
345
346
347 clean-all: clean clean-doc clean-gen
348
349 clean: $(CLEANDIRS)
350         @echo "Cleaning"
351         $(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
352               dir-test ioctl-test quick-test send-test library-test library-test-static \
353               btrfs.static mkfs.btrfs.static \
354               $(check_defs) \
355               $(libs) $(lib_links) \
356               $(progs_static) $(progs_extra)
357
358 clean-doc:
359         @echo "Cleaning Documentation"
360         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
361
362 clean-gen:
363         @echo "Cleaning Generated Files"
364         $(Q)$(RM) -rf version.h config.status config.cache connfig.log \
365                 configure.lineno config.status.lineno Makefile \
366                 Documentation/Makefile \
367                 config.log config.h config.h.in~ aclocal.m4 \
368                 configure autom4te.cache/ config/
369
370 $(CLEANDIRS):
371         @echo "Cleaning $(patsubst clean-%,%,$@)"
372         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
373
374 install: $(libs) $(progs_install) $(INSTALLDIRS)
375         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
376         $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
377         $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
378         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
379         $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
380         $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
381         $(INSTALL) $(libs) $(DESTDIR)$(libdir)
382         cp -a $(lib_links) $(DESTDIR)$(libdir)
383         $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
384         $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
385
386 install-static: $(progs_static) $(INSTALLDIRS)
387         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
388         $(INSTALL) $(progs_static) $(DESTDIR)$(bindir)
389         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
390         $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
391
392 $(INSTALLDIRS):
393         @echo "Making install in $(patsubst install-%,%,$@)"
394         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
395
396 uninstall:
397         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
398         cd $(DESTDIR)$(incdir); $(RM) -f $(headers)
399         $(RMDIR) -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
400         cd $(DESTDIR)$(libdir); $(RM) -f $(lib_links) $(libs)
401         cd $(DESTDIR)$(bindir); $(RM) -f btrfsck fsck.btrfs $(progs_install)
402
403 ifneq ($(MAKECMDGOALS),clean)
404 -include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
405 endif