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.

170 lines
5.0 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. GIT2DEBCL = ./tools/git2debcl
  36. CPPFIND = ./tools/cppfind
  37. ifeq ($(PKGCONFIG),"")
  38. $(error "pkg-config not installed"
  39. endif
  40. ifeq ($(PANDOC),"")
  41. $(warning "pandoc does not appear available: manpage won't be buildable")
  42. endif
  43. XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
  44. FUSE_AVAILABLE = $(shell ! pkg-config --exists fuse; echo $$?)
  45. ifeq ($(FUSE_AVAILABLE),0)
  46. FUSE_AVAILABLE = $(shell test ! -e /usr/include/fuse.h; echo $$?)
  47. endif
  48. ifeq ($(FUSE_AVAILABLE),0)
  49. $(error "FUSE development package doesn't appear available")
  50. endif
  51. FLAG_NOPATH = $(shell $(CPPFIND) "flag_nopath")
  52. FALLOCATE = $(shell $(CPPFIND) "fuse_fs_fallocate")
  53. FLOCK = $(shell $(CPPFIND) "fuse_fs_flock")
  54. READ_BUF = $(shell $(CPPFIND) "fuse_fs_read_buf")
  55. WRITE_BUF = $(shell $(CPPFIND) "fuse_fs_write_buf")
  56. OPTS = -O2
  57. SRC = $(wildcard src/*.cpp)
  58. OBJ = $(SRC:src/%.cpp=obj/%.o)
  59. DEPS = $(OBJ:obj/%.o=obj/%.d)
  60. TARGET = mergerfs
  61. MANPAGE = $(TARGET).1
  62. FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
  63. CFLAGS = -g -Wall \
  64. $(OPTS) \
  65. $(FUSE_CFLAGS) \
  66. -DFUSE_USE_VERSION=26 \
  67. -MMD \
  68. -DFLAG_NOPATH=$(FLAG_NOPATH) \
  69. -DFALLOCATE=$(FALLOCATE) \
  70. -DFLOCK=$(FLOCK) \
  71. -DREAD_BUF=$(READ_BUF) \
  72. -DWRITE_BUF=$(WRITE_BUF)
  73. LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
  74. BINDIR = $(PREFIX)/usr/bin
  75. MANDIR = $(PREFIX)/usr/share/man/man1
  76. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  77. INSTALLMANDIR = $(DESTDIR)$(MANDIR)
  78. ifeq ($(XATTR_AVAILABLE),0)
  79. $(warning "xattr not available: disabling")
  80. CFLAGS += -DWITHOUT_XATTR
  81. endif
  82. all: $(TARGET) clonepath
  83. help:
  84. @echo "usage: make"
  85. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  86. $(TARGET): obj/obj-stamp $(OBJ)
  87. $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
  88. clonepath: $(TARGET)
  89. $(LN) -s $< $@
  90. changelog:
  91. $(GIT) log --pretty --numstat --summary | git2cl > ChangeLog
  92. obj/obj-stamp:
  93. $(MKDIR) -p obj
  94. $(TOUCH) $@
  95. obj/%.o: src/%.cpp
  96. $(CXX) $(CFLAGS) -c $< -o $@
  97. clean:
  98. $(RM) -rf obj
  99. $(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
  100. $(FIND) -name "*~" -delete
  101. distclean: clean
  102. $(GIT) clean -fd
  103. install: install-base install-clonepath install-man
  104. install-base: $(TARGET)
  105. $(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  106. install-clonepath: clonepath
  107. $(CP) -a $< "$(INSTALLBINDIR)/$<"
  108. install-man: $(MANPAGE)
  109. $(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMANDIR)/$(MANPAGE)"
  110. install-strip: install-base
  111. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  112. uninstall: uninstall-base uninstall-clonepath uninstall-man
  113. uninstall-base:
  114. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  115. uninstall-clonepath:
  116. $(RM) -f "$(INSTALLBINDIR)/clonepath"
  117. uninstall-man:
  118. $(RM) -f "$(INSTALLMANDIR)/$(MANPAGE")
  119. $(MANPAGE): README.md
  120. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  121. man: $(MANPAGE)
  122. tarball: clean changelog man
  123. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  124. $(eval FILENAME := $(TARGET)-$(VERSION))
  125. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  126. $(MKDIR) $(TMPDIR)/$(FILENAME)
  127. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  128. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f ../$(FILENAME).tar.gz $(FILENAME)
  129. $(RM) -rf $(TMPDIR)
  130. deb:
  131. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  132. $(GIT2DEBCL) $(TARGET) $(VERSION) > debian/changelog
  133. $(GIT) buildpackage --git-ignore-new
  134. .PHONY: all clean install help
  135. include $(wildcard obj/*.d)