Makefile: make Makefile portable

Tested with
- GNU Make 4.2.1
- bmake 20160220-2+b1
memfd
Manos Pitsidianakis 4 years ago
parent bb80de91ae
commit bc98a0ef48
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710

@ -28,61 +28,63 @@ CARGO_BIN ?= cargo
# Installation parameters # Installation parameters
MANPAGES ?= meli.1 meli.conf.5 meli-themes.5 MANPAGES ?= meli.1 meli.conf.5 meli-themes.5
ifdef MELI_FEATURES FEATURES ?= --features="$(MELI_FEATURES)"
FEATURES ?= --features="$(MELI_FEATURES)"
else MANPATHS := `manpath 2> /dev/null`
FEATURES ?=
endif
ifndef MANPATH
MANPATH = `manpath`
endif
VERSION ?= `sed -n "s/^version\s*=\s*\"\(.*\)\"/\1/p" Cargo.toml` VERSION ?= `sed -n "s/^version\s*=\s*\"\(.*\)\"/\1/p" Cargo.toml`
# Output parameters # Output parameters
BOLD ?= tput bold BOLD ?= `tput bold`
UNDERLINE ?= tput smul UNDERLINE ?= `tput smul`
ANSI_RESET ?= tput sgr0 ANSI_RESET ?= `tput sgr0`
ifdef NO_COLOR CARGO_COLOR ?= `[ -z $${NO_COLOR+x} ] && echo "" || echo "--color=never "`
RED ?= RED ?= `[ -z $${NO_COLOR+x} ] && tput setaf 1 || echo ""`
GREEN ?= GREEN ?= `[ -z $${NO_COLOR+x} ] && tput setaf 2 || echo ""`
CARGO_COLOR ?= --color=never
else
RED ?= tput setaf 1
GREEN ?= tput setaf 2
endif
.POSIX: .POSIX:
.SUFFIXES: .SUFFIXES:
help: help:
@echo "For a quick start, build and install locally:\n `${BOLD}``${GREEN}`PREFIX=~/.local make install`${ANSI_RESET}`\n" @echo "For a quick start, build and install locally:\n ${BOLD}${GREEN}PREFIX=~/.local make install${ANSI_RESET}\n"
@echo "Available subcommands:" @echo "Available subcommands:"
@echo " - `${BOLD}`install`${ANSI_RESET}` (installs binary and documentation)" @echo " - ${BOLD}install${ANSI_RESET} (installs binary and documentation)"
@echo " - `${BOLD}`uninstall`${ANSI_RESET}`" @echo " - ${BOLD}uninstall${ANSI_RESET}"
@echo "Secondary subcommands:" @echo "Secondary subcommands:"
@echo " - `${BOLD}`clean`${ANSI_RESET}` (cleans build artifacts)" @echo " - ${BOLD}clean${ANSI_RESET} (cleans build artifacts)"
@echo " - `${BOLD}`check-deps`${ANSI_RESET}` (checks dependencies)" @echo " - ${BOLD}check-deps${ANSI_RESET} (checks dependencies)"
@echo " - `${BOLD}`install-bin`${ANSI_RESET}` (installs binary to BINDIR)" @echo " - ${BOLD}install-bin${ANSI_RESET} (installs binary to BINDIR)"
@echo " - `${BOLD}`install-doc`${ANSI_RESET}` (installs manpages to MANDIR)" @echo " - ${BOLD}install-doc${ANSI_RESET} (installs manpages to MANDIR)"
@echo " - `${BOLD}`help`${ANSI_RESET}` (prints this information)" @echo " - ${BOLD}help${ANSI_RESET} (prints this information)"
@echo " - `${BOLD}`dist`${ANSI_RESET}` (creates release tarball named meli-${VERSION}.tar.gz)" @echo " - ${BOLD}dist${ANSI_RESET} (creates release tarball named meli-"${VERSION}".tar.gz)"
@echo " - `${BOLD}`deb-dist`${ANSI_RESET}` (builds debian package)" @echo " - ${BOLD}deb-dist${ANSI_RESET} (builds debian package)"
@echo " - `${BOLD}`distclean`${ANSI_RESET}` (cleans distribution build artifacts)" @echo " - ${BOLD}distclean${ANSI_RESET} (cleans distribution build artifacts)"
@echo "\nENVIRONMENT variables of interest:" @echo "\nENVIRONMENT variables of interest:"
@echo "* PREFIX = ${PREFIX}" @echo "* PREFIX = ${UNDERLINE}${PREFIX}${ANSI_RESET}"
@echo "* MELI_FEATURES = ${MELI_FEATURES}" @echo -n "* MELI_FEATURES = ${UNDERLINE}"
@echo "* BINDIR = ${BINDIR}" @[ -z $${MELI_FEATURES+x} ] && echo -n "unset" || echo -n ${MELI_FEATURES}
@echo "* MANDIR = ${MANDIR}" @echo ${ANSI_RESET}
@echo "* BINDIR = ${UNDERLINE}${BINDIR}${ANSI_RESET}"
@echo "* MANDIR = ${UNDERLINE}${MANDIR}${ANSI_RESET}"
@echo -n "* MANPATH = ${UNDERLINE}"
@[ $${MANPATH+x} ] && echo -n $${MANPATH} || echo -n "unset"
@echo ${ANSI_RESET}
@echo "* output of manpath(1) = ${UNDERLINE}${MANPATHS}${ANSI_RESET}"
@echo -n "* NO_MAN ${UNDERLINE}"
@[ $${NO_MAN+x} ] && echo -n "set" || echo -n "unset"
@echo ${ANSI_RESET}
@echo -n "* NO_COLOR ${UNDERLINE}"
@[ $${NO_COLOR+x} ] && echo -n "set" || echo -n "unset"
@echo ${ANSI_RESET}
@#@echo "* CARGO_COLOR = ${CARGO_COLOR}"
meli: check-deps meli: check-deps
${CARGO_BIN} build ${CARGO_COLOR}--target-dir="${CARGO_TARGET_DIR}" $(FEATURES)--release @${CARGO_BIN} build ${CARGO_COLOR}--target-dir="${CARGO_TARGET_DIR}" ${FEATURES} --release
.PHONY: check-deps .PHONY: check-deps
check-deps: check-deps:
@if ! echo ${MIN_RUSTC}\\n`${CARGO_BIN} --version | 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`" \ @(if ! echo ${MIN_RUSTC}\\n`${CARGO_BIN} --version | 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`" \
"\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 "\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)
.PHONY: clean .PHONY: clean
@ -102,31 +104,29 @@ uninstall:
.PHONY: install-doc .PHONY: install-doc
install-doc: install-doc:
ifndef NO_MAN @(if [ -z $${NO_MAN+x} ]; then \
@mkdir -p $(DESTDIR)${MANDIR}/man1 mkdir -p $(DESTDIR)${MANDIR}/man1 ; \
@mkdir -p $(DESTDIR)${MANDIR}/man5 mkdir -p $(DESTDIR)${MANDIR}/man5 ; \
@echo " - `${BOLD}`Installing manpages to `${ANSI_RESET}`${DESTDIR}${MANDIR}:" echo " - ${BOLD}Installing manpages to ${ANSI_RESET}${DESTDIR}${MANDIR}:" ; \
@for MANPAGE in ${MANPAGES}; do \ for MANPAGE in ${MANPAGES}; do \
SECTION=`echo $${MANPAGE} | rev | cut -d "." -f 1`; \ SECTION=`echo $${MANPAGE} | rev | cut -d "." -f 1`; \
MANPAGEPATH=${DESTDIR}${MANDIR}/man$${SECTION}/$${MANPAGE}.gz; \ MANPAGEPATH=${DESTDIR}${MANDIR}/man$${SECTION}/$${MANPAGE}.gz; \
echo " * installing $${MANPAGE} → `${GREEN}`$${MANPAGEPATH}`${ANSI_RESET}`"; \ echo " * installing $${MANPAGE} → ${GREEN}$${MANPAGEPATH}${ANSI_RESET}"; \
gzip < $${MANPAGE} > $${MANPAGEPATH} \ gzip < $${MANPAGE} > $${MANPAGEPATH} \
; done ; done ; \
@case ":${MANPATH}:" in \ (case ":${MANPATHS}:" in \
*:${DESTDIR}${MANDIR}:*) echo -n "";; \ *:${DESTDIR}${MANDIR}:*) echo -n "";; \
*) 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\`: ${MANPATH}" ;; \ *) 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 esac) ; \
else else echo "NO_MAN is defined, so no documentation is going to be installed." ; fi)
@echo "NO_MAN is defined, so no documentation is going to be installed."
endif
.PHONY: install-bin .PHONY: install-bin
install-bin: meli install-bin: meli
@mkdir -p $(DESTDIR)${BINDIR} @mkdir -p $(DESTDIR)${BINDIR}
@echo " - `${BOLD}`Installing binary to `${ANSI_RESET}``${GREEN}`${DESTDIR}${BINDIR}/meli`${ANSI_RESET}`" @echo " - ${BOLD}Installing binary to ${ANSI_RESET}${GREEN}${DESTDIR}${BINDIR}/meli${ANSI_RESET}"
@case ":${PATH}:" in \ @case ":${PATH}:" in \
*:${DESTDIR}${BINDIR}:*) echo -n "";; \ *:${DESTDIR}${BINDIR}:*) echo -n "";; \
*) 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}";; \ *) 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}";; \
esac esac
@install -D ./${CARGO_TARGET_DIR}/release/meli $(DESTDIR)${BINDIR}/meli @install -D ./${CARGO_TARGET_DIR}/release/meli $(DESTDIR)${BINDIR}/meli
@ -134,10 +134,10 @@ install-bin: meli
.PHONY: install .PHONY: install
.NOTPARALLEL: yes .NOTPARALLEL: yes
install: meli install-bin install-doc install: meli install-bin install-doc
ifndef NO_MAN @(if [ -z $${NO_MAN+x} ]; then \
@echo "\n You're ready to go. You might want to read the \"STARTING WITH meli\" section in the manpage (\`man meli\`)" echo "\n You're ready to go. You might want to read the \"STARTING WITH meli\" section in the manpage (\`man meli\`)" ;\
endif fi)
@echo " - Report bugs in the mailing list or git issue tracker `${UNDERLINE}`https://git.meli.delivery`${ANSI_RESET}`" @echo " - Report bugs in the mailing list or git issue tracker ${UNDERLINE}https://git.meli.delivery${ANSI_RESET}"
@echo " - If you have a specific feature or workflow you want to use, you can post in the mailing list or git issue tracker." @echo " - If you have a specific feature or workflow you want to use, you can post in the mailing list or git issue tracker."
.PHONY: dist .PHONY: dist
@ -148,4 +148,4 @@ dist:
.PHONY: deb-dist .PHONY: deb-dist
deb-dist: deb-dist:
@dpkg-buildpackage -b -rfakeroot -us -uc @dpkg-buildpackage -b -rfakeroot -us -uc
@echo `${BOLD}``${GREEN}`Generated`${ANSI_RESET}` ../meli_${VERSION}-1_amd64.deb @echo ${BOLD}${GREEN}Generated${ANSI_RESET} ../meli_${VERSION}-1_amd64.deb

Loading…
Cancel
Save