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