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.2 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. MANDIR = $(DATAROOTDIR)/man
  86. MAN1DIR = $(MANDIR)/man1
  87. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  88. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  89. ifeq ($(XATTR_AVAILABLE),0)
  90. $(warning "xattr not available: disabling")
  91. CFLAGS += -DWITHOUT_XATTR
  92. endif
  93. all: $(TARGET) clone
  94. help:
  95. @echo "usage: make"
  96. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  97. $(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
  98. $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
  99. clone: $(TARGET)
  100. $(LN) -s $< $@
  101. changelog:
  102. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  103. authors:
  104. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  105. src/version.hpp:
  106. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  107. @echo "#ifndef _VERSION_HPP" > src/version.hpp
  108. @echo "#define _VERSION_HPP" >> src/version.hpp
  109. @echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
  110. @echo "#endif" >> src/version.hpp
  111. obj/obj-stamp:
  112. $(MKDIR) -p obj
  113. $(TOUCH) $@
  114. obj/%.o: src/%.cpp
  115. $(CXX) $(CFLAGS) -c $< -o $@
  116. clean: rpm-clean
  117. $(RM) -rf obj
  118. $(RM) -f src/version.hpp
  119. $(RM) -f "$(TARGET)" "$(MANPAGE)" clone
  120. $(FIND) . -name "*~" -delete
  121. distclean: clean
  122. $(GIT) clean -fd
  123. install: install-base install-clone install-man
  124. install-base: $(TARGET)
  125. $(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  126. install-clone: clone
  127. $(CP) -a $< "$(INSTALLBINDIR)/$<"
  128. install-man: $(MANPAGE)
  129. $(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  130. install-strip: install-base
  131. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  132. uninstall: uninstall-base uninstall-clone uninstall-man
  133. uninstall-base:
  134. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  135. uninstall-clone:
  136. $(RM) -f "$(INSTALLBINDIR)/clone"
  137. uninstall-man:
  138. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  139. $(MANPAGE): README.md
  140. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  141. man: $(MANPAGE)
  142. tarball: clean man changelog authors src/version.hpp
  143. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  144. $(eval VERSION := $(subst -,_,$(VERSION)))
  145. $(eval FILENAME := $(TARGET)-$(VERSION))
  146. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  147. $(MKDIR) $(TMPDIR)/$(FILENAME)
  148. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  149. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
  150. $(RM) -rf $(TMPDIR)
  151. debian-changelog:
  152. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  153. signed-deb: debian-changelog
  154. dpkg-buildpackage
  155. deb: debian-changelog
  156. dpkg-buildpackage -uc -us
  157. rpm-clean:
  158. $(RM) -rf rpmbuild
  159. rpm: tarball
  160. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  161. $(eval VERSION := $(subst -,_,$(VERSION)))
  162. $(MKDIR) -p rpmbuild/{BUILD,RPMS,SOURCES}
  163. $(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
  164. rpmbuild/SOURCES/$(TARGET).spec
  165. cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
  166. $(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
  167. --define "_topdir $(CURDIR)/rpmbuild"
  168. .PHONY: all clean install help
  169. include $(wildcard obj/*.d)