# File: Makefile for logout-manager # Location: logout-manager source package # Author: bgstack15 # Startdate: 2020-03-10 # Title: Makefile for logout-manager source package # Purpose: To use traditional Unix make utility # History: # Usage: # Reference: # https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile/26339924#26339924 # https://stackoverflow.com/questions/19105241/how-do-you-conditionally-call-a-target-based-on-a-target-variable-makefile/19107231#19107231 # https://stackoverflow.com/questions/5917576/sort-a-text-file-by-line-length-including-spaces # https://superuser.com/questions/352289/bash-scripting-test-for-empty-directory/667100#667100 # bgscripts Makefile # Improve: # Document: # Includes a nice way to dynamically generate dependencies as self-reported by all the files. # Dependencies: # exclude-raw: go-md2man # exclude-devuan: go-md2man APPNAME = logout-manager APPVERSION = 0.0.3 SRCDIR = $(CURDIR) prefix = /usr SYSCONFDIR = $(DESTDIR)/etc DEFAULTDIR = $(DESTDIR)/etc/sysconfig # for debian use '$(DESTDIR)/etc/default' BINDIR = $(DESTDIR)$(prefix)/bin SHAREDIR = $(DESTDIR)$(prefix)/share LIBEXECDIR = $(DESTDIR)$(prefix)/libexec APPDIR = $(SHAREDIR)/$(APPNAME) APPSDIR = $(SHAREDIR)/applications BASHCDIR = $(SHAREDIR)/bash-completion/completions DOCDIR = $(SHAREDIR)/doc/$(APPNAME) MANDIR = $(SHAREDIR)/man SUDOERSDIR = $(SYSCONFDIR)/sudoers.d XDGAUTODIR = $(SYSCONFDIR)/xdg/autostart awkbin :=$(shell which awk) cpbin :=$(shell which cp) echobin :=$(shell which echo) findbin :=$(shell which find) grepbin :=$(shell which grep) gzipbin :=$(shell which gzip) installbin :=$(shell which install) lnbin :=$(shell which ln) md2manbin :=$(shell which go-md2man) rmbin :=$(shell which rm) sedbin :=$(shell which sed) sortbin :=$(shell which sort) truebin :=$(shell which true) uniqbin :=$(shell which uniq) xargsbin :=$(shell which xargs) SEPARATOR ?=, all: @${echobin} "No compilation in this package." .PHONY: clean install uninstall list deplist deplist_opts install_files install_man list: @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | ${awkbin} -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | ${sortbin} | ${grepbin} -E -v -e '^[^[:alnum:]]' -e '^$@$$' deplist: @if test -z "$(DISTRO)" ; then ${echobin} "Please run \`make deplist\` with DISTRO= one of: `make deplist_opts 2>&1 1>/dev/null | ${xargsbin}`. Aborted." ; exit 1 ; fi @# deplist 2020-03-24 input must be comma separated @${grepbin} -h --exclude-dir='doc' -riIE '\&2 install: install_files install_man install_files: @${echobin} Installing files to ${DESTDIR} ${installbin} -d ${SYSCONFDIR} ${DEFAULTDIR} ${BINDIR} \ ${APPSDIR} ${APPDIR} ${DOCDIR} ${BASHCDIR} ${SUDOERSDIR} \ ${LIBEXECDIR}/${APPNAME} ${XDGAUTODIR} ${cpbin} -pr ${SRCDIR}/etc/*.* ${SYSCONFDIR} ${cpbin} -pr ${SRCDIR}/etc/sysconfig/* ${DEFAULTDIR} ${cpbin} -pr ${SRCDIR}/usr/bin/* ${BINDIR} ${cpbin} -pr ${SRCDIR}/usr/share/applications/* ${APPSDIR} ${cpbin} -pr ${SRCDIR}/usr/share/${APPNAME}/*.* ${APPDIR} ${cpbin} -pr ${SRCDIR}/usr/share/doc/${APPNAME}/* ${DOCDIR} ${installbin} -m 0644 -t ${BASHCDIR} ${SRCDIR}/usr/share/bash-completion/completions/* ${installbin} -m 0640 -t ${SUDOERSDIR} ${SRCDIR}/etc/sudoers.d/* ${installbin} -m 0755 -t ${LIBEXECDIR}/${APPNAME} ${SRCDIR}/usr/libexec/${APPNAME}/* ${installbin} -m 0644 -t ${XDGAUTODIR} ${SRCDIR}/etc/xdg/autostart/* # symlink, when alternatives is not being used ${lnbin} -s logout-manager-gtk ${BINDIR}/logout-manager || : install_man: ifeq ($(md2manbin),) @${echobin} Cannot install man pages, because go-md2man is not found. @false endif ${installbin} -d ${MANDIR}/man1 ${MANDIR}/man5 ${MANDIR}/man7 for tm in $$( ${findbin} ${SRCDIR}/usr/share/man ! -type d -name '*[0-9].md' -printf '%P\n' ) ; do ${md2manbin} < ${SRCDIR}/usr/share/man/$${tm} | ${gzipbin} > ${MANDIR}/$${tm%%.md}.gz ; done uninstall: @${echobin} SRCDIR=${SRCDIR} ${rmbin} -f $$( ${findbin} ${SRCDIR} -mindepth 1 ! -type d ! -name 'Makefile' -printf '%p\n' | ${sedbin} -r -e "s:^${SRCDIR}:${DESTDIR}:" -e '/man[0-9]\/.*[0-9]\.md$$/{s:\.md$$:.gz:}' ) ${DEFAULTDIR}/${APPNAME} ${BINDIR}/logout-manager # remove all installed directories that are now blank. rmdir ${DEFAULTDIR} 2>/dev/null ; for word in $$( ${findbin} ${SRCDIR} -mindepth 1 -type d -printf '%p\n' | ${sedbin} -r -e "s:^${SRCDIR}:${DESTDIR}:" | ${awkbin} '{ print length, $$0 }' | sort -rn | ${awkbin} '{print $$2}' ) ; do ${findbin} $${word} -mindepth 1 1>/dev/null 2>&1 | read 1>/dev/null 2>&1 || { rmdir "$${word}" 2>/dev/null || ${truebin} ; } ; done clean: -@${echobin} "target $@ not implemented yet! Gotta say unh."