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.

243 lines
6.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
10 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 = $(shell which git)
  15. TAR = $(shell which tar)
  16. MKDIR = $(shell which mkdir)
  17. TOUCH = $(shell which touch)
  18. CP = $(shell which cp)
  19. RM = $(shell which rm)
  20. LN = $(shell which ln)
  21. FIND = $(shell which find)
  22. INSTALL = $(shell which install)
  23. MKTEMP = $(shell which mktemp)
  24. STRIP = $(shell which strip)
  25. PANDOC = $(shell which pandoc)
  26. SED = $(shell which sed)
  27. GZIP = $(shell which gzip)
  28. RPMBUILD = $(shell which rpmbuild)
  29. GIT2DEBCL = ./tools/git2debcl
  30. PKGCONFIG = pkg-config
  31. GIT_REPO = 0
  32. ifneq ($(GIT),)
  33. ifeq ($(shell test -e .git; echo $$?),0)
  34. GIT_REPO = 1
  35. endif
  36. endif
  37. ifeq ($(PANDOC),)
  38. $(warning "pandoc does not appear available: manpage won't be buildable")
  39. endif
  40. USE_XATTR = 1
  41. INTERNAL_FUSE = 1
  42. EXTERNAL_FUSE_MIN_REQ = 2.9.7
  43. ifeq ($(INTERNAL_FUSE),1)
  44. FUSE_CFLAGS = -D_FILE_OFFSET_BITS=64 -Ilibfuse/include
  45. FUSE_LIBS = libfuse/lib/.libs/libfuse.a
  46. FUSE_TARGET = $(FUSE_LIBS)
  47. else
  48. FUSE_CFLAGS := $(shell $(PKGCONFIG) --cflags 'fuse >= $(EXTERNAL_FUSE_MIN_REQ)')
  49. FUSE_LIBS := $(shell $(PKGCONFIG) --libs 'fuse >= $(EXTERNAL_FUSE_MIN_REQ)')
  50. FUSE_TARGET :=
  51. ifeq ($(FUSE_CFLAGS)$(FUSE_LIBS),)
  52. $(error "Use of external FUSE requested, but no libfuse >= $(EXTERNAL_FUSE_MIN_REQ) found.")
  53. endif
  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. CFLAGS = -g -Wall \
  63. $(OPTS) \
  64. -Wno-unused-result \
  65. $(FUSE_CFLAGS) \
  66. -DFUSE_USE_VERSION=29 \
  67. -MMD \
  68. -DUSE_XATTR=$(USE_XATTR) \
  69. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  70. PREFIX = /usr/local
  71. EXEC_PREFIX = $(PREFIX)
  72. DATAROOTDIR = $(PREFIX)/share
  73. DATADIR = $(DATAROOTDIR)
  74. BINDIR = $(EXEC_PREFIX)/bin
  75. SBINDIR = $(EXEC_PREFIX)/sbin
  76. MANDIR = $(DATAROOTDIR)/man
  77. MAN1DIR = $(MANDIR)/man1
  78. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  79. INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
  80. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  81. all: $(TARGET)
  82. help:
  83. @echo "usage: make"
  84. @echo "make USE_XATTR=0 - build program without xattrs functionality"
  85. @echo "make INTERNAL_FUSE=0 - to build program with external (system) libfuse rather than the bundled one ('-o threads=' option will be unavailable)"
  86. $(TARGET): version obj/obj-stamp $(FUSE_TARGET) $(OBJ)
  87. $(CXX) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@ $(FUSE_LIBS) -ldl -pthread -lrt
  88. mount.mergerfs: $(TARGET)
  89. $(LN) -fs "$<" "$@"
  90. changelog:
  91. ifeq ($(GIT_REPO),1)
  92. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  93. endif
  94. authors:
  95. ifeq ($(GIT_REPO),1)
  96. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  97. endif
  98. version:
  99. tools/update-version
  100. obj/obj-stamp:
  101. $(MKDIR) -p obj
  102. $(TOUCH) $@
  103. obj/%.o: src/%.cpp
  104. $(CXX) $(CFLAGS) -c $< -o $@
  105. clean: rpm-clean libfuse_Makefile
  106. $(RM) -f src/version.hpp
  107. $(RM) -rf obj
  108. $(RM) -f "$(TARGET)" mount.mergerfs
  109. $(FIND) . -name "*~" -delete
  110. ifeq ($(INTERNAL_FUSE),1)
  111. cd libfuse && $(MAKE) clean
  112. endif
  113. distclean: clean libfuse_Makefile
  114. ifeq ($(INTERNAL_FUSE),1)
  115. cd libfuse && $(MAKE) distclean
  116. endif
  117. ifeq ($(GIT_REPO),1)
  118. $(GIT) clean -fd
  119. endif
  120. install: install-base install-mount.mergerfs install-man
  121. install-base: $(TARGET)
  122. $(MKDIR) -p "$(INSTALLBINDIR)"
  123. $(INSTALL) -v -m 0755 "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  124. install-mount.mergerfs: mount.mergerfs
  125. $(MKDIR) -p "$(INSTALLBINDIR)"
  126. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  127. install-man: $(MANPAGE)
  128. $(MKDIR) -p "$(INSTALLMAN1DIR)"
  129. $(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  130. install-strip: install-base
  131. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  132. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  133. uninstall-base:
  134. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  135. uninstall-mount.mergerfs:
  136. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  137. uninstall-man:
  138. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  139. $(MANPAGE): README.md
  140. ifneq ($(PANDOC),)
  141. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  142. endif
  143. man: $(MANPAGE)
  144. tarball: distclean man changelog authors version
  145. $(eval VERSION := $(shell cat VERSION))
  146. $(eval VERSION := $(subst -,_,$(VERSION)))
  147. $(eval FILENAME := $(TARGET)-$(VERSION))
  148. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  149. $(MKDIR) $(TMPDIR)/$(FILENAME)
  150. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  151. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  152. $(RM) -rf $(TMPDIR)
  153. debian-changelog:
  154. ifeq ($(GIT_REPO),1)
  155. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  156. else
  157. cp ChangeLog debian/changelog
  158. endif
  159. signed-deb: debian-changelog
  160. dpkg-buildpackage
  161. deb: debian-changelog
  162. dpkg-buildpackage -uc -us
  163. rpm-clean:
  164. $(RM) -rf rpmbuild
  165. rpm: tarball
  166. $(eval VERSION := $(shell cat VERSION))
  167. $(eval VERSION := $(subst -,_,$(VERSION)))
  168. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  169. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  170. rpmbuild/SOURCES/$(TARGET).spec
  171. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  172. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  173. --define "_topdir $(CURDIR)/rpmbuild"
  174. install-build-pkgs:
  175. ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0)
  176. apt-get -qy update
  177. apt-get -qy --no-install-suggests --no-install-recommends --force-yes \
  178. install build-essential git g++ debhelper python automake libtool lsb-release
  179. else ifeq ($(shell test -e /usr/bin/dnf; echo $$?),0)
  180. dnf -y update
  181. dnf -y install git rpm-build gcc-c++ make which python automake libtool gettext-devel
  182. else ifeq ($(shell test -e /usr/bin/yum; echo $$?),0)
  183. yum -y update
  184. yum -y install git rpm-build gcc-c++ make which python automake libtool gettext-devel
  185. endif
  186. unexport CFLAGS
  187. .PHONY: libfuse_Makefile
  188. libfuse_Makefile:
  189. ifeq ($(INTERNAL_FUSE),1)
  190. ifeq ($(shell test -e libfuse/Makefile; echo $$?),1)
  191. cd libfuse && \
  192. $(MKDIR) -p m4 && \
  193. autoreconf --force --install && \
  194. ./configure --enable-lib --disable-util --disable-example
  195. endif
  196. endif
  197. libfuse/lib/.libs/libfuse.a: libfuse_Makefile
  198. cd libfuse && $(MAKE)
  199. .PHONY: all clean install help version
  200. -include $(DEPS)