From 27376bb81de1577ab87be75a1b943f300a167b8a Mon Sep 17 00:00:00 2001 From: Paul Jewell Date: Fri, 11 Sep 2015 22:48:32 +0100 Subject: [PATCH] Added Linux uninstall target Simplified earlier changes added -r option to RM definition fixed white space --- Makefile | 2 +- package/Linux.mk | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 40b2fffe9..6982ac107 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,7 @@ $(foreach var, $(SANITIZE_DEPRECATED_VARS), $(eval $(call SANITIZE_VAR,$(var),de # Make sure this isn't being run as root unless installing (no whoami on Windows, but that is ok here) ifeq ($(shell whoami 2>/dev/null),root) - ifeq ($(filter install,$(MAKECMDGOALS)),) + ifeq ($(filter install uninstall,$(MAKECMDGOALS)),) ifndef FAKEROOTKEY $(error You should not be running this as root) endif diff --git a/package/Linux.mk b/package/Linux.mk index d6edfded5..62d8d3190 100644 --- a/package/Linux.mk +++ b/package/Linux.mk @@ -34,9 +34,10 @@ udevrulesdir := /etc/udev/rules.d INSTALL = cp -a --no-preserve=ownership LN = ln LN_S = ln -s - +RM_RF = rm -rf +RM_F = rm -f .PHONY: install -install: +install: uninstall @$(ECHO) " INSTALLING GCS TO $(DESTDIR)/)" $(V1) $(MKDIR) -p $(DESTDIR)$(bindir) $(V1) $(MKDIR) -p $(DESTDIR)$(libdir) @@ -57,3 +58,25 @@ ifneq ($(enable-udev-rules), no) $(V1) $(MKDIR) -p $(DESTDIR)$(udevrulesdir) $(V1) $(INSTALL) -T $(ROOT_DIR)/package/linux/45-uav.rules $(DESTDIR)$(udevrulesdir)/45-$(ORG_SMALL_NAME).rules endif + +# uninstall target to ensure no side effects from previous installations +.PHONY: uninstall +uninstall: + @$(ECHO) " UNINSTALLING GCS FROM $(DESTDIR)/)" +# Protect against inadvertant 'rm -rf /' +ifeq ($(GCS_SMALL_NAME),) + @$(ECHO) "Error in build configuration - GCS_SMALL_NAME not defined" + exit 1 +endif +ifeq ($(ORG_SMALL_NAME),) + @$(ECHO) "Error in build configuration - ORG_SMALL_NAME not defined" + exit 1 +endif +# ...safe to Proceed + $(V1) $(RM_RF) $(DESTDIR)$(bindir)/$(GCS_SMALL_NAME) # Remove application + $(V1) $(RM_RF) $(DESTDIR)$(libdir)/$(GCS_SMALL_NAME) # Remove libraries + $(V1) $(RM_RF) $(DESTDOR)$(datadir)/$(GCS_SMALL_NAME) # Remove other data + $(V1) $(RM_F) $(DESTDIR)$(datadir)/applications/$(ORG_SMALL_NAME).desktop + $(V1) $(RM_F) $(DESTDIR)$(datadir)/pixmaps/$(ORG_SMALL_NAME).png + $(V1) $(RM_F) $(DESTDIR)$(udevrulesdir)/45-$(ORG_SMALL_NAME).rules +