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.
 
 
 
 
 
 

154 lines
6.7 KiB

  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. EXPANDED_PREFIX := `cd ${PREFIX} && pwd -P`
  22. BINDIR ?= ${EXPANDED_PREFIX}/bin
  23. MANDIR ?= ${EXPANDED_PREFIX}/share/man
  24. CARGO_TARGET_DIR ?= target
  25. MIN_RUSTC ?= 1.39.0
  26. CARGO_BIN ?= cargo
  27. # Installation parameters
  28. MANPAGES ?= meli.1 meli.conf.5 meli-themes.5
  29. FEATURES ?= --features "${MELI_FEATURES}"
  30. 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 -n $${ACCUM} | sed 's/^://'`
  31. VERSION ?= `sed -n "s/^version\s*=\s*\"\(.*\)\"/\1/p" Cargo.toml`
  32. # Output parameters
  33. BOLD ?= `[ -z $${TERM} ] && echo "" || tput bold`
  34. UNDERLINE ?= `[ -z $${TERM} ] && echo "" || tput smul`
  35. ANSI_RESET ?= `[ -z $${TERM} ] && echo "" || tput sgr0`
  36. CARGO_COLOR ?= `[ -z $${NO_COLOR+x} ] && echo "" || echo "--color=never "`
  37. RED ?= `[ -z $${NO_COLOR+x} ] && ([ -z $${TERM} ] && echo "" || tput setaf 1) || echo ""`
  38. GREEN ?= `[ -z $${NO_COLOR+x} ] && ([ -z $${TERM} ] && echo "" || tput setaf 2) || echo ""`
  39. .POSIX:
  40. .SUFFIXES:
  41. help:
  42. @echo "For a quick start, build and install locally:\n ${BOLD}${GREEN}PREFIX=~/.local make install${ANSI_RESET}\n"
  43. @echo "Available subcommands:"
  44. @echo " - ${BOLD}meli${ANSI_RESET} (builds meli with optimizations in \$$CARGO_TARGET_DIR)"
  45. @echo " - ${BOLD}install${ANSI_RESET} (installs binary in \$$BINDIR and documentation to \$$MANDIR)"
  46. @echo " - ${BOLD}uninstall${ANSI_RESET}"
  47. @echo "Secondary subcommands:"
  48. @echo " - ${BOLD}clean${ANSI_RESET} (cleans build artifacts)"
  49. @echo " - ${BOLD}check-deps${ANSI_RESET} (checks dependencies)"
  50. @echo " - ${BOLD}install-bin${ANSI_RESET} (installs binary to \$$BINDIR)"
  51. @echo " - ${BOLD}install-doc${ANSI_RESET} (installs manpages to \$$MANDIR)"
  52. @echo " - ${BOLD}help${ANSI_RESET} (prints this information)"
  53. @echo " - ${BOLD}dist${ANSI_RESET} (creates release tarball named meli-"${VERSION}".tar.gz in this directory)"
  54. @echo " - ${BOLD}deb-dist${ANSI_RESET} (builds debian package in the parent directory)"
  55. @echo " - ${BOLD}distclean${ANSI_RESET} (cleans distribution build artifacts)"
  56. @echo "\nENVIRONMENT variables of interest:"
  57. @echo "* PREFIX = ${UNDERLINE}${EXPANDED_PREFIX}${ANSI_RESET}"
  58. @echo -n "* MELI_FEATURES = ${UNDERLINE}"
  59. @[ -z $${MELI_FEATURES+x} ] && echo -n "unset" || echo -n ${MELI_FEATURES}
  60. @echo ${ANSI_RESET}
  61. @echo "* BINDIR = ${UNDERLINE}${BINDIR}${ANSI_RESET}"
  62. @echo "* MANDIR = ${UNDERLINE}${MANDIR}${ANSI_RESET}"
  63. @echo -n "* MANPATH = ${UNDERLINE}"
  64. @[ $${MANPATH+x} ] && echo -n $${MANPATH} || echo -n "unset"
  65. @echo ${ANSI_RESET}
  66. @echo "* (cleaned) output of manpath(1) = ${UNDERLINE}${MANPATHS}${ANSI_RESET}"
  67. @echo -n "* NO_MAN ${UNDERLINE}"
  68. @[ $${NO_MAN+x} ] && echo -n "set" || echo -n "unset"
  69. @echo ${ANSI_RESET}
  70. @echo -n "* NO_COLOR ${UNDERLINE}"
  71. @[ $${NO_COLOR+x} ] && echo -n "set" || echo -n "unset"
  72. @echo ${ANSI_RESET}
  73. @#@echo "* CARGO_COLOR = ${CARGO_COLOR}"
  74. meli: check-deps
  75. @${CARGO_BIN} build ${CARGO_COLOR}--target-dir="${CARGO_TARGET_DIR}" ${FEATURES} --release
  76. .PHONY: check-deps
  77. check-deps:
  78. @(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`" \
  79. "\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)
  80. .PHONY: clean
  81. clean:
  82. -rm -rf ./${CARGO_TARGET_DIR}/
  83. .PHONY: distclean
  84. distclean: clean
  85. @rm -f meli-${VERSION}.tar.gz
  86. .PHONY: uninstall
  87. uninstall:
  88. rm -f $(DESTDIR)${BINDIR}/meli
  89. -rm $(DESTDIR)${MANDIR}/man1/meli.1.gz
  90. -rm $(DESTDIR)${MANDIR}/man5/meli.conf.5.gz
  91. -rm $(DESTDIR)${MANDIR}/man5/meli-themes.5.gz
  92. .PHONY: install-doc
  93. install-doc:
  94. @(if [ -z $${NO_MAN+x} ]; then \
  95. mkdir -p $(DESTDIR)${MANDIR}/man1 ; \
  96. mkdir -p $(DESTDIR)${MANDIR}/man5 ; \
  97. echo " - ${BOLD}Installing manpages to ${ANSI_RESET}${DESTDIR}${MANDIR}:" ; \
  98. for MANPAGE in ${MANPAGES}; do \
  99. SECTION=`echo $${MANPAGE} | rev | cut -d "." -f 1`; \
  100. MANPAGEPATH=${DESTDIR}${MANDIR}/man$${SECTION}/$${MANPAGE}.gz; \
  101. echo " * installing $${MANPAGE} → ${GREEN}$${MANPAGEPATH}${ANSI_RESET}"; \
  102. gzip -n < $${MANPAGE} > $${MANPAGEPATH} \
  103. ; done ; \
  104. (case ":${MANPATHS}:" in \
  105. *:${DESTDIR}${MANDIR}:*) echo -n "";; \
  106. *) 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}" ;; \
  107. esac) ; \
  108. else echo "NO_MAN is defined, so no documentation is going to be installed." ; fi)
  109. .PHONY: install-bin
  110. install-bin: meli
  111. @mkdir -p $(DESTDIR)${BINDIR}
  112. @echo " - ${BOLD}Installing binary to ${ANSI_RESET}${GREEN}${DESTDIR}${BINDIR}/meli${ANSI_RESET}"
  113. @case ":${PATH}:" in \
  114. *:${DESTDIR}${BINDIR}:*) echo -n "";; \
  115. *) 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}";; \
  116. esac
  117. @install -D ./${CARGO_TARGET_DIR}/release/meli $(DESTDIR)${BINDIR}/meli
  118. .PHONY: install
  119. .NOTPARALLEL: yes
  120. install: meli install-bin install-doc
  121. @(if [ -z $${NO_MAN+x} ]; then \
  122. echo "\n You're ready to go. You might want to read the \"STARTING WITH meli\" section in the manpage (\`man meli\`)" ;\
  123. fi)
  124. @echo " - Report bugs in the mailing list or git issue tracker ${UNDERLINE}https://git.meli.delivery${ANSI_RESET}"
  125. @echo " - If you have a specific feature or workflow you want to use, you can post in the mailing list or git issue tracker."
  126. .PHONY: dist
  127. dist:
  128. @git archive --format=tar.gz --prefix=meli-${VERSION}/ HEAD >meli-${VERSION}.tar.gz
  129. @echo meli-${VERSION}.tar.gz
  130. .PHONY: deb-dist
  131. deb-dist:
  132. @dpkg-buildpackage -b -rfakeroot -us -uc
  133. @echo ${BOLD}${GREEN}Generated${ANSI_RESET} ../meli_${VERSION}-1_amd64.deb