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.

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