From ad038d1a467218f16d70bcaf68c04a9b258f37d8 Mon Sep 17 00:00:00 2001
From: DJ Lucas <dj@lucasit.com>
Date: Sat, 30 Sep 2017 02:40:10 -0500
Subject: [PATCH] Add uninstall and clean target, install systemd units

---
 CHANGELOG |  3 ++-
 Makefile  | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG b/CHANGELOG
index 9ce5b32..4426738 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,5 @@
-0.5      - Add example systemd timer and service units
+0.5      - Install systemd timer and service units
+         - Add uninstall and clean targets
 0.4      - Add email and code signing flat file certificate stores
 0.3      - Generate single file stores (Java and GNUTLS) using main OpenSSL
            store as source to avoid duplicates
diff --git a/Makefile b/Makefile
index 53b7ea6..34e726c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,30 @@
 MANDIR=/usr/share/man
 SBINDIR=/usr/sbin
+INIT=$(shell ps -p 1 --no-header | cut -d " " -f 15)
+
 
 all:
 	chmod 755 make-ca help2man
 	./help2man -s 8 -N ./make-ca -i include.h2m -o make-ca.8
 
+clean:
+	rm -f make-ca.8
+	chmod 0644 help2man
+	chmod 0644 make-ca
+
 install: all
 	/usr/bin/install -vdm755 $(DESTDIR)$(SBINDIR)
 	/usr/bin/install -vdm755 $(DESTDIR)$(MANDIR)/man8
 	install -vm755 make-ca $(DESTDIR)$(SBINDIR)
 	install -vm644 make-ca.8 $(DESTDIR)$(MANDIR)/man8
+	if test "$(INIT)" == "systemd"; then \
+	    install -vdm755 $(DESTDIR)/etc/systemd/system; \
+	    install -vm644 systemd/* $(DESTDIR)/etc/systemd/system; \
+	fi
+
+uninstall:
+	rm -f $(DESTDIR)$(SBINDIR)/make-ca
+	rm -f $(DESTDIR)$(MANDIR)/man8/make-ca.8
 
 .PHONY: all install