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.

275 lines
6.8 KiB

7 years ago
7 years ago
8 months 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. -Isrc
  68. CXXFLAGS := \
  69. ${CXXFLAGS} \
  70. -std=c++11 \
  71. $(STATIC_FLAGS) \
  72. $(LTO_FLAGS) \
  73. -Wall \
  74. -Wno-unused-result \
  75. -MMD
  76. FUSE_FLAGS = \
  77. -Ilibfuse/include \
  78. -D_FILE_OFFSET_BITS=64
  79. MFS_FLAGS = \
  80. -DUSE_XATTR=$(USE_XATTR) \
  81. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  82. TESTS_FLAGS = \
  83. -Isrc \
  84. -DTESTS
  85. LDFLAGS := \
  86. ${LDFLAGS} \
  87. -pthread \
  88. -lrt
  89. # https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
  90. DESTDIR =
  91. PREFIX = /usr/local
  92. EXEC_PREFIX = $(PREFIX)
  93. DATAROOTDIR = $(PREFIX)/share
  94. DATADIR = $(DATAROOTDIR)
  95. BINDIR = $(EXEC_PREFIX)/bin
  96. SBINDIR = $(EXEC_PREFIX)/sbin
  97. LIBDIR = $(EXEC_PREFIX)/lib
  98. MANDIR = $(DATAROOTDIR)/man
  99. MAN1DIR = $(MANDIR)/man1
  100. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  101. INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
  102. INSTALLLIBDIR = $(DESTDIR)$(LIBDIR)/mergerfs
  103. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  104. .PHONY: all
  105. all: mergerfs
  106. .PHONY: help
  107. help:
  108. @echo "usage: make\n"
  109. @echo "make USE_XATTR=0 - build program without xattrs functionality"
  110. @echo "make STATIC=1 - build static binary"
  111. @echo "make LTO=1 - build with link time optimization"
  112. objects: version build/stamp
  113. $(MAKE) $(OBJS)
  114. tests-objects:
  115. $(MAKE) $(TESTS_OBJS)
  116. build/mergerfs: libfuse objects
  117. $(CXX) $(CXXFLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) $(OBJS) -o $@ libfuse/build/libfuse.a $(LDFLAGS)
  118. build/tests: build/mergerfs tests-objects
  119. $(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) $(TESTS_OBJS) -o $@ libfuse/build/libfuse.a $(LDFLAGS)
  120. mergerfs: build/mergerfs
  121. tests: build/tests
  122. changelog:
  123. ifeq ($(GIT_REPO),1)
  124. $(GIT2DEBCL) --name mergerfs > ChangeLog
  125. else
  126. @echo "WARNING: need git repo to generate ChangeLog"
  127. endif
  128. .PHONY: version
  129. version:
  130. ./buildtools/update-version
  131. build/stamp:
  132. $(MKDIR) -p build/.src build/.tests
  133. $(TOUCH) $@
  134. build/.src/%.o: src/%.cpp
  135. $(CXX) $(CXXFLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
  136. build/.tests/%.o: tests/%.cpp
  137. $(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
  138. build/preload.so: build/stamp tools/preload.c
  139. $(CC) -shared -fPIC $(CFLAGS) $(CPPFLAGS) -o $@ tools/preload.c
  140. preload: build/preload.so
  141. .PHONY: clean
  142. clean: rpm-clean
  143. $(RM) -rf build
  144. $(FIND) . -name "*~" -delete
  145. $(MAKE) -C libfuse clean
  146. distclean: clean
  147. ifeq ($(GIT_REPO),1)
  148. $(GIT) clean -xfd
  149. endif
  150. .PHONY: install
  151. install: install-base install-mount-tools install-preload install-man
  152. install-base: build/mergerfs
  153. $(MKDIR) -p "$(INSTALLBINDIR)"
  154. $(INSTALL) -v -m 0755 build/mergerfs "$(INSTALLBINDIR)/mergerfs"
  155. install-mount-tools: install-base
  156. $(MKDIR) -p "$(INSTALLBINDIR)"
  157. $(MAKE) -C libfuse install
  158. install-man: $(MANPAGE)
  159. $(MKDIR) -p "$(INSTALLMAN1DIR)"
  160. $(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  161. install-preload: preload
  162. $(MKDIR) -p "$(INSTALLLIBDIR)"
  163. $(INSTALL) -v -m 444 "build/preload.so" "$(INSTALLLIBDIR)/preload.so"
  164. install-strip: install-base
  165. $(STRIP) "$(INSTALLBINDIR)/mergerfs"
  166. .PHONY: uninstall
  167. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  168. uninstall-base:
  169. $(RM) -f "$(INSTALLBINDIR)/mergerfs"
  170. uninstall-mount.mergerfs:
  171. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  172. uninstall-man:
  173. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  174. $(MANPAGE): README.md
  175. ifneq ($(shell $(PANDOC) --version 2> /dev/null),)
  176. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  177. else
  178. $(warning "pandoc does not appear available: unable to build manpage")
  179. endif
  180. man: $(MANPAGE)
  181. .PHONY: tarball
  182. tarball: man changelog version
  183. $(eval VERSION := $(shell cat VERSION))
  184. $(eval VERSION := $(subst -,_,$(VERSION)))
  185. $(eval FILENAME := mergerfs-$(VERSION))
  186. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  187. $(MKDIR) $(TMPDIR)/$(FILENAME)
  188. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  189. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  190. $(RM) -rf $(TMPDIR)
  191. debian-changelog:
  192. ifeq ($(GIT_REPO),1)
  193. $(GIT2DEBCL) --name mergerfs > debian/changelog
  194. else
  195. cp ChangeLog debian/changelog
  196. endif
  197. signed-deb:
  198. $(MAKE) distclean
  199. $(MAKE) debian-changelog
  200. # dpkg-source -b .
  201. dpkg-buildpackage -nc
  202. deb:
  203. $(MAKE) distclean
  204. $(MAKE) debian-changelog
  205. # dpkg-source -b .
  206. dpkg-buildpackage -nc -uc -us
  207. .PHONY: rpm-clean
  208. rpm-clean:
  209. $(RM) -rf rpmbuild
  210. rpm: tarball
  211. $(eval VERSION := $(shell cat VERSION))
  212. $(eval VERSION := $(subst -,_,$(VERSION)))
  213. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  214. $(SED) 's/__VERSION__/$(VERSION)/g' mergerfs.spec > \
  215. rpmbuild/SOURCES/mergerfs.spec
  216. cp -ar mergerfs-$(VERSION).tar.gz rpmbuild/SOURCES
  217. $(RPMBUILD) -ba rpmbuild/SOURCES/mergerfs.spec \
  218. --define "_topdir $(CURDIR)/rpmbuild"
  219. .PHONY: install-build-pkgs
  220. install-build-pkgs:
  221. ./buildtools/install-build-pkgs
  222. .PHONY: libfuse
  223. libfuse:
  224. $(MAKE) DEBUG=$(DEBUG) -C libfuse
  225. -include $(DEPS)