Skip to content

Commit c2f1bbe

Browse files
committed
Eliminate rm -rf from Makefile. Use safer file-by-file rm and rmdir.
1 parent e4e2f5e commit c2f1bbe

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

Makefile

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
SRCS := $(wildcard *.cc)
66
INCS := $(wildcard *.h)
77
OBJS := $(addprefix $O,$(SRCS:.cc=.o))
8+
DEPS := ${OBJS:.o=.d}
89

910
################ Compilation ###########################################
1011

11-
.PHONY: all clean html check dist distclean maintainer-clean
12+
.PHONY: all clean html check distclean maintainer-clean
1213

1314
all: Config.mk config.h ${NAME}/config.h
1415
ALLTGTS := Config.mk config.h ${NAME}/config.h
@@ -75,8 +76,11 @@ ${RINCI}: ${NAME}.h
7576
@${INSTALLDATA} $< $@
7677
uninstall: uninstall-incs
7778
uninstall-incs:
78-
@echo "Removing ${LIDIR}/ and ${LIDIR}.h ..."
79-
@(cd ${INCDIR}; rm -f ${INCSI} ${NAME}.h; [ ! -d ${NAME} ] || rm -rf ${NAME})
79+
@if [ -d ${LIDIR} -o -f ${LIDIR}.h ]; then\
80+
echo "Removing ${LIDIR}/ and ${LIDIR}.h ...";\
81+
rm -f ${INCSI} ${RINCI};\
82+
rmdir ${LIDIR};\
83+
fi
8084
endif
8185

8286
####### Install libraries (shared and/or static)
@@ -108,30 +112,14 @@ endif
108112
################ Maintenance ###########################################
109113

110114
clean:
111-
@[ ! -d ./$O ] || rm -rf ./$O
115+
@if [ -d $O ]; then\
116+
rm -f ${SLIBT} ${SLINKS} ${OBJS} ${DEPS};\
117+
rmdir $O;\
118+
fi
112119

113120
html: ${SRCS} ${INCS} ${NAME}doc.in
114121
@${DOXYGEN} ${NAME}doc.in
115122

116-
ifdef MAJOR
117-
DISTVER := ${MAJOR}.${MINOR}
118-
DISTNAM := ${NAME}-${DISTVER}
119-
DISTLSM := ${DISTNAM}.lsm
120-
DISTTAR := ${DISTNAM}.tar.bz2
121-
122-
dist:
123-
@echo "Generating ${DISTTAR} and ${DISTLSM} ..."
124-
@mkdir .${DISTNAM}
125-
@rm -f ${DISTTAR}
126-
@cp -r * .${DISTNAM} && mv .${DISTNAM} ${DISTNAM}
127-
@+${MAKE} -sC ${DISTNAM} maintainer-clean
128-
@tar jcf ${DISTTAR} ${DISTNAM} && rm -rf ${DISTNAM}
129-
@echo "s/@version@/${DISTVER}/" > ${DISTLSM}.sed
130-
@echo "s/@date@/`date +%F`/" >> ${DISTLSM}.sed
131-
@echo -n "s/@disttar@/`du -h --apparent-size ${DISTTAR}`/" >> ${DISTLSM}.sed;
132-
@sed -f ${DISTLSM}.sed docs/${NAME}.lsm > ${DISTLSM} && rm -f ${DISTLSM}.sed
133-
endif
134-
135123
distclean: clean
136124
@rm -f Config.mk config.h config.status ${NAME}
137125

bvt/Module.mk

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ endif
1414
ifdef NOLIBSTDCPP
1515
bvt/LIBS += ${STAL_LIBS} -lm
1616
endif
17+
bvt/DEPS := ${bvt/OBJS:.o=.d} $Obvt/stdtest.d $Obvt/bench.d
1718

1819
################ Compilation ###########################################
1920

@@ -44,12 +45,13 @@ bvt/bench: $Obvt/bench.o $Obvt/stdtest.o ${ALLTGTS}
4445

4546
clean: bvt/clean
4647
bvt/clean:
47-
@rm -f ${bvt/BVTS} ${bvt/OBJS} $(bvt/OBJS:.o=.d) bvt/bench $Obvt/bench.o $Obvt/stdtest.o $Obvt/bench.d $Obvt/stdtest.d
48-
@rmdir $O/bvt &> /dev/null || true
49-
48+
@if [ -d $Obvt ]; then\
49+
rm -f ${bvt/BVTS} ${bvt/OBJS} ${bvt/DEPS} bvt/bench $Obvt/bench.o $Obvt/stdtest.o;\
50+
rmdir $Obvt;\
51+
fi
5052
check: bvt/run
5153
bvt/check: check
5254

5355
${bvt/OBJS} $Obvt/stdtest.o $Obvt/bench.o: Makefile bvt/Module.mk Config.mk ${NAME}/config.h
5456

55-
-include ${bvt/OBJS:.o=.d} $Obvt/stdtest.d
57+
-include ${bvt/DEPS}

0 commit comments

Comments
 (0)