]> git.sesse.net Git - bcachefs-tools-debian/blob - Makefile
Fix errors related to rst2man warning message:
[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 include Makefile.compiler
26
27 CFLAGS+=$(call cc-disable-warning, unused-but-set-variable)
28 CFLAGS+=$(call cc-disable-warning, stringop-overflow)
29 CFLAGS+=$(call cc-disable-warning, zero-length-bounds)
30 CFLAGS+=$(call cc-disable-warning, missing-braces)
31 CFLAGS+=$(call cc-disable-warning, zero-length-array)
32 CFLAGS+=$(call cc-disable-warning, shift-overflow)
33 CFLAGS+=$(call cc-disable-warning, enum-conversion)
34
35 PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd libudev"
36 ifdef BCACHEFS_FUSE
37         PKGCONFIG_LIBS+="fuse3 >= 3.7"
38         CFLAGS+=-DBCACHEFS_FUSE
39 endif
40
41 PKGCONFIG_CFLAGS:=$(shell $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
42 ifeq (,$(PKGCONFIG_CFLAGS))
43     $(error pkg-config error, command: $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
44 endif
45 PKGCONFIG_LDLIBS:=$(shell $(PKG_CONFIG) --libs   $(PKGCONFIG_LIBS))
46 ifeq (,$(PKGCONFIG_LDLIBS))
47     $(error pkg-config error, command: $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
48 endif
49
50 CFLAGS+=$(PKGCONFIG_CFLAGS)
51 LDLIBS+=$(PKGCONFIG_LDLIBS)
52
53 LDLIBS+=-lm -lpthread -lrt -lscrypt -lkeyutils -laio -ldl
54 LDLIBS+=$(EXTRA_LDLIBS)
55
56 ifeq ($(PREFIX),/usr)
57         ROOT_SBINDIR=/sbin
58         INITRAMFS_DIR=$(PREFIX)/share/initramfs-tools
59 else
60         ROOT_SBINDIR=$(PREFIX)/sbin
61         INITRAMFS_DIR=/etc/initramfs-tools
62 endif
63
64 STATUS:=$(shell rst2man -V 2>/dev/null; echo $$?)
65 ifeq ($(STATUS),0)
66         RST2MAN=rst2man
67 endif
68
69 STATUS:=$(shell rst2man.py -V 2>/dev/null; echo $$?)
70 ifeq ($(STATUS),0)
71         RST2MAN=rst2man.py
72 endif
73
74 .PHONY: all
75 all: bcachefs bcachefs.5
76
77 .PHONY: tests
78 tests: tests/test_helper
79
80 .PHONY: check
81 check: tests bcachefs
82         $(PYTEST)
83
84 .PHONY: TAGS tags
85 TAGS:
86         ctags -e -R .
87
88 tags:
89         ctags -R .
90
91 DOCSRC := opts_macro.h bcachefs.5.rst.tmpl
92 DOCGENERATED := bcachefs.5 doc/bcachefs.5.rst
93 DOCDEPS := $(addprefix ./doc/,$(DOCSRC))
94 bcachefs.5: $(DOCDEPS)  libbcachefs/opts.h
95 ifneq (,$(RST2MAN))
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 else
100         @echo "WARNING: no rst2man found! Man page not generated."
101 endif
102
103 SRCS=$(shell find . -type f -iname '*.c')
104 DEPS=$(SRCS:.c=.d)
105 -include $(DEPS)
106
107 OBJS=$(SRCS:.c=.o)
108 bcachefs: $(filter-out ./tests/%.o, $(OBJS))
109
110 MOUNT_SRCS=$(shell find mount/src -type f -iname '*.rs') \
111     mount/Cargo.toml mount/Cargo.lock mount/build.rs
112
113 debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
114 debug: bcachefs
115
116 libbcachefs_mount.a: $(MOUNT_SRCS)
117         LIBBCACHEFS_INCLUDE=$(CURDIR) cargo build --manifest-path mount/Cargo.toml --release
118         cp mount/target/release/libbcachefs_mount.a $@
119
120 MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
121 mount.bcachefs: libbcachefs_mount.a $(MOUNT_OBJ)
122         $(CC) -Wl,--gc-sections libbcachefs_mount.a $(MOUNT_OBJ) -o $@ $(LDLIBS)
123
124 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
125
126 # If the version string differs from the last build, update the last version
127 ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
128 .PHONY: .version
129 endif
130 .version:
131         echo '$(VERSION)' > $@
132
133 # Rebuild the 'version' command any time the version string changes
134 cmd_version.o : .version
135
136 .PHONY: install
137 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
138 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
139 install: bcachefs
140         $(INSTALL) -m0755 -D bcachefs      -t $(DESTDIR)$(ROOT_SBINDIR)
141         $(INSTALL) -m0755    fsck.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
142         $(INSTALL) -m0755    mkfs.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
143         $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
144         $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
145         $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
146         $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
147         sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
148         echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
149
150 .PHONY: clean
151 clean:
152         $(RM) bcachefs mount.bcachefs libbcachefs_mount.a tests/test_helper .version $(OBJS) $(DEPS) $(DOCGENERATED)
153         $(RM) -rf mount/target
154
155 .PHONY: deb
156 deb: all
157         debuild -us -uc -nc -b -i -I
158
159 .PHONY: update-bcachefs-sources
160 update-bcachefs-sources:
161         git rm -rf --ignore-unmatch libbcachefs
162         test -d libbcachefs || mkdir libbcachefs
163         cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
164         git add libbcachefs/*.[ch]
165         cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
166         git add include/trace/events/bcachefs.h
167         cp $(LINUX_DIR)/include/linux/xxhash.h include/linux/
168         git add include/linux/xxhash.h
169         cp $(LINUX_DIR)/lib/xxhash.c linux/
170         git add linux/xxhash.c
171         cp $(LINUX_DIR)/kernel/locking/six.c linux/
172         git add linux/six.c
173         cp $(LINUX_DIR)/include/linux/six.h include/linux/
174         git add include/linux/six.h
175         cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
176         git add include/linux/list_nulls.h
177         cp $(LINUX_DIR)/include/linux/poison.h include/linux/
178         git add include/linux/poison.h
179         cp $(LINUX_DIR)/scripts/Makefile.compiler ./
180         git add Makefile.compiler
181         $(RM) libbcachefs/*.mod.c
182         git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
183         git add .bcachefs_revision
184
185 .PHONY: update-commit-bcachefs-sources
186 update-commit-bcachefs-sources: update-bcachefs-sources
187         git commit -m "Update bcachefs sources to $(shell git -C $(LINUX_DIR) show --oneline --no-patch)"