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