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.

225 lines
6.3 KiB

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