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.

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