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.

178 lines
5.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. 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. KERNEL = $(shell uname -s)
  83. ifeq ($(KERNEL),Linux)
  84. CFLAGS += -DLINUX
  85. endif
  86. ifeq ($(KERNEL),Darwin)
  87. CFLAGS += -DOSX
  88. endif
  89. all: $(TARGET) clonepath
  90. help:
  91. @echo "usage: make"
  92. @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
  93. $(TARGET): obj/obj-stamp $(OBJ)
  94. $(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
  95. clonepath: $(TARGET)
  96. $(LN) -s $< $@
  97. changelog:
  98. $(GIT) log --pretty --numstat --summary | git2cl > ChangeLog
  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)" "$(INSTALLMANDIR)/$(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 "$(INSTALLMANDIR)/$(MANPAGE")
  126. $(MANPAGE): README.md
  127. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  128. man: $(MANPAGE)
  129. tarball: clean changelog man
  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. deb:
  138. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  139. $(GIT2DEBCL) $(TARGET) $(VERSION) > debian/changelog
  140. $(GIT) buildpackage --git-ignore-new
  141. .PHONY: all clean install help
  142. include $(wildcard obj/*.d)