]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/doc: fix parallel build of refcard related targets
authorAndrew Burgess <aburgess@redhat.com>
Wed, 8 May 2024 17:55:18 +0000 (18:55 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 24 Jun 2024 11:13:57 +0000 (12:13 +0100)
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 <tom@tromey.com>
gdb/doc/Makefile.in

index d0489c4b54b7fa75c9bf29142baf1aa2c0c35280..cfd3b3597fb55f4c7f1d9a4c9a08a95f0ed02cff 100644 (file)
@@ -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