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.

208 lines
6.1 KiB

10 years ago
10 years ago
10 years ago
10 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. OPTS = -O2
  60. SRC = $(wildcard src/*.cpp)
  61. OBJ = $(SRC:src/%.cpp=obj/%.o)
  62. DEPS = $(OBJ:obj/%.o=obj/%.d)
  63. TARGET = mergerfs
  64. MANPAGE = $(TARGET).1
  65. FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
  66. CFLAGS = -g -Wall \
  67. $(OPTS) \
  68. $(FUSE_CFLAGS) \
  69. -DFUSE_USE_VERSION=26 \
  70. -MMD \
  71. -DFLAG_NOPATH=$(FLAG_NOPATH) \
  72. -DFALLOCATE=$(FALLOCATE) \
  73. -DFLOCK=$(FLOCK) \
  74. -DREAD_BUF=$(READ_BUF) \
  75. -DWRITE_BUF=$(WRITE_BUF)
  76. LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
  77. PREFIX = /usr/local
  78. EXEC_PREFIX = $(PREFIX)
  79. DATAROOTDIR = $(PREFIX)/share
  80. DATADIR = $(DATAROOTDIR)
  81. BINDIR = $(EXEC_PREFIX)/bin
  82. MANDIR = $(DATAROOTDIR)/man
  83. MAN1DIR = $(MANDIR)/man1
  84. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  85. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  86. ifeq ($(XATTR_AVAILABLE),0)
  87. $(warning "xattr not available: disabling")
  88. CFLAGS += -DWITHOUT_XATTR
  89. endif
  90. all: $(TARGET) clonepath
  91. help:
  92. @echo "usage: make"
  93. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  94. $(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
  95. $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
  96. clonepath: $(TARGET)
  97. $(LN) -s $< $@
  98. changelog:
  99. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  100. authors:
  101. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  102. src/version.hpp:
  103. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  104. @echo "#ifndef _VERSION_HPP" > src/version.hpp
  105. @echo "#define _VERSION_HPP" >> src/version.hpp
  106. @echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
  107. @echo "#endif" >> src/version.hpp
  108. obj/obj-stamp:
  109. $(MKDIR) -p obj
  110. $(TOUCH) $@
  111. obj/%.o: src/%.cpp
  112. $(CXX) $(CFLAGS) -c $< -o $@
  113. clean: rpm-clean
  114. $(RM) -rf obj
  115. $(RM) -f src/version.hpp
  116. $(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
  117. $(FIND) . -name "*~" -delete
  118. distclean: clean
  119. $(GIT) clean -fd
  120. install: install-base install-clonepath install-man
  121. install-base: $(TARGET)
  122. $(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  123. install-clonepath: clonepath
  124. $(CP) -a $< "$(INSTALLBINDIR)/$<"
  125. install-man: $(MANPAGE)
  126. $(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  127. install-strip: install-base
  128. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  129. uninstall: uninstall-base uninstall-clonepath uninstall-man
  130. uninstall-base:
  131. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  132. uninstall-clonepath:
  133. $(RM) -f "$(INSTALLBINDIR)/clonepath"
  134. uninstall-man:
  135. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  136. $(MANPAGE): README.md
  137. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  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. deb: debian-changelog
  151. dpkg-buildpackage
  152. unsigned-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,RPMS,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)