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