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.

210 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=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)
  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. $(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  120. install-mount.mergerfs: mount.mergerfs
  121. $(MKDIR) -p "$(INSTALLBINDIR)"
  122. $(CP) -a "$<" "$(INSTALLBINDIR)/$<"
  123. install-man: $(MANPAGE)
  124. $(INSTALL) -v -m 0644 -D "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  125. install-strip: install-base
  126. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  127. uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
  128. uninstall-base:
  129. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  130. uninstall-mount.mergerfs:
  131. $(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
  132. uninstall-man:
  133. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  134. $(MANPAGE): README.md
  135. ifneq (,$(PANDOC))
  136. $(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
  137. endif
  138. man: $(MANPAGE)
  139. tarball: clean man changelog authors src/version.hpp
  140. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  141. $(eval VERSION := $(subst -,_,$(VERSION)))
  142. $(eval FILENAME := $(TARGET)-$(VERSION))
  143. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  144. $(MKDIR) $(TMPDIR)/$(FILENAME)
  145. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  146. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  147. $(RM) -rf $(TMPDIR)
  148. debian-changelog:
  149. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  150. signed-deb: debian-changelog
  151. dpkg-buildpackage
  152. deb: debian-changelog
  153. dpkg-buildpackage -uc -us
  154. rpm-clean:
  155. $(RM) -rf rpmbuild
  156. rpm: tarball
  157. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  158. $(eval VERSION := $(subst -,_,$(VERSION)))
  159. $(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
  160. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  161. rpmbuild/SOURCES/$(TARGET).spec
  162. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  163. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  164. --define "_topdir $(CURDIR)/rpmbuild"
  165. .PHONY: all clean install help
  166. include $(wildcard obj/*.d)