From a2c914b375abbc5476acadbb3375049c2a48b070 Mon Sep 17 00:00:00 2001
From: Ismael Luceno <ismael@iodev.co.uk>
Date: Wed, 15 Sep 2021 00:03:54 +0200
Subject: [PATCH 4/4] Makefile: Cleanup install target

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 Makefile | 71 ++++++++++++++++++++++----------------------------------
 1 file changed, 28 insertions(+), 43 deletions(-)

diff --git a/Makefile b/Makefile
index 62e81ef74788..d2dac721db69 100644
--- a/Makefile
+++ b/Makefile
@@ -55,8 +55,8 @@ distr:
 		tar czvf /tmp/atop.tar.gz *
 
 
-install:
-		@echo Choose either \'make systemdinstall\' or \'make sysvinstall\'
+.PHONY: all install genericinstall
+install: genericinstall
 
 systemdinstall:	genericinstall
 		if [ ! -d $(DESTDIR)$(SYSDPATH) ]; 			\
@@ -137,49 +137,32 @@ sysvinstall:	genericinstall
 		fi
 
 genericinstall:	atop atopacctd atopconvert atopcat
-		if [ ! -d $(DESTDIR)$(LOGPATH) ]; 		\
-		then	mkdir -p $(DESTDIR)$(LOGPATH); fi
-		if [ ! -d $(DESTDIR)$(DEFPATH) ]; 		\
-		then	mkdir -p $(DESTDIR)$(DEFPATH); fi
-		if [ ! -d $(DESTDIR)$(BINPATH) ]; 		\
-		then	mkdir -p $(DESTDIR)$(BINPATH); fi
-		if [ ! -d $(DESTDIR)$(SBINPATH) ]; 		\
-		then mkdir -p $(DESTDIR)$(SBINPATH); fi
-		if [ ! -d $(DESTDIR)$(MAN1PATH) ]; 		\
-		then	mkdir -p $(DESTDIR)$(MAN1PATH);	fi
-		if [ ! -d $(DESTDIR)$(MAN5PATH) ]; 		\
-		then	mkdir -p $(DESTDIR)$(MAN5PATH);	fi
-		if [ ! -d $(DESTDIR)$(MAN8PATH) ]; 		\
-		then	mkdir -p $(DESTDIR)$(MAN8PATH);	fi
-		#
+		install -d $(DESTDIR)$(LOGPATH) \
+			$(DESTDIR)$(DEFPATH) \
+			$(DESTDIR)$(BINPATH) \
+			$(DESTDIR)$(SBINPATH) \
+			$(DESTDIR)$(MAN1PATH) \
+			$(DESTDIR)$(MAN5PATH) \
+			$(DESTDIR)$(MAN8PATH)
 		touch       		$(DESTDIR)$(DEFPATH)/atop
 		chmod 644      		$(DESTDIR)$(DEFPATH)/atop
-		#
-		cp atop   		$(DESTDIR)$(BINPATH)/atop
-		chown root		$(DESTDIR)$(BINPATH)/atop
-		chmod 04711 		$(DESTDIR)$(BINPATH)/atop
-		ln -sf atop             $(DESTDIR)$(BINPATH)/atopsar
-		cp atopacctd  		$(DESTDIR)$(SBINPATH)/atopacctd
-		chown root		$(DESTDIR)$(SBINPATH)/atopacctd
-		chmod 0700 		$(DESTDIR)$(SBINPATH)/atopacctd
-		cp atopgpud  		$(DESTDIR)$(SBINPATH)/atopgpud
-		chown root		$(DESTDIR)$(SBINPATH)/atopgpud
-		chmod 0700 		$(DESTDIR)$(SBINPATH)/atopgpud
-		cp atop   		$(DESTDIR)$(BINPATH)/atop-$(VERS)
-		ln -sf atop-$(VERS)     $(DESTDIR)$(BINPATH)/atopsar-$(VERS)
-		cp atopconvert 		$(DESTDIR)$(BINPATH)/atopconvert
-		chown root		$(DESTDIR)$(BINPATH)/atopconvert
-		chmod 0711 		$(DESTDIR)$(BINPATH)/atopconvert
-		cp atopcat 		$(DESTDIR)$(BINPATH)/atopcat
-		chown root		$(DESTDIR)$(BINPATH)/atopcat
-		chmod 0711 		$(DESTDIR)$(BINPATH)/atopcat
-		cp man/atop.1    	$(DESTDIR)$(MAN1PATH)
-		cp man/atopsar.1 	$(DESTDIR)$(MAN1PATH)
-		cp man/atopconvert.1 	$(DESTDIR)$(MAN1PATH)
-		cp man/atopcat.1 	$(DESTDIR)$(MAN1PATH)
-		cp man/atoprc.5  	$(DESTDIR)$(MAN5PATH)
-		cp man/atopacctd.8  	$(DESTDIR)$(MAN8PATH)
-		cp man/atopgpud.8  	$(DESTDIR)$(MAN8PATH)
+		install -m500 atopacctd atopgpud $(DESTDIR)$(SBINPATH)
+		install -m4511 atop $(DESTDIR)$(BINPATH)/
+		install -m511 atop $(DESTDIR)$(BINPATH)/atopsar
+		install -m511 atopconvert atopcat $(DESTDIR)$(BINPATH)
+		install -m444 \
+			man/atop.1 \
+			man/atopsar.1 \
+			man/atopconvert.1 \
+			man/atopcat.1 \
+			$(DESTDIR)$(MAN1PATH)
+		install -m444 \
+			man/atoprc.5 \
+			$(DESTDIR)$(MAN5PATH)
+		install -m444 \
+			man/atopacctd.8 \
+			man/atopgpud.8 \
+			$(DESTDIR)$(MAN8PATH)
 
 ##########################################################################
 
-- 
2.33.0

