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.
 
 
 
 

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