Makefile.am: avoid double `bison` execution on parallel build

Before the change `make -j16` ran `bison` twice on the same input:

    $ make -j16
    ...
    make[1]: Entering directory '/build/source/Source'
    bison -d -Wall -Werror  --output=CParse/parser.c ./CParse/parser.y
    gcc -g -O2 -Wall -W -I.   -c -o mdfour.o mdfour.c
    bison -d -Wall -Werror  --output=CParse/parser.c ./CParse/parser.y
    ...

Note how two parallel `bison` calls both generate the same files. It works
most of the time, but is prone to generate unexpected output.

This happens because Makefile rules like:

    a b: c; COMMAND
    all: a b

will run COMMAND for each target (twice here: once for `a` and once for
`b`),

The fix uses GNU make's Grouped Targets to use single command to produce
multiple targets.
This commit is contained in:
Sergei Trofimovich 2025-04-19 16:11:25 +01:00 committed by Olly Betts
parent d2056de196
commit 01bf5808dd
1 changed files with 3 additions and 1 deletions

View File

@ -99,7 +99,9 @@ eswig_SOURCES = CParse/cscanner.c \
bin_PROGRAMS = eswig
CParse/parser.c CParse/parser.h: CParse/parser.y
# Use GNU make's grouped targets to avoid repeated bison execution for
# each target.
CParse/parser.c CParse/parser.h &: CParse/parser.y
$(BISON) $(AM_YFLAGS) $(YFLAGS) --output=CParse/parser.c $(srcdir)/CParse/parser.y
# The executable is copied to the root directory for installation and running the test-suite.