# Inspired from # `info make` # MIT https://git.suckless.org/dwm # GPL-2.0-or-later https://git.joeyh.name/index.cgi/moreutils.git/tree/Makefile # For a comment inside a Makefile recipe not to echo itself on terminal, put # at very first character # For a command not to echo itself, prefix @ to the command # https://unix.stackexchange.com/a/740226/459013 # SH = $(wildcard sh/*) will print filenames with sh/ dir (more about wildcard see `info make` ) # - more make commands maybe able to substitute it to only basename, maybe see https://stackoverflow.com/a/14447924 # I use `find sh -type f -printf '%f '` which only prints basename # - note: "SH = $$(...)" seems replace ${SH} with $(...), so everytime I use ${SH}, shell command in $(...) is run once, which is not ideal # - so I use "SH = $(shell ...)" to only run it once when assign variable # alternative: `find sh -type f -execdir basename -a '{}' \+` # busybox find does not support -printf and -execdir, so here's another alternative: `find sh -type f -exec basename -a '{}' \+` # about $$: https://stackoverflow.com/q/28533059 SH = $(shell find sh -type f -printf '%f ') PACMAN_HOOKS = $(shell find pacman_hooks -type f -printf '%f ') PREFIX = /usr/local install: mkdir -p ${DESTDIR}${PREFIX}/bin # Another way would be define and use INSTALL INSTALL_PROGRAM INSTALL_DATA instead of use `cp -f` or `install` directly, see `info make` for i in ${SH}; do cp -f sh/$$i ${DESTDIR}${PREFIX}/bin; done mkdir -p ${DESTDIR}${PREFIX}/share/libalpm/hooks # /usr/local/share/libalpm/hooks default does not work, need to change pacman.conf for i in ${PACMAN_HOOKS}; do cp -f pacman_hooks/$$i ${DESTDIR}${PREFIX}/share/libalpm/hooks; done uninstall: for i in ${SH}; do rm -f ${DESTDIR}${PREFIX}/bin/$$i; done for i in ${PACMAN_HOOKS}; do rm -f ${DESTDIR}${PREFIX}/share/libalpm/hooks/$$i; done # RM is default to `rm -f`, see `info make` # for i in ${SH}; do ${RM} ${DESTDIR}${PREFIX}/bin/$$i; done .PHONY: install uninstall