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.

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