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.

183 lines
5.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. 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. PREFIX = /usr/local
  75. EXEC_PREFIX = $(PREFIX)
  76. DATAROOTDIR = $(PREFIX)/share
  77. DATADIR = $(DATAROOTDIR)
  78. BINDIR = $(EXEC_PREFIX)/bin
  79. MANDIR = $(DATAROOTDIR)/man
  80. MAN1DIR = $(MANDIR)/man1
  81. INSTALLBINDIR = $(DESTDIR)$(BINDIR)
  82. INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
  83. ifeq ($(XATTR_AVAILABLE),0)
  84. $(warning "xattr not available: disabling")
  85. CFLAGS += -DWITHOUT_XATTR
  86. endif
  87. all: $(TARGET) clonepath
  88. help:
  89. @echo "usage: make"
  90. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  91. $(TARGET): obj/obj-stamp $(OBJ)
  92. $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
  93. clonepath: $(TARGET)
  94. $(LN) -s $< $@
  95. changelog:
  96. $(GIT2DEBCL) --name $(TARGET) > ChangeLog
  97. authors:
  98. $(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
  99. obj/obj-stamp:
  100. $(MKDIR) -p obj
  101. $(TOUCH) $@
  102. obj/%.o: src/%.cpp
  103. $(CXX) $(CFLAGS) -c $< -o $@
  104. clean:
  105. $(RM) -rf obj
  106. $(RM) -f "$(TARGET)" "$(MANPAGE)" clonepath
  107. $(FIND) . -name "*~" -delete
  108. distclean: clean
  109. $(GIT) clean -fd
  110. install: install-base install-clonepath install-man
  111. install-base: $(TARGET)
  112. $(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
  113. install-clonepath: clonepath
  114. $(CP) -a $< "$(INSTALLBINDIR)/$<"
  115. install-man: $(MANPAGE)
  116. $(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
  117. install-strip: install-base
  118. $(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
  119. uninstall: uninstall-base uninstall-clonepath uninstall-man
  120. uninstall-base:
  121. $(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
  122. uninstall-clonepath:
  123. $(RM) -f "$(INSTALLBINDIR)/clonepath"
  124. uninstall-man:
  125. $(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
  126. $(MANPAGE): README.md
  127. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  128. man: $(MANPAGE)
  129. tarball: clean man changelog authors
  130. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  131. $(eval FILENAME := $(TARGET)-$(VERSION))
  132. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  133. $(MKDIR) $(TMPDIR)/$(FILENAME)
  134. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  135. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f ../$(FILENAME).tar.gz $(FILENAME)
  136. $(RM) -rf $(TMPDIR)
  137. debian-changelog:
  138. $(GIT2DEBCL) --name $(TARGET) > debian/changelog
  139. deb: debian-changelog
  140. dpkg-buildpackage
  141. unsigned-deb: debian-changelog
  142. dpkg-buildpackage -uc -us
  143. .PHONY: all clean install help
  144. include $(wildcard obj/*.d)