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