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.

224 lines
6.3 KiB

11 years ago
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. PKGCONFIG = $(shell which pkg-config)
  15. GIT = $(shell which git)
  16. TAR = $(shell which tar)
  17. MKDIR = $(shell which mkdir)
  18. TOUCH = $(shell which touch)
  19. CP = $(shell which cp)
  20. RM = $(shell which rm)
  21. LN = $(shell which ln)
  22. FIND = $(shell which find)
  23. INSTALL = $(shell which install)
  24. MKTEMP = $(shell which mktemp)
  25. STRIP = $(shell which strip)
  26. PANDOC = $(shell which pandoc)
  27. SED = $(shell which sed)
  28. GZIP = $(shell which gzip)
  29. RPMBUILD = $(shell which rpmbuild)
  30. GIT2DEBCL = ./tools/git2debcl
  31. CPPFIND = ./tools/cppfind
  32. ifeq ($(PKGCONFIG),"")
  33. $(error "pkg-config not installed")
  34. endif
  35. ifeq ($(PANDOC),"")
  36. $(warning "pandoc does not appear available: manpage won't be buildable")
  37. endif
  38. XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
  39. FUSE_AVAILABLE = $(shell ! pkg-config --exists fuse; echo $$?)
  40. ifeq ($(FUSE_AVAILABLE),0)
  41. FUSE_AVAILABLE = $(shell test ! -e /usr/include/fuse.h; echo $$?)
  42. endif
  43. ifeq ($(FUSE_AVAILABLE),0)
  44. $(error "FUSE development package doesn't appear available")
  45. endif
  46. FLAG_NOPATH = $(shell $(CPPFIND) "flag_nopath")
  47. FALLOCATE = $(shell $(CPPFIND) "fuse_fs_fallocate")
  48. FLOCK = $(shell $(CPPFIND) "fuse_fs_flock")
  49. READ_BUF = $(shell $(CPPFIND) "fuse_fs_read_buf")
  50. WRITE_BUF = $(shell $(CPPFIND) "fuse_fs_write_buf")
  51. UGID_USE_RWLOCK = 0
  52. OPTS = -O2
  53. SRC = $(wildcard src/*.cpp)
  54. OBJ = $(SRC:src/%.cpp=obj/%.o)
  55. DEPS = $(OBJ:obj/%.o=obj/%.d)
  56. TARGET = mergerfs
  57. MANPAGE = $(TARGET).1
  58. FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
  59. CFLAGS = -g -Wall \
  60. $(OPTS) \
  61. -Wno-unused-result \
  62. $(FUSE_CFLAGS) \
  63. -DFUSE_USE_VERSION=26 \
  64. -MMD \
  65. -DFLAG_NOPATH=$(FLAG_NOPATH) \
  66. -DFALLOCATE=$(FALLOCATE) \
  67. -DFLOCK=$(FLOCK) \
  68. -DREAD_BUF=$(READ_BUF) \
  69. -DWRITE_BUF=$(WRITE_BUF) \
  70. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  71. LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
  72. PREFIX = /usr/local
  73. EXEC_PREFIX = $(PREFIX)
  74. DATAROOTDIR = $(PREFIX)/share
  75. DATADIR = $(DATAROOTDIR)
  76. BINDIR = $(EXEC_PREFIX)/bin
  77. SBINDIR = $(EXEC_PREFIX)/sbin
  78. MANDIR = $(DATAROOTDIR)/man
  79. MAN1DIR = $(MANDIR)/man1
  80. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  81. INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
  82. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  83. ifeq ($(XATTR_AVAILABLE),0)
  84. $(warning "xattr not available: disabling")
  85. CFLAGS += -DWITHOUT_XATTR
  86. endif
  87. all: $(TARGET) clone
  88. help:
  89. @echo "usage: make"
  90. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  91. $(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
  92. $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
  93. clone: $(TARGET)
  94. $(LN) -fs "$<" "$@"
  95. fsck.mergerfs: tools/fsck.mergerfs
  96. mount.mergerfs: $(TARGET)
  97. $(LN) -fs "$<" "$@"
  98. changelog:
  99. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  100. authors:
  101. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  102. src/version.hpp:
  103. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  104. @echo "#ifndef _VERSION_HPP" > src/version.hpp
  105. @echo "#define _VERSION_HPP" >> src/version.hpp
  106. @echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
  107. @echo "#endif" >> src/version.hpp
  108. obj/obj-stamp:
  109. $(MKDIR) -p obj
  110. $(TOUCH) $@
  111. obj/%.o: src/%.cpp
  112. $(CXX) $(CFLAGS) -c $< -o $@
  113. clean: rpm-clean
  114. $(RM) -rf obj
  115. $(RM) -f src/version.hpp
  116. $(RM) -f "$(TARGET)" "$(MANPAGE)" clone
  117. $(FIND) . -name "*~" -delete
  118. distclean: clean
  119. $(GIT) clean -fd
  120. install: install-base install-clone install-mount.mergerfs install-tools install-man
  121. install-base: $(TARGET)
  122. $(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  123. install-clone: clone
  124. $(MKDIR) -p "$(INSTALLBINDIR)"
  125. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  126. install-mount.mergerfs: mount.mergerfs
  127. $(MKDIR) -p "$(INSTALLBINDIR)"
  128. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  129. install-tools: fsck.mergerfs
  130. $(INSTALL) -v -m 0755 -D "tools/$<" "$(INSTALLSBINDIR)/$<"
  131. install-man: $(MANPAGE)
  132. $(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  133. install-strip: install-base
  134. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  135. uninstall: uninstall-base uninstall-clone uninstall-man
  136. uninstall-base:
  137. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  138. uninstall-clone:
  139. $(RM) -f "$(INSTALLBINDIR)/clone"
  140. uninstall-man:
  141. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  142. $(MANPAGE): README.md
  143. ifneq (,$(PANDOC))
  144. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  145. else
  146. $(CP) man/mergerfs.1 .
  147. endif
  148. man: $(MANPAGE)
  149. tarball: clean man changelog authors src/version.hpp
  150. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  151. $(eval VERSION := $(subst -,_,$(VERSION)))
  152. $(eval FILENAME := $(TARGET)-$(VERSION))
  153. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  154. $(MKDIR) $(TMPDIR)/$(FILENAME)
  155. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  156. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  157. $(RM) -rf $(TMPDIR)
  158. debian-changelog:
  159. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  160. signed-deb: debian-changelog
  161. dpkg-buildpackage
  162. deb: debian-changelog
  163. dpkg-buildpackage -uc -us
  164. rpm-clean:
  165. $(RM) -rf rpmbuild
  166. rpm: tarball
  167. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  168. $(eval VERSION := $(subst -,_,$(VERSION)))
  169. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  170. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  171. rpmbuild/SOURCES/$(TARGET).spec
  172. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  173. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  174. --define "_topdir $(CURDIR)/rpmbuild"
  175. .PHONY: all clean install help
  176. include $(wildcard obj/*.d)