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.

226 lines
6.3 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. GIT_REPO = 0
  31. ifneq ($(GIT),)
  32. ifeq ($(shell test -e .git; echo $$?),0)
  33. GIT_REPO = 1
  34. endif
  35. endif
  36. ifeq ($(PANDOC),)
  37. $(warning "pandoc does not appear available: manpage won't be buildable")
  38. endif
  39. XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
  40. UGID_USE_RWLOCK = 0
  41. OPTS = -O2
  42. SRC = $(wildcard src/*.cpp)
  43. OBJ = $(SRC:src/%.cpp=obj/%.o)
  44. DEPS = $(OBJ:obj/%.o=obj/%.d)
  45. TARGET = mergerfs
  46. MANPAGE = $(TARGET).1
  47. FUSE_CFLAGS = -D_FILE_OFFSET_BITS=64 -Ilibfuse/include
  48. CFLAGS = -g -Wall \
  49. $(OPTS) \
  50. -Wno-unused-result \
  51. $(FUSE_CFLAGS) \
  52. -DFUSE_USE_VERSION=29 \
  53. -MMD \
  54. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  55. LDFLAGS = -pthread -lrt
  56. PREFIX = /usr/local
  57. EXEC_PREFIX = $(PREFIX)
  58. DATAROOTDIR = $(PREFIX)/share
  59. DATADIR = $(DATAROOTDIR)
  60. BINDIR = $(EXEC_PREFIX)/bin
  61. SBINDIR = $(EXEC_PREFIX)/sbin
  62. MANDIR = $(DATAROOTDIR)/man
  63. MAN1DIR = $(MANDIR)/man1
  64. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  65. INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
  66. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  67. ifeq ($(XATTR_AVAILABLE),0)
  68. $(warning "xattr not available: disabling")
  69. CFLAGS += -DWITHOUT_XATTR
  70. endif
  71. all: $(TARGET)
  72. help:
  73. @echo "usage: make"
  74. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  75. $(TARGET): version obj/obj-stamp libfuse/lib/.libs/libfuse.a $(OBJ)
  76. cd libfuse && make
  77. $(CXX) $(CFLAGS) $(OBJ) -o $@ libfuse/lib/.libs/libfuse.a -ldl $(LDFLAGS)
  78. mount.mergerfs: $(TARGET)
  79. $(LN) -fs "$<" "$@"
  80. changelog:
  81. ifeq ($(GIT_REPO),1)
  82. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  83. endif
  84. authors:
  85. ifeq ($(GIT_REPO),1)
  86. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  87. endif
  88. version:
  89. tools/update-version
  90. obj/obj-stamp:
  91. $(MKDIR) -p obj
  92. $(TOUCH) $@
  93. obj/%.o: src/%.cpp
  94. $(CXX) $(CFLAGS) -c $< -o $@
  95. clean: rpm-clean libfuse_Makefile
  96. $(RM) -f src/version.hpp
  97. $(RM) -rf obj
  98. $(RM) -f "$(TARGET)" mount.mergerfs
  99. $(FIND) . -name "*~" -delete
  100. cd libfuse && $(MAKE) clean
  101. distclean: clean libfuse_Makefile
  102. cd libfuse && $(MAKE) distclean
  103. ifeq ($(GIT_REPO),1)
  104. $(GIT) clean -fd
  105. endif
  106. install: install-base install-mount.mergerfs install-man
  107. install-base: $(TARGET)
  108. $(MKDIR) -p "$(INSTALLBINDIR)"
  109. $(INSTALL) -v -m 0755 "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  110. install-mount.mergerfs: mount.mergerfs
  111. $(MKDIR) -p "$(INSTALLBINDIR)"
  112. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  113. install-man: $(MANPAGE)
  114. $(MKDIR) -p "$(INSTALLMAN1DIR)"
  115. $(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  116. install-strip: install-base
  117. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  118. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  119. uninstall-base:
  120. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  121. uninstall-mount.mergerfs:
  122. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  123. uninstall-man:
  124. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  125. $(MANPAGE): README.md
  126. ifneq ($(PANDOC),)
  127. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  128. endif
  129. man: $(MANPAGE)
  130. tarball: distclean man changelog authors version
  131. $(eval VERSION := $(shell cat VERSION))
  132. $(eval VERSION := $(subst -,_,$(VERSION)))
  133. $(eval FILENAME := $(TARGET)-$(VERSION))
  134. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  135. $(MKDIR) $(TMPDIR)/$(FILENAME)
  136. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  137. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  138. $(RM) -rf $(TMPDIR)
  139. debian-changelog:
  140. ifeq ($(GIT_REPO),1)
  141. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  142. else
  143. cp ChangeLog debian/changelog
  144. endif
  145. signed-deb: debian-changelog
  146. dpkg-buildpackage
  147. deb: debian-changelog
  148. dpkg-buildpackage -uc -us
  149. rpm-clean:
  150. $(RM) -rf rpmbuild
  151. rpm: tarball
  152. $(eval VERSION := $(shell cat VERSION))
  153. $(eval VERSION := $(subst -,_,$(VERSION)))
  154. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  155. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  156. rpmbuild/SOURCES/$(TARGET).spec
  157. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  158. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  159. --define "_topdir $(CURDIR)/rpmbuild"
  160. install-build-pkgs:
  161. ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0)
  162. apt-get -qy update
  163. apt-get -qy --no-install-suggests --no-install-recommends --force-yes \
  164. install build-essential git g++ debhelper libattr1-dev python automake libtool lsb-release
  165. else ifeq ($(shell test -e /usr/bin/dnf; echo $$?),0)
  166. dnf -y update
  167. dnf -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
  168. else ifeq ($(shell test -e /usr/bin/yum; echo $$?),0)
  169. yum -y update
  170. yum -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
  171. endif
  172. unexport CFLAGS LDFLAGS
  173. .PHONY: libfuse_Makefile
  174. libfuse_Makefile:
  175. ifeq ($(shell test -e libfuse/Makefile; echo $$?),1)
  176. cd libfuse && \
  177. $(MKDIR) -p m4 && \
  178. autoreconf --force --install && \
  179. ./configure --enable-lib --disable-util --disable-example
  180. endif
  181. libfuse/lib/.libs/libfuse.a: libfuse_Makefile
  182. cd libfuse && $(MAKE)
  183. .PHONY: all clean install help version
  184. -include $(DEPS)