mergerfs/Makefile

232 lines
6.7 KiB
Makefile
Raw Normal View History

2014-05-13 00:41:46 +08:00
# The MIT License (MIT)
#
# Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
2014-05-29 19:23:46 +08:00
PKGCONFIG = $(shell which pkg-config)
2014-11-05 02:42:20 +08:00
GIT = $(shell which git)
TAR = $(shell which tar)
MKDIR = $(shell which mkdir)
TOUCH = $(shell which touch)
CP = $(shell which cp)
RM = $(shell which rm)
2015-01-28 07:25:20 +08:00
LN = $(shell which ln)
2014-11-05 02:42:20 +08:00
FIND = $(shell which find)
INSTALL = $(shell which install)
MKTEMP = $(shell which mktemp)
STRIP = $(shell which strip)
PANDOC = $(shell which pandoc)
2015-09-06 05:56:45 +08:00
SED = $(shell which sed)
GZIP = $(shell which gzip)
RPMBUILD = $(shell which rpmbuild)
GIT2DEBCL = ./tools/git2debcl
2014-11-05 02:42:20 +08:00
CPPFIND = ./tools/cppfind
ifeq ($(PKGCONFIG),"")
2015-09-06 05:56:45 +08:00
$(error "pkg-config not installed")
endif
ifeq ($(PANDOC),"")
$(warning "pandoc does not appear available: manpage won't be buildable")
endif
XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?)
FUSE_AVAILABLE = $(shell ! pkg-config --exists fuse; echo $$?)
ifeq ($(FUSE_AVAILABLE),0)
FUSE_AVAILABLE = $(shell test ! -e /usr/include/fuse.h; echo $$?)
endif
ifeq ($(FUSE_AVAILABLE),0)
$(error "FUSE development package doesn't appear available")
endif
2014-05-29 19:23:46 +08:00
2014-11-05 02:42:20 +08:00
FLAG_NOPATH = $(shell $(CPPFIND) "flag_nopath")
FALLOCATE = $(shell $(CPPFIND) "fuse_fs_fallocate")
FLOCK = $(shell $(CPPFIND) "fuse_fs_flock")
READ_BUF = $(shell $(CPPFIND) "fuse_fs_read_buf")
WRITE_BUF = $(shell $(CPPFIND) "fuse_fs_write_buf")
UGID_USE_RWLOCK = 0
2014-11-05 02:42:20 +08:00
OPTS = -O2
SRC = $(wildcard src/*.cpp)
OBJ = $(SRC:src/%.cpp=obj/%.o)
DEPS = $(OBJ:obj/%.o=obj/%.d)
TARGET = mergerfs
MANPAGE = $(TARGET).1
FUSE_CFLAGS = $(shell $(PKGCONFIG) --cflags fuse)
CFLAGS = -g -Wall \
$(OPTS) \
-Wno-unused-result \
2014-11-05 02:42:20 +08:00
$(FUSE_CFLAGS) \
-DFUSE_USE_VERSION=26 \
-MMD \
-DFLAG_NOPATH=$(FLAG_NOPATH) \
-DFALLOCATE=$(FALLOCATE) \
-DFLOCK=$(FLOCK) \
-DREAD_BUF=$(READ_BUF) \
-DWRITE_BUF=$(WRITE_BUF) \
-DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
2014-11-05 02:42:20 +08:00
LDFLAGS = $(shell $(PKGCONFIG) fuse --libs)
2015-08-07 01:11:17 +08:00
PREFIX = /usr/local
EXEC_PREFIX = $(PREFIX)
DATAROOTDIR = $(PREFIX)/share
DATADIR = $(DATAROOTDIR)
BINDIR = $(EXEC_PREFIX)/bin
SBINDIR = $(EXEC_PREFIX)/sbin
2015-08-07 01:11:17 +08:00
MANDIR = $(DATAROOTDIR)/man
MAN1DIR = $(MANDIR)/man1
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
2015-08-07 01:11:17 +08:00
INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
2014-05-13 00:41:46 +08:00
2014-05-29 09:38:31 +08:00
ifeq ($(XATTR_AVAILABLE),0)
$(warning "xattr not available: disabling")
2014-05-29 09:38:31 +08:00
CFLAGS += -DWITHOUT_XATTR
2014-05-13 00:41:46 +08:00
endif
all: $(TARGET) clone
2014-05-13 00:41:46 +08:00
help:
2014-05-29 19:23:46 +08:00
@echo "usage: make"
@echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)"
2014-05-13 00:41:46 +08:00
2015-09-06 09:48:15 +08:00
$(TARGET): src/version.hpp obj/obj-stamp $(OBJ)
2014-05-29 09:38:31 +08:00
$(CXX) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
2014-05-13 00:41:46 +08:00
clone: $(TARGET)
$(LN) -fs "$<" "$@"
2015-01-28 07:25:20 +08:00
fsck.mergerfs: tools/fsck.mergerfs
mount.mergerfs: $(TARGET)
$(LN) -fs "$<" "$@"
2014-05-29 19:23:46 +08:00
changelog:
2015-08-07 01:11:17 +08:00
$(GIT2DEBCL) --name $(TARGET) > ChangeLog
authors:
$(GIT) log --format='%aN <%aE>' | sort -f | uniq > AUTHORS
2014-05-29 19:23:46 +08:00
2015-09-06 09:48:15 +08:00
src/version.hpp:
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
@echo "#ifndef _VERSION_HPP" > src/version.hpp
@echo "#define _VERSION_HPP" >> src/version.hpp
@echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp
@echo "#endif" >> src/version.hpp
2014-05-13 00:41:46 +08:00
obj/obj-stamp:
2014-05-29 19:23:46 +08:00
$(MKDIR) -p obj
$(TOUCH) $@
2014-05-13 00:41:46 +08:00
obj/%.o: src/%.cpp
2014-05-29 09:38:31 +08:00
$(CXX) $(CFLAGS) -c $< -o $@
2014-05-13 00:41:46 +08:00
2015-09-06 05:56:45 +08:00
clean: rpm-clean
2015-01-28 07:25:20 +08:00
$(RM) -rf obj
2015-09-06 10:29:28 +08:00
$(RM) -f src/version.hpp
$(RM) -f "$(TARGET)" "$(MANPAGE)" clone
2015-08-07 01:11:17 +08:00
$(FIND) . -name "*~" -delete
2014-05-29 19:23:46 +08:00
distclean: clean
$(GIT) clean -fd
2014-05-29 19:23:46 +08:00
install: install-base install-clone install-mount.mergerfs install-tools install-man
2015-01-28 07:25:20 +08:00
install-base: $(TARGET)
$(INSTALL) -v -m 0755 -D "$(TARGET)" "$(INSTALLBINDIR)/$(TARGET)"
install-clone: clone
$(MKDIR) -p "$(INSTALLBINDIR)"
$(CP) -a "$<" "$(INSTALLBINDIR)/$<"
install-mount.mergerfs: mount.mergerfs
$(MKDIR) -p "$(INSTALLBINDIR)"
$(CP) -a "$<" "$(INSTALLBINDIR)/$<"
2015-01-28 07:25:20 +08:00
install-tools: fsck.mergerfs
$(INSTALL) -v -m 0755 -D "tools/$<" "$(INSTALLSBINDIR)/$<"
2015-01-28 07:25:20 +08:00
install-man: $(MANPAGE)
2015-08-07 01:11:17 +08:00
$(INSTALL) -v -m 0644 -D "$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
2015-01-28 07:25:20 +08:00
install-strip: install-base
$(STRIP) "$(INSTALLBINDIR)/$(TARGET)"
uninstall: uninstall-base uninstall-clone uninstall-man
2015-01-28 07:25:20 +08:00
uninstall-base:
$(RM) -f "$(INSTALLBINDIR)/$(TARGET)"
2014-05-29 19:23:46 +08:00
uninstall-clone:
$(RM) -f "$(INSTALLBINDIR)/clone"
2014-05-29 19:23:46 +08:00
2015-01-28 07:25:20 +08:00
uninstall-man:
2015-08-07 01:11:17 +08:00
$(RM) -f "$(INSTALLMAN1DIR)/$(MANPAGE)"
$(MANPAGE): README.md
ifneq (,$(PANDOC))
$(PANDOC) -s -t man -o $(MANPAGE) README.md
else
$(CP) man/mergerfs.1 .
endif
man: $(MANPAGE)
2014-05-29 19:23:46 +08:00
2015-09-06 09:48:15 +08:00
tarball: clean man changelog authors src/version.hpp
2014-05-29 19:23:46 +08:00
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
2015-09-06 05:56:45 +08:00
$(eval VERSION := $(subst -,_,$(VERSION)))
2014-05-29 19:23:46 +08:00
$(eval FILENAME := $(TARGET)-$(VERSION))
$(eval TMPDIR := $(shell $(MKTEMP) --tmpdir -d .$(FILENAME).XXXXXXXX))
$(MKDIR) $(TMPDIR)/$(FILENAME)
$(CP) -ar . $(TMPDIR)/$(FILENAME)
2015-09-06 05:56:45 +08:00
$(TAR) --exclude=.git -cz -C $(TMPDIR) -f $(FILENAME).tar.gz $(FILENAME)
2014-05-29 19:23:46 +08:00
$(RM) -rf $(TMPDIR)
2015-08-07 01:11:17 +08:00
debian-changelog:
$(GIT2DEBCL) --name $(TARGET) > debian/changelog
signed-deb: debian-changelog
2015-08-07 01:11:17 +08:00
dpkg-buildpackage
deb: debian-changelog
2015-08-07 01:11:17 +08:00
dpkg-buildpackage -uc -us
2014-05-13 00:41:46 +08:00
2015-09-06 05:56:45 +08:00
rpm-clean:
$(RM) -rf rpmbuild
rpm: tarball
$(eval VERSION := $(shell $(GIT) describe --always --tags --dirty))
$(eval VERSION := $(subst -,_,$(VERSION)))
$(MKDIR) -p rpmbuild/{BUILD,RPMS,SOURCES}
$(SED) 's/__VERSION__/$(VERSION)/g' $(TARGET).spec > \
rpmbuild/SOURCES/$(TARGET).spec
cp -ar $(TARGET)-$(VERSION).tar.gz rpmbuild/SOURCES
$(RPMBUILD) -ba rpmbuild/SOURCES/$(TARGET).spec \
--define "_topdir $(CURDIR)/rpmbuild"
2014-05-29 19:23:46 +08:00
.PHONY: all clean install help
2014-05-13 00:41:46 +08:00
include $(wildcard obj/*.d)