Makefile trick: deplist
I whipped together a snippet for a Makefile I plan on using more in the future. This target, deplist, searches the entire source tree for my "# Dependencies:" tags, by distribution name, and lists them on standard out.
deplist:
@if test -z "$(DISTRO)" ; then echo "Please run \`make deplist\` with DISTRO= one of: `make deplist_opts 2>&1 1>/dev/null | xargs`. Aborted." ; exit 1 ; fi
@grep -h --exclude='Makefile' --exclude-dir='doc' -A5 -riIE dependencies $(SRCDIR) | \
awk -v 'distro=$(DISTRO)' 'tolower($$0) ~ distro {$$1="";$$2="";print}' | \
awk 'BEGIN{cmd="xargs -n1"} $$0 !~ /\(/{print $$0 | cmd ; close(cmd);} $$0 ~ /\(/{print;}' | \
sort | uniq | sed -r -e 's/$$/$(SEPARATOR)/' | xargs
deplist_opts:
@echo "el7" 1>&2
@echo "devuan" 1>&2
And, of course, probably place these in your .PHONY list because these are not real files to be built.
.PHONY: clean install uninstall list deplist deplist_opts
Every file in the project that has an external dependency should have some comments in this format:
# Dependencies:
# devuan: python3-tk python3-pil
# el7: python36 python36-pil
To use this target in a debuild recipe, so that it will dynamically build the dpkg dependency list, use:
override_dh_gencontrol:
printf "misc:Depends=" > debian/${APPNAME}.substvars
make -C src deplist DISTRO=devuan SEPARATOR=',' | grep -vE 'make\[[0-9]' >> debian/${APPNAME}.substvars
dh_gencontrol
References
Inspiration from rpm's Dynamic Build Dependency feature. Original research.
Comments