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