]> git.sesse.net Git - bcachefs-tools-debian/blob - Makefile
Rust now integrated into bcachefs binary
[bcachefs-tools-debian] / Makefile
1 PREFIX?=/usr/local
2 PKG_CONFIG?=pkg-config
3 INSTALL=install
4
5 ifeq ("$(origin V)", "command line")
6   BUILD_VERBOSE = $(V)
7 endif
8 ifndef BUILD_VERBOSE
9   BUILD_VERBOSE = 0
10 endif
11
12 ifeq ($(BUILD_VERBOSE),1)
13   Q =
14 else
15   Q = @
16 endif
17
18 CFLAGS+=-std=gnu11 -O2 -g -MMD -Wall -fPIC                      \
19         -Wno-pointer-sign                                       \
20         -Wno-deprecated-declarations                            \
21         -fno-strict-aliasing                                    \
22         -fno-delete-null-pointer-checks                         \
23         -I. -Iinclude -Iraid                                    \
24         -D_FILE_OFFSET_BITS=64                                  \
25         -D_GNU_SOURCE                                           \
26         -D_LGPL_SOURCE                                          \
27         -DRCU_MEMBARRIER                                        \
28         -DZSTD_STATIC_LINKING_ONLY                              \
29         -DFUSE_USE_VERSION=32                                   \
30         -DNO_BCACHEFS_CHARDEV                                   \
31         -DNO_BCACHEFS_FS                                        \
32         -DNO_BCACHEFS_SYSFS                                     \
33         -DVERSION_STRING='"$(VERSION)"'                         \
34         $(EXTRA_CFLAGS)
35 LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
36
37 ## Configure Tools
38 PYTEST_ARGS?=
39 PYTEST_CMD?=$(shell \
40         command -v pytest-3 \
41         || which pytest-3 2>/dev/null \
42 )
43 PYTEST:=$(PYTEST_CMD) $(PYTEST_ARGS)
44
45 CARGO_ARGS=
46 CARGO=cargo $(CARGO_ARGS)
47 CARGO_PROFILE=release
48 # CARGO_PROFILE=debug
49
50 CARGO_BUILD_ARGS=--$(CARGO_PROFILE)
51 CARGO_BUILD=$(CARGO) build $(CARGO_BUILD_ARGS)
52 VERSION?=$(shell git describe --dirty=+ 2>/dev/null || echo v0.1-nogit)
53
54 include Makefile.compiler
55
56 CFLAGS+=$(call cc-disable-warning, unused-but-set-variable)
57 CFLAGS+=$(call cc-disable-warning, stringop-overflow)
58 CFLAGS+=$(call cc-disable-warning, zero-length-bounds)
59 CFLAGS+=$(call cc-disable-warning, missing-braces)
60 CFLAGS+=$(call cc-disable-warning, zero-length-array)
61 CFLAGS+=$(call cc-disable-warning, shift-overflow)
62 CFLAGS+=$(call cc-disable-warning, enum-conversion)
63
64 PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd libudev libkeyutils"
65 ifdef BCACHEFS_FUSE
66         PKGCONFIG_LIBS+="fuse3 >= 3.7"
67         CFLAGS+=-DBCACHEFS_FUSE
68 endif
69
70 PKGCONFIG_CFLAGS:=$(shell $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
71 ifeq (,$(PKGCONFIG_CFLAGS))
72     $(error pkg-config error, command: $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
73 endif
74 PKGCONFIG_LDLIBS:=$(shell $(PKG_CONFIG) --libs   $(PKGCONFIG_LIBS))
75 ifeq (,$(PKGCONFIG_LDLIBS))
76     $(error pkg-config error, command: $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
77 endif
78
79 CFLAGS+=$(PKGCONFIG_CFLAGS)
80 LDLIBS+=$(PKGCONFIG_LDLIBS)
81 LDLIBS+=-lm -lpthread -lrt -lkeyutils -laio -ldl
82 LDLIBS+=$(EXTRA_LDLIBS)
83
84 ifeq ($(PREFIX),/usr)
85         ROOT_SBINDIR=/sbin
86         INITRAMFS_DIR=$(PREFIX)/share/initramfs-tools
87 else
88         ROOT_SBINDIR=$(PREFIX)/sbin
89         INITRAMFS_DIR=/etc/initramfs-tools
90 endif
91
92 .PHONY: all
93 all: bcachefs
94
95 .PHONY: debug
96 debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
97 debug: bcachefs
98
99 .PHONY: tests
100 tests: tests/test_helper
101
102 .PHONY: check
103 check: tests bcachefs
104 ifneq (,$(PYTEST_CMD))
105         $(PYTEST)
106 else
107         @echo "WARNING: pytest not found or specified, tests could not be run."
108 endif
109
110 .PHONY: TAGS tags
111 TAGS:
112         ctags -e -R .
113
114 tags:
115         ctags -R .
116
117 SRCS=$(shell find . -type f ! -path '*/.*/*' -iname '*.c')
118 DEPS=$(SRCS:.c=.d)
119 -include $(DEPS)
120
121 OBJS=$(SRCS:.c=.o)
122
123 %.o: %.c
124         @echo "    [CC]     $@"
125         $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
126
127 bcachefs: libbcachefs.a rust-src/target/release/libbcachefs_rust.a
128         @echo "    [LD]     $@"
129         $(Q)$(CC) $(LDFLAGS) -Wl,--whole-archive $+ $(LOADLIBES) -Wl,--no-whole-archive $(LDLIBS) -o $@
130
131 libbcachefs.a: $(filter-out ./tests/%.o, $(OBJS))
132         @echo "    [AR]     $@"
133         $(Q)ar -rc $@ $+
134
135 RUST_SRCS=$(shell find rust-src/ -type f -iname '*.rs')
136 rust-src/target/release/libbcachefs_rust.a: libbcachefs.a $(RUST_SRCS)
137         $(CARGO_BUILD) --manifest-path rust-src/Cargo.toml
138
139 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
140         @echo "    [LD]     $@"
141         $(Q)$(CC) $(LDFLAGS) $+ $(LOADLIBES) $(LDLIBS) -o $@
142
143 # If the version string differs from the last build, update the last version
144 ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
145 .PHONY: .version
146 endif
147 .version:
148         @echo "  [VERS]    $@"
149         $(Q)echo '$(VERSION)' > $@
150
151 # Rebuild the 'version' command any time the version string changes
152 cmd_version.o : .version
153
154 .PHONY: install
155 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
156 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
157 install: bcachefs
158         $(INSTALL) -m0755 -D bcachefs      -t $(DESTDIR)$(ROOT_SBINDIR)
159         $(INSTALL) -m0755    fsck.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
160         $(INSTALL) -m0755    mkfs.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
161         $(INSTALL) -m0755    mount.bcachefs   $(DESTDIR)$(ROOT_SBINDIR)
162         $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
163         $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
164         $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
165
166         sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
167         echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
168
169 .PHONY: clean
170 clean:
171         @echo "Cleaning all"
172         $(Q)$(RM) bcachefs libbcachefs.a tests/test_helper .version *.tar.xz $(OBJS) $(DEPS) $(DOCGENERATED)
173         $(Q)$(RM) -rf rust-src/*/target
174
175 .PHONY: deb
176 deb: all
177         debuild -us -uc -nc -b -i -I
178
179 bcachefs-principles-of-operation.pdf: doc/bcachefs-principles-of-operation.tex
180         pdflatex doc/bcachefs-principles-of-operation.tex
181         pdflatex doc/bcachefs-principles-of-operation.tex
182
183 doc: bcachefs-principles-of-operation.pdf
184
185 .PHONY: update-bcachefs-sources
186 update-bcachefs-sources:
187         git rm -rf --ignore-unmatch libbcachefs
188         test -d libbcachefs || mkdir libbcachefs
189         cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
190         git add libbcachefs/*.[ch]
191         cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
192         git add include/trace/events/bcachefs.h
193         cp $(LINUX_DIR)/include/linux/xxhash.h include/linux/
194         git add include/linux/xxhash.h
195         cp $(LINUX_DIR)/lib/xxhash.c linux/
196         git add linux/xxhash.c
197         cp $(LINUX_DIR)/kernel/locking/six.c linux/
198         git add linux/six.c
199         cp $(LINUX_DIR)/include/linux/six.h include/linux/
200         git add include/linux/six.h
201         cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
202         git add include/linux/list_nulls.h
203         cp $(LINUX_DIR)/include/linux/poison.h include/linux/
204         git add include/linux/poison.h
205         cp $(LINUX_DIR)/include/linux/generic-radix-tree.h include/linux/
206         git add include/linux/generic-radix-tree.h
207         cp $(LINUX_DIR)/lib/generic-radix-tree.c linux/
208         git add linux/generic-radix-tree.c
209         cp $(LINUX_DIR)/include/linux/kmemleak.h include/linux/
210         git add include/linux/kmemleak.h
211         cp $(LINUX_DIR)/lib/math/int_sqrt.c linux/
212         git add linux/int_sqrt.c
213         cp $(LINUX_DIR)/scripts/Makefile.compiler ./
214         git add Makefile.compiler
215         $(RM) libbcachefs/*.mod.c
216         git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
217         git add .bcachefs_revision
218
219
220 .PHONY: update-commit-bcachefs-sources
221 update-commit-bcachefs-sources: update-bcachefs-sources
222         git commit -m "Update bcachefs sources to $(shell git -C $(LINUX_DIR) show --oneline --no-patch)"
223
224 SRCTARXZ = bcachefs-tools-$(VERSION).tar.xz
225 SRCDIR=bcachefs-tools-$(VERSION)
226
227 .PHONY: tarball
228 tarball: $(SRCTARXZ)
229
230 $(SRCTARXZ) : .gitcensus
231         $(Q)tar --transform "s,^,$(SRCDIR)/," -Jcf $(SRCDIR).tar.xz  \
232             `cat .gitcensus` 
233         @echo Wrote: $@
234
235 .PHONY: .gitcensus
236 .gitcensus:
237         $(Q)if test -d .git; then \
238           git ls-files > .gitcensus; \
239         fi