diff --git a/Makefile b/Makefile
index c200a4c4e6c80b119dd9756d38db4d4c1d1e929a..ab3b39f00e9bad5e18d35f39cfb9e8c5ee0c02d5 100644
--- a/Makefile
+++ b/Makefile
@@ -20,19 +20,13 @@ all: Makefile.coq
 
 clean: Makefile.coq
 	+@make -f Makefile.coq clean
-	find \( -name "*.v.d" -o -name "*.vo" -o -name "*.aux" -o -name "*.cache" -o -name "*.glob" -o -name "*.vio" \) -print -delete
+	find theories \( -name "*.v.d" -o -name "*.vo" -o -name "*.aux" -o -name "*.cache" -o -name "*.glob" -o -name "*.vio" \) -print -delete
 	rm -f Makefile.coq
 
 # Create Coq Makefile
-Makefile.coq: _CoqProject Makefile
-	@# we want to pass the correct name to coq_makefile or it will be confused.
+Makefile.coq: _CoqProject Makefile awk.Makefile
 	coq_makefile $(COQ_MAKEFILE_FLAGS) -f _CoqProject -o Makefile.coq
-	mv Makefile.coq Makefile.coq.tmp
-	@# The sed script is for Coq 8.5 only, it fixes 'make verify'.
-	@# The awk script fixes 'make uninstall'.
-	sed 's/$$(COQCHK) $$(COQCHKFLAGS) $$(COQLIBS)/$$(COQCHK) $$(COQCHKFLAGS) $$(subst -Q,-R,$$(COQLIBS))/' < Makefile.coq.tmp \
-	  | awk '/^uninstall:/{print "uninstall:";print "\tif [ -d \"$$(DSTROOT)\"$$(COQLIBINSTALL)/iris/ ]; then find \"$$(DSTROOT)\"$$(COQLIBINSTALL)/iris/ -name \"*.vo\" -print -delete; fi";getline;next}1' > Makefile.coq
-	rm Makefile.coq.tmp
+	awk -i inplace -f awk.Makefile Makefile.coq
 
 # Install build-dependencies
 build-dep:
@@ -45,6 +39,7 @@ build-dep:
 # some fiels that do *not* need to be forwarded to Makefile.coq
 Makefile: ;
 _CoqProject: ;
+awk.Makefile: ;
 
 # Phony targets (i.e. targets that should be run no matter the timestamps of the involved files)
 phony: ;
diff --git a/awk.Makefile b/awk.Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..781493ff36d1be17aab703ae76ece2b1cbd7c7d5
--- /dev/null
+++ b/awk.Makefile
@@ -0,0 +1,26 @@
+# awk program that patches the Makefile generated by Coq.
+
+# Patch the uninstall target to work properly, and to also uninstall stale files.
+# Also see <https://coq.inria.fr/bugs/show_bug.cgi?id=4907>.
+/^uninstall:/ {
+	print "uninstall:";
+	print "\tif [ -d \"$$(DSTROOT)\"$$(COQLIBINSTALL)/iris/ ]; then find \"$$(DSTROOT)\"$$(COQLIBINSTALL)/iris/ -name \"*.vo\" -print -delete; fi";
+	getline;
+	next
+}
+
+# Patch vio2vo to (a) run "make quick" with the same number of jobs, ensuring
+# that the .vio files are up-to-date, and (b) only schedule vio2vo for those
+# files where the .vo is *older* than the .vio.
+/^vio2vo:/ {
+	print "vio2vo:";
+	print "\t@make -j $(J) quick"
+	print "\t@VIOFILES=$$(for file in $(VOFILES:%.vo=%.vio); do if [ \"$$(echo \"$$file\" | sed \"s/\\.vio/.vo/\")\" -ot \"$$file\" ]; then echo -n \"$$file \"; fi; done); \\"
+	print "\t echo \"VIO2VO: $$VIOFILES\"; \\"
+	print "\t if [ -n \"$$VIOFILES\" ]; then $(COQC) $(COQDEBUG) $(COQFLAGS) -schedule-vio2vo $(J) $$VIOFILES; fi"
+	getline;
+	next
+}
+
+# This forwards all unchanged lines
+1