]> git.sesse.net Git - bcachefs-tools-debian/blob - Makefile
Documentation fixup: made filenames more descriptive, switched parsing utility to...
[bcachefs-tools-debian] / Makefile
1 PREFIX?=/usr/local
2 PKG_CONFIG?=pkg-config
3 INSTALL=install
4 PYTEST=pytest-3
5 CFLAGS+=-std=gnu89 -O2 -g -MMD -Wall                            \
6         -Wno-pointer-sign                                       \
7         -fno-strict-aliasing                                    \
8         -fno-delete-null-pointer-checks                         \
9         -I. -Iinclude -Iraid                                    \
10         -D_FILE_OFFSET_BITS=64                                  \
11         -D_GNU_SOURCE                                           \
12         -D_LGPL_SOURCE                                          \
13         -DRCU_MEMBARRIER                                        \
14         -DZSTD_STATIC_LINKING_ONLY                              \
15         -DFUSE_USE_VERSION=32                                   \
16         -DNO_BCACHEFS_CHARDEV                                   \
17         -DNO_BCACHEFS_FS                                        \
18         -DNO_BCACHEFS_SYSFS                                     \
19         -DVERSION_STRING='"$(VERSION)"'                         \
20         $(EXTRA_CFLAGS)
21 LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
22
23 VERSION?=$(shell git describe --dirty=+ 2>/dev/null || echo v0.1-nogit)
24
25 CC_VERSION=$(shell $(CC) -v 2>&1|grep -E '(gcc|clang) version')
26
27 ifneq (,$(findstring gcc,$(CC_VERSION)))
28         CFLAGS+=-Wno-unused-but-set-variable                    \
29                 -Wno-zero-length-bounds                         \
30                 -Wno-stringop-overflow
31 endif
32
33 ifneq (,$(findstring clang,$(CC_VERSION)))
34         CFLAGS+=-Wno-missing-braces                             \
35                 -Wno-zero-length-array                          \
36                 -Wno-shift-overflow                             \
37                 -Wno-enum-conversion
38 endif
39
40 ifdef BCACHEFS_DEBUG
41         CFLAGS+=-Werror
42         CFLAGS+=-DCONFIG_BCACHEFS_DEBUG=y
43 endif
44         CFLAGS+=-DCONFIG_VALGRIND=y
45
46 PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd libudev"
47 ifdef BCACHEFS_FUSE
48         PKGCONFIG_LIBS+="fuse3 >= 3.7"
49         CFLAGS+=-DBCACHEFS_FUSE
50 endif
51
52 PKGCONFIG_CFLAGS:=$(shell $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
53 ifeq (,$(PKGCONFIG_CFLAGS))
54     $(error pkg-config error, command: $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
55 endif
56 PKGCONFIG_LDLIBS:=$(shell $(PKG_CONFIG) --libs   $(PKGCONFIG_LIBS))
57 ifeq (,$(PKGCONFIG_LDLIBS))
58     $(error pkg-config error, command: $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
59 endif
60
61 CFLAGS+=$(PKGCONFIG_CFLAGS)
62 LDLIBS+=$(PKGCONFIG_LDLIBS)
63
64 LDLIBS+=-lm -lpthread -lrt -lscrypt -lkeyutils -laio -ldl
65 LDLIBS+=$(EXTRA_LDLIBS)
66
67 ifeq ($(PREFIX),/usr)
68         ROOT_SBINDIR=/sbin
69         INITRAMFS_DIR=$(PREFIX)/share/initramfs-tools
70 else
71         ROOT_SBINDIR=$(PREFIX)/sbin
72         INITRAMFS_DIR=/etc/initramfs-tools
73 endif
74
75 .PHONY: all
76 all: bcachefs bcachefs.5
77
78 .PHONY: tests
79 tests: tests/test_helper
80
81 .PHONY: check
82 check: tests bcachefs
83         cd tests; $(PYTEST)
84
85 .PHONY: TAGS tags
86 TAGS:
87         ctags -e -R .
88
89 tags:
90         ctags -R .
91
92 DOCSRC := opts_macro.h bcachefs.5.rst.tmpl
93 DOCGENERATED := bcachefs.5 doc/bcachefs.5.rst
94 DOCDEPS := $(addprefix ./doc/,$(DOCSRC))
95 bcachefs.5: $(DOCDEPS)  libbcachefs/opts.h
96         $(CC) doc/opts_macro.h -I libbcachefs -I include -E 2>/dev/null \
97                 | doc/macro2rst.py
98         rst2man doc/bcachefs.5.rst bcachefs.5
99
100 SRCS=$(shell find . -type f -iname '*.c')
101 DEPS=$(SRCS:.c=.d)
102 -include $(DEPS)
103
104 OBJS=$(SRCS:.c=.o)
105 bcachefs: $(filter-out ./tests/%.o, $(OBJS))
106
107 MOUNT_SRCS=$(shell find mount/src -type f -iname '*.rs') \
108     mount/Cargo.toml mount/Cargo.lock mount/build.rs
109 libbcachefs_mount.a: $(MOUNT_SRCS)
110         LIBBCACHEFS_INCLUDE=$(CURDIR) cargo build --manifest-path mount/Cargo.toml --release
111         cp mount/target/release/libbcachefs_mount.a $@
112
113 MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
114 mount.bcachefs: libbcachefs_mount.a $(MOUNT_OBJ)
115         $(CC) -Wl,--gc-sections libbcachefs_mount.a $(MOUNT_OBJ) -o $@ $(LDLIBS)
116
117 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
118
119 # If the version string differs from the last build, update the last version
120 ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
121 .PHONY: .version
122 endif
123 .version:
124         echo '$(VERSION)' > $@
125
126 # Rebuild the 'version' command any time the version string changes
127 cmd_version.o : .version
128
129 .PHONY: install
130 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
131 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
132 install: bcachefs
133         $(INSTALL) -m0755 -D bcachefs      -t $(DESTDIR)$(ROOT_SBINDIR)
134         $(INSTALL) -m0755    fsck.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
135         $(INSTALL) -m0755    mkfs.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
136         $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
137         $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
138         $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
139         $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
140         sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
141         echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
142
143 .PHONY: clean
144 clean:
145         $(RM) bcachefs mount.bcachefs libbcachefs_mount.a tests/test_helper .version $(OBJS) $(DEPS) $(DOCGENERATED)
146         $(RM) -rf mount/target
147
148 .PHONY: deb
149 deb: all
150         debuild -us -uc -nc -b -i -I
151
152 .PHONY: update-bcachefs-sources
153 update-bcachefs-sources:
154         git rm -rf --ignore-unmatch libbcachefs
155         test -d libbcachefs || mkdir libbcachefs
156         cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
157         git add libbcachefs/*.[ch]
158         cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
159         git add include/trace/events/bcachefs.h
160         cp $(LINUX_DIR)/include/linux/xxhash.h include/linux/
161         git add include/linux/xxhash.h
162         cp $(LINUX_DIR)/lib/xxhash.c linux/
163         git add linux/xxhash.c
164         cp $(LINUX_DIR)/kernel/locking/six.c linux/
165         git add linux/six.c
166         cp $(LINUX_DIR)/include/linux/six.h include/linux/
167         git add include/linux/six.h
168         cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
169         git add include/linux/list_nulls.h
170         cp $(LINUX_DIR)/include/linux/poison.h include/linux/
171         git add include/linux/poison.h
172         $(RM) libbcachefs/*.mod.c
173         git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
174         git add .bcachefs_revision
175
176 .PHONY: update-commit-bcachefs-sources
177 update-commit-bcachefs-sources: update-bcachefs-sources
178         git commit -m "Update bcachefs sources to $(shell git -C $(LINUX_DIR) show --oneline --no-patch)"