From f4aca14e5fbb1e60d1d2f38f1dc41e9292ba95d5 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Wed, 8 May 2024 18:55:18 +0100 Subject: gdb/doc: fix parallel build of refcard related targets There are two problems we encounter when trying to build the refcard related target in parallel, i.e.: $ make -j20 -C gdb/doc/ refcard.dvi refcard.ps refcard.pdf These problems are: (1) The refcard.dvi and refcard.pdf targets both try and generate the tmp.sed and sedref.tex files. If two make threads end up trying to create these files at the same time then the result is these files become corrupted. I've fixed this by creating a new rule that creates sedref.tex, both refcard.dvi and refcard.pdf now depend on this, and make will build sedref.tex just once. The tmp.sed file is now generated as refcard.sed, this is generated and deleted as a temporary file within the sedref.tex recipe. (2) Having created sedref.tex the recipes for refcard.dvi and refcard.pdf both run various LaTeX based tools with sedref.tex as the input file. The problem with this is that these tools all rely on creating temporary files calls sedref.*. If the refcard.dvi and refcard.pdf rules run at the same time then these temporary files clash and overwrite each other causing the build to fail. We already copy the result file in order to rename it, our input file is sedref.tex which results in an output file named sedref.dvi or sedref.pdf, but we actually want refcard.dvi or refcard.pdf. So within the recipe for refcard.dvi I copy the input file from sedref.tex to sedref_dvi.tex. Now all the temp files are named sedref_dvi.* and the output is sedref_dvi.dvi, I then rename this new output file to refcard.dvi. I've done the same thing for refcard.pdf, but I copy the input to sedref_pdf.tex. In this way the temp files no longer clash, and both recipes can safely run in parallel. After this commit I was able to reliably build all of the refcard targets in parallel. There should be no change in the final file. Approved-By: Tom Tromey --- gdb/doc/Makefile.in | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/gdb/doc/Makefile.in b/gdb/doc/Makefile.in index d0489c4..cfd3b35 100644 --- a/gdb/doc/Makefile.in +++ b/gdb/doc/Makefile.in @@ -408,31 +408,32 @@ de-stage3: force -(cd stage3 ; mv -f * ..) -rmdir stage3 -# GDB QUICK REFERENCE (dvi output) -refcard.dvi : refcard.tex $(REFEDITS) - $(SILENCE) echo > tmp.sed + +sedref.tex : refcard.tex $(REFEDITS) + $(SILENCE) echo > refcard.sed $(SILENCE) for f in x $(REFEDITS) ; do \ test x$$f = xx && continue ; \ - cat $(srcdir)/$$f >>tmp.sed ; \ + cat $(srcdir)/$$f >>refcard.sed ; \ done - $(SILENCE) sed -f tmp.sed $(srcdir)/refcard.tex >sedref.tex - $(ECHO_TEX) $(SET_TEXINPUTS) $(TEX) sedref.tex - $(SILENCE) mv sedref.dvi refcard.dvi - $(SILENCE) rm -f sedref.log sedref.tex tmp.sed + $(ECHO_GEN) sed -f refcard.sed $(srcdir)/refcard.tex >$@ + $(SILENCE) rm -f refcard.sed + + +# GDB QUICK REFERENCE (dvi output) +refcard.dvi : sedref.tex + $(SILENCE) rm -f sedref_dvi.* + $(SILENCE) cp $< sedref_dvi.tex + $(ECHO_TEX) $(SET_TEXINPUTS) $(TEX) sedref_dvi.tex && \ + mv sedref_dvi.dvi $@ refcard.ps : refcard.dvi $(ECHO_DVIPS) $(DVIPS) $(SILENT_Q_FLAG) -t landscape -o $@ $? -refcard.pdf : refcard.tex $(REFEDITS) - $(SILENCE) echo > tmp.sed - $(SILENCE) for f in x $(REFEDITS) ; do \ - test x$$f = xx && continue ; \ - cat $(srcdir)/$$f >>tmp.sed ; \ - done - $(SILENCE) sed -f tmp.sed $(srcdir)/refcard.tex >sedref.tex - $(ECHO_PDFTEX) $(SET_TEXINPUTS) $(PDFTEX) sedref.tex - $(SILENCE) mv sedref.pdf refcard.pdf - $(SILENCE) rm -f sedref.log sedref.tex tmp.sed +refcard.pdf : sedref.tex + $(SILENCE) rm -f sedref_pdf.* + $(SILENCE) cp $< sedref_pdf.tex + $(ECHO_PDFTEX) $(SET_TEXINPUTS) $(PDFTEX) sedref_pdf.tex && \ + mv sedref_pdf.pdf $@ # File to record current GDB version number. # @@ -685,7 +686,7 @@ mostlyclean: rm -f $(GDB_TEX_TMPS) rm -f $(STABS_TEX_TMPS) rm -f $(ANNOTATE_TEX_TMPS) - rm -f sedref.dvi sedref.tex tmp.sed sedref.log + rm -f refcard.sed sedref.tex sedref_dvi.* sedref_pdf.* rm -f $(POD_FILE_TMPS) clean: mostlyclean -- cgit v1.1