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.

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