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.

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