Skip to content

Commit

Permalink
Make: add uninstall target for Makefiles
Browse files Browse the repository at this point in the history
make uninstall deletes all files that would have been installed
by make install and removes the directories make install would
have created. Directories that are not empty after uninstalling
the files will be preserved.

Change-Id: I53587dfd765e112e99fb6ab078a33a6174828987
  • Loading branch information
obgm committed Jun 25, 2020
1 parent ce6de44 commit 5c83d4b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
17 changes: 15 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Makefile for tinydtls
#
#
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Olaf Bergmann (TZI) and others.
# Copyright (c) 2011-2020 Olaf Bergmann (TZI) and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
Expand Down Expand Up @@ -36,6 +36,7 @@ includedir = @includedir@/@PACKAGE_NAME@
package = @PACKAGE_TARNAME@-@PACKAGE_VERSION@

install := cp
RMDIR?=rmdir

# files and flags
SOURCES:= dtls.c crypto.c ccm.c hmac.c netq.c peer.c dtls_time.c session.c dtls_debug.c dtls_prng.c
Expand All @@ -60,7 +61,7 @@ LDFLAGS:=@LDFLAGS@ @LIBS@
ARFLAGS:=cru
doc:=doc

.PHONY: all dirs clean install dist distclean .gitignore doc TAGS
.PHONY: all dirs clean install dist distclean .gitignore doc TAGS uninstall

ifneq ("@WITH_CONTIKI@", "1")
.SUFFIXES:
Expand Down Expand Up @@ -122,6 +123,18 @@ install: $(LIBS) $(HEADERS) $(SUBDIRS)
$(MAKE) -C $$dir install="$(install)" includedir=$(includedir) install; \
done

uninstall:
for file in $(LIBS); do \
if test -f $(DESTDIR)$(libdir)/$$file ; then $(RM) $(DESTDIR)$(libdir)/$$file ; fi ;\
done
for file in $(HEADERS); do \
if test -f $(DESTDIR)$(includedir)/$$file ; then $(RM) $(DESTDIR)$(includedir)/$$file ; fi ;\
done
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir install="$(install)" includedir=$(includedir) RMDIR=$(RMDIR) uninstall; \
done
if test -d $(DESTDIR)$(includedir) ; then $(RMDIR) $(DESTDIR)$(includedir) ; fi

TAGS:
$(ETAGS) -o $@.new $(SOURCES)
$(ETAGS) -a -o $@.new $(HEADERS)
Expand Down
10 changes: 8 additions & 2 deletions aes/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for tinydtls
#
# Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
# Copyright (c) 2011-2020 Olaf Bergmann (TZI) and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
Expand Down Expand Up @@ -36,7 +36,7 @@ LDLIBS=@LIBS@
FILES:=Makefile.in $(SOURCES) $(HEADERS)
DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@

.PHONY: all dirs clean install dist distclean .gitignore doc
.PHONY: all dirs clean install dist distclean .gitignore doc uninstall

.SUFFIXES:
.SUFFIXES: .c .o
Expand Down Expand Up @@ -65,5 +65,11 @@ install: $(HEADERS)
test -d $(DESTDIR)$(includedir)/aes || mkdir -p $(DESTDIR)$(includedir)/aes
$(install) $(HEADERS) $(DESTDIR)$(includedir)/aes

uninstall:
for file in $(HEADERS); do \
if test -f $(DESTDIR)$(includedir)/aes/$$file ; then $(RM) $(DESTDIR)$(includedir)/aes/$$file ; fi ;\
done
if test -d $(DESTDIR)$(includedir)/aes ; then $(RMDIR) $(DESTDIR)$(includedir)/aes ; fi

