]> git.sesse.net Git - bcachefs-tools-debian/blob - Makefile
Makefile: detect rst2man
[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 var := $(shell rst2man 2>/dev/null)
76 ifeq ($(.SHELLSTATUS),0)
77         RST2MAN=rst2man
78 endif
79
80 var := $(shell rst2man.py 2>/dev/null)
81 ifeq ($(.SHELLSTATUS),0)
82         RST2MAN=rst2man.py
83 endif
84
85 undefine var
86
87 .PHONY: all
88 all: bcachefs bcachefs.5
89
90 .PHONY: tests
91 tests: tests/test_helper
92
93 .PHONY: check
94 check: tests bcachefs
95         cd tests; $(PYTEST)
96
97 .PHONY: TAGS tags
98 TAGS:
99         ctags -e -R .
100
101 tags:
102         ctags -R .
103
104 DOCSRC := opts_macro.h bcachefs.5.rst.tmpl
105 DOCGENERATED := bcachefs.5 doc/bcachefs.5.rst
106 DOCDEPS := $(addprefix ./doc/,$(DOCSRC))
107 bcachefs.5: $(DOCDEPS)  libbcachefs/opts.h
108         $(CC) doc/opts_macro.h -I libbcachefs -I include -E 2>/dev/null \
109                 | doc/macro2rst.py
110         $(RST2MAN) doc/bcachefs.5.rst bcachefs.5
111
112 SRCS=$(shell find . -type f -iname '*.c')
113 DEPS=$(SRCS:.c=.d)
114 -include $(DEPS)
115
116 OBJS=$(SRCS:.c=.o)
117 bcachefs: $(filter-out ./tests/%.o, $(OBJS))
118
119 MOUNT_SRCS=$(shell find mount/src -type f -iname '*.rs') \
120     mount/Cargo.toml mount/Cargo.lock mount/build.rs
121
122 debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
123 debug: bcachefs
124
125 libbcachefs_mount.a: $(MOUNT_SRCS)
126         LIBBCACHEFS_INCLUDE=$(CURDIR) cargo build --manifest-path mount/Cargo.toml --release
127         cp mount/target/release/libbcachefs_mount.a $@
128
129 MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
130 mount.bcachefs: libbcachefs_mount.a $(MOUNT_OBJ)
131         $(CC) -Wl,--gc-sections libbcachefs_mount.a $(MOUNT_OBJ) -o $@ $(LDLIBS)
132
133 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
134
135 # If the version string differs from the last build, update the last version
136 ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
137 .PHONY: .version
138 endif
139 .version:
140         echo '$(VERSION)' > $@
141
142 # Rebuild the 'version' command any time the version string changes
143 cmd_version.o : .version
144
145 .PHONY: install
146 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
147 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
148 install: bcachefs
149         $(INSTALL) -m0755 -D bcachefs      -t $(DESTDIR)$(ROOT_SBINDIR)
150         $(INSTALL) -m0755    fsck.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
151         $(INSTALL) -m0755    mkfs.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
152         $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
153         $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
154         $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
155         $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
156         sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
157         echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
158
159 .PHONY: clean
160 clean:
161         $(RM) bcachefs mount.bcachefs libbcachefs_mount.a tests/test_helper .version $(OBJS) $(DEPS) $(DOCGENERATED)
162         $(RM) -rf mount/target
163
164 .PHONY: deb
165 deb: all
166         debuild -us -uc -nc -b -i -I
167
168 .PHONY: update-bcachefs-sources
169 update-bcachefs-sources:
170         git rm -rf --ignore-unmatch libbcachefs
171         test -d libbcachefs || mkdir libbcachefs
172         cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
173         git add libbcachefs/*.[ch]
174         cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
175         git add include/trace/events/bcachefs.h
176         cp $(LINUX_DIR)/include/linux/xxhash.h include/linux/
177         git add include/linux/xxhash.h
178         cp $(LINUX_DIR)/lib/xxhash.c linux/
179         git add linux/xxhash.c
180         cp $(LINUX_DIR)/kernel/locking/six.c linux/
181         git add linux/six.c
182         cp $(LINUX_DIR)/include/linux/six.h include/linux/
183         git add include/linux/six.h
184         cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
185         git add include/linux/list_nulls.h
186         cp $(LINUX_DIR)/include/linux/poison.h include/linux/
187         git add include/linux/poison.h
188         $(RM) libbcachefs/*.mod.c
189         git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
190         git add .bcachefs_revision
191
192 .PHONY: update-commit-bcachefs-sources
193 update-commit-bcachefs-sources: update-bcachefs-sources
194         git commit -m "Update bcachefs sources to $(shell git -C $(LINUX_DIR) show --oneline --no-patch)"