From ddf8e99a737999645092800a263439b893313a82 Mon Sep 17 00:00:00 2001 From: Henry Cox Date: Mon, 3 Mar 2025 17:19:11 -0500 Subject: [PATCH] Less agressive 'uninstall' target: don't remove directory unless it was created by 'install' process. See #389, #390 Signed-off-by: Henry Cox --- Makefile | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 687dc93..eabf2c8 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,7 @@ EXES = \ # any of their names SCRIPTS = $(shell ls scripts | grep -v -E '([\#\~]|\.orig|\.bak|\.BAK)' ) LIBS = lcovutil.pm +MAN_SECTIONS= 1 5 # similarly, lets not talk about man pages MANPAGES = $(foreach m, $(shell cd man ; ls *.1), man1/$(m)) \ $(foreach m, $(shell cd man ; ls *.5), man5/$(m)) @@ -83,7 +84,7 @@ CHECKSTYLE = $(CURDIR)/bin/checkstyle.sh INSTALL = install FIX = $(realpath bin/fix.pl) -RM = rm +RM = rm -f export V ifeq ("${V}","1") @@ -109,8 +110,8 @@ info: clean: $(call echocmd," CLEAN lcov") - $(RM) -f lcov-*.tar.gz lcov-*.rpm - $(RM) -rf ./bin/__pycache__ + $(RM) lcov-*.tar.gz lcov-*.rpm + $(RM) -r ./bin/__pycache__ $(MAKE) -C example -s clean $(MAKE) -C tests -s clean find . -name '*.tdy' -o -name '*.orig' | xargs rm -f @@ -144,7 +145,7 @@ install: --fixver --fixlibdir --fixbindir \ --exec $(LIB_INST_DIR)/$$l ; \ done - for section in 1 5 ; do \ + for section in $(MAN_SECTIONS) ; do \ DEST=$(MAN_INST_DIR)/man$$section ; \ $(INSTALL) -d -m 755 $$DEST ; \ for m in man/*.$$section ; do \ @@ -173,24 +174,34 @@ install: uninstall: for b in $(EXES) ; do \ $(call echocmd," UNINST $(BIN_INST_DIR)/$$b") \ - $(RM) -f $(BIN_INST_DIR)/$$b ; \ + $(RM) $(BIN_INST_DIR)/$$b ; \ done rmdir --ignore-fail-on-non-empty $(BIN_INST_DIR) || true - for s in $(SCRIPTS) ; do \ - $(call echocmd," UNINST $(SCRIPT_INST_DIR)/$$s") \ - $(RM) -f $(SCRIPT_INST_DIR)/$$s ; \ - done - rmdir --ignore-fail-on-non-empty $(SCRIPT_INST_DIR) - for l in $(LIBS) ; do \ - $(call echocmd," UNINST $(LIB_INST_DIR)/$$l") \ - $(RM) -f $(LIB_INST_DIR)/$$l ; \ + # .../lib/lcov installed by us - so safe to remove + $(call echocmd," UNINST $(LIB_INST_DIR)") + $(RM) -r $(LIB_INST_DIR) + $(call echocmd," UNINST $(shell dirname $(LIB_INST_DIR)) (if empty)") + rmdir --ignore-fail-on-non-empty `dirname $(LIB_INST_DIR)` || true + # .../share/lcov installed by us - so safe to remove + $(call echocmd," UNINST $(SHARE_INST_DIR)") + $(RM) -r $(SHARE_INST_DIR) + $(call echocmd," UNINST $(MAN_INST_DIR) pages") + for section in $(MAN_SECTIONS) ; do \ + DEST=$(MAN_INST_DIR)/man$$section ; \ + for m in man/*.$$section ; do \ + F=`basename $$m` ; \ + $(RM) $$DEST/$$F ; \ + done ; \ + rmdir --ignore-fail-on-non-empty $$DEST || true; \ done - rmdir --ignore-fail-on-non-empty $(LIB_INST_DIR) || true - rmdir `dirname $(LIB_INST_DIR)` || true - rm -rf `dirname $(SHARE_INST_DIR)` + $(call echocmd," UNINST $(MAN_INST_DIR) (if empty)") + rmdir --ignore-fail-on-non-empty $(MAN_INST_DIR) || true; + $(call echocmd," UNINST $(shell dirname $(SHARE_INST_DIR)) (if empty)") + rmdir --ignore-fail-on-non-empty `dirname $(SHARE_INST_DIR)` $(call echocmd," UNINST $(CFG_INST_DIR)/lcovrc") - $(RM) -f $(CFG_INST_DIR)/lcovrc + $(RM) $(CFG_INST_DIR)/lcovrc rmdir --ignore-fail-on-non-empty $(CFG_INST_DIR) || true + $(call echocmd," UNINST $(DESTDIR)/$(PREFIX)") rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX) || true dist: lcov-$(VERSION).tar.gz lcov-$(VERSION)-$(RELEASE).noarch.rpm \ @@ -198,7 +209,7 @@ dist: lcov-$(VERSION).tar.gz lcov-$(VERSION)-$(RELEASE).noarch.rpm \ lcov-$(VERSION).tar.gz: $(FILES) $(call echocmd," DIST lcov-$(VERSION).tar.gz") - $(RM) -rf $(TMP_DIR)/lcov-$(VERSION) + $(RM) -r $(TMP_DIR)/lcov-$(VERSION) mkdir -p $(TMP_DIR)/lcov-$(VERSION) cp -r $(DIST_CONTENT) $(TMP_DIR)/lcov-$(VERSION) ./bin/copy_dates.sh . $(TMP_DIR)/lcov-$(VERSION) @@ -214,7 +225,7 @@ lcov-$(VERSION).tar.gz: $(FILES) tar cfz $(TMP_DIR)/lcov-$(VERSION).tar.gz lcov-$(VERSION) \ --owner root --group root mv $(TMP_DIR)/lcov-$(VERSION).tar.gz . - rm -rf $(TMP_DIR) + $(RM) -r $(TMP_DIR) lcov-$(VERSION)-$(RELEASE).noarch.rpm: rpms lcov-$(VERSION)-$(RELEASE).src.rpm: rpms @@ -239,7 +250,7 @@ rpms: lcov-$(VERSION).tar.gz mv $(TMP_DIR)/RPMS/noarch/lcov-$(VERSION)-$(RELEASE).noarch.rpm . $(call echocmd," DIST lcov-$(VERSION)-$(RELEASE).src.rpm") mv $(TMP_DIR)/SRPMS/lcov-$(VERSION)-$(RELEASE).src.rpm . - rm -rf $(TMP_DIR) + $(RM) -r $(TMP_DIR) ifeq ($(COVERAGE), 1) # write to .../tests/cover_db