]> git.sesse.net Git - bcachefs-tools-debian/blob - Makefile
Bring back debug makefile target
[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
110 debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
111 debug: bcachefs
112
113 libbcachefs_mount.a: $(MOUNT_SRCS)
114         LIBBCACHEFS_INCLUDE=$(CURDIR) cargo build --manifest-path mount/Cargo.toml --release
115         cp mount/target/release/libbcachefs_mount.a $@
116
117 MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
118 mount.bcachefs: libbcachefs_mount.a $(MOUNT_OBJ)
119         $(CC) -Wl,--gc-sections libbcachefs_mount.a $(MOUNT_OBJ) -o $@ $(LDLIBS)
120
121 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
122
123 # If the version string differs from the last build, update the last version
124 ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
125 .PHONY: .version
126 endif
127 .version:
128         echo '$(VERSION)' > $@
129
130 # Rebuild the 'version' command any time the version string changes
131 cmd_version.o : .version
132
133 .PHONY: install
134 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
135 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
136 install: bcachefs
137         $(INSTALL) -m0755 -D bcachefs      -t $(DESTDIR)$(ROOT_SBINDIR)
138         $(INSTALL) -m0755    fsck.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
139         $(INSTALL) -m0755    mkfs.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
140         $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
141         $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
142         $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
143         $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
144         sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
145         echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
146
147 .PHONY: clean
148 clean:
149         $(RM) bcachefs mount.bcachefs libbcachefs_mount.a tests/test_helper .version $(OBJS) $(DEPS) $(DOCGENERATED)
150         $(RM) -rf mount/target
151
152 .PHONY: deb
153 deb: all
154         debuild -us -uc -nc -b -i -I
155
156 .PHONY: update-bcachefs-sources
157 update-bcachefs-sources:
158         git rm -rf --ignore-unmatch libbcachefs
159         test -d libbcachefs || mkdir libbcachefs
160         cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
161         git add libbcachefs/*.[ch]
162         cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
163         git add include/trace/events/bcachefs.h
164         cp $(LINUX_DIR)/include/linux/xxhash.h include/linux/
165         git add include/linux/xxhash.h
166         cp $(LINUX_DIR)/lib/xxhash.c linux/
167         git add linux/xxhash.c
168         cp $(LINUX_DIR)/kernel/locking/six.c linux/
169         git add linux/six.c
170         cp $(LINUX_DIR)/include/linux/six.h include/linux/
171         git add include/linux/six.h
172         cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
173         git add include/linux/list_nulls.h
174         cp $(LINUX_DIR)/include/linux/poison.h include/linux/
175         git add include/linux/poison.h
176         $(RM) libbcachefs/*.mod.c
177         git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
178         git add .bcachefs_revision
179
180 .PHONY: update-commit-bcachefs-sources
181 update-commit-bcachefs-sources: update-bcachefs-sources
182         git commit -m "Update bcachefs sources to $(shell git -C $(LINUX_DIR) show --oneline --no-patch)"