diff options
author | Explorer09 <explorer09@gmail.com> | 2024-04-02 04:17:58 +0800 |
---|---|---|
committer | Will Estes <westes@users.noreply.github.com> | 2024-04-02 07:01:20 -0400 |
commit | 4f7f19e6bc462d1002f3ffa96c39ccb86c9e2659 (patch) | |
tree | bf4bbcb125c2c30185c784ceb6395c5a82c4b709 | |
parent | 2e5f4bc9d8f2d39ad162b9b50882e20cf4154ead (diff) | |
download | flex-4f7f19e6bc462d1002f3ffa96c39ccb86c9e2659.tar.gz |
build: Add stage2scan.c and byte comparison check for bootstrap.
With stage1scan.c being deterministic, it's possible to add a bootstrap
check that ensures the generated flex program can build the scanner of
itself flawlessly. The check is performed on native build only.
Code is partly inspired from GCC's makefile.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
-rw-r--r-- | src/.gitignore | 4 | ||||
-rw-r--r-- | src/Makefile.am | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/.gitignore b/src/.gitignore index d49ebc4..cbae2e3 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -10,8 +10,10 @@ libfl.pc parse.c parse.h scan.c -stage1scan.[cl] +stage1scan.c stage1flex +stage2compare +stage2scan.c # for MSWindows diff --git a/src/Makefile.am b/src/Makefile.am index 3611bde..ff00742 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,9 @@ m4 = @M4@ bin_PROGRAMS = flex if ENABLE_BOOTSTRAP noinst_PROGRAMS = stage1flex +if !CROSS +noinst_DATA = stage2compare +endif endif if ENABLE_LIBFL @@ -106,7 +109,9 @@ EXTRA_DIST = \ MOSTLYCLEANFILES = \ $(SKELINCLUDES) \ - stage1scan.c + stage1scan.c \ + stage2scan.c \ + stage2compare CLEANFILES = stage1flex$(EXEEXT) @@ -138,6 +143,24 @@ stage1scan.c: scan.l stage1flex$(EXEEXT) $(AM_LFLAGS) $(LFLAGS) -o scan.c -t scan.l ) >$@ || \ { s=$$?; rm -f $@; exit $$s; } +# Unlike stage1scan.c, we leave stage2scan.c intact when the generation +# fails. This allow users to examine generation errors. +stage2scan.c: scan.l flex$(EXEEXT) stage1scan.c + ( cd $(srcdir) && $(abs_builddir)/flex$(EXEEXT) \ + $(AM_LFLAGS) $(LFLAGS) -o scan.c -t scan.l ) >$@ + +stage2compare: stage1scan.c + @rm -f stage2scan.c; \ + $(MAKE) $(AM_MAKEFLAGS) stage2scan.c; \ + echo Comparing stage1scan.c and stage2scan.c; \ + cmp stage1scan.c stage2scan.c || { \ + s=$$?; \ + echo "Bootstrap comparison failure!"; \ + exit $$s; \ + }; \ + echo Comparison successful.; \ + echo success >$@ + dist-hook: scan.l flex$(EXEEXT) chmod u+w $(distdir) && \ chmod u+w $(distdir)/scan.c && \ |