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