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.

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