You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
6.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # Copyright (c) 2024, Antonio SJ Musumeci <trapexit@spawn.link>
  2. #
  3. # Permission to use, copy, modify, and/or distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. GIT = git
  15. TAR = tar
  16. MKDIR = mkdir
  17. TOUCH = touch
  18. CP = cp
  19. RM = rm
  20. LN = ln
  21. FIND = find
  22. INSTALL = install
  23. MKTEMP = mktemp
  24. STRIP = strip
  25. PANDOC = pandoc
  26. SED = sed
  27. RPMBUILD = rpmbuild
  28. GIT2DEBCL = ./buildtools/git2debcl
  29. PKGCONFIG = pkg-config
  30. GIT_REPO = 0
  31. ifneq ($(shell $(GIT) --version 2> /dev/null),)
  32. ifeq ($(shell test -e .git; echo $$?),0)
  33. GIT_REPO = 1
  34. endif
  35. endif
  36. USE_XATTR = 1
  37. UGID_USE_RWLOCK = 0
  38. ifeq ($(DEBUG),1)
  39. OPT_FLAGS := -O0 -g -fsanitize=undefined
  40. else
  41. OPT_FLAGS := -O2 -DNDEBUG
  42. endif
  43. ifeq ($(STATIC),1)
  44. STATIC_FLAGS := -static
  45. else
  46. STATIC_FLAGS :=
  47. endif
  48. ifeq ($(LTO),1)
  49. LTO_FLAGS := -flto
  50. else
  51. LTO_FLAGS :=
  52. endif
  53. SRC = $(wildcard src/*.cpp)
  54. OBJS = $(SRC:src/%.cpp=build/.src/%.o)
  55. DEPS = $(SRC:src/%.cpp=build/.src/%.d)
  56. TESTS = $(wildcard tests/*.cpp)
  57. TESTS_OBJS = $(filter-out build/.src/mergerfs.o,$(OBJS))
  58. TESTS_OBJS += $(TESTS:tests/%.cpp=build/.tests/%.o)
  59. TESTS_DEPS = $(TESTS:tests/%.cpp=build/.tests/%.d)
  60. TESTS_DEPS += $(DEPS)
  61. MANPAGE = mergerfs.1
  62. CFLAGS ?= ${OPT_FLAGS}
  63. CFLAGS := ${CFLAGS} \
  64. -Wall \
  65. -Wno-unused-result
  66. CXXFLAGS ?= ${OPT_FLAGS}
  67. CXXFLAGS := \
  68. ${CXXFLAGS} \
  69. -std=c++11 \
  70. $(STATIC_FLAGS) \
  71. $(LTO_FLAGS) \
  72. -Wall \
  73. -Wno-unused-result \
  74. -MMD
  75. FUSE_FLAGS = \
  76. -Ilibfuse/include \
  77. -D_FILE_OFFSET_BITS=64
  78. MFS_FLAGS = \
  79. -DUSE_XATTR=$(USE_XATTR) \
  80. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  81. TESTS_FLAGS = \
  82. -Isrc \
  83. -DTESTS
  84. LDFLAGS := \
  85. ${LDFLAGS} \
  86. -pthread \
  87. -lrt
  88. # https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
  89. DESTDIR =
  90. PREFIX = /usr/local
  91. EXEC_PREFIX = $(PREFIX)
  92. DATAROOTDIR = $(PREFIX)/share
  93. DATADIR = $(DATAROOTDIR)
  94. BINDIR = $(EXEC_PREFIX)/bin
  95. SBINDIR = $(EXEC_PREFIX)/sbin
  96. LIBDIR = $(EXEC_PREFIX)/lib
  97. MANDIR = $(DATAROOTDIR)/man
  98. MAN1DIR = $(MANDIR)/man1
  99. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  100. INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
  101. INSTALLLIBDIR = $(DESTDIR)$(LIBDIR)/mergerfs
  102. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  103. .PHONY: all
  104. all: mergerfs
  105. .PHONY: help
  106. help:
  107. @echo "usage: make\n"
  108. @echo "make USE_XATTR=0 - build program without xattrs functionality"
  109. @echo "make STATIC=1 - build static binary"
  110. @echo "make LTO=1 - build with link time optimization"
  111. objects: version build/stamp
  112. $(MAKE) $(OBJS)
  113. tests-objects:
  114. $(MAKE) $(TESTS_OBJS)
  115. build/mergerfs: libfuse objects
  116. $(CXX) $(CXXFLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) $(OBJS) -o $@ libfuse/build/libfuse.a $(LDFLAGS)
  117. build/tests: build/mergerfs tests-objects
  118. $(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) $(TESTS_OBJS) -o $@ libfuse/build/libfuse.a $(LDFLAGS)
  119. mergerfs: build/mergerfs
  120. tests: build/tests
  121. changelog:
  122. ifeq ($(GIT_REPO),1)
  123. $(GIT2DEBCL) --name mergerfs > ChangeLog
  124. else
  125. @echo "WARNING: need git repo to generate ChangeLog"
  126. endif
  127. .PHONY: version
  128. version:
  129. ./buildtools/update-version
  130. build/stamp:
  131. $(MKDIR) -p build/.src build/.tests
  132. $(TOUCH) $@
  133. build/.src/%.o: src/%.cpp
  134. $(CXX) $(CXXFLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
  135. build/.tests/%.o: tests/%.cpp
  136. $(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
  137. build/preload.so: build/stamp tools/preload.c
  138. $(CC) -shared -fPIC $(CFLAGS) $(CPPFLAGS) -o $@ tools/preload.c
  139. preload: build/preload.so
  140. .PHONY: clean
  141. clean: rpm-clean
  142. $(RM) -rf build
  143. $(FIND) . -name "*~" -delete
  144. $(MAKE) -C libfuse clean
  145. distclean: clean
  146. ifeq ($(GIT_REPO),1)
  147. $(GIT) clean -xfd
  148. endif
  149. .PHONY: install
  150. install: install-base install-mount-tools install-preload install-man
  151. install-base: build/mergerfs
  152. $(MKDIR) -p "$(INSTALLBINDIR)"
  153. $(INSTALL) -v -m 0755 build/mergerfs "$(INSTALLBINDIR)/mergerfs"
  154. install-mount-tools: install-base
  155. $(MKDIR) -p "$(INSTALLBINDIR)"
  156. $(MAKE) -C libfuse install
  157. install-man: $(MANPAGE)
  158. $(MKDIR) -p "$(INSTALLMAN1DIR)"
  159. $(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  160. install-preload: preload
  161. $(MKDIR) -p "$(INSTALLLIBDIR)"
  162. $(INSTALL) -v -m 444 "build/preload.so" "$(INSTALLLIBDIR)/preload.so"
  163. install-strip: install-base
  164. $(STRIP) "$(INSTALLBINDIR)/mergerfs"
  165. .PHONY: uninstall
  166. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  167. uninstall-base:
  168. $(RM) -f "$(INSTALLBINDIR)/mergerfs"
  169. uninstall-mount.mergerfs:
  170. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  171. uninstall-man:
  172. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  173. $(MANPAGE): README.md
  174. ifneq ($(shell $(PANDOC) --version 2> /dev/null),)
  175. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  176. else
  177. $(warning "pandoc does not appear available: unable to build manpage")
  178. endif
  179. man: $(MANPAGE)
  180. .PHONY: tarball
  181. tarball: man changelog version
  182. $(eval VERSION := $(shell cat VERSION))
  183. $(eval VERSION := $(subst -,_,$(VERSION)))
  184. $(eval FILENAME := mergerfs-$(VERSION))
  185. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  186. $(MKDIR) $(TMPDIR)/$(FILENAME)
  187. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  188. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  189. $(RM) -rf $(TMPDIR)
  190. debian-changelog:
  191. ifeq ($(GIT_REPO),1)
  192. $(GIT2DEBCL) --name mergerfs > debian/changelog
  193. else
  194. cp ChangeLog debian/changelog
  195. endif
  196. signed-deb:
  197. $(MAKE) distclean
  198. $(MAKE) debian-changelog
  199. # dpkg-source -b .
  200. dpkg-buildpackage -nc
  201. deb:
  202. $(MAKE) distclean
  203. $(MAKE) debian-changelog
  204. # dpkg-source -b .
  205. dpkg-buildpackage -nc -uc -us
  206. .PHONY: rpm-clean
  207. rpm-clean:
  208. $(RM) -rf rpmbuild
  209. rpm: tarball
  210. $(eval VERSION := $(shell cat VERSION))
  211. $(eval VERSION := $(subst -,_,$(VERSION)))
  212. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  213. $(SED) 's/__VERSION__/$(VERSION)/g' mergerfs.spec > \
  214. rpmbuild/SOURCES/mergerfs.spec
  215. cp -ar mergerfs-$(VERSION).tar.gz rpmbuild/SOURCES
  216. $(RPMBUILD) -ba rpmbuild/SOURCES/mergerfs.spec \
  217. --define "_topdir $(CURDIR)/rpmbuild"
  218. .PHONY: install-build-pkgs
  219. install-build-pkgs:
  220. ./buildtools/install-build-pkgs
  221. .PHONY: libfuse
  222. libfuse:
  223. $(MAKE) DEBUG=$(DEBUG) -C libfuse
  224. -include $(DEPS)