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.

167 lines
5.0 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. RPMBUILD = $(shell which rpmbuild)
  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. INSTALLTARGET = $(DESTDIR)/$(BINDIR)/$(TARGET)
  77. MANTARGET = $(DESTDIR)/$(MANDIR)/$(MANPAGE)
  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)
  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. changelog:
  96. $(GIT) log --pretty --numstat --summary | git2cl > ChangeLog
  97. obj/obj-stamp:
  98. $(MKDIR) -p obj
  99. $(TOUCH) $@
  100. obj/%.o: src/%.cpp
  101. $(CXX) $(CFLAGS) -c $< -o $@
  102. clean:
  103. $(RM) -rf obj "$(TARGET)" "$(MANPAGE)" rpmbuild
  104. $(FIND) -name "*~" -delete
  105. distclean: clean
  106. $(GIT) clean -fd
  107. install: $(TARGET) $(MANPAGE)
  108. $(INSTALL) -m 0755 -D "$(TARGET)" "$(INSTALLTARGET)"
  109. $(INSTALL) -m 0644 -D "$(MANPAGE)" "$(MANTARGET)"
  110. install-strip: install
  111. $(STRIP) "$(INSTALLTARGET)"
  112. uninstall:
  113. $(RM) "$(INSTALLTARGET)"
  114. $(RM) "$(MANTARGET)"
  115. $(MANPAGE): README.md
  116. $(PANDOC) -s -t man -o $(MANPAGE) README.md
  117. man: $(MANPAGE)
  118. tarball: clean changelog man
  119. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  120. $(eval FILENAME := $(TARGET)-$(VERSION))
  121. $(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
  122. $(MKDIR) $(TMPDIR)/$(FILENAME)
  123. $(CP) -ar . $(TMPDIR)/$(FILENAME)
  124. $(TAR) --exclude=.git -cz -C $(TMPDIR) -f ../$(FILENAME).tar.gz $(FILENAME)
  125. $(RM) -rf $(TMPDIR)
  126. deb:
  127. $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
  128. $(GIT2DEBCL) $(TARGET) $(VERSION) > debian/changelog
  129. $(GIT) buildpackage --git-ignore-new
  130. rpm:
  131. $(eval VERSION := $(subst -,_,$(shell $(GIT) describe --always --tags --dirty)))
  132. $(RPMBUILD) -bb $(TARGET).spec \
  133. --define "_topdir $(CURDIR)/rpmbuild" \
  134. --define "_builddir $(CURDIR)" \
  135. --define "pkg_version $(VERSION)"
  136. .PHONY: all clean install help
  137. include $(wildcard obj/*.d)