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.

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