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.

247 lines
6.9 KiB

7 years ago
11 years ago
11 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
11 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. XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
  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. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  69. PREFIX = /usr/local
  70. EXEC_PREFIX = $(PREFIX)
  71. DATAROOTDIR = $(PREFIX)/share
  72. DATADIR = $(DATAROOTDIR)
  73. BINDIR = $(EXEC_PREFIX)/bin
  74. SBINDIR = $(EXEC_PREFIX)/sbin
  75. MANDIR = $(DATAROOTDIR)/man
  76. MAN1DIR = $(MANDIR)/man1
  77. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  78. INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
  79. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  80. ifeq ($(XATTR_AVAILABLE),0)
  81. $(warning "xattr not available: disabling")
  82. CFLAGS += -DWITHOUT_XATTR
  83. endif
  84. all: $(TARGET)
  85. help:
  86. @echo "usage: make"
  87. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  88. @echo "make INTERNAL_FUSE=0 - to build program with external (system) libfuse rather than the bundled one ('-o threads=' option will be unavailable)"
  89. $(TARGET): version obj/obj-stamp $(FUSE_TARGET) $(OBJ)
  90. $(CXX) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@ $(FUSE_LIBS) -ldl -pthread -lrt
  91. mount.mergerfs: $(TARGET)
  92. $(LN) -fs "$<" "$@"
  93. changelog:
  94. ifeq ($(GIT_REPO),1)
  95. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  96. endif
  97. authors:
  98. ifeq ($(GIT_REPO),1)
  99. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  100. endif
  101. version:
  102. tools/update-version
  103. obj/obj-stamp:
  104. $(MKDIR) -p obj
  105. $(TOUCH) $@
  106. obj/%.o: src/%.cpp
  107. $(CXX) $(CFLAGS) -c $< -o $@
  108. clean: rpm-clean libfuse_Makefile
  109. $(RM) -f src/version.hpp
  110. $(RM) -rf obj
  111. $(RM) -f "$(TARGET)" mount.mergerfs
  112. $(FIND) . -name "*~" -delete
  113. ifeq ($(INTERNAL_FUSE),1)
  114. cd libfuse && $(MAKE) clean
  115. endif
  116. distclean: clean libfuse_Makefile
  117. ifeq ($(INTERNAL_FUSE),1)
  118. cd libfuse && $(MAKE) distclean
  119. endif
  120. ifeq ($(GIT_REPO),1)
  121. $(GIT) clean -fd
  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 ($(PANDOC),)
  144. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  145. endif
  146. man: $(MANPAGE)
  147. tarball: distclean man changelog authors version
  148. $(eval VERSION := $(shell cat VERSION))
  149. $(eval VERSION := $(subst -,_,$(VERSION)))
  150. $(eval FILENAME := $(TARGET)-$(VERSION))
  151. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  152. $(MKDIR) $(TMPDIR)/$(FILENAME)
  153. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  154. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  155. $(RM) -rf $(TMPDIR)
  156. debian-changelog:
  157. ifeq ($(GIT_REPO),1)
  158. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  159. else
  160. cp ChangeLog debian/changelog
  161. endif
  162. signed-deb: debian-changelog
  163. dpkg-buildpackage
  164. deb: debian-changelog
  165. dpkg-buildpackage -uc -us
  166. rpm-clean:
  167. $(RM) -rf rpmbuild
  168. rpm: tarball
  169. $(eval VERSION := $(shell cat VERSION))
  170. $(eval VERSION := $(subst -,_,$(VERSION)))
  171. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  172. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  173. rpmbuild/SOURCES/$(TARGET).spec
  174. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  175. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  176. --define "_topdir $(CURDIR)/rpmbuild"
  177. install-build-pkgs:
  178. ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0)
  179. apt-get -qy update
  180. apt-get -qy --no-install-suggests --no-install-recommends --force-yes \
  181. install build-essential git g++ debhelper libattr1-dev python automake libtool lsb-release
  182. else ifeq ($(shell test -e /usr/bin/dnf; echo $$?),0)
  183. dnf -y update
  184. dnf -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
  185. else ifeq ($(shell test -e /usr/bin/yum; echo $$?),0)
  186. yum -y update
  187. yum -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
  188. endif
  189. unexport CFLAGS
  190. .PHONY: libfuse_Makefile
  191. libfuse_Makefile:
  192. ifeq ($(INTERNAL_FUSE),1)
  193. ifeq ($(shell test -e libfuse/Makefile; echo $$?),1)
  194. cd libfuse && \
  195. $(MKDIR) -p m4 && \
  196. autoreconf --force --install && \
  197. ./configure --enable-lib --disable-util --disable-example
  198. endif
  199. endif
  200. libfuse/lib/.libs/libfuse.a: libfuse_Makefile
  201. cd libfuse && $(MAKE)
  202. .PHONY: all clean install help version
  203. -include $(DEPS)