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