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.

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