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.

229 lines
6.6 KiB

11 years ago
11 years ago
11 years ago
11 years ago
  1. # The MIT License (MIT)
  2. #
  3. # Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22. PKGCONFIG = $(shell which pkg-config)
  23. GIT = $(shell which git)
  24. TAR = $(shell which tar)
  25. MKDIR = $(shell which mkdir)
  26. TOUCH = $(shell which touch)
  27. CP = $(shell which cp)
  28. RM = $(shell which rm)
  29. LN = $(shell which ln)
  30. FIND = $(shell which find)
  31. INSTALL = $(shell which install)
  32. MKTEMP = $(shell which mktemp)
  33. STRIP = $(shell which strip)
  34. PANDOC = $(shell which pandoc)
  35. SED = $(shell which sed)
  36. GZIP = $(shell which gzip)
  37. RPMBUILD = $(shell which rpmbuild)
  38. GIT2DEBCL = ./tools/git2debcl
  39. CPPFIND = ./tools/cppfind
  40. ifeq ($(PKGCONFIG),"")
  41. $(error "pkg-config not installed")
  42. endif
  43. ifeq ($(PANDOC),"")
  44. $(warning "pandoc does not appear available: manpage won't be buildable")
  45. endif
  46. XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
  47. FUSE_AVAILABLE = $(shell ! pkg-config --exists fuse; echo $$?)
  48. ifeq ($(FUSE_AVAILABLE),0)
  49. FUSE_AVAILABLE = $(shell test ! -e /usr/include/fuse.h; echo $$?)
  50. endif
  51. ifeq ($(FUSE_AVAILABLE),0)
  52. $(error "FUSE development package doesn't appear available")
  53. endif
  54. FLAG_NOPATH = $(shell $(CPPFIND) "flag_nopath")
  55. FALLOCATE = $(shell $(CPPFIND) "fuse_fs_fallocate")
  56. FLOCK = $(shell $(CPPFIND) "fuse_fs_flock")
  57. READ_BUF = $(shell $(CPPFIND) "fuse_fs_read_buf")
  58. WRITE_BUF = $(shell $(CPPFIND) "fuse_fs_write_buf")
  59. UGID_USE_RWLOCK = 0
  60. OPTS = -O2
  61. SRC = $(wildcard src/*.cpp)
  62. OBJ = $(SRC:src/%.cpp=obj/%.o)
  63. DEPS = $(OBJ:obj/%.o=obj/%.d)
  64. TARGET = mergerfs
  65. MANPAGE = $(TARGET).1
  66. FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
  67. CFLAGS = -g -Wall \
  68. $(OPTS) \
  69. -Wno-unused-result \
  70. $(FUSE_CFLAGS) \
  71. -DFUSE_USE_VERSION=26 \
  72. -MMD \
  73. -DFLAG_NOPATH=$(FLAG_NOPATH) \
  74. -DFALLOCATE=$(FALLOCATE) \
  75. -DFLOCK=$(FLOCK) \
  76. -DREAD_BUF=$(READ_BUF) \
  77. -DWRITE_BUF=$(WRITE_BUF) \
  78. -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
  79. LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
  80. PREFIX = /usr/local
  81. EXEC_PREFIX = $(PREFIX)
  82. DATAROOTDIR = $(PREFIX)/share
  83. DATADIR = $(DATAROOTDIR)
  84. BINDIR = $(EXEC_PREFIX)/bin
  85. SBINDIR = $(EXEC_PREFIX)/sbin
  86. MANDIR = $(DATAROOTDIR)/man
  87. MAN1DIR = $(MANDIR)/man1
  88. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  89. INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
  90. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  91. ifeq ($(XATTR_AVAILABLE),0)
  92. $(warning "xattr not available: disabling")
  93. CFLAGS += -DWITHOUT_XATTR
  94. endif
  95. all: $(TARGET) clone
  96. help:
  97. @echo "usage: make"
  98. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  99. $(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
  100. $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
  101. clone: $(TARGET)
  102. $(LN) -fs "$<" "$@"
  103. fsck.mergerfs: tools/fsck.mergerfs
  104. mount.mergerfs: $(TARGET)
  105. $(LN) -fs "$<" "$@"
  106. changelog:
  107. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  108. authors:
  109. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  110. src/version.hpp:
  111. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  112. @echo "#ifndef _VERSION_HPP" > src/version.hpp
  113. @echo "#define _VERSION_HPP" >> src/version.hpp
  114. @echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
  115. @echo "#endif" >> src/version.hpp
  116. obj/obj-stamp:
  117. $(MKDIR) -p obj
  118. $(TOUCH) $@
  119. obj/%.o: src/%.cpp
  120. $(CXX) $(CFLAGS) -c $< -o $@
  121. clean: rpm-clean
  122. $(RM) -rf obj
  123. $(RM) -f src/version.hpp
  124. $(RM) -f "$(TARGET)" "$(MANPAGE)" clone
  125. $(FIND) . -name "*~" -delete
  126. distclean: clean
  127. $(GIT) clean -fd
  128. install: install-base install-clone install-mount.mergerfs install-tools install-man
  129. install-base: $(TARGET)
  130. $(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  131. install-clone: clone
  132. $(MKDIR) -p "$(INSTALLBINDIR)"
  133. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  134. install-mount.mergerfs: mount.mergerfs
  135. $(MKDIR) -p "$(INSTALLBINDIR)"
  136. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  137. install-tools: fsck.mergerfs
  138. $(INSTALL) -v -m 0755 -D "tools/$<" "$(INSTALLSBINDIR)/$<"
  139. install-man: $(MANPAGE)
  140. $(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  141. install-strip: install-base
  142. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  143. uninstall: uninstall-base uninstall-clone uninstall-man
  144. uninstall-base:
  145. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  146. uninstall-clone:
  147. $(RM) -f "$(INSTALLBINDIR)/clone"
  148. uninstall-man:
  149. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  150. $(MANPAGE): README.md
  151. ifneq (,$(PANDOC))
  152. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  153. endif
  154. man: $(MANPAGE)
  155. tarball: clean man changelog authors src/version.hpp
  156. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  157. $(eval VERSION := $(subst -,_,$(VERSION)))
  158. $(eval FILENAME := $(TARGET)-$(VERSION))
  159. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  160. $(MKDIR) $(TMPDIR)/$(FILENAME)
  161. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  162. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  163. $(RM) -rf $(TMPDIR)
  164. debian-changelog:
  165. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  166. signed-deb: debian-changelog
  167. dpkg-buildpackage
  168. deb: debian-changelog
  169. dpkg-buildpackage -uc -us
  170. rpm-clean:
  171. $(RM) -rf rpmbuild
  172. rpm: tarball
  173. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  174. $(eval VERSION := $(subst -,_,$(VERSION)))
  175. $(MKDIR) -p rpmbuild/{BUILD,RPMS,SOURCES}
  176. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  177. rpmbuild/SOURCES/$(TARGET).spec
  178. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  179. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  180. --define "_topdir $(CURDIR)/rpmbuild"
  181. .PHONY: all clean install help
  182. include $(wildcard obj/*.d)