2020-01-29 22:25:51 +00:00
# meli - Makefile
#
# Copyright 2017-2020 Manos Pitsidianakis
#
# This file is part of meli.
#
# meli is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# meli is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with meli. If not, see <http://www.gnu.org/licenses/>.
2022-08-27 14:41:07 +00:00
.POSIX :
.SUFFIXES :
2023-07-01 13:34:06 +00:00
CARGO_TARGET_DIR ?= target
CARGO_BIN ?= cargo
2023-07-13 13:47:11 +00:00
TAGREF_BIN ?= tagref
2023-07-01 13:34:06 +00:00
CARGO_ARGS ?=
2023-08-11 16:15:14 +00:00
RUSTFLAGS ?= -D warnings -W unreachable-pub -W rust-2021-compatibility
2023-07-01 13:34:06 +00:00
CARGO_SORT_BIN = cargo-sort
2024-01-01 09:38:42 +00:00
CARGO_HACK_BIN = cargo-hack
2023-12-09 16:01:12 +00:00
PRINTF = /usr/bin/printf
2020-01-29 22:25:51 +00:00
2020-01-29 19:44:55 +00:00
# Options
2019-12-18 07:18:28 +00:00
PREFIX ?= /usr/local
2020-05-19 09:57:09 +00:00
EXPANDED_PREFIX := ` cd ${ PREFIX } && pwd -P`
BINDIR ?= ${ EXPANDED_PREFIX } /bin
MANDIR ?= ${ EXPANDED_PREFIX } /share/man
2019-09-16 13:21:29 +00:00
2020-01-29 19:44:55 +00:00
# Installation parameters
2023-07-06 06:03:19 +00:00
DOCS_SUBDIR ?= meli/docs/
2023-12-03 15:18:58 +00:00
MANPAGES ?= meli.1 meli.conf.5 meli-themes.5 meli.7
2020-02-09 00:46:27 +00:00
FEATURES ?= --features " ${ MELI_FEATURES } "
2020-01-31 01:45:55 +00:00
2023-12-03 15:18:58 +00:00
MANPATHS != ACCUM = "" ; for m in ` manpath 2> /dev/null | tr ':' ' ' ` ; do if [ -d " $$ {m} " ] ; then REAL_PATH = ` cd $$ { m} && pwd ` ACCUM = " $$ {ACCUM}: $$ {REAL_PATH} " ; fi ; done ; echo $$ { ACCUM} '\c' | sed 's/^://'
VERSION = ` grep -m1 version meli/Cargo.toml | head -n1 | cut -d'"' -f 2 | head -n1`
2023-12-09 16:01:12 +00:00
MIN_RUSTC = ` grep -m1 rust-version meli/Cargo.toml | head -n1 | cut -d'"' -f 2 | head -n1`
2023-12-03 15:18:58 +00:00
GIT_COMMIT = ` git show-ref -s --abbrev HEAD`
DATE = ` date -I`
2020-01-29 19:44:55 +00:00
# Output parameters
2020-02-05 01:40:35 +00:00
BOLD ?= ` [ -z $$ { TERM} ] && echo "" || tput bold`
UNDERLINE ?= ` [ -z $$ { TERM} ] && echo "" || tput smul`
ANSI_RESET ?= ` [ -z $$ { TERM} ] && echo "" || tput sgr0`
2020-01-31 01:45:55 +00:00
CARGO_COLOR ?= ` [ -z $$ { NO_COLOR+x} ] && echo "" || echo "--color=never " `
2020-02-05 01:40:35 +00:00
RED ?= ` [ -z $$ { NO_COLOR+x} ] && ( [ -z $$ { TERM} ] && echo "" || tput setaf 1) || echo "" `
GREEN ?= ` [ -z $$ { NO_COLOR+x} ] && ( [ -z $$ { TERM} ] && echo "" || tput setaf 2) || echo "" `
2023-12-03 15:18:58 +00:00
YELLOW ?= ` [ -z $$ { NO_COLOR+x} ] && ( [ -z $$ { TERM} ] && echo "" || tput setaf 3) || echo "" `
2020-01-29 19:44:55 +00:00
2022-08-27 14:41:07 +00:00
.PHONY : meli
2020-07-25 23:40:01 +00:00
meli : check -deps
2022-11-13 16:59:12 +00:00
@${ CARGO_BIN } build ${ CARGO_ARGS } ${ CARGO_COLOR } --target-dir= " ${ CARGO_TARGET_DIR } " ${ FEATURES } --release --bin meli
2020-07-25 23:40:01 +00:00
2022-08-27 14:41:07 +00:00
.PHONY : help
2020-01-29 19:44:55 +00:00
help :
2023-12-03 15:18:58 +00:00
@echo " For a quick start, build and install locally:\n\n ${ BOLD } ${ GREEN } make PREFIX=~/.local install ${ ANSI_RESET } \n "
2020-01-29 19:44:55 +00:00
@echo "Available subcommands:"
2020-02-04 13:52:12 +00:00
@echo " - ${ BOLD } meli ${ ANSI_RESET } (builds meli with optimizations in \$ $CARGO_TARGET_DIR ) "
@echo " - ${ BOLD } install ${ ANSI_RESET } (installs binary in \$ $BINDIR and documentation to \$ $MANDIR ) "
2020-01-31 01:45:55 +00:00
@echo " - ${ BOLD } uninstall ${ ANSI_RESET } "
2023-12-03 15:18:58 +00:00
@echo "\nSecondary subcommands:"
2020-01-31 01:45:55 +00:00
@echo " - ${ BOLD } clean ${ ANSI_RESET } (cleans build artifacts) "
@echo " - ${ BOLD } check-deps ${ ANSI_RESET } (checks dependencies) "
2020-02-04 13:52:12 +00:00
@echo " - ${ BOLD } install-bin ${ ANSI_RESET } (installs binary to \$ $BINDIR ) "
@echo " - ${ BOLD } install-doc ${ ANSI_RESET } (installs manpages to \$ $MANDIR ) "
2020-01-31 01:45:55 +00:00
@echo " - ${ BOLD } help ${ ANSI_RESET } (prints this information) "
2020-02-04 13:52:12 +00:00
@echo " - ${ BOLD } dist ${ ANSI_RESET } (creates release tarball named meli- " ${ VERSION } ".tar.gz in this directory)"
@echo " - ${ BOLD } deb-dist ${ ANSI_RESET } (builds debian package in the parent directory) "
2020-01-31 01:45:55 +00:00
@echo " - ${ BOLD } distclean ${ ANSI_RESET } (cleans distribution build artifacts) "
2020-09-12 20:50:40 +00:00
@echo " - ${ BOLD } build-rustdoc ${ ANSI_RESET } (builds rustdoc documentation for all packages in \$ $CARGO_TARGET_DIR ) "
2020-01-29 19:44:55 +00:00
@echo "\nENVIRONMENT variables of interest:"
2020-05-19 09:57:09 +00:00
@echo " * PREFIX = ${ UNDERLINE } ${ EXPANDED_PREFIX } ${ ANSI_RESET } "
2023-12-03 15:18:58 +00:00
@echo " * MELI_FEATURES = ${ UNDERLINE } \n "
@[ -z $$ { MELI_FEATURES+x} ] && echo "unset\c" || echo ${ MELI_FEATURES } '\c'
2020-01-31 01:45:55 +00:00
@echo ${ ANSI_RESET }
@echo " * BINDIR = ${ UNDERLINE } ${ BINDIR } ${ ANSI_RESET } "
@echo " * MANDIR = ${ UNDERLINE } ${ MANDIR } ${ ANSI_RESET } "
2023-12-03 15:18:58 +00:00
@echo " * MANPATH = ${ UNDERLINE } \c "
@[ $$ { MANPATH+x} ] && echo $$ { MANPATH} '\c' || echo "unset\c"
2020-01-31 01:45:55 +00:00
@echo ${ ANSI_RESET }
2020-05-19 09:57:09 +00:00
@echo " * (cleaned) output of manpath(1) = ${ UNDERLINE } ${ MANPATHS } ${ ANSI_RESET } "
2023-12-03 15:18:58 +00:00
@echo " * NO_MAN ${ UNDERLINE } \c "
@[ $$ { NO_MAN+x} ] && echo "set\c" || echo "unset\c"
2020-01-31 01:45:55 +00:00
@echo ${ ANSI_RESET }
2023-12-03 15:18:58 +00:00
@echo " * NO_COLOR ${ UNDERLINE } \c "
@[ $$ { NO_COLOR+x} ] && echo "set\c" || echo "unset\c"
2020-01-31 01:45:55 +00:00
@echo ${ ANSI_RESET }
2020-11-05 19:11:27 +00:00
@echo " * CARGO_BIN = ${ UNDERLINE } ${ CARGO_BIN } ${ ANSI_RESET } "
@echo " * CARGO_ARGS = ${ UNDERLINE } ${ CARGO_ARGS } ${ ANSI_RESET } "
@echo " * MIN_RUSTC = ${ UNDERLINE } ${ MIN_RUSTC } ${ ANSI_RESET } "
2023-12-03 15:18:58 +00:00
@echo " * VERSION = ${ UNDERLINE } ${ VERSION } ${ ANSI_RESET } "
@echo " * GIT_COMMIT = ${ UNDERLINE } ${ GIT_COMMIT } ${ ANSI_RESET } "
2020-01-31 01:45:55 +00:00
@#@echo " * CARGO_COLOR = ${ CARGO_COLOR } "
2020-01-29 19:44:55 +00:00
2020-07-25 23:40:01 +00:00
.PHONY : check
2023-07-13 13:47:11 +00:00
check : check -tagrefs
2023-08-11 16:15:14 +00:00
@RUSTFLAGS= '${RUSTFLAGS}' ${ CARGO_BIN } check ${ CARGO_ARGS } ${ CARGO_COLOR } --target-dir= " ${ CARGO_TARGET_DIR } " ${ FEATURES } --all --tests --examples --benches --bins
2023-05-01 05:43:36 +00:00
2023-07-01 13:34:06 +00:00
.PHONY : fmt
fmt :
@$( CARGO_BIN) +nightly fmt --all || $( CARGO_BIN) fmt --all
@OUT= $$ ( $( CARGO_SORT_BIN) -w 2>& 1) || $( PRINTF) "WARN: %s cargo-sort failed or binary not found in PATH.\n" " $$ OUT "
.PHONY : lint
lint :
2023-08-11 16:15:14 +00:00
@RUSTFLAGS= '${RUSTFLAGS}' $( CARGO_BIN) clippy --no-deps --all-features --all --tests --examples --benches --bins
2023-07-01 13:34:06 +00:00
2023-05-01 05:43:36 +00:00
.PHONY : test
2023-09-22 10:26:42 +00:00
test : test -docs
2023-08-11 16:15:14 +00:00
@RUSTFLAGS= '${RUSTFLAGS}' ${ CARGO_BIN } test ${ CARGO_ARGS } ${ CARGO_COLOR } --target-dir= " ${ CARGO_TARGET_DIR } " --all --tests --examples --benches --bins
2020-01-29 19:44:55 +00:00
2023-09-22 10:26:42 +00:00
.PHONY : test -docs
test-docs :
@RUSTFLAGS= '${RUSTFLAGS}' ${ CARGO_BIN } test ${ CARGO_ARGS } ${ CARGO_COLOR } --target-dir= " ${ CARGO_TARGET_DIR } " --all --doc
2024-01-01 09:38:42 +00:00
.PHONY : test -feature -permutations
test-feature-permutations :
$( CARGO_HACK_BIN) hack --feature-powerset
2020-01-29 19:44:55 +00:00
.PHONY : check -deps
check-deps :
2020-11-05 19:11:27 +00:00
@( if ! echo ${ MIN_RUSTC } \\ n` ${ CARGO_BIN } --version | grep ^cargo | cut -d ' ' -f 2` | sort -CV; then echo " rust version >= ${ RED } ${ MIN_RUSTC } ${ ANSI_RESET } required, found: `which ${ CARGO_BIN } ` ` ${ CARGO_BIN } --version | cut -d ' ' -f 2` " \
2020-01-31 01:45:55 +00:00
" \nYour options:\n - Set CARGO_BIN to a supported version\n - Install a supported version from your distribution's package manager\n - Install a supported version from ${ UNDERLINE } https://rustup.rs/ ${ ANSI_RESET } " ; exit 1; fi )
2020-01-29 19:44:55 +00:00
2019-09-16 13:21:29 +00:00
.PHONY : clean
2019-12-09 16:33:46 +00:00
clean :
2020-01-29 19:44:55 +00:00
-rm -rf ./${ CARGO_TARGET_DIR } /
2019-09-16 13:21:29 +00:00
2020-01-29 19:44:55 +00:00
.PHONY : distclean
2023-12-10 17:00:53 +00:00
distclean :
2020-01-29 19:44:55 +00:00
@rm -f meli-${ VERSION } .tar.gz
2023-12-10 17:00:53 +00:00
@rm -rf .pc # rm debian stuff
2019-09-16 13:21:29 +00:00
.PHONY : uninstall
2019-12-09 16:33:46 +00:00
uninstall :
2020-01-29 19:44:55 +00:00
rm -f $( DESTDIR) ${ BINDIR } /meli
2023-12-03 15:18:58 +00:00
for MANPAGE in ${ MANPAGES } ; do \
SECTION = ` echo $$ { MANPAGE} | rev | cut -d "." -f 1` ; \
MANPAGEPATH = " ${ DESTDIR } ${ MANDIR } /man $$ {SECTION}/ $$ {MANPAGE}.gz " ; \
rm -f " $$ {MANAGEPATH} "
; done
2020-01-29 19:44:55 +00:00
.PHONY : install -doc
install-doc :
2020-01-31 01:45:55 +00:00
@( if [ -z $$ { NO_MAN+x} ] ; then \
echo " - ${ BOLD } Installing manpages to ${ ANSI_RESET } ${ DESTDIR } ${ MANDIR } : " ; \
for MANPAGE in ${ MANPAGES } ; do \
2020-01-29 19:44:55 +00:00
SECTION = ` echo $$ { MANPAGE} | rev | cut -d "." -f 1` ; \
2023-12-03 15:18:58 +00:00
mkdir -p $( DESTDIR) ${ MANDIR } /man$$ { SECTION} ; \
2020-01-29 19:44:55 +00:00
MANPAGEPATH = ${ DESTDIR } ${ MANDIR } /man$$ { SECTION} /$$ { MANPAGE} .gz; \
2020-01-31 01:45:55 +00:00
echo " * installing $$ {MANPAGE} → ${ GREEN } $$ {MANPAGEPATH} ${ ANSI_RESET } " ; \
2020-09-20 20:10:46 +00:00
gzip -n < ${ DOCS_SUBDIR } $$ { MANPAGE} > $$ { MANPAGEPATH} \
2022-08-27 14:41:07 +00:00
; done ; \
2020-01-31 01:45:55 +00:00
( case " : ${ MANPATHS } : " in \
2023-12-03 15:18:58 +00:00
*:${ DESTDIR } ${ MANDIR } :*) echo "\c" ; ; \
2020-01-31 01:45:55 +00:00
*) echo " \n ${ RED } ${ BOLD } WARNING ${ ANSI_RESET } : ${ UNDERLINE } Path ${ DESTDIR } ${ MANDIR } is not contained in your MANPATH variable or the output of \`manpath\` command. ${ ANSI_RESET } \`man\` might fail finding the installed manpages. Consider adding it if necessary.\nMANPATH variable / output of \`manpath\`: ${ MANPATHS } " ; ; \
esac ) ; \
else echo "NO_MAN is defined, so no documentation is going to be installed." ; fi )
2020-01-29 19:44:55 +00:00
.PHONY : install -bin
install-bin : meli
@mkdir -p $( DESTDIR) ${ BINDIR }
2020-01-31 01:45:55 +00:00
@echo " - ${ BOLD } Installing binary to ${ ANSI_RESET } ${ GREEN } ${ DESTDIR } ${ BINDIR } /meli ${ ANSI_RESET } "
2020-01-29 19:44:55 +00:00
@case " : ${ PATH } : " in \
2023-12-03 15:18:58 +00:00
*:${ DESTDIR } ${ BINDIR } :*) echo "\n" ; ; \
2020-01-31 01:45:55 +00:00
*) echo " \n ${ RED } ${ BOLD } WARNING ${ ANSI_RESET } : ${ UNDERLINE } Path ${ DESTDIR } ${ BINDIR } is not contained in your PATH variable. ${ ANSI_RESET } Consider adding it if necessary.\nPATH variable: ${ PATH } " ; ; \
2020-01-29 19:44:55 +00:00
esac
2020-11-05 19:09:42 +00:00
@mkdir -p $( DESTDIR) ${ BINDIR }
@rm -f $( DESTDIR) ${ BINDIR } /meli
@cp ./${ CARGO_TARGET_DIR } /release/meli $( DESTDIR) ${ BINDIR } /meli
@chmod 755 $( DESTDIR) ${ BINDIR } /meli
2020-01-29 19:44:55 +00:00
2019-09-16 13:21:29 +00:00
.PHONY : install
2020-01-29 19:44:55 +00:00
.NOTPARALLEL : yes
install : meli install -bin install -doc
2020-01-31 01:45:55 +00:00
@( if [ -z $$ { NO_MAN+x} ] ; then \
2024-03-10 11:08:58 +00:00
$( PRINTF) "\n You're ready to go. You might want to read the \"STARTING WITH meli\" section in the manpage (\`man meli\`)" ; \
$( PRINTF) "\n or the tutorial in meli(7) (\`man 7 meli\`).\n" ; \
2020-01-31 01:45:55 +00:00
fi )
2024-03-10 11:08:58 +00:00
@$( PRINTF) " - Report bugs in the mailing list or git issue tracker ${ UNDERLINE } https://git.meli-email.org ${ ANSI_RESET } \n "
@$( PRINTF) " - If you have a specific feature or workflow you want to use, you can post in the mailing list or git issue tracker.\n"
2020-01-29 19:44:55 +00:00
.PHONY : dist
dist :
@git archive --format= tar.gz --prefix= meli-${ VERSION } / HEAD >meli-${ VERSION } .tar.gz
@echo meli-${ VERSION } .tar.gz
2020-01-31 00:47:10 +00:00
.PHONY : deb -dist
deb-dist :
2023-12-10 15:48:17 +00:00
@author= $( grep -m1 authors meli/Cargo.toml | head -n1 | cut -d'"' -f 2 | head -n1)
@dpkg-buildpackage -b -rfakeroot -us -uc --build-by= " ${ author } " --release-by= " ${ author } "
2023-12-12 16:20:50 +00:00
@echo ${ BOLD } ${ GREEN } Generated${ ANSI_RESET } ../meli_${ VERSION } -1_` dpkg --print-architecture` .deb
2020-09-12 20:50:40 +00:00
.PHONY : build -rustdoc
build-rustdoc :
2020-11-05 19:11:27 +00:00
@RUSTDOCFLAGS= " --crate-version ${ VERSION } _ ${ GIT_COMMIT } _ ${ DATE } " ${ CARGO_BIN } doc ${ CARGO_ARGS } ${ CARGO_COLOR } --target-dir= " ${ CARGO_TARGET_DIR } " --all-features --no-deps --workspace --document-private-items --open
2023-07-13 13:47:11 +00:00
.PHONY : check -tagrefs
check-tagrefs :
@( if ! command -v " $( TAGREF_BIN) " > /dev/null; \
then \
$( PRINTF) "Warning: tagref binary not in PATH.\n" 1>& 2; \
exit; \
else \
$( TAGREF_BIN) ; \
fi )
2023-12-03 15:18:58 +00:00
.PHONY : test -makefile
test-makefile :
@$( PRINTF) "Checking that current version is detected. "
@( [ ! -z " ${ VERSION } " ] && $( PRINTF) " ${ GREEN } OK ${ ANSI_RESET } \n " ) || $( PRINTF) " ${ RED } ERROR ${ ANSI_RESET } \nVERSION env var is empty, check its definition.\n " 1>& 2
@$( PRINTF) "Checking that 'date -I' works on this platform. "
@export DATEVAL = $$ ( printf "%s" ${ DATE } | wc -c | tr -d "[:blank:]" 2>& 1) ; ( [ " $$ {DATEVAL} " = "10" ] && $( PRINTF) " ${ GREEN } OK ${ ANSI_RESET } \n " ) || $( PRINTF) " ${ RED } ERROR ${ ANSI_RESET } \n'date -I' does not produce a YYYY-MM-DD output on this platform.\n " 1>& 2
@$( PRINTF) "Checking that the git commit SHA can be detected. "
@( [ ! -z " $( GIT_COMMIT) " ] && $( PRINTF) " ${ GREEN } OK ${ ANSI_RESET } \n " ) || $( PRINTF) " ${ YELLOW } WARN ${ ANSI_RESET } \nGIT_COMMIT env var is empty.\n " 1>& 2
2024-03-06 14:28:27 +00:00
# Checking if mdoc changes produce new lint warnings from mandoc(1) compared to HEAD version:
#
# example invocation: `mandoc_lint meli.1`
#
# with diff(1)
# ============
#function mandoc_lint () {
#diff <(mandoc -T lint <(git show HEAD:./meli/docs/$1) 2> /dev/null | cut -d':' -f 3-) <(mandoc -T lint ./meli/docs/$1 2> /dev/null | cut -d':' -f 3-)
#}
#
# with sdiff(1) (side by side)
# ============================
#
#function mandoc_lint () {
#sdiff <(mandoc -T lint <(git show HEAD:./meli/docs/$1) 2> /dev/null | cut -d':' -f 3-) <(mandoc -T lint ./meli/docs/$1 2> /dev/null | cut -d':' -f 3-)
#}
#
# with delta(1)
# =============
#
#function mandoc_lint () {
#delta --side-by-side <(mandoc -T lint <(git show HEAD:./meli/docs/$1) 2> /dev/null | cut -d':' -f 3-) <(mandoc -T lint ./meli/docs/$1 2> /dev/null | cut -d':' -f 3-)
#}