.gitignore:
echo "core\n*~\n*.[oa]\n*.gz\n*.cap\n$(PROGRAM)\n$(DISTDIR)\n.gitignore" >$@
7 changes: 7 additions & 0 deletions doc/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ dist: doc
install: $(doc) html
test -d $(DESTDIR)$(htmldir) || mkdir -p $(DESTDIR)$(htmldir)
cp -r html/* $(DESTDIR)$(htmldir)

uninstall:
for file in $(DESTDIR)$(htmldir)/* $(DESTDIR)$(htmldir)/search/*; do \
if test -f $$file ; then $(RM) $$file ; fi ;\
done
if test -d $(DESTDIR)$(htmldir)/search ; then $(RMDIR) $(DESTDIR)$(htmldir)/search ; fi
if test -d $(DESTDIR)$(htmldir) ; then $(RMDIR) $(DESTDIR)$(htmldir) ; fi
10 changes: 8 additions & 2 deletions ecc/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for tinydtls
#
# Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
# Copyright (c) 2011-2020 Olaf Bergmann (TZI) and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
Expand Down Expand Up @@ -42,7 +42,7 @@ CFLAGS=-Wall -std=c99 -pedantic @CFLAGS@ -DTEST_INCLUDE
LDFLAGS=@LDFLAGS@
LDLIBS=@LIBS@

.PHONY: all dirs clean install distclean .gitignore doc
.PHONY: all dirs clean install distclean .gitignore doc uninstall

.SUFFIXES:
.SUFFIXES: .c .o
Expand Down Expand Up @@ -79,5 +79,11 @@ install: $(ECC_HEADERS)
test -d $(DESTDIR)$(includedir)/ecc || mkdir -p $(DESTDIR)$(includedir)/ecc
$(install) $(ECC_HEADERS) $(DESTDIR)$(includedir)/ecc

uninstall:
for file in $(ECC_HEADERS); do \
if test -f $(DESTDIR)$(includedir)/ecc/$$file ; then $(RM) $(DESTDIR)$(includedir)/ecc/$$file ; fi ;\
done
if test -d $(DESTDIR)$(includedir)/ecc ; then $(RMDIR) $(DESTDIR)$(includedir)/ecc ; fi

.gitignore:
echo "core\n*~\n*.[oa]\n*.gz\n*.cap\n$(PROGRAM)\n$(DISTDIR)\n.gitignore" >$@
3 changes: 3 additions & 0 deletions platform-specific/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ dist:
# this directory contains no installation candidates
install:
:

uninstall:
:
10 changes: 8 additions & 2 deletions sha2/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for tinydtls
#
# Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
# Copyright (c) 2011-2020 Olaf Bergmann (TZI) and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
Expand Down Expand Up @@ -36,7 +36,7 @@ LDLIBS=@LIBS@
FILES:=Makefile.in $(SOURCES) $(HEADERS) README sha2prog.c sha2speed.c sha2test.pl
DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@

.PHONY: all dirs clean install dist distclean .gitignore doc
.PHONY: all dirs clean install dist distclean .gitignore doc uninstall

.SUFFIXES:
.SUFFIXES: .c .o
Expand Down Expand Up @@ -67,5 +67,11 @@ install: $(HEADERS)
test -d $(DESTDIR)$(includedir)/sha2 || mkdir -p $(DESTDIR)$(includedir)/sha2
$(install) $(HEADERS) $(DESTDIR)$(includedir)/sha2

uninstall:
for file in $(HEADERS); do \
if test -f $(DESTDIR)$(includedir)/sha2/$$file ; then $(RM) $(DESTDIR)$(includedir)/sha2/$$file ; fi ;\
done
if test -d $(DESTDIR)$(includedir)/sha2 ; then $(RMDIR) $(DESTDIR)$(includedir)/sha2 ; fi

.gitignore:
echo "core\n*~\n*.[oa]\n*.gz\n*.cap\n$(PROGRAM)\n$(DISTDIR)\n.gitignore" >$@
5 changes: 4 additions & 1 deletion tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LDLIBS:=$(top_srcdir)/libtinydtls.a @LIBS@
DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@
FILES:=Makefile.in $(SOURCES) ccm-testdata.c #cbc_aes128-testdata.c

.PHONY: all dirs clean distclean .gitignore doc
.PHONY: all dirs clean distclean .gitignore doc install uninstall

.SUFFIXES:
.SUFFIXES: .c .o
Expand Down Expand Up @@ -72,5 +72,8 @@ dist: $(FILES)
install:
:

uninstall:
:

.gitignore:
echo "core\n*~\n*.[oa]\n*.gz\n*.cap\n$(PROGRAM)\n$(DISTDIR)\n.gitignore" >$@

0 comments on commit 5c83d4b

Please sign in to comment.