0

I compile a project using a Makefile. Somehow (after reading a lot about Makefiles), I can't solve the following problem:

I have a main file edu.tex and a file edu-tut.tex, which is imported to edu.tex using \input{edu-tut.tex}. So edu.pdf depends on edu.tex and edu-tut.tex.

If edu-tut.tex is edited, another Makefile in the subdirectory doc/ is called, which creates a lot of figures.

Summarized, that's how it should work if I want to build edu.pdf:

  • edu.tex edited: compile edu.tex
  • edu-tut.texedited: call the Makefile inside doc/ and then compile edu.tex

That's an excerpt of my current state, but it doesn't work:

all: edu.pdf

edu.pdf: edu-tut.tex edu.tex
    [build edu.pdf -- this works!]

edu-tut.tex:
    make -C doc/

I hope this is comprehensible. I am a layman to Makefiles ...

  • It would be really helpful if we would have some .tex files to work with, Herr 'Kollege' ;-) – user31729 Jul 24 '16 at 21:01
  • 1
    Do you depend on the make file? Editors like texstudio are capable to automatically detect the master file (in your case edu.tex) and compile this, no matter if you are editing edu.tex or edu-tut.tex. If you need automatic compilation, there are automating tools like ltx2any which are capable of more complex setups. – user36296 Jul 24 '16 at 21:19
  • @Christian: Usually I post a MWE. The problem is, that my project is already complex. As it seems to be a conceptional problem I thought the makefile is enough. Maybe somebody can explain it without a MWE? Greetings to the 'Schwarzwald'! :-) – dawu Jul 24 '16 at 21:20
  • @samcarter: Yes, I do. My project is quite complex and I need the flexibility of a Makefile. – dawu Jul 24 '16 at 21:22
2

The following (untested) use of a run-stamp file looks straightforward to me:

# Either some file(s) generated by "make -C doc" or some run-stamp file
EXFIGS = doc/exfigs.done

all: edu.pdf

edu.pdf: edu-tut.tex edu.tex $(EXFIGS)
        # Your build commands go here

$(EXFIGS): edu-tut.tex
        $(MAKE) -C doc/
        # If the above does not actually create $(EXFIGS), add:
        touch $(EXFIGS)

Notes:

  1. If you copy-paste the above, make sure that indents are done with tabs.
  2. $(EXFIGS) are supposed to be real files, so do not flag them as .PHONY.
1

The day after I posted my question (and befor @ccorn's answer) I did some tests related to this question. And I think I found another (rather simple) solution.

The idea is to check the dependency to edu.cls inside doc/Makefile:

Makefile in / (root directory)

all: edu.pdf

edu.pdf: edu-tut.tex edu.tex
    [build stuff ...]
    make -C doc/
    [build stuff ...]

Makefile in /doc

%.pdf: ../edu-tut.tex
    [build stuff]

This seems to work as well.

  • This calls make -C doc unconditionally (contrary to the question), but that make -C doc figures out whether expensive recompilations are necessary. This approach is preferrable, and I often see it used in Makefile hierarchies. – ccorn Jul 31 '16 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.