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.

153 lines
6.4KB

  1. # meli - Makefile
  2. #
  3. # Copyright 2017-2020 Manos Pitsidianakis
  4. #
  5. # This file is part of meli.
  6. #
  7. # meli is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # meli is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with meli. If not, see <http://www.gnu.org/licenses/>.
  19. # Options
  20. PREFIX ?= /usr/local
  21. BINDIR ?= ${PREFIX}/bin
  22. MANDIR ?= ${PREFIX}/share/man
  23. CARGO_TARGET_DIR ?= target
  24. MIN_RUSTC ?= 1.39.0
  25. CARGO_BIN ?= cargo
  26. # Installation parameters
  27. MANPAGES ?= meli.1 meli.conf.5 meli-themes.5
  28. FEATURES ?= --features "${MELI_FEATURES}"
  29. MANPATHS := `manpath 2> /dev/null`
  30. VERSION ?= `sed -n "s/^version\s*=\s*\"\(.*\)\"/\1/p" Cargo.toml`
  31. # Output parameters
  32. BOLD ?= `[ -z $${TERM} ] && echo "" || tput bold`
  33. UNDERLINE ?= `[ -z $${TERM} ] && echo "" || tput smul`
  34. ANSI_RESET ?= `[ -z $${TERM} ] && echo "" || tput sgr0`
  35. CARGO_COLOR ?= `[ -z $${NO_COLOR+x} ] && echo "" || echo "--color=never "`
  36. RED ?= `[ -z $${NO_COLOR+x} ] && ([ -z $${TERM} ] && echo "" || tput setaf 1) || echo ""`
  37. GREEN ?= `[ -z $${NO_COLOR+x} ] && ([ -z $${TERM} ] && echo "" || tput setaf 2) || echo ""`
  38. .POSIX:
  39. .SUFFIXES:
  40. help:
  41. @echo "For a quick start, build and install locally:\n ${BOLD}${GREEN}PREFIX=~/.local make install${ANSI_RESET}\n"
  42. @echo "Available subcommands:"
  43. @echo " - ${BOLD}meli${ANSI_RESET} (builds meli with optimizations in \$$CARGO_TARGET_DIR)"
  44. @echo " - ${BOLD}install${ANSI_RESET} (installs binary in \$$BINDIR and documentation to \$$MANDIR)"
  45. @echo " - ${BOLD}uninstall${ANSI_RESET}"
  46. @echo "Secondary subcommands:"
  47. @echo " - ${BOLD}clean${ANSI_RESET} (cleans build artifacts)"
  48. @echo " - ${BOLD}check-deps${ANSI_RESET} (checks dependencies)"
  49. @echo " - ${BOLD}install-bin${ANSI_RESET} (installs binary to \$$BINDIR)"
  50. @echo " - ${BOLD}install-doc${ANSI_RESET} (installs manpages to \$$MANDIR)"
  51. @echo " - ${BOLD}help${ANSI_RESET} (prints this information)"
  52. @echo " - ${BOLD}dist${ANSI_RESET} (creates release tarball named meli-"${VERSION}".tar.gz in this directory)"
  53. @echo " - ${BOLD}deb-dist${ANSI_RESET} (builds debian package in the parent directory)"
  54. @echo " - ${BOLD}distclean${ANSI_RESET} (cleans distribution build artifacts)"
  55. @echo "\nENVIRONMENT variables of interest:"
  56. @echo "* PREFIX = ${UNDERLINE}${PREFIX}${ANSI_RESET}"
  57. @echo -n "* MELI_FEATURES = ${UNDERLINE}"
  58. @[ -z $${MELI_FEATURES+x} ] && echo -n "unset" || echo -n ${MELI_FEATURES}
  59. @echo ${ANSI_RESET}
  60. @echo "* BINDIR = ${UNDERLINE}${BINDIR}${ANSI_RESET}"
  61. @echo "* MANDIR = ${UNDERLINE}${MANDIR}${ANSI_RESET}"
  62. @echo -n "* MANPATH = ${UNDERLINE}"
  63. @[ $${MANPATH+x} ] && echo -n $${MANPATH} || echo -n "unset"
  64. @echo ${ANSI_RESET}
  65. @echo "* output of manpath(1) = ${UNDERLINE}${MANPATHS}${ANSI_RESET}"
  66. @echo -n "* NO_MAN ${UNDERLINE}"
  67. @[ $${NO_MAN+x} ] && echo -n "set" || echo -n "unset"
  68. @echo ${ANSI_RESET}
  69. @echo -n "* NO_COLOR ${UNDERLINE}"
  70. @[ $${NO_COLOR+x} ] && echo -n "set" || echo -n "unset"
  71. @echo ${ANSI_RESET}
  72. @#@echo "* CARGO_COLOR = ${CARGO_COLOR}"
  73. meli: check-deps
  74. @${CARGO_BIN} build ${CARGO_COLOR}--target-dir="${CARGO_TARGET_DIR}" ${FEATURES} --release
  75. .PHONY: check-deps
  76. check-deps:
  77. @(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`" \
  78. "\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)
  79. .PHONY: clean
  80. clean:
  81. -rm -rf ./${CARGO_TARGET_DIR}/
  82. .PHONY: distclean
  83. distclean: clean
  84. @rm -f meli-${VERSION}.tar.gz
  85. .PHONY: uninstall
  86. uninstall:
  87. rm -f $(DESTDIR)${BINDIR}/meli
  88. -rm $(DESTDIR)${MANDIR}/man1/meli.1.gz
  89. -rm $(DESTDIR)${MANDIR}/man5/meli.conf.5.gz
  90. -rm $(DESTDIR)${MANDIR}/man5/meli-themes.5.gz
  91. .PHONY: install-doc
  92. install-doc:
  93. @(if [ -z $${NO_MAN+x} ]; then \
  94. mkdir -p $(DESTDIR)${MANDIR}/man1 ; \
  95. mkdir -p $(DESTDIR)${MANDIR}/man5 ; \
  96. echo " - ${BOLD}Installing manpages to ${ANSI_RESET}${DESTDIR}${MANDIR}:" ; \
  97. for MANPAGE in ${MANPAGES}; do \
  98. SECTION=`echo $${MANPAGE} | rev | cut -d "." -f 1`; \
  99. MANPAGEPATH=${DESTDIR}${MANDIR}/man$${SECTION}/$${MANPAGE}.gz; \
  100. echo " * installing $${MANPAGE} → ${GREEN}$${MANPAGEPATH}${ANSI_RESET}"; \
  101. gzip -n < $${MANPAGE} > $${MANPAGEPATH} \
  102. ; done ; \
  103. (case ":${MANPATHS}:" in \
  104. *:${DESTDIR}${MANDIR}:*) echo -n "";; \
  105. *) 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}" ;; \
  106. esac) ; \
  107. else echo "NO_MAN is defined, so no documentation is going to be installed." ; fi)
  108. .PHONY: install-bin
  109. install-bin: meli
  110. @mkdir -p $(DESTDIR)${BINDIR}
  111. @echo " - ${BOLD}Installing binary to ${ANSI_RESET}${GREEN}${DESTDIR}${BINDIR}/meli${ANSI_RESET}"
  112. @case ":${PATH}:" in \
  113. *:${DESTDIR}${BINDIR}:*) echo -n "";; \
  114. *) 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}";; \
  115. esac
  116. @install -D ./${CARGO_TARGET_DIR}/release/meli $(DESTDIR)${BINDIR}/meli
  117. .PHONY: install
  118. .NOTPARALLEL: yes
  119. install: meli install-bin install-doc
  120. @(if [ -z $${NO_MAN+x} ]; then \
  121. echo "\n You're ready to go. You might want to read the \"STARTING WITH meli\" section in the manpage (\`man meli\`)" ;\
  122. fi)
  123. @echo " - Report bugs in the mailing list or git issue tracker ${UNDERLINE}https://git.meli.delivery${ANSI_RESET}"
  124. @echo " - If you have a specific feature or workflow you want to use, you can post in the mailing list or git issue tracker."
  125. .PHONY: dist
  126. dist:
  127. @git archive --format=tar.gz --prefix=meli-${VERSION}/ HEAD >meli-${VERSION}.tar.gz
  128. @echo meli-${VERSION}.tar.gz
  129. .PHONY: deb-dist
  130. deb-dist:
  131. @dpkg-buildpackage -b -rfakeroot -us -uc
  132. @echo ${BOLD}${GREEN}Generated${ANSI_RESET} ../meli_${VERSION}-1_amd64.deb