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.

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