btrfs-progs: introduce inspect-internal dump-super
[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-inspect-dump-tree.o cmds-inspect-dump-super.o
75 cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
76                cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
77                cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
78                cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \
79                cmds-property.o cmds-fi-usage.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
130 SUBDIRS =
131 BUILDDIRS = $(patsubst %,build-%,$(SUBDIRS))
132 INSTALLDIRS = $(patsubst %,install-%,$(SUBDIRS))
133 CLEANDIRS = $(patsubst %,clean-%,$(SUBDIRS))
134
135 ifneq ($(DISABLE_DOCUMENTATION),1)
136 BUILDDIRS += build-Documentation
137 INSTALLDIRS += install-Documentation
138 endif
139
140 .PHONY: $(SUBDIRS)
141 .PHONY: $(BUILDDIRS)
142 .PHONY: $(INSTALLDIRS)
143 .PHONY: $(TESTDIRS)
144 .PHONY: $(CLEANDIRS)
145 .PHONY: all install clean
146
147 # Create all the static targets
148 static_objects = $(patsubst %.o, %.static.o, $(objects))
149 static_cmds_objects = $(patsubst %.o, %.static.o, $(cmds_objects))
150 static_libbtrfs_objects = $(patsubst %.o, %.static.o, $(libbtrfs_objects))
151
152 libs_shared = libbtrfs.so.0.1
153 libs_static = libbtrfs.a
154 libs = $(libs_shared) $(libs_static)
155 lib_links = libbtrfs.so.0 libbtrfs.so
156 headers = $(libbtrfs_headers)
157
158 # make C=1 to enable sparse
159 ifdef C
160         # We're trying to use sparse against glibc headers which go wild
161         # trying to use internal compiler macros to test features.  We
162         # copy gcc's and give them to sparse.  But not __SIZE_TYPE__
163         # 'cause sparse defines that one.
164         #
165         dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
166                         grep -v __SIZE_TYPE__ > $(check_defs))
167         check = $(CHECKER)
168         check_echo = echo
169 else
170         check = true
171         check_echo = true
172 endif
173
174 %.o.d: %.c
175         $(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(CFLAGS) $<
176
177 .c.o:
178         @$(check_echo) "    [SP]     $<"
179         $(Q)$(check) $(CFLAGS) $(CHECKER_FLAGS) $<
180         @echo "    [CC]     $@"
181         $(Q)$(CC) $(CFLAGS) -c $<
182
183 %.static.o: %.c
184         @echo "    [CC]     $@"
185         $(Q)$(CC) $(STATIC_CFLAGS) -c $< -o $@
186
187 all: $(progs) $(BUILDDIRS)
188 $(SUBDIRS): $(BUILDDIRS)
189 $(BUILDDIRS):
190         @echo "Making all in $(patsubst build-%,%,$@)"
191         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
192
193 test-convert: btrfs btrfs-convert
194         @echo "    [TEST]   convert-tests.sh"
195         $(Q)bash tests/convert-tests.sh
196
197 test-fsck: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs
198         @echo "    [TEST]   fsck-tests.sh"
199         $(Q)bash tests/fsck-tests.sh
200
201 test-misc: btrfs btrfs-image btrfs-corrupt-block btrfs-debug-tree mkfs.btrfs btrfstune
202         @echo "    [TEST]   misc-tests.sh"
203         $(Q)bash tests/misc-tests.sh
204
205 test-mkfs: btrfs mkfs.btrfs
206         @echo "    [TEST]   mkfs-tests.sh"
207         $(Q)bash tests/mkfs-tests.sh
208
209 test-fuzz: btrfs
210         @echo "    [TEST]   fuzz-tests.sh"
211         $(Q)bash tests/fuzz-tests.sh
212
213 test-clean:
214         @echo "Cleaning tests"
215         $(Q)bash tests/clean-tests.sh
216
217 test: test-fsck test-mkfs test-convert test-misc test-fuzz
218
219 #
220 # NOTE: For static compiles, you need to have all the required libs
221 #       static equivalent available
222 #
223 static: $(progs_static)
224
225 version.h: version.sh version.h.in configure.ac
226         @echo "    [SH]     $@"
227         $(Q)bash ./config.status --silent $@
228
229 $(libs_shared): $(libbtrfs_objects) $(lib_links) send.h
230         @echo "    [LD]     $@"
231         $(Q)$(CC) $(CFLAGS) $(libbtrfs_objects) $(LDFLAGS) $(LIBBTRFS_LIBS) \
232                 -shared -Wl,-soname,libbtrfs.so.0 -o libbtrfs.so.0.1
233
234 $(libs_static): $(libbtrfs_objects)
235         @echo "    [AR]     $@"
236         $(Q)$(AR) cr libbtrfs.a $(libbtrfs_objects)
237
238 $(lib_links):
239         @echo "    [LN]     $@"
240         $(Q)$(LN_S) -f libbtrfs.so.0.1 $@
241
242 # keep intermediate files from the below implicit rules around
243 .PRECIOUS: $(addsuffix .o,$(progs))
244
245 # Make any btrfs-foo out of btrfs-foo.o, with appropriate libs.
246 # The $($(subst...)) bits below takes the btrfs_*_libs definitions above and
247 # turns them into a list of libraries to link against if they exist
248 #
249 # For static variants, use an extra $(subst) to get rid of the ".static"
250 # from the target name before translating to list of libs
251
252 btrfs-%.static: $(static_objects) btrfs-%.static.o $(static_libbtrfs_objects)
253         @echo "    [LD]     $@"
254         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ $@.o $(static_objects) \
255                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
256                 $($(subst -,_,$(subst .static,,$@)-libs)) $(STATIC_LIBS)
257
258 btrfs-%: $(objects) $(libs_static) btrfs-%.o
259         @echo "    [LD]     $@"
260         $(Q)$(CC) $(CFLAGS) -o $@ $(objects) $@.o $(libs_static) \
261                 $(LDFLAGS) $(LIBS) $($(subst -,_,$@-libs))
262
263 btrfs: $(objects) btrfs.o $(cmds_objects) $(libs_static)
264         @echo "    [LD]     $@"
265         $(Q)$(CC) $(CFLAGS) -o btrfs btrfs.o $(cmds_objects) \
266                 $(objects) $(libs_static) $(LDFLAGS) $(LIBS)
267
268 btrfs.static: $(static_objects) btrfs.static.o $(static_cmds_objects) $(static_libbtrfs_objects)
269         @echo "    [LD]     $@"
270         $(Q)$(CC) $(STATIC_CFLAGS) -o btrfs.static btrfs.static.o $(static_cmds_objects) \
271                 $(static_objects) $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
272
273 # For backward compatibility, 'btrfs' changes behaviour to fsck if it's named 'btrfsck'
274 btrfsck: btrfs
275         @echo "    [LN]     $@"
276         $(Q)$(LN_S) -f btrfs btrfsck
277
278 btrfsck.static: btrfs.static
279         @echo "    [LN]     $@"
280         $(Q)$(LN_S) -f $^ $@
281
282 mkfs.btrfs: $(objects) $(libs_static) mkfs.o
283         @echo "    [LD]     $@"
284         $(Q)$(CC) $(CFLAGS) -o mkfs.btrfs $(objects) $(libs_static) mkfs.o $(LDFLAGS) $(LIBS)
285
286 mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects)
287         @echo "    [LD]     $@"
288         $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \
289                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
290
291 btrfstune: $(objects) $(libs_static) btrfstune.o
292         @echo "    [LD]     $@"
293         $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(libs_static) $(LDFLAGS) $(LIBS)
294
295 btrfstune.static: $(static_objects) btrfstune.static.o $(static_libbtrfs_objects)
296         @echo "    [LD]     $@"
297         $(Q)$(CC) $(STATIC_CFLAGS) -o $@ btrfstune.static.o $(static_objects) \
298                 $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS)
299
300 dir-test: $(objects) $(libs) dir-test.o
301         @echo "    [LD]     $@"
302         $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) $(libs) dir-test.o $(LDFLAGS) $(LIBS)
303
304 quick-test: $(objects) $(libs) quick-test.o
305         @echo "    [LD]     $@"
306         $(Q)$(CC) $(CFLAGS) -o quick-test $(objects) $(libs) quick-test.o $(LDFLAGS) $(LIBS)
307
308 ioctl-test: $(objects) $(libs) ioctl-test.o
309         @echo "    [LD]     $@"
310         $(Q)$(CC) $(CFLAGS) -o ioctl-test $(objects) $(libs) ioctl-test.o $(LDFLAGS) $(LIBS)
311
312 send-test: $(objects) $(libs) send-test.o
313         @echo "    [LD]     $@"
314         $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS)
315
316 library-test: $(libs_shared) library-test.o
317         @echo "    [LD]     $@"
318         $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs
319
320 library-test.static: $(libs_static) library-test.o
321         @echo "    [LD]     $@"
322         $(Q)$(CC) $(CFLAGS) -o library-test-static library-test.o $(LDFLAGS) $(libs_static)
323
324 test-build: test-build-pre test-build-real
325
326 test-build-pre:
327         $(MAKE) clean-all
328         ./autogen.sh
329         ./configure
330
331 test-build-real:
332         $(MAKE) library-test
333         -$(MAKE) library-test.static
334         $(MAKE) -j 8 all
335         -$(MAKE) -j 8 static
336         $(MAKE) -j 8 $(progs_extra)
337
338 manpages:
339         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation
340
341
342 clean-all: clean clean-doc clean-gen
343
344 clean: $(CLEANDIRS)
345         @echo "Cleaning"
346         $(Q)$(RM) -f $(progs) cscope.out *.o *.o.d \
347               dir-test ioctl-test quick-test send-test library-test library-test-static \
348               btrfs.static mkfs.btrfs.static \
349               $(check_defs) \
350               $(libs) $(lib_links) \
351               $(progs_static) $(progs_extra)
352
353 clean-doc:
354         @echo "Cleaning Documentation"
355         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation clean
356
357 clean-gen:
358         @echo "Cleaning Generated Files"
359         $(Q)$(RM) -rf version.h config.status config.cache connfig.log \
360                 configure.lineno config.status.lineno Makefile \
361                 Documentation/Makefile \
362                 config.log config.h config.h.in~ aclocal.m4 \
363                 configure autom4te.cache/ config/
364
365 $(CLEANDIRS):
366         @echo "Cleaning $(patsubst clean-%,%,$@)"
367         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst clean-%,%,$@) clean
368
369 install: $(libs) $(progs_install) $(INSTALLDIRS)
370         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
371         $(INSTALL) $(progs_install) $(DESTDIR)$(bindir)
372         $(INSTALL) fsck.btrfs $(DESTDIR)$(bindir)
373         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
374         $(LN_S) -f btrfs $(DESTDIR)$(bindir)/btrfsck
375         $(INSTALL) -m755 -d $(DESTDIR)$(libdir)
376         $(INSTALL) $(libs) $(DESTDIR)$(libdir)
377         cp -a $(lib_links) $(DESTDIR)$(libdir)
378         $(INSTALL) -m755 -d $(DESTDIR)$(incdir)
379         $(INSTALL) -m644 $(headers) $(DESTDIR)$(incdir)
380
381 install-static: $(progs_static) $(INSTALLDIRS)
382         $(INSTALL) -m755 -d $(DESTDIR)$(bindir)
383         $(INSTALL) $(progs_static) $(DESTDIR)$(bindir)
384         # btrfsck is a link to btrfs in the src tree, make it so for installed file as well
385         $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static
386
387 $(INSTALLDIRS):
388         @echo "Making install in $(patsubst install-%,%,$@)"
389         $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install
390
391 uninstall:
392         $(Q)$(MAKE) $(MAKEOPTS) -C Documentation uninstall
393         cd $(DESTDIR)$(incdir); $(RM) -f $(headers)
394         $(RMDIR) -p --ignore-fail-on-non-empty $(DESTDIR)$(incdir)
395         cd $(DESTDIR)$(libdir); $(RM) -f $(lib_links) $(libs)
396         cd $(DESTDIR)$(bindir); $(RM) -f btrfsck fsck.btrfs $(progs_install)
397
398 ifneq ($(MAKECMDGOALS),clean)
399 -include $(objects:.o=.o.d) $(cmds_objects:.o=.o.d) $(subst .btrfs,, $(filter-out btrfsck.o.d, $(progs:=.o.d)))
400 endif