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.

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