sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

[Quickstart] Allow calling the Makefile using `make -f path/to/Makefile <target>`

Open leogermond opened this issue 2 years ago • 4 comments

Subject: Allow calling the quickstart Makefile with make -f

Feature or Bugfix

  • Bugfix

Purpose

  • This PR modifies the default Makefile so that it can be called using make -f. Otherwise it would call it with a target that is the path to the Makefile itself, this would result in a weird "path/to/Makefile is not a directory" error.
  • This PR does impacts people using the quickstart setup. It relies on the shell having the pwd command.

Relates

  • https://github.com/sphinx-doc/sphinx/issues/10706

leogermond avatar Jul 25 '22 13:07 leogermond

I do not understand:

  • when moving to source (where conf.py and Makefile are), make -f Makefile html works for me with current Makefile, already
  • if I rename Makefile to something else and try to use (in same directory) this new name via make -f then it does not work indeed, but this applies both to current Sphinx and to your branch, with sphinx-build complaining about not knowing the builder, as you mention,
  • if I issue make -f from parent directory (cf your #10706) I get the expected error about this directory not containing a conf.py. And this applies whether or not using your branch. This seems to be what you report at #10706 but my understanding of https://www.gnu.org/software/make/manual/make.html#Makefile-Names is that this is to be expected.

Besides as you already mention in #10706, using make -C does work fine, from an arbitrary location, if argument of -C is the relative or absolute path to source directory.

My make is GNU Make 4.2.1

jfbu avatar Jul 26 '22 14:07 jfbu

Hmm it seems this may solve it:

diff --git a/sphinx/templates/quickstart/Makefile.new_t b/sphinx/templates/quickstart/Makefile.new_t
index 1a527578b..5d5985d3b 100644
--- a/sphinx/templates/quickstart/Makefile.new_t
+++ b/sphinx/templates/quickstart/Makefile.new_t
@@ -12,10 +12,10 @@ BUILDDIR      = {{ rbuilddir }}
 help:
 	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
 
-.PHONY: help Makefile
+.PHONY: help
 
 # Catch-all target: route all unknown targets to Sphinx using the new
 # "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
-%: Makefile
+.DEFAULT:
 	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

For example renaming this to MyMakefile then make -f MyMakefile html pseudoxml latexpdf works fine at my locale.

I got the hint from this stackoverflow answer but some advice would be needed to make sure we do not break things.

jfbu avatar Jul 26 '22 15:07 jfbu

cf https://www.gnu.org/software/make/manual/make.html#Last-Resort

jfbu avatar Jul 26 '22 15:07 jfbu

I guess this change will cause trouble for Windows users. So it's better not to use pwd command as possible. Could you check the advice from jfbu, please?

tk0miya avatar Jul 28 '22 00:07 tk0miya

We want to move away from Makefile long-term, so I'm closing this. Thank you for your time, though.

A

AA-Turner avatar Aug 14 '23 23:08 AA-Turner