mergerfs/Makefile

276 lines
6.8 KiB
Makefile
Raw Normal View History

# Copyright (c) 2024, Antonio SJ Musumeci <trapexit@spawn.link>
2014-05-13 00:41:46 +08:00
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
2014-05-13 00:41:46 +08:00
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
GIT = git
TAR = tar
MKDIR = mkdir
TOUCH = touch
CP = cp
RM = rm
LN = ln
FIND = find
INSTALL = install
MKTEMP = mktemp
STRIP = strip
PANDOC = pandoc
SED = sed
RPMBUILD = rpmbuild
GIT2DEBCL = ./buildtools/git2debcl
PKGCONFIG = pkg-config
2017-08-07 02:39:56 +08:00
GIT_REPO = 0
ifneq ($(shell $(GIT) --version 2> /dev/null),)
2017-08-07 02:39:56 +08:00
ifeq ($(shell test -e .git; echo $$?),0)
GIT_REPO = 1
endif
endif
2018-10-09 23:58:06 +08:00
USE_XATTR = 1
2020-02-21 21:01:49 +08:00
UGID_USE_RWLOCK = 0
ifeq ($(DEBUG),1)
OPT_FLAGS := -O0 -g -fsanitize=undefined
else
OPT_FLAGS := -O2 -DNDEBUG
endif
ifeq ($(STATIC),1)
STATIC_FLAGS := -static
else
STATIC_FLAGS :=
endif
ifeq ($(LTO),1)
LTO_FLAGS := -flto
else
LTO_FLAGS :=
endif
2014-11-05 02:42:20 +08:00
SRC = $(wildcard src/*.cpp)
OBJS = $(SRC:src/%.cpp=build/.src/%.o)
DEPS = $(SRC:src/%.cpp=build/.src/%.d)
TESTS = $(wildcard tests/*.cpp)
TESTS_OBJS = $(filter-out build/.src/mergerfs.o,$(OBJS))
TESTS_OBJS += $(TESTS:tests/%.cpp=build/.tests/%.o)
TESTS_DEPS = $(TESTS:tests/%.cpp=build/.tests/%.d)
TESTS_DEPS += $(DEPS)
2019-04-25 04:19:01 +08:00
MANPAGE = mergerfs.1
CFLAGS ?= ${OPT_FLAGS}
CFLAGS := ${CFLAGS} \
-Wall \
-Wno-unused-result
CXXFLAGS ?= ${OPT_FLAGS}
CXXFLAGS := \
${CXXFLAGS} \
-std=c++11 \
$(STATIC_FLAGS) \
$(LTO_FLAGS) \
2024-02-16 13:09:11 +08:00
-Isrc \
-Wall \
-Wno-unused-result \
2020-02-21 21:01:49 +08:00
-MMD
FUSE_FLAGS = \
-Ilibfuse/include \
-D_FILE_OFFSET_BITS=64
2020-02-21 21:01:49 +08:00
MFS_FLAGS = \
2018-10-09 23:58:06 +08:00
-DUSE_XATTR=$(USE_XATTR) \
-DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
TESTS_FLAGS = \
-Isrc \
-DTESTS
LDFLAGS := \
${LDFLAGS} \
-pthread \
-lrt
2014-11-05 02:42:20 +08:00
# https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
2020-02-21 21:01:49 +08:00
DESTDIR =
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
LIBDIR = $(EXEC_PREFIX)/lib
2015-08-07 01:11:17 +08:00
MANDIR = $(DATAROOTDIR)/man
MAN1DIR = $(MANDIR)/man1
INSTALLBINDIR = $(DESTDIR)$(BINDIR)
INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
INSTALLLIBDIR = $(DESTDIR)$(LIBDIR)/mergerfs
2015-08-07 01:11:17 +08:00
INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
2014-05-13 00:41:46 +08:00
2019-04-25 04:19:01 +08:00
.PHONY: all
all: mergerfs
2014-05-13 00:41:46 +08:00
2019-04-25 04:19:01 +08:00
.PHONY: help
2014-05-13 00:41:46 +08:00
help:
@echo "usage: make\n"
2018-10-09 23:58:06 +08:00
@echo "make USE_XATTR=0 - build program without xattrs functionality"
@echo "make STATIC=1 - build static binary"
@echo "make LTO=1 - build with link time optimization"
2014-05-13 00:41:46 +08:00
2019-04-25 04:19:01 +08:00
objects: version build/stamp
$(MAKE) $(OBJS)
2014-05-13 00:41:46 +08:00
tests-objects:
$(MAKE) $(TESTS_OBJS)
2019-04-25 04:19:01 +08:00
build/mergerfs: libfuse objects
2020-02-21 21:01:49 +08:00
$(CXX) $(CXXFLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) $(OBJS) -o $@ libfuse/build/libfuse.a $(LDFLAGS)
2019-04-25 04:19:01 +08:00
build/tests: build/mergerfs tests-objects
$(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) $(TESTS_OBJS) -o $@ libfuse/build/libfuse.a $(LDFLAGS)
2019-04-25 04:19:01 +08:00
mergerfs: build/mergerfs
tests: build/tests
2014-05-29 19:23:46 +08:00
changelog:
2017-08-07 02:39:56 +08:00
ifeq ($(GIT_REPO),1)
2019-04-25 04:19:01 +08:00
$(GIT2DEBCL) --name mergerfs > ChangeLog
else
@echo "WARNING: need git repo to generate ChangeLog"
2017-08-07 02:39:56 +08:00
endif
2015-08-07 01:11:17 +08:00
2019-04-25 04:19:01 +08:00
.PHONY: version
2017-08-07 02:39:56 +08:00
version:
./buildtools/update-version
2015-09-06 09:48:15 +08:00
2019-04-25 04:19:01 +08:00
build/stamp:
$(MKDIR) -p build/.src build/.tests
2014-05-29 19:23:46 +08:00
$(TOUCH) $@
2014-05-13 00:41:46 +08:00
build/.src/%.o: src/%.cpp
2020-02-21 21:01:49 +08:00
$(CXX) $(CXXFLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
2014-05-13 00:41:46 +08:00
build/.tests/%.o: tests/%.cpp
$(CXX) $(CXXFLAGS) $(TESTS_FLAGS) $(FUSE_FLAGS) $(MFS_FLAGS) $(CPPFLAGS) -c $< -o $@
build/preload.so: build/stamp tools/preload.c
$(CC) -shared -fPIC $(CFLAGS) $(CPPFLAGS) -o $@ tools/preload.c
preload: build/preload.so
2019-04-25 04:19:01 +08:00
.PHONY: clean
clean: rpm-clean
2019-04-25 04:19:01 +08:00
$(RM) -rf build
2015-08-07 01:11:17 +08:00
$(FIND) . -name "*~" -delete
2019-04-25 04:19:01 +08:00
$(MAKE) -C libfuse clean
2014-05-29 19:23:46 +08:00
distclean: clean
ifeq ($(GIT_REPO),1)
$(GIT) clean -xfd
endif
2019-04-25 04:19:01 +08:00
.PHONY: install
install: install-base install-mount-tools install-preload install-man
2015-01-28 07:25:20 +08:00
2019-04-25 04:19:01 +08:00
install-base: build/mergerfs
2016-10-25 05:26:45 +08:00
$(MKDIR) -p "$(INSTALLBINDIR)"
2019-04-25 04:19:01 +08:00
$(INSTALL) -v -m 0755 build/mergerfs "$(INSTALLBINDIR)/mergerfs"
2015-01-28 07:25:20 +08:00
2020-02-21 21:01:49 +08:00
install-mount-tools: install-base
$(MKDIR) -p "$(INSTALLBINDIR)"
2020-02-21 21:01:49 +08:00
$(MAKE) -C libfuse install
2015-01-28 07:25:20 +08:00
install-man: $(MANPAGE)
2016-10-25 05:26:45 +08:00
$(MKDIR) -p "$(INSTALLMAN1DIR)"
$(INSTALL) -v -m 0644 "man/$(MANPAGE)" "$(INSTALLMAN1DIR)/$(MANPAGE)"
2015-01-28 07:25:20 +08:00
install-preload: preload
$(MKDIR) -p "$(INSTALLLIBDIR)"
$(INSTALL) -v -m 444 "build/preload.so" "$(INSTALLLIBDIR)/preload.so"
2015-01-28 07:25:20 +08:00
install-strip: install-base
2019-04-25 04:19:01 +08:00
$(STRIP) "$(INSTALLBINDIR)/mergerfs"
2015-01-28 07:25:20 +08:00
2019-04-25 04:19:01 +08:00
.PHONY: uninstall
2016-01-22 03:48:12 +08:00
uninstall: uninstall-base uninstall-mount.mergerfs uninstall-man
2015-01-28 07:25:20 +08:00
uninstall-base:
2019-04-25 04:19:01 +08:00
$(RM) -f "$(INSTALLBINDIR)/mergerfs"
2014-05-29 19:23:46 +08:00
2016-01-22 03:48:12 +08:00
uninstall-mount.mergerfs:
$(RM) -f "$(INSTALLBINDIR)/mount.mergerfs"
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 ($(shell $(PANDOC) --version 2> /dev/null),)
2016-03-11 07:42:32 +08:00
$(PANDOC) -s -t man -o "man/$(MANPAGE)" README.md
else
$(warning "pandoc does not appear available: unable to build manpage")
endif
man: $(MANPAGE)
2014-05-29 19:23:46 +08:00
2019-04-25 04:19:01 +08:00
.PHONY: tarball
tarball: man changelog version
2017-08-07 02:39:56 +08:00
$(eval VERSION := $(shell cat VERSION))
2015-09-06 05:56:45 +08:00
$(eval VERSION := $(subst -,_,$(VERSION)))
2019-04-25 04:19:01 +08:00
$(eval FILENAME := mergerfs-$(VERSION))
2014-05-29 19:23:46 +08:00
$(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:
2017-08-07 02:39:56 +08:00
ifeq ($(GIT_REPO),1)
2019-04-25 04:19:01 +08:00
$(GIT2DEBCL) --name mergerfs > debian/changelog
2017-08-07 02:39:56 +08:00
else
cp ChangeLog debian/changelog
endif
2015-08-07 01:11:17 +08:00
2019-04-25 04:19:01 +08:00
signed-deb:
$(MAKE) distclean
$(MAKE) debian-changelog
# dpkg-source -b .
2019-02-23 14:35:22 +08:00
dpkg-buildpackage -nc
2015-08-07 01:11:17 +08:00
2019-03-13 11:11:15 +08:00
deb:
$(MAKE) distclean
$(MAKE) debian-changelog
# dpkg-source -b .
2019-02-23 14:35:22 +08:00
dpkg-buildpackage -nc -uc -us
2014-05-13 00:41:46 +08:00
2019-04-25 04:19:01 +08:00
.PHONY: rpm-clean
2015-09-06 05:56:45 +08:00
rpm-clean:
$(RM) -rf rpmbuild
rpm: tarball
2017-08-07 02:39:56 +08:00
$(eval VERSION := $(shell cat VERSION))
2015-09-06 05:56:45 +08:00
$(eval VERSION := $(subst -,_,$(VERSION)))
$(MKDIR) -p rpmbuild/BUILD rpmbuild/RPMS rpmbuild/SOURCES
2019-04-25 04:19:01 +08:00
$(SED) 's/__VERSION__/$(VERSION)/g' mergerfs.spec > \
rpmbuild/SOURCES/mergerfs.spec
cp -ar mergerfs-$(VERSION).tar.gz rpmbuild/SOURCES
$(RPMBUILD) -ba rpmbuild/SOURCES/mergerfs.spec \
2015-09-06 05:56:45 +08:00
--define "_topdir $(CURDIR)/rpmbuild"
2019-04-25 04:19:01 +08:00
.PHONY: install-build-pkgs
install-build-pkgs:
./buildtools/install-build-pkgs
2019-04-25 04:19:01 +08:00
.PHONY: libfuse
libfuse:
$(MAKE) DEBUG=$(DEBUG) -C libfuse
2014-05-13 00:41:46 +08:00
-include $(DEPS)