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.
 
 
 
 
 

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