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.

234 lines
6.6 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
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): src/version.hpp 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. ifeq ($(GIT_REPO),1)
  90. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  91. @echo "$(VERSION)" > VERSION
  92. endif
  93. src/version.hpp: version
  94. $(eval VERSION := $(shell cat VERSION))
  95. @echo "#pragma once" > src/version.hpp
  96. @echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
  97. obj/obj-stamp:
  98. $(MKDIR) -p obj
  99. $(TOUCH) $@
  100. obj/%.o: src/%.cpp
  101. $(CXX) $(CFLAGS) -c $< -o $@
  102. clean: rpm-clean libfuse_Makefile
  103. $(RM) -f src/version.hpp
  104. $(RM) -rf obj
  105. $(RM) -f "$(TARGET)" mount.mergerfs
  106. $(FIND) . -name "*~" -delete
  107. cd libfuse && $(MAKE) clean
  108. distclean: clean libfuse_Makefile
  109. cd libfuse && $(MAKE) distclean
  110. ifeq ($(GIT_REPO),1)
  111. $(GIT) clean -fd
  112. endif
  113. install: install-base install-mount.mergerfs install-man
  114. install-base: $(TARGET)
  115. $(MKDIR) -p "$(INSTALLBINDIR)"
  116. $(INSTALL) -v -m 0755 "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  117. install-mount.mergerfs: mount.mergerfs
  118. $(MKDIR) -p "$(INSTALLBINDIR)"
  119. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  120. install-man: $(MANPAGE)
  121. $(MKDIR) -p "$(INSTALLMAN1DIR)"
  122. $(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  123. install-strip: install-base
  124. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  125. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  126. uninstall-base:
  127. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  128. uninstall-mount.mergerfs:
  129. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  130. uninstall-man:
  131. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  132. $(MANPAGE): README.md
  133. ifneq ($(PANDOC),)
  134. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  135. endif
  136. man: $(MANPAGE)
  137. tarball: distclean man changelog authors version
  138. $(eval VERSION := $(shell cat VERSION))
  139. $(eval VERSION := $(subst -,_,$(VERSION)))
  140. $(eval FILENAME := $(TARGET)-$(VERSION))
  141. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  142. $(MKDIR) $(TMPDIR)/$(FILENAME)
  143. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  144. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  145. $(RM) -rf $(TMPDIR)
  146. debian-changelog:
  147. ifeq ($(GIT_REPO),1)
  148. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  149. else
  150. cp ChangeLog debian/changelog
  151. endif
  152. signed-deb: debian-changelog
  153. dpkg-buildpackage
  154. deb: debian-changelog
  155. dpkg-buildpackage -uc -us
  156. rpm-clean:
  157. $(RM) -rf rpmbuild
  158. rpm: tarball
  159. $(eval VERSION := $(shell cat VERSION))
  160. $(eval VERSION := $(subst -,_,$(VERSION)))
  161. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  162. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  163. rpmbuild/SOURCES/$(TARGET).spec
  164. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  165. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  166. --define "_topdir $(CURDIR)/rpmbuild"
  167. install-build-pkgs:
  168. ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0)
  169. apt-get -qy update
  170. apt-get -qy --no-install-suggests --no-install-recommends --force-yes \
  171. install build-essential git g++ debhelper libattr1-dev python automake libtool lsb-release
  172. else ifeq ($(shell test -e /usr/bin/dnf; echo $$?),0)
  173. dnf -y update
  174. dnf -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
  175. else ifeq ($(shell test -e /usr/bin/yum; echo $$?),0)
  176. yum -y update
  177. yum -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel
  178. endif
  179. unexport CFLAGS LDFLAGS
  180. .PHONY: libfuse_Makefile
  181. libfuse_Makefile:
  182. ifeq ($(shell test -e libfuse/Makefile; echo $$?),1)
  183. cd libfuse && \
  184. $(MKDIR) -p m4 && \
  185. autoreconf --force --install && \
  186. ./configure --enable-lib --disable-util --disable-example
  187. endif
  188. libfuse/lib/.libs/libfuse.a: libfuse_Makefile
  189. cd libfuse && $(MAKE)
  190. .PHONY: all clean install help
  191. -include $(DEPS)