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.

255 lines
6.5 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
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. INTERNAL_FUSE = 1
  38. EXTERNAL_FUSE_MIN_REQ = 2.9.7
  39. ifeq ($(INTERNAL_FUSE),1)
  40. FUSE_CFLAGS = -D_FILE_OFFSET_BITS=64 -Ilibfuse/include
  41. FUSE_LIBS = libfuse/lib/.libs/libfuse.a
  42. FUSE_TARGET = $(FUSE_LIBS)
  43. else
  44. FUSE_CFLAGS := $(shell $(PKGCONFIG) --cflags 'fuse >= $(EXTERNAL_FUSE_MIN_REQ)')
  45. FUSE_LIBS := $(shell $(PKGCONFIG) --libs 'fuse >= $(EXTERNAL_FUSE_MIN_REQ)')
  46. FUSE_TARGET :=
  47. ifeq ($(FUSE_CFLAGS)$(FUSE_LIBS),)
  48. $(error "Use of external FUSE requested, but no libfuse >= $(EXTERNAL_FUSE_MIN_REQ) found.")
  49. endif
  50. endif
  51. ifeq ($(STATIC),1)
  52. STATIC_FLAG := -static
  53. else
  54. STATIC_FLAG :=
  55. endif
  56. ifeq ($(LTO),1)
  57. LTO_FLAG := -flto
  58. else
  59. LTO_FLAG :=
  60. endif
  61. UGID_USE_RWLOCK = 0
  62. OPTS = -O2 -g
  63. SRC = $(wildcard src/*.cpp)
  64. OBJ = $(SRC:src/%.cpp=obj/%.o)
  65. DEPS = $(OBJ:obj/%.o=obj/%.d)
  66. TARGET = mergerfs
  67. MANPAGE = $(TARGET).1
  68. CXXFLAGS = $(OPTS) \
  69. $(STATIC_FLAG) \
  70. $(LTO_FLAG) \
  71. -Wall \
  72. -Wno-unused-result \
  73. $(FUSE_CFLAGS) \
  74. -DFUSE_USE_VERSION=29 \
  75. -MMD \
  76. -DUSE_XATTR=$(USE_XATTR) \
  77. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  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. all: $(TARGET)
  90. help:
  91. @echo "usage: make\n"
  92. @echo "make USE_XATTR=0 - build program without xattrs functionality"
  93. @echo "make INTERNAL_FUSE=0 - to build program with external (system) libfuse rather than the bundled one ('-o threads=' option will be unavailable)"
  94. @echo "make STATIC=1 - build static binary"
  95. @echo "make LTO=1 - build with link time optimization"
  96. $(TARGET): version obj/obj-stamp $(FUSE_TARGET) $(OBJ)
  97. $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(OBJ) -o $@ $(FUSE_LIBS) -ldl -pthread -lrt
  98. mount.mergerfs: $(TARGET)
  99. $(LN) -fs "$<" "$@"
  100. changelog:
  101. ifeq ($(GIT_REPO),1)
  102. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  103. else
  104. @echo "WARNING: need git repo to generate ChangeLog"
  105. endif
  106. authors:
  107. ifeq ($(GIT_REPO),1)
  108. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  109. else
  110. @echo "WARNING: need git repo to generate AUTHORS"
  111. endif
  112. version:
  113. tools/update-version
  114. obj/obj-stamp:
  115. $(MKDIR) -p obj
  116. $(TOUCH) $@
  117. obj/%.o: src/%.cpp
  118. $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
  119. clean: rpm-clean libfuse_Makefile
  120. $(RM) -f src/version.hpp
  121. $(RM) -rf obj
  122. $(RM) -f "$(TARGET)" mount.mergerfs
  123. $(FIND) . -name "*~" -delete
  124. ifeq ($(INTERNAL_FUSE),1)
  125. cd libfuse && $(MAKE) clean
  126. endif
  127. distclean: clean libfuse_Makefile
  128. ifeq ($(INTERNAL_FUSE),1)
  129. cd libfuse && $(MAKE) distclean
  130. endif
  131. ifeq ($(GIT_REPO),1)
  132. $(GIT) clean -fd
  133. endif
  134. superclean: distclean
  135. ifeq ($(GIT_REPO),1)
  136. $(GIT) clean -xfd
  137. endif
  138. install: install-base install-mount.mergerfs install-man
  139. install-base: $(TARGET)
  140. $(MKDIR) -p "$(INSTALLBINDIR)"
  141. $(INSTALL) -v -m 0755 "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  142. install-mount.mergerfs: mount.mergerfs
  143. $(MKDIR) -p "$(INSTALLBINDIR)"
  144. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  145. install-man: $(MANPAGE)
  146. $(MKDIR) -p "$(INSTALLMAN1DIR)"
  147. $(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  148. install-strip: install-base
  149. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  150. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  151. uninstall-base:
  152. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  153. uninstall-mount.mergerfs:
  154. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  155. uninstall-man:
  156. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  157. $(MANPAGE): README.md
  158. ifneq ($(shell $(PANDOC) --version 2> /dev/null),)
  159. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  160. else
  161. $(warning "pandoc does not appear available: unable to build manpage")
  162. endif
  163. man: $(MANPAGE)
  164. tarball: superclean man changelog authors version
  165. $(eval VERSION := $(shell cat VERSION))
  166. $(eval VERSION := $(subst -,_,$(VERSION)))
  167. $(eval FILENAME := $(TARGET)-$(VERSION))
  168. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  169. $(MKDIR) $(TMPDIR)/$(FILENAME)
  170. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  171. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  172. $(RM) -rf $(TMPDIR)
  173. debian-changelog:
  174. ifeq ($(GIT_REPO),1)
  175. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  176. else
  177. cp ChangeLog debian/changelog
  178. endif
  179. signed-deb: debian-changelog
  180. dpkg-buildpackage
  181. deb: debian-changelog
  182. dpkg-buildpackage -uc -us
  183. rpm-clean:
  184. $(RM) -rf rpmbuild
  185. rpm: tarball
  186. $(eval VERSION := $(shell cat VERSION))
  187. $(eval VERSION := $(subst -,_,$(VERSION)))
  188. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  189. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  190. rpmbuild/SOURCES/$(TARGET).spec
  191. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  192. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  193. --define "_topdir $(CURDIR)/rpmbuild"
  194. install-build-pkgs:
  195. tools/install-build-pkgs
  196. unexport CFLAGS
  197. .PHONY: libfuse_Makefile
  198. libfuse_Makefile:
  199. ifeq ($(INTERNAL_FUSE),1)
  200. ifeq ($(shell test -e libfuse/Makefile; echo $$?),1)
  201. cd libfuse && \
  202. $(MKDIR) -p m4 && \
  203. autoreconf --force --install && \
  204. ./configure --enable-lib --disable-util --disable-example
  205. endif
  206. endif
  207. libfuse/lib/.libs/libfuse.a: libfuse_Makefile
  208. cd libfuse && $(MAKE)
  209. .PHONY: all clean install help version
  210. -include $(DEPS)