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.

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