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