Skip to content

Commit 38a82d5

Browse files
authored
Less agressive 'uninstall' target: don't remove directory unless it was created by the install process (#393)
See #389, #390 Signed-off-by: Henry Cox <[email protected]>
1 parent 1908004 commit 38a82d5

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

Diff for: Makefile

+36-25
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ EXES = \
7474
# any of their names
7575
SCRIPTS = $(shell ls scripts | grep -v -E '([\#\~]|\.orig|\.bak|\.BAK)' )
7676
LIBS = lcovutil.pm
77+
MAN_SECTIONS = 1 5
7778
# similarly, lets not talk about man pages
78-
MANPAGES = $(foreach m, $(shell cd man ; ls *.1), man1/$(m)) \
79-
$(foreach m, $(shell cd man ; ls *.5), man5/$(m))
79+
MANPAGES = $(foreach s, $(MAN_SECTIONS), $(foreach m, $(shell cd man ; ls *.$(s)), man$(s)/$(m)))
8080

8181
# Program for checking coding style
8282
CHECKSTYLE = $(CURDIR)/bin/checkstyle.sh
8383

8484
INSTALL = install
8585
FIX = $(realpath bin/fix.pl)
86-
RM = rm
86+
RM = rm -f
87+
RMDIR = rmdir
8788

8889
export V
8990
ifeq ("${V}","1")
@@ -109,8 +110,8 @@ info:
109110

110111
clean:
111112
$(call echocmd," CLEAN lcov")
112-
$(RM) -f lcov-*.tar.gz lcov-*.rpm
113-
$(RM) -rf ./bin/__pycache__
113+
$(RM) lcov-*.tar.gz lcov-*.rpm
114+
$(RM) -r ./bin/__pycache__
114115
$(MAKE) -C example -s clean
115116
$(MAKE) -C tests -s clean
116117
find . -name '*.tdy' -o -name '*.orig' | xargs rm -f
@@ -144,7 +145,7 @@ install:
144145
--fixver --fixlibdir --fixbindir \
145146
--exec $(LIB_INST_DIR)/$$l ; \
146147
done
147-
for section in 1 5 ; do \
148+
for section in $(MAN_SECTIONS) ; do \
148149
DEST=$(MAN_INST_DIR)/man$$section ; \
149150
$(INSTALL) -d -m 755 $$DEST ; \
150151
for m in man/*.$$section ; do \
@@ -173,32 +174,42 @@ install:
173174
uninstall:
174175
for b in $(EXES) ; do \
175176
$(call echocmd," UNINST $(BIN_INST_DIR)/$$b") \
176-
$(RM) -f $(BIN_INST_DIR)/$$b ; \
177+
$(RM) $(BIN_INST_DIR)/$$b ; \
177178
done
178-
rmdir --ignore-fail-on-non-empty $(BIN_INST_DIR) || true
179-
for s in $(SCRIPTS) ; do \
180-
$(call echocmd," UNINST $(SCRIPT_INST_DIR)/$$s") \
181-
$(RM) -f $(SCRIPT_INST_DIR)/$$s ; \
182-
done
183-
rmdir --ignore-fail-on-non-empty $(SCRIPT_INST_DIR)
184-
for l in $(LIBS) ; do \
185-
$(call echocmd," UNINST $(LIB_INST_DIR)/$$l") \
186-
$(RM) -f $(LIB_INST_DIR)/$$l ; \
179+
$(RMDIR) $(BIN_INST_DIR) || true
180+
# .../lib/lcov installed by us - so safe to remove
181+
$(call echocmd," UNINST $(LIB_INST_DIR)")
182+
$(RM) -r $(LIB_INST_DIR)
183+
$(call echocmd," UNINST $(shell dirname $(LIB_INST_DIR)) (if empty)")
184+
$(RMDIR) `dirname $(LIB_INST_DIR)` || true
185+
# .../share/lcov installed by us - so safe to remove
186+
$(call echocmd," UNINST $(SHARE_INST_DIR)")
187+
$(RM) -r $(SHARE_INST_DIR)
188+
$(call echocmd," UNINST $(MAN_INST_DIR) pages")
189+
for section in $(MAN_SECTIONS) ; do \
190+
DEST=$(MAN_INST_DIR)/man$$section ; \
191+
for m in man/*.$$section ; do \
192+
F=`basename $$m` ; \
193+
$(RM) $$DEST/$$F ; \
194+
done ; \
195+
$(RMDIR) $$DEST || true; \
187196
done
188-
rmdir --ignore-fail-on-non-empty $(LIB_INST_DIR) || true
189-
rmdir `dirname $(LIB_INST_DIR)` || true
190-
rm -rf `dirname $(SHARE_INST_DIR)`
197+
$(call echocmd," UNINST $(MAN_INST_DIR) (if empty)")
198+
$(RMDIR) $(MAN_INST_DIR) || true;
199+
$(call echocmd," UNINST $(shell dirname $(SHARE_INST_DIR)) (if empty)")
200+
$(RMDIR) `dirname $(SHARE_INST_DIR)`
191201
$(call echocmd," UNINST $(CFG_INST_DIR)/lcovrc")
192-
$(RM) -f $(CFG_INST_DIR)/lcovrc
193-
rmdir --ignore-fail-on-non-empty $(CFG_INST_DIR) || true
194-
rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX) || true
202+
$(RM) $(CFG_INST_DIR)/lcovrc
203+
$(RMDIR) $(CFG_INST_DIR) || true
204+
$(call echocmd," UNINST $(DESTDIR)/$(PREFIX)")
205+
$(RMDIR) $(DESTDIR)$(PREFIX) || true
195206

196207
dist: lcov-$(VERSION).tar.gz lcov-$(VERSION)-$(RELEASE).noarch.rpm \
197208
lcov-$(VERSION)-$(RELEASE).src.rpm
198209

199210
lcov-$(VERSION).tar.gz: $(FILES)
200211
$(call echocmd," DIST lcov-$(VERSION).tar.gz")
201-
$(RM) -rf $(TMP_DIR)/lcov-$(VERSION)
212+
$(RM) -r $(TMP_DIR)/lcov-$(VERSION)
202213
mkdir -p $(TMP_DIR)/lcov-$(VERSION)
203214
cp -r $(DIST_CONTENT) $(TMP_DIR)/lcov-$(VERSION)
204215
./bin/copy_dates.sh . $(TMP_DIR)/lcov-$(VERSION)
@@ -214,7 +225,7 @@ lcov-$(VERSION).tar.gz: $(FILES)
214225
tar cfz $(TMP_DIR)/lcov-$(VERSION).tar.gz lcov-$(VERSION) \
215226
--owner root --group root
216227
mv $(TMP_DIR)/lcov-$(VERSION).tar.gz .
217-
rm -rf $(TMP_DIR)
228+
$(RM) -r $(TMP_DIR)
218229

219230
lcov-$(VERSION)-$(RELEASE).noarch.rpm: rpms
220231
lcov-$(VERSION)-$(RELEASE).src.rpm: rpms
@@ -239,7 +250,7 @@ rpms: lcov-$(VERSION).tar.gz
239250
mv $(TMP_DIR)/RPMS/noarch/lcov-$(VERSION)-$(RELEASE).noarch.rpm .
240251
$(call echocmd," DIST lcov-$(VERSION)-$(RELEASE).src.rpm")
241252
mv $(TMP_DIR)/SRPMS/lcov-$(VERSION)-$(RELEASE).src.rpm .
242-
rm -rf $(TMP_DIR)
253+
$(RM) -r $(TMP_DIR)
243254

244255
ifeq ($(COVERAGE), 1)
245256
# write to .../tests/cover_db

0 commit comments

Comments
 (0)