diff --git a/packages/gendoc/Makefile b/packages/gendoc/Makefile
index 479b2e27d657aa2810d87e639f6b468bbed2eabd..9de0231665fd43582ff620fdcd01b9a849257f6e 100644
--- a/packages/gendoc/Makefile
+++ b/packages/gendoc/Makefile
@@ -8,6 +8,12 @@ $(addprefix Welcome-, Linux Darwin MINGW)
 markdown = $(addsuffix .md, $(targets))
 html = $(addsuffix .html, $(targets))
 
+# python -m markdown setup. We may need to invoke python as python3 on systems
+# which still have python2 as the default. You can also set this manually by
+# passing python-markdown=python-markdown-command to make if python-markdown
+# gets invoked in an unusual way.
+python-markdown = $(shell python3 -m markdown 2>/dev/null < /dev/null && echo python3 -m markdown || echo python -m markdown)
+
 # Note: This requires special tools (python-markdown, awk).
 all: html
 
@@ -20,7 +26,7 @@ ReadMe-%.md: ReadMe.md
 
 ReadMe-%.html: osname = $(patsubst ReadMe-%.html,%,$@)
 ReadMe-%.html: ReadMe-%.md pandoc-template.html
-	python -m markdown $< > ReadMe-body.html
+	$(python-markdown) $< > ReadMe-body.html
 	sed -e "s/@version@/$(version) ($(osname))/g" -e '/--stylesheet--/r gh-pandoc.css' -e '/--body--/r ReadMe-body.html' pandoc-template.html > $@
 	rm -f ReadMe-body.html
 
@@ -30,7 +36,7 @@ Welcome-%.md: Welcome.md
 
 Welcome-%.html: osname = $(patsubst Welcome-%.html,%,$@)
 Welcome-%.html: Welcome-%.md pandoc-template.html
-	python -m markdown $< > Welcome-body.html
+	$(python-markdown) $< > Welcome-body.html
 	sed -e "s/@version@/$(version) ($(osname))/g" -e '/--stylesheet--/r gh-pandoc.css' -e '/--body--/r Welcome-body.html' pandoc-template.html > $@
 	rm -f Welcome-body.html