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.

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