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.

216 lines
6.3 KiB

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