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.

212 lines
6.1 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=29 \
  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)
  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. mount.mergerfs: $(TARGET)
  94. $(LN) -fs "$<" "$@"
  95. changelog:
  96. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  97. authors:
  98. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  99. src/version.hpp:
  100. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  101. @echo "#ifndef _VERSION_HPP" > src/version.hpp
  102. @echo "#define _VERSION_HPP" >> src/version.hpp
  103. @echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
  104. @echo "#endif" >> src/version.hpp
  105. obj/obj-stamp:
  106. $(MKDIR) -p obj
  107. $(TOUCH) $@
  108. obj/%.o: src/%.cpp
  109. $(CXX) $(CFLAGS) -c $< -o $@
  110. clean: rpm-clean
  111. $(RM) -rf obj
  112. $(RM) -f src/version.hpp
  113. $(RM) -f "$(TARGET)" mount.mergerfs
  114. $(FIND) . -name "*~" -delete
  115. distclean: clean
  116. $(GIT) clean -fd
  117. install: install-base install-mount.mergerfs install-man
  118. install-base: $(TARGET)
  119. $(MKDIR) -p "$(INSTALLBINDIR)"
  120. $(INSTALL) -v -m 0755 "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  121. install-mount.mergerfs: mount.mergerfs
  122. $(MKDIR) -p "$(INSTALLBINDIR)"
  123. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  124. install-man: $(MANPAGE)
  125. $(MKDIR) -p "$(INSTALLMAN1DIR)"
  126. $(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  127. install-strip: install-base
  128. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  129. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  130. uninstall-base:
  131. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  132. uninstall-mount.mergerfs:
  133. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  134. uninstall-man:
  135. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  136. $(MANPAGE): README.md
  137. ifneq (,$(PANDOC))
  138. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  139. endif
  140. man: $(MANPAGE)
  141. tarball: clean man changelog authors src/version.hpp
  142. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  143. $(eval VERSION := $(subst -,_,$(VERSION)))
  144. $(eval FILENAME := $(TARGET)-$(VERSION))
  145. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  146. $(MKDIR) $(TMPDIR)/$(FILENAME)
  147. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  148. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  149. $(RM) -rf $(TMPDIR)
  150. debian-changelog:
  151. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  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 $(GIT) describe --always --tags --dirty))
  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. .PHONY: all clean install help
  168. include $(wildcard obj/*.d)