aboutsummaryrefslogtreecommitdiff
path: root/src/Makefile
blob: c48eefa7e5202c4cd2bc8bdb5893b4d808ce98d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File: Makefile for freeipa-helper
# Location: freeipa-helper source package
# Author: bgstack15
# Startdate: 2020-03-11
# Title: Makefile for freeipa-helper source package
# Purpose: To use traditional Unix make utility
# History:
# Usage:
# Reference:
#    bgscripts Makefile
# Improve:
# Document:
# Dependencies:

APPNAME    = freeipa-helper
APPVERSION = 0.0.1
SRCDIR     = $(CURDIR)
prefix     = /usr
SYSCONFDIR = $(DESTDIR)/etc
BINDIR     = $(DESTDIR)$(prefix)/bin
BINDIR1    = $(DESTDIR)/bin
SBINDIR    = $(DESTDIR)$(prefix)/sbin
SHAREDIR   = $(DESTDIR)$(prefix)/share
DOCDIR     = $(SHAREDIR)/doc/$(APPNAME)
APPDIR     = $(SHAREDIR)/$(APPNAME)

awkbin     :=$(shell which awk)
cpbin      :=$(shell which cp)
echobin    :=$(shell which echo)
findbin    :=$(shell which find)
grepbin    :=$(shell which grep)
installbin :=$(shell which install)
rmbin      :=$(shell which rm)
sedbin     :=$(shell which sed)
sortbin    :=$(shell which sort)
truebin    :=$(shell which true)
lnbin      :=$(shell which ln)
xargsbin   :=$(shell which xargs)
uniqbin    :=$(shell which uniq)

all:
	${echobin} "No compilation in this package."

.PHONY: clean install uninstall list deplist deplist_opts

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
	@${grepbin} -h --exclude='Makefile' --exclude-dir='doc' -A5 -riIE dependencies $(SRCDIR) | ${awkbin} -v 'distro=$(DISTRO)' 'tolower($$0) ~ distro {$$1="";$$2="";print}' | ${awkbin} 'BEGIN{cmd="${xargsbin} -n1"} $$0 !~ /\(/{print $$0 | cmd ; close(cmd);} $$0 ~ /\(/{print;}' | ${sortbin} | ${uniqbin} | ${sedbin} -r -e 's/$$/$(SEPARATOR)/' | ${xargsbin}

deplist_opts:
	@${echobin} "el7" 1>&2
	@${echobin} "devuan" 1>&2

install: 
	@${echobin} Installing files to ${DESTDIR}
	${installbin} -d ${SBINDIR} ${DOCDIR} ${BINDIR} ${BINDIR1}
	${installbin} -m 0755 -t ${SBINDIR} ${SRCDIR}/usr/sbin/*
	test -L ${BINDIR1}/systemctl          || ${lnbin} -s ${SBINDIR}/systemctl ${BINDIR1}/systemctl
	test -L ${BINDIR}/hostnamectl         || ${lnbin} -s ${SBINDIR}/systemctl ${BINDIR}/hostnamectl
	test -L ${BINDIR}/systemd-detect-virt || ${lnbin} -s ${SBINDIR}/systemctl ${BINDIR}/systemd-detect-virt

uninstall:
	@${echobin} "#" SRCDIR=${SRCDIR}
	${rmbin} -f $$( ${findbin} ${SRCDIR} -mindepth 1 ! -type d -printf '%p\n' | ${sedbin} -r -e "s:^${SRCDIR}:${DESTDIR}:" )
	${rmbin} ${BINDIR1}/systemctl || :
	${rmbin} ${BINDIR}/hostnamectl || :
	${rmbin} ${BINDIR}/systemd-detect-virt || :

	# remove all installed directories that are now blank.
	rmdir ${BINDIR} ${BINDIR1} || :
	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."
bgstack15