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