From 2b701be49c357324d3866e6d46572382da55829b Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Fri, 10 May 2024 23:14:57 +0800 Subject: [PATCH 01/10] Reorganize gitignore file lists Group the files by "category", i.e. reasons for ignoring, and adjust some of the file name patterns. --- .gitignore | 56 ++++++++++++++++++++++++++++++++------------------ po/.gitignore | 38 ++++++++++++++++++++-------------- src/.gitignore | 40 +++++++++++++++++++----------------- 3 files changed, 80 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index daf0ef997..309019204 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,40 @@ +*.sig +stamp-* + +# Backup files generated by various editors *.orig *.rej -*.sig -*.tar.gz -*.tar.lz *~ -.deps -.libs -ABOUT-NLS -ChangeLog -Makefile + +# 'autoscan' log files +/autoscan.log +/configure.scan + +# Files generated by Autotools +/ABOUT-NLS +/ChangeLog +/aclocal.m4 +/autom4te.cache/ +/build-aux/ +/configure +/m4/ Makefile.in -aclocal.m4 -autom4te.cache -autoscan.log -build-aux/ -config.log -config.status -configure -configure.scan -flex-*/ -libtool -m4/ -stamp-* + +# Files generated by 'configure' +/config.cache +/config.log +/config.status +/libtool +Makefile + +# Built object files and support files +*.lo +*.o +*.obj +.deps/ +.libs/ + +# Distribution tarballs and directory +/flex-*/ +*.tar.gz +*.tar.lz diff --git a/po/.gitignore b/po/.gitignore index 3c6f57d67..c3e4c382f 100644 --- a/po/.gitignore +++ b/po/.gitignore @@ -1,18 +1,26 @@ -*.gmo -Makefile -Makefile.in -Makefile.in.in -Makevars.template -POTFILES -Rules-quot -boldquot.sed -en@boldquot.*header en@boldquot.po -en@quot.*header en@quot.po -flex.pot -insert-header.sin -quot.sed -remove-potcdate.sed -remove-potcdate.sin stamp-* + +# Files generated by Autotools +/Makefile.in.in +/Makevars.template +/Rules-quot +/boldquot.sed +/en@boldquot.header +/en@quot.header +/insert-header.sin +/quot.sed +/remove-potcdate.sin + +# Files generated by 'configure' +/Makefile +/Makefile.in +/POTFILES + +# Built object files and support files +/*.gmo +/en@boldquot.insert-header +/en@quot.insert-header +/flex.pot +/remove-potcdate.sed diff --git a/src/.gitignore b/src/.gitignore index cbae2e3b6..8cfea9dd5 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,21 +1,23 @@ -*.la -*.lo -*.o -*-flex.h -config.h -config.h.in -config_for_build.h -flex -libfl.pc -parse.c -parse.h -scan.c -stage1scan.c -stage1flex -stage2compare -stage2scan.c +# Files generated by Autotools +/config.h.in -# for MSWindows +# Files generated by 'configure' +/config.h +/config_for_build.h +/libfl.pc -*.obj -*.exe +# Generated code, included in distribution tarball only +/parse.c +/parse.h +/scan.c + +# Built object files and support files +/*-flex.h +/flex +/flex.exe +/libfl.la +/stage1scan.c +/stage1flex +/stage1flex.exe +/stage2compare +/stage2scan.c From 8ec9104851e3beeccc49eddd6499d37065e65bfd Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 9 May 2024 23:08:31 +0800 Subject: [PATCH 02/10] build: Rename 'dist-hook' target in src/Makefile.am This change is a prerequisite for converting src/Makefile.am for non-recursive use. --- src/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b9ead0740..019a3d0ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -160,7 +160,9 @@ stage2compare: stage1scan.c echo Comparison successful.; \ echo success >$@ -dist-hook: scan.l flex$(EXEEXT) +dist-hook: dist-hook-src + +dist-hook-src: scan.l flex$(EXEEXT) chmod u+w $(distdir) && \ chmod u+w $(distdir)/scan.c && \ ( cd $(srcdir) && $(abs_builddir)/flex$(EXEEXT) \ @@ -228,4 +230,4 @@ indent: $(top_srcdir)/.indent.pro echo $$f FAILED to indent; \ done; -.PHONY: indent +.PHONY: dist-hook-src indent From 90c8d2f846c3ef75325ca6295d18dd563a77a830 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Fri, 10 May 2024 23:25:04 +0800 Subject: [PATCH 03/10] build: Non-recursive makefile for 'src' directory --- .gitignore | 5 + Makefile.am | 23 +++-- configure.ac | 1 - doc/Makefile.am | 8 +- src/.gitignore | 5 - src/Makefile.am | 233 ---------------------------------------------- src/local.mk | 232 +++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 2 +- 8 files changed, 253 insertions(+), 256 deletions(-) delete mode 100644 src/Makefile.am create mode 100644 src/local.mk diff --git a/.gitignore b/.gitignore index 309019204..f3e3e84e0 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,11 @@ Makefile.in Makefile # Built object files and support files +/flex +/flex.exe +/libfl.la +/stage1flex +/stage1flex.exe *.lo *.o *.obj diff --git a/Makefile.am b/Makefile.am index 848f7c8a3..40da932ec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,33 +47,35 @@ dist_noinst_SCRIPTS = \ po/update_linguas.sh SUBDIRS = \ - src \ + . \ doc \ examples \ po \ tests \ tools +MOSTLYCLEANFILES = + +CLEANFILES = + +include src/local.mk + # Convenience targets to build libfl only # These are actually wrappers around automake- and libtool-generated targets -libfl: - cd src && $(MAKE) $(AM_MAKEFLAGS) libfl.la libfl.pc +libfl: libfl.la src/libfl.pc install-libfl: - cd src && \ $(MAKE) $(AM_MAKEFLAGS) lib_LTLIBRARIES=libfl.la \ - pkgconfig_DATA=libfl.pc install-libLTLIBRARIES install-pkgconfigDATA + pkgconfig_DATA=src/libfl.pc install-libLTLIBRARIES install-pkgconfigDATA uninstall-libfl: - cd src && \ $(MAKE) $(AM_MAKEFLAGS) \ - lib_LTLIBRARIES=libfl.la pkgconfig_DATA=libfl.pc \ + lib_LTLIBRARIES=libfl.la pkgconfig_DATA=src/libfl.pc \ uninstall-libLTLIBRARIES uninstall-pkgconfigDATA # libfl.pc is cleaned via 'distclean' target clean-libfl: - cd src && \ $(MAKE) $(AM_MAKEFLAGS) lib_LTLIBRARIES=libfl.la clean-libLTLIBRARIES \ clean-libtool @@ -84,9 +86,6 @@ ChangeLog: $(srcdir)/tools/git2cl $(srcdir)/tools/git2cl > $@ \ ; fi -indent: - cd src && $(MAKE) $(AM_MAKEFLAGS) indent - install-exec-hook: cd $(DESTDIR)$(bindir) && \ $(LN_S) -f flex$(EXEEXT) flex++$(EXEEXT) @@ -95,4 +94,4 @@ lint: shellcheck -f gcc tests/*.sh src/*.sh *.sh .PHONY: libfl install-libfl uninstall-libfl clean-libfl \ - ChangeLog indent lint + ChangeLog lint diff --git a/configure.ac b/configure.ac index e166c8af4..e58c01280 100644 --- a/configure.ac +++ b/configure.ac @@ -221,7 +221,6 @@ examples/fastwc/Makefile examples/manual/Makefile po/Makefile.in src/libfl.pc -src/Makefile tools/Makefile tests/Makefile ) diff --git a/doc/Makefile.am b/doc/Makefile.am index a32f81c60..b1f4de18a 100755 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,7 +1,7 @@ if CROSS -FLEX = $(top_builddir)/src/stage1flex +FLEX = $(top_builddir)/stage1flex else -FLEX = $(top_builddir)/src/flex$(EXEEXT) +FLEX = $(top_builddir)/flex$(EXEEXT) endif TEXI2DVI = @TEXI2DVI@ -I $(srcdir)/../examples/manual/ @@ -37,8 +37,8 @@ CLEANFILES = \ # usage string, but not file extensions. flex.1: $(top_srcdir)/configure.ac $(top_srcdir)/src/cpp-flex.skl $(top_srcdir)/src/options.c $(top_srcdir)/src/options.h - ( cd $(top_builddir)/src && \ - prog_name=`echo '$(FLEX)' | sed 's|^$(top_builddir)/src/||'` && \ + ( cd $(top_builddir) && \ + prog_name=`echo '$(FLEX)' | sed 's|^$(top_builddir)/||'` && \ $(MAKE) $(AM_MAKEFLAGS) $$prog_name \ ) $(INSTALL) -m 700 $(FLEX) flex$(EXEEXT) diff --git a/src/.gitignore b/src/.gitignore index 8cfea9dd5..d5ae0af23 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -13,11 +13,6 @@ # Built object files and support files /*-flex.h -/flex -/flex.exe -/libfl.la /stage1scan.c -/stage1flex -/stage1flex.exe /stage2compare /stage2scan.c diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index 019a3d0ba..000000000 --- a/src/Makefile.am +++ /dev/null @@ -1,233 +0,0 @@ -AM_YFLAGS = -d -AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -AM_CFLAGS = $(WARNINGFLAGS) -LIBS = @LIBS@ -pkgconfigdir = @pkgconfigdir@ - -m4 = @M4@ - -bin_PROGRAMS = flex -if ENABLE_BOOTSTRAP -noinst_PROGRAMS = stage1flex -if !CROSS -noinst_DATA = stage2compare -endif -endif - -if ENABLE_LIBFL -lib_LTLIBRARIES = libfl.la -pkgconfig_DATA = libfl.pc -endif -libfl_la_SOURCES = \ - libmain.c \ - libyywrap.c -libfl_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ - -stage1flex_SOURCES = \ - scan.l \ - $(COMMON_SOURCES) - -nodist_stage1flex_SOURCES = \ - $(SKELINCLUDES) - -if CROSS -stage1flex_LDADD = -stage1flex_SOURCES += \ - ../lib/malloc.c \ - ../lib/realloc.c -stage1flex_LINK = $(LIBTOOL) --tag=CC --mode=link $(CC_FOR_BUILD) \ - $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ - -$(stage1flex_OBJECTS): CC=$(CC_FOR_BUILD) -$(stage1flex_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD) -DUSE_CONFIG_FOR_BUILD -$(stage1flex_OBJECTS): CPP=$(CPP_FOR_BUILD) -$(stage1flex_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD) -$(stage1flex_OBJECTS): LDFLAGS=$(LDFLAGS_FOR_BUILD) -else -stage1flex_LDADD = $(LDADD) -stage1flex_LINK = $(LINK) -stage1flex_CFLAGS = $(AM_CFLAGS) -endif - -flex_SOURCES = \ - $(COMMON_SOURCES) - -nodist_flex_SOURCES = \ - $(SKELINCLUDES) - -if ENABLE_BOOTSTRAP -nodist_flex_SOURCES += stage1scan.c -else -flex_SOURCES += scan.l -endif - -COMMON_SOURCES = \ - buf.c \ - ccl.c \ - dfa.c \ - ecs.c \ - filter.c \ - flexdef.h \ - flexint.h \ - flexint_shared.h \ - gen.c \ - main.c \ - misc.c \ - nfa.c \ - options.c \ - options.h \ - parse.y \ - regex.c \ - scanflags.c \ - scanopt.c \ - scanopt.h \ - skeletons.c \ - sym.c \ - tables.c \ - tables.h \ - tables_shared.c \ - tables_shared.h \ - tblcmp.c \ - version.h \ - yylex.c - -LDADD = $(LIBOBJS) @LIBINTL@ - -$(LIBOBJS): $(LIBOBJDIR)$(am__dirstamp) - -include_HEADERS = \ - FlexLexer.h - -EXTRA_DIST = \ - c99-flex.skl \ - cpp-flex.skl \ - go-flex.skl \ - mkskel.sh \ - gettext.h \ - chkskel.sh - -MOSTLYCLEANFILES = \ - $(SKELINCLUDES) \ - stage1scan.c \ - stage2scan.c \ - stage2compare - -CLEANFILES = stage1flex$(EXEEXT) - -SKELINCLUDES = \ - cpp-flex.h \ - c99-flex.h \ - go-flex.h - -cpp-flex.h: cpp-flex.skl mkskel.sh flexint_shared.h tables_shared.h tables_shared.c - $(SHELL) $(srcdir)/mkskel.sh cpp $(srcdir) $(m4) $(VERSION) > $@.tmp - $(SHELL) $(srcdir)/chkskel.sh $@.tmp - mv -f $@.tmp $@ - -c99-flex.h: c99-flex.skl mkskel.sh - $(SHELL) $(srcdir)/mkskel.sh c99 $(srcdir) $(m4) $(VERSION) > $@.tmp - $(SHELL) $(srcdir)/chkskel.sh $@.tmp - mv -f $@.tmp $@ - -go-flex.h: go-flex.skl mkskel.sh - $(SHELL) $(srcdir)/mkskel.sh go $(srcdir) $(m4) $(VERSION) > $@.tmp - $(SHELL) $(srcdir)/chkskel.sh $@.tmp - mv -f $@.tmp $@ - -# The input and output file names are fixed for deterministic scanner -# generation. If scan.l is not modified by builders, stage1scan.c should -# be bit-identical to the scan.c pregenerated on release. -stage1scan.c: scan.l stage1flex$(EXEEXT) - ( cd $(srcdir) && $(abs_builddir)/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: dist-hook-src - -dist-hook-src: scan.l flex$(EXEEXT) - chmod u+w $(distdir) && \ - chmod u+w $(distdir)/scan.c && \ - ( cd $(srcdir) && $(abs_builddir)/flex$(EXEEXT) \ - -o scan.c -t scan.l ) >scan.c && \ - mv -f scan.c $(distdir) - -# make needs to be told to make inclusions so that parallelized runs will -# not fail. - -stage1flex-skeletons.$(OBJEXT): $(SKELINCLUDES) -skeletons.$(OBJEXT): $(SKELINCLUDES) - -stage1flex-main.$(OBJEXT): parse.h -main.$(OBJEXT): parse.h - -stage1flex-yylex.$(OBJEXT): parse.h -yylex.$(OBJEXT): parse.h - -stage1flex-scan.$(OBJEXT): parse.h -stage1scan.$(OBJEXT): parse.h -scan.$(OBJEXT): parse.h - -# Run GNU indent on sources. Don't run this unless all the sources compile cleanly. -# -# Whole idea: -# 1. Check for .indent.pro, otherwise indent will use unknown -# settings, or worse, the GNU defaults.) -# 2. Check that this is GNU indent. -# 3. Make sure to process only the NON-generated .c and .h files. -# 4. Run indent twice per file. The first time is a test. -# Otherwise, indent overwrites your file even if it fails! -indentfiles = \ - buf.c \ - ccl.c \ - dfa.c \ - ecs.c \ - scanflags.c \ - filter.c \ - flexdef.h \ - gen.c \ - libmain.c \ - libyywrap.c \ - main.c \ - misc.c \ - nfa.c \ - options.c \ - options.h \ - regex.c \ - scanopt.c \ - scanopt.h \ - sym.c \ - tables.c \ - tables.h \ - tables_shared.c \ - tables_shared.h \ - tblcmp.c - -indent: $(top_srcdir)/.indent.pro - cd $(top_srcdir) && \ - for f in $(indentfiles); do \ - f=src/$$f; \ - echo indenting $$f; \ - INDENT_PROFILE=.indent.pro $(INDENT) <$$f >/dev/null && \ - INDENT_PROFILE=.indent.pro $(INDENT) $$f || \ - echo $$f FAILED to indent; \ - done; - -.PHONY: dist-hook-src indent diff --git a/src/local.mk b/src/local.mk new file mode 100644 index 000000000..5d0eb8dc9 --- /dev/null +++ b/src/local.mk @@ -0,0 +1,232 @@ +AM_YFLAGS = -d +AM_CPPFLAGS = -I$(srcdir)/src -DLOCALEDIR=\"$(localedir)\" +AM_CFLAGS = $(WARNINGFLAGS) +LIBS = @LIBS@ +pkgconfigdir = @pkgconfigdir@ + +m4 = @M4@ + +bin_PROGRAMS = flex +if ENABLE_BOOTSTRAP +noinst_PROGRAMS = stage1flex +if !CROSS +noinst_DATA = src/stage2compare +endif +endif + +if ENABLE_LIBFL +lib_LTLIBRARIES = libfl.la +pkgconfig_DATA = src/libfl.pc +endif +libfl_la_SOURCES = \ + src/libmain.c \ + src/libyywrap.c +libfl_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ + +stage1flex_SOURCES = \ + src/scan.l \ + $(COMMON_SOURCES) + +nodist_stage1flex_SOURCES = \ + $(SKELINCLUDES) + +if CROSS +stage1flex_LDADD = +stage1flex_SOURCES += \ + lib/malloc.c \ + lib/realloc.c +stage1flex_LINK = $(LIBTOOL) --tag=CC --mode=link $(CC_FOR_BUILD) \ + $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ + +$(stage1flex_OBJECTS): CC=$(CC_FOR_BUILD) +$(stage1flex_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD) -DUSE_CONFIG_FOR_BUILD +$(stage1flex_OBJECTS): CPP=$(CPP_FOR_BUILD) +$(stage1flex_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD) +$(stage1flex_OBJECTS): LDFLAGS=$(LDFLAGS_FOR_BUILD) +else +stage1flex_LDADD = $(LDADD) +stage1flex_LINK = $(LINK) +stage1flex_CFLAGS = $(AM_CFLAGS) +endif + +flex_SOURCES = \ + $(COMMON_SOURCES) + +nodist_flex_SOURCES = \ + $(SKELINCLUDES) + +if ENABLE_BOOTSTRAP +nodist_flex_SOURCES += src/stage1scan.c +else +flex_SOURCES += src/scan.l +endif + +COMMON_SOURCES = \ + src/buf.c \ + src/ccl.c \ + src/dfa.c \ + src/ecs.c \ + src/filter.c \ + src/flexdef.h \ + src/flexint.h \ + src/flexint_shared.h \ + src/gen.c \ + src/main.c \ + src/misc.c \ + src/nfa.c \ + src/options.c \ + src/options.h \ + src/parse.y \ + src/regex.c \ + src/scanflags.c \ + src/scanopt.c \ + src/scanopt.h \ + src/skeletons.c \ + src/sym.c \ + src/tables.c \ + src/tables.h \ + src/tables_shared.c \ + src/tables_shared.h \ + src/tblcmp.c \ + src/version.h \ + src/yylex.c + +LDADD = $(LIBOBJS) @LIBINTL@ + +$(LIBOBJS): $(LIBOBJDIR)$(am__dirstamp) + +include_HEADERS = \ + src/FlexLexer.h + +EXTRA_DIST += \ + src/c99-flex.skl \ + src/cpp-flex.skl \ + src/go-flex.skl \ + src/mkskel.sh \ + src/gettext.h \ + src/chkskel.sh + +MOSTLYCLEANFILES += \ + $(SKELINCLUDES) \ + src/stage1scan.c \ + src/stage2scan.c \ + src/stage2compare + +CLEANFILES += stage1flex$(EXEEXT) + +SKELINCLUDES = \ + src/cpp-flex.h \ + src/c99-flex.h \ + src/go-flex.h + +src/cpp-flex.h: src/cpp-flex.skl src/mkskel.sh src/flexint_shared.h src/tables_shared.h src/tables_shared.c + $(SHELL) $(srcdir)/src/mkskel.sh cpp $(srcdir)/src $(m4) $(VERSION) > $@.tmp + $(SHELL) $(srcdir)/src/chkskel.sh $@.tmp + mv -f $@.tmp $@ + +src/c99-flex.h: src/c99-flex.skl src/mkskel.sh + $(SHELL) $(srcdir)/src/mkskel.sh c99 $(srcdir)/src $(m4) $(VERSION) > $@.tmp + $(SHELL) $(srcdir)/src/chkskel.sh $@.tmp + mv -f $@.tmp $@ + +src/go-flex.h: src/go-flex.skl src/mkskel.sh + $(SHELL) $(srcdir)/src/mkskel.sh go $(srcdir)/src $(m4) $(VERSION) > $@.tmp + $(SHELL) $(srcdir)/src/chkskel.sh $@.tmp + mv -f $@.tmp $@ + +# The input and output file names are fixed for deterministic scanner +# generation. If scan.l is not modified by builders, stage1scan.c should +# be bit-identical to the scan.c pregenerated on release. +src/stage1scan.c: src/scan.l stage1flex$(EXEEXT) + ( cd $(srcdir)/src && $(abs_builddir)/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. +src/stage2scan.c: src/scan.l flex$(EXEEXT) src/stage1scan.c + ( cd $(srcdir)/src && $(abs_builddir)/flex$(EXEEXT) \ + $(AM_LFLAGS) $(LFLAGS) -o scan.c -t scan.l ) >$@ + +src/stage2compare: src/stage1scan.c + @rm -f src/stage2scan.c; \ + $(MAKE) $(AM_MAKEFLAGS) src/stage2scan.c; \ + echo Comparing stage1scan.c and stage2scan.c; \ + cmp src/stage1scan.c src/stage2scan.c || { \ + s=$$?; \ + echo "Bootstrap comparison failure!"; \ + exit $$s; \ + }; \ + echo Comparison successful.; \ + echo success >$@ + +dist-hook: dist-hook-src + +dist-hook-src: src/scan.l flex$(EXEEXT) + chmod u+w $(distdir)/src && \ + chmod u+w $(distdir)/src/scan.c && \ + ( cd $(srcdir)/src && $(abs_builddir)/flex$(EXEEXT) \ + -o scan.c -t scan.l ) >src/scan.c && \ + mv -f src/scan.c $(distdir)/src/scan.c + +# make needs to be told to make inclusions so that parallelized runs will +# not fail. + +src/stage1flex-skeletons.$(OBJEXT): $(SKELINCLUDES) +src/skeletons.$(OBJEXT): $(SKELINCLUDES) + +src/stage1flex-main.$(OBJEXT): src/parse.h +src/main.$(OBJEXT): src/parse.h + +src/stage1flex-yylex.$(OBJEXT): src/parse.h +src/yylex.$(OBJEXT): src/parse.h + +src/stage1flex-scan.$(OBJEXT): src/parse.h +src/stage1scan.$(OBJEXT): src/parse.h +src/scan.$(OBJEXT): src/parse.h + +# Run GNU indent on sources. Don't run this unless all the sources compile cleanly. +# +# Whole idea: +# 1. Check for .indent.pro, otherwise indent will use unknown +# settings, or worse, the GNU defaults.) +# 2. Check that this is GNU indent. +# 3. Make sure to process only the NON-generated .c and .h files. +# 4. Run indent twice per file. The first time is a test. +# Otherwise, indent overwrites your file even if it fails! +indentfiles = \ + src/buf.c \ + src/ccl.c \ + src/dfa.c \ + src/ecs.c \ + src/scanflags.c \ + src/filter.c \ + src/flexdef.h \ + src/gen.c \ + src/libmain.c \ + src/libyywrap.c \ + src/main.c \ + src/misc.c \ + src/nfa.c \ + src/options.c \ + src/options.h \ + src/regex.c \ + src/scanopt.c \ + src/scanopt.h \ + src/sym.c \ + src/tables.c \ + src/tables.h \ + src/tables_shared.c \ + src/tables_shared.h \ + src/tblcmp.c + +indent: $(top_srcdir)/.indent.pro + cd $(top_srcdir) && \ + for f in $(indentfiles); do \ + echo indenting $$f; \ + INDENT_PROFILE=.indent.pro $(INDENT) <$$f >/dev/null && \ + INDENT_PROFILE=.indent.pro $(INDENT) $$f || \ + echo $$f FAILED to indent; \ + done; + +.PHONY: dist-hook-src indent diff --git a/tests/Makefile.am b/tests/Makefile.am index fd94e67d4..7d9e55f0f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -320,7 +320,7 @@ pthread_pthread_LDADD = @LIBPTHREAD@ TESTOPTS = -L -FLEX = $(top_builddir)/src/flex +FLEX = $(top_builddir)/flex .l.c: $(FLEX) $(AM_V_LEX)$(FLEX) $(TESTOPTS) -o $@ $< From 8f276f752614092d91b329d5dbc40b7fe4d9ea73 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Fri, 10 May 2024 23:31:28 +0800 Subject: [PATCH 04/10] Move 'make indent' target to top-level Makefile.am --- Makefile.am | 22 +++++++++++++++++++++- src/local.mk | 22 ++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Makefile.am b/Makefile.am index 40da932ec..6f3c407a7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -58,6 +58,8 @@ MOSTLYCLEANFILES = CLEANFILES = +indentfiles = + include src/local.mk # Convenience targets to build libfl only @@ -86,6 +88,24 @@ ChangeLog: $(srcdir)/tools/git2cl $(srcdir)/tools/git2cl > $@ \ ; fi +# Run GNU indent on sources. Don't run this unless all the sources compile cleanly. +# +# Whole idea: +# 1. Check for .indent.pro, otherwise indent will use unknown +# settings, or worse, the GNU defaults.) +# 2. Check that this is GNU indent. +# 3. Make sure to process only the NON-generated .c and .h files. +# 4. Run indent twice per file. The first time is a test. +# Otherwise, indent overwrites your file even if it fails! + +indent: .indent.pro + for f in $(indentfiles); do \ + echo indenting $$f; \ + INDENT_PROFILE=.indent.pro $(INDENT) <$$f >/dev/null && \ + INDENT_PROFILE=.indent.pro $(INDENT) $$f || \ + echo $$f FAILED to indent; \ + done; + install-exec-hook: cd $(DESTDIR)$(bindir) && \ $(LN_S) -f flex$(EXEEXT) flex++$(EXEEXT) @@ -94,4 +114,4 @@ lint: shellcheck -f gcc tests/*.sh src/*.sh *.sh .PHONY: libfl install-libfl uninstall-libfl clean-libfl \ - ChangeLog lint + ChangeLog indent lint diff --git a/src/local.mk b/src/local.mk index 5d0eb8dc9..44b0e6922 100644 --- a/src/local.mk +++ b/src/local.mk @@ -185,16 +185,7 @@ src/stage1flex-scan.$(OBJEXT): src/parse.h src/stage1scan.$(OBJEXT): src/parse.h src/scan.$(OBJEXT): src/parse.h -# Run GNU indent on sources. Don't run this unless all the sources compile cleanly. -# -# Whole idea: -# 1. Check for .indent.pro, otherwise indent will use unknown -# settings, or worse, the GNU defaults.) -# 2. Check that this is GNU indent. -# 3. Make sure to process only the NON-generated .c and .h files. -# 4. Run indent twice per file. The first time is a test. -# Otherwise, indent overwrites your file even if it fails! -indentfiles = \ +indentfiles += \ src/buf.c \ src/ccl.c \ src/dfa.c \ @@ -220,13 +211,4 @@ indentfiles = \ src/tables_shared.h \ src/tblcmp.c -indent: $(top_srcdir)/.indent.pro - cd $(top_srcdir) && \ - for f in $(indentfiles); do \ - echo indenting $$f; \ - INDENT_PROFILE=.indent.pro $(INDENT) <$$f >/dev/null && \ - INDENT_PROFILE=.indent.pro $(INDENT) $$f || \ - echo $$f FAILED to indent; \ - done; - -.PHONY: dist-hook-src indent +.PHONY: dist-hook-src From b3d21da40c816edfd56dc525f79cdca4ad4efb52 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 9 May 2024 23:08:31 +0800 Subject: [PATCH 05/10] build: Rename 'FLEX' variable in doc/Makefile.am This change is a prerequisite for converting doc/Makefile.am for non-recursive use. --- doc/Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/Makefile.am b/doc/Makefile.am index b1f4de18a..f2e2b47aa 100755 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,7 +1,7 @@ if CROSS -FLEX = $(top_builddir)/stage1flex +FLEX_FOR_DOC = $(top_builddir)/stage1flex else -FLEX = $(top_builddir)/flex$(EXEEXT) +FLEX_FOR_DOC = $(top_builddir)/flex$(EXEEXT) endif TEXI2DVI = @TEXI2DVI@ -I $(srcdir)/../examples/manual/ @@ -38,10 +38,10 @@ CLEANFILES = \ flex.1: $(top_srcdir)/configure.ac $(top_srcdir)/src/cpp-flex.skl $(top_srcdir)/src/options.c $(top_srcdir)/src/options.h ( cd $(top_builddir) && \ - prog_name=`echo '$(FLEX)' | sed 's|^$(top_builddir)/||'` && \ + prog_name=`echo '$(FLEX_FOR_DOC)' | sed 's|^$(top_builddir)/||'` && \ $(MAKE) $(AM_MAKEFLAGS) $$prog_name \ ) - $(INSTALL) -m 700 $(FLEX) flex$(EXEEXT) + $(INSTALL) -m 700 $(FLEX_FOR_DOC) flex$(EXEEXT) $(HELP2MAN) \ --name='$(PACKAGE_NAME)' \ --section=1 \ From a9458e1d19184521818ff8830ddf1f73c6a35651 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 11 May 2024 00:02:07 +0800 Subject: [PATCH 06/10] build: Non-recursive makefile for 'doc' directory --- Makefile.am | 2 +- configure.ac | 1 - doc/Makefile.am | 51 ------------------------------------------------- doc/local.mk | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 53 deletions(-) delete mode 100755 doc/Makefile.am create mode 100644 doc/local.mk diff --git a/Makefile.am b/Makefile.am index 6f3c407a7..9a1cad642 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,7 +48,6 @@ dist_noinst_SCRIPTS = \ SUBDIRS = \ . \ - doc \ examples \ po \ tests \ @@ -60,6 +59,7 @@ CLEANFILES = indentfiles = +include doc/local.mk include src/local.mk # Convenience targets to build libfl only diff --git a/configure.ac b/configure.ac index e58c01280..2a8a32c81 100644 --- a/configure.ac +++ b/configure.ac @@ -215,7 +215,6 @@ AS_IF([test "$cross_compiling" = yes], AC_CONFIG_FILES( Makefile -doc/Makefile examples/Makefile examples/fastwc/Makefile examples/manual/Makefile diff --git a/doc/Makefile.am b/doc/Makefile.am deleted file mode 100755 index f2e2b47aa..000000000 --- a/doc/Makefile.am +++ /dev/null @@ -1,51 +0,0 @@ -if CROSS -FLEX_FOR_DOC = $(top_builddir)/stage1flex -else -FLEX_FOR_DOC = $(top_builddir)/flex$(EXEEXT) -endif - -TEXI2DVI = @TEXI2DVI@ -I $(srcdir)/../examples/manual/ -TEXI2PDF = @TEXI2PDF@ -I $(srcdir)/../examples/manual/ - -info_TEXINFOS = flex.texi -AM_MAKEINFOFLAGS = -I $(srcdir)/../examples/manual/ -dist_man_MANS = flex.1 -MAINTAINERCLEANFILES = flex.1 - -CLEANFILES = \ - *.aux \ - *.cp \ - *.cps \ - *.fn \ - *.fns \ - *.hk \ - *.hks \ - *.ky \ - *.log \ - *.op \ - *.ops\ - *.pg \ - *.toc \ - *.tp \ - *.tps \ - *.vr \ - *.vrs \ - flex - -# Use a fixed program name, without extension (such as ".exe"), for man -# page generation. 'help2man' strips directory prefix ("./") from the -# usage string, but not file extensions. - -flex.1: $(top_srcdir)/configure.ac $(top_srcdir)/src/cpp-flex.skl $(top_srcdir)/src/options.c $(top_srcdir)/src/options.h - ( cd $(top_builddir) && \ - prog_name=`echo '$(FLEX_FOR_DOC)' | sed 's|^$(top_builddir)/||'` && \ - $(MAKE) $(AM_MAKEFLAGS) $$prog_name \ - ) - $(INSTALL) -m 700 $(FLEX_FOR_DOC) flex$(EXEEXT) - $(HELP2MAN) \ - --name='$(PACKAGE_NAME)' \ - --section=1 \ - --source='The Flex Project' \ - --manual='Programming' \ - --output=$@ \ - ./flex diff --git a/doc/local.mk b/doc/local.mk new file mode 100644 index 000000000..89cca6b35 --- /dev/null +++ b/doc/local.mk @@ -0,0 +1,51 @@ +if CROSS +FLEX_FOR_DOC = $(top_builddir)/stage1flex +else +FLEX_FOR_DOC = $(top_builddir)/flex$(EXEEXT) +endif + +TEXI2DVI = @TEXI2DVI@ -I $(srcdir)/examples/manual/ +TEXI2PDF = @TEXI2PDF@ -I $(srcdir)/examples/manual/ + +info_TEXINFOS = doc/flex.texi +AM_MAKEINFOFLAGS = -I $(srcdir)/examples/manual/ +dist_man_MANS = doc/flex.1 +MAINTAINERCLEANFILES = doc/flex.1 + +CLEANFILES += \ + doc/*.aux \ + doc/*.cp \ + doc/*.cps \ + doc/*.fn \ + doc/*.fns \ + doc/*.hk \ + doc/*.hks \ + doc/*.ky \ + doc/*.log \ + doc/*.op \ + doc/*.ops \ + doc/*.pg \ + doc/*.toc \ + doc/*.tp \ + doc/*.tps \ + doc/*.vr \ + doc/*.vrs \ + doc/flex + +# Use a fixed program name, without extension (such as ".exe"), for man +# page generation. 'help2man' strips directory prefix ("./") from the +# usage string, but not file extensions. + +doc/flex.1: $(top_srcdir)/configure.ac $(top_srcdir)/src/cpp-flex.skl $(top_srcdir)/src/options.c $(top_srcdir)/src/options.h + ( cd $(top_builddir) && \ + prog_name=`echo '$(FLEX_FOR_DOC)' | sed 's|^$(top_builddir)/||'` && \ + $(MAKE) $(AM_MAKEFLAGS) $$prog_name \ + ) + $(INSTALL) -m 700 $(FLEX_FOR_DOC) doc/flex$(EXEEXT) + $(HELP2MAN) \ + --name='$(PACKAGE_NAME)' \ + --section=1 \ + --source='The Flex Project' \ + --manual='Programming' \ + --output=$@ \ + doc/flex From a46fdaff963c6b85780af462482a3600cb10a6f8 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 11 May 2024 00:28:03 +0800 Subject: [PATCH 07/10] build: doc/local.mk code simplification --- doc/local.mk | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/doc/local.mk b/doc/local.mk index 89cca6b35..44d5c6a3a 100644 --- a/doc/local.mk +++ b/doc/local.mk @@ -1,7 +1,7 @@ if CROSS -FLEX_FOR_DOC = $(top_builddir)/stage1flex +FLEX_FOR_DOC = stage1flex else -FLEX_FOR_DOC = $(top_builddir)/flex$(EXEEXT) +FLEX_FOR_DOC = flex$(EXEEXT) endif TEXI2DVI = @TEXI2DVI@ -I $(srcdir)/examples/manual/ @@ -36,11 +36,8 @@ CLEANFILES += \ # page generation. 'help2man' strips directory prefix ("./") from the # usage string, but not file extensions. -doc/flex.1: $(top_srcdir)/configure.ac $(top_srcdir)/src/cpp-flex.skl $(top_srcdir)/src/options.c $(top_srcdir)/src/options.h - ( cd $(top_builddir) && \ - prog_name=`echo '$(FLEX_FOR_DOC)' | sed 's|^$(top_builddir)/||'` && \ - $(MAKE) $(AM_MAKEFLAGS) $$prog_name \ - ) +doc/flex.1: $(srcdir)/configure.ac $(srcdir)/src/cpp-flex.skl $(srcdir)/src/options.c $(srcdir)/src/options.h + $(MAKE) $(AM_MAKEFLAGS) $(FLEX_FOR_DOC) $(INSTALL) -m 700 $(FLEX_FOR_DOC) doc/flex$(EXEEXT) $(HELP2MAN) \ --name='$(PACKAGE_NAME)' \ From 45fc7f39b8d9c8b4fc869a91543bbbefe60c7c9a Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 11 May 2024 00:02:07 +0800 Subject: [PATCH 08/10] build: Non-recursive makefile for 'examples' directory --- Makefile.am | 2 +- configure.ac | 3 -- examples/fastwc/{Makefile.am => local.mk} | 16 +++---- examples/{Makefile.am => local.mk} | 13 +++-- examples/manual/Makefile.am | 58 ----------------------- examples/manual/local.mk | 58 +++++++++++++++++++++++ 6 files changed, 73 insertions(+), 77 deletions(-) rename examples/fastwc/{Makefile.am => local.mk} (82%) rename examples/{Makefile.am => local.mk} (86%) delete mode 100644 examples/manual/Makefile.am create mode 100644 examples/manual/local.mk diff --git a/Makefile.am b/Makefile.am index 9a1cad642..f0d2b82c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,7 +48,6 @@ dist_noinst_SCRIPTS = \ SUBDIRS = \ . \ - examples \ po \ tests \ tools @@ -60,6 +59,7 @@ CLEANFILES = indentfiles = include doc/local.mk +include examples/local.mk include src/local.mk # Convenience targets to build libfl only diff --git a/configure.ac b/configure.ac index 2a8a32c81..a141974c4 100644 --- a/configure.ac +++ b/configure.ac @@ -215,9 +215,6 @@ AS_IF([test "$cross_compiling" = yes], AC_CONFIG_FILES( Makefile -examples/Makefile -examples/fastwc/Makefile -examples/manual/Makefile po/Makefile.in src/libfl.pc tools/Makefile diff --git a/examples/fastwc/Makefile.am b/examples/fastwc/local.mk similarity index 82% rename from examples/fastwc/Makefile.am rename to examples/fastwc/local.mk index b2831d986..dfc07e442 100644 --- a/examples/fastwc/Makefile.am +++ b/examples/fastwc/local.mk @@ -19,11 +19,11 @@ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE. -EXTRA_DIST = \ - wc5.l \ - wc4.l \ - wc3.l \ - wc2.l \ - wc1.l \ - mywc.c \ - README +EXTRA_DIST += \ + examples/fastwc/wc5.l \ + examples/fastwc/wc4.l \ + examples/fastwc/wc3.l \ + examples/fastwc/wc2.l \ + examples/fastwc/wc1.l \ + examples/fastwc/mywc.c \ + examples/fastwc/README diff --git a/examples/Makefile.am b/examples/local.mk similarity index 86% rename from examples/Makefile.am rename to examples/local.mk index 62688babb..85d7741f7 100644 --- a/examples/Makefile.am +++ b/examples/local.mk @@ -19,11 +19,10 @@ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE. -EXTRA_DIST = \ - testxxLexer.l \ - debflex.awk \ - README +EXTRA_DIST += \ + examples/testxxLexer.l \ + examples/debflex.awk \ + examples/README -SUBDIRS = \ - manual \ - fastwc +include examples/fastwc/local.mk +include examples/manual/local.mk diff --git a/examples/manual/Makefile.am b/examples/manual/Makefile.am deleted file mode 100644 index 24affe1b9..000000000 --- a/examples/manual/Makefile.am +++ /dev/null @@ -1,58 +0,0 @@ -# This file is part of flex. - -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: - -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. - -# Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. - -# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE. - -EXTRA_DIST = \ - ChangeLog \ - Makefile.examples \ - README \ - cat.lex \ - dates.lex \ - datetest.dat \ - eof_rules.lex \ - eof_test01.txt \ - eof_test02.txt \ - eof_test03.txt \ - example_er.lex \ - example_r.lex \ - example_nr.lex \ - expr.lex \ - expr.y \ - front.lex \ - front.y \ - j2t.lex \ - myname.lex \ - myname.txt \ - myname2.lex \ - numbers.lex \ - pas_include.lex \ - pascal.lex \ - reject.lex \ - replace.lex \ - string1.lex \ - string2.lex \ - strtest.dat \ - unput.lex \ - user_act.lex \ - userinit.lex \ - wc.lex \ - yymore.lex \ - yymore2.lex \ - yymoretest.dat diff --git a/examples/manual/local.mk b/examples/manual/local.mk new file mode 100644 index 000000000..726ddac54 --- /dev/null +++ b/examples/manual/local.mk @@ -0,0 +1,58 @@ +# This file is part of flex. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE. + +EXTRA_DIST += \ + examples/manual/ChangeLog \ + examples/manual/Makefile.examples \ + examples/manual/README \ + examples/manual/cat.lex \ + examples/manual/dates.lex \ + examples/manual/datetest.dat \ + examples/manual/eof_rules.lex \ + examples/manual/eof_test01.txt \ + examples/manual/eof_test02.txt \ + examples/manual/eof_test03.txt \ + examples/manual/example_er.lex \ + examples/manual/example_r.lex \ + examples/manual/example_nr.lex \ + examples/manual/expr.lex \ + examples/manual/expr.y \ + examples/manual/front.lex \ + examples/manual/front.y \ + examples/manual/j2t.lex \ + examples/manual/myname.lex \ + examples/manual/myname.txt \ + examples/manual/myname2.lex \ + examples/manual/numbers.lex \ + examples/manual/pas_include.lex \ + examples/manual/pascal.lex \ + examples/manual/reject.lex \ + examples/manual/replace.lex \ + examples/manual/string1.lex \ + examples/manual/string2.lex \ + examples/manual/strtest.dat \ + examples/manual/unput.lex \ + examples/manual/user_act.lex \ + examples/manual/userinit.lex \ + examples/manual/wc.lex \ + examples/manual/yymore.lex \ + examples/manual/yymore2.lex \ + examples/manual/yymoretest.dat From 3691fc6b473fbc7bd72f006a56bc1963e20760b5 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 11 May 2024 00:02:07 +0800 Subject: [PATCH 09/10] build: Non-recursive makefile for 'tools' directory --- Makefile.am | 4 ++-- configure.ac | 1 - tools/Makefile.am | 2 -- tools/local.mk | 2 ++ 4 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 tools/Makefile.am create mode 100644 tools/local.mk diff --git a/Makefile.am b/Makefile.am index f0d2b82c7..1046b9bc8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,8 +49,7 @@ dist_noinst_SCRIPTS = \ SUBDIRS = \ . \ po \ - tests \ - tools + tests MOSTLYCLEANFILES = @@ -61,6 +60,7 @@ indentfiles = include doc/local.mk include examples/local.mk include src/local.mk +include tools/local.mk # Convenience targets to build libfl only # These are actually wrappers around automake- and libtool-generated targets diff --git a/configure.ac b/configure.ac index a141974c4..dec7466c4 100644 --- a/configure.ac +++ b/configure.ac @@ -217,7 +217,6 @@ AC_CONFIG_FILES( Makefile po/Makefile.in src/libfl.pc -tools/Makefile tests/Makefile ) diff --git a/tools/Makefile.am b/tools/Makefile.am deleted file mode 100644 index 46743a669..000000000 --- a/tools/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -EXTRA_DIST = \ - git2cl diff --git a/tools/local.mk b/tools/local.mk new file mode 100644 index 000000000..f8b15be32 --- /dev/null +++ b/tools/local.mk @@ -0,0 +1,2 @@ +EXTRA_DIST += \ + tools/git2cl From 1d32e6152e132303ac1b7ee93a48a72eb35af92b Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Mon, 13 May 2024 22:17:52 +0800 Subject: [PATCH 10/10] refactor(build): Portable bootstrap in makefiles Avoid "target-specific variable values" (that looks like "target: variable=value") that works with GNU make only when building 'stage1flex'. A portable alternative is starting a sub-instance of 'make' with overridden variables (CC="$CC_FOR_BUILD" etc.). Make the bootstrap work even when EXEEXT and BUILD_EXEEXT might differ. The makefiles are designed that only the main instance of 'make' would handle the 'stage1bin/flex$(BUILD_EXEEXT)' so that no data contention can potentially occur. --- .gitignore | 1 + configure.ac | 4 +++ doc/.gitignore | 3 -- doc/local.mk | 44 +++++++++++++++++++----- src/local.mk | 92 ++++++++++++++++++++++++++++++++++++++------------ 5 files changed, 112 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index f3e3e84e0..c0690f1c7 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ Makefile /flex /flex.exe /libfl.la +/stage1bin/ /stage1flex /stage1flex.exe *.lo diff --git a/configure.ac b/configure.ac index dec7466c4..0eeaf38dd 100644 --- a/configure.ac +++ b/configure.ac @@ -127,6 +127,10 @@ AC_PATH_PROG([HELP2MAN], help2man, [\${top_srcdir}/build-aux/missing help2man]) AC_MSG_WARN(help2man: program not found: building man page will not work) ) +AM_CONDITIONAL([AUTO_BUILD_MAN_PAGE], + [test "$HELP2MAN" != "\${top_srcdir}/build-aux/missing help2man" && + { test "x$enable_bootstrap" = xyes || test "$cross_compiling" = no; }]) + AC_PATH_PROGS([TEXI2DVI], [gtexi2dvi texi2dvi], [\${top_srcdir}/build-aux/missing texi2dvi]) AS_IF([test "$TEXI2DVI" = "\${top_srcdir}/build-aux/missing texi2dvi"], AC_MSG_WARN(texi2dvi: program not found: building pdf version of manual will not work) diff --git a/doc/.gitignore b/doc/.gitignore index a685ba6e7..83b010866 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -25,6 +25,3 @@ flex.ps version.texi flex.html flex.t2p - -flex -flex.exe diff --git a/doc/local.mk b/doc/local.mk index 44d5c6a3a..dedcf6109 100644 --- a/doc/local.mk +++ b/doc/local.mk @@ -1,7 +1,7 @@ if CROSS -FLEX_FOR_DOC = stage1flex +FLEX_FOR_DOC = stage1bin/flex else -FLEX_FOR_DOC = flex$(EXEEXT) +FLEX_FOR_DOC = flex endif TEXI2DVI = @TEXI2DVI@ -I $(srcdir)/examples/manual/ @@ -33,16 +33,44 @@ CLEANFILES += \ doc/flex # Use a fixed program name, without extension (such as ".exe"), for man -# page generation. 'help2man' strips directory prefix ("./") from the -# usage string, but not file extensions. +# page generation. 'help2man' strips directory prefix from the usage +# string, but not file extensions. +# +# Note: Do NOT run the '$(FLEX_FOR_DOC)$(BUILD_EXEEXT)' target in +# another instance of 'make'! The scanner code also depends on the +# target and two 'make' instances may contest building the same file. -doc/flex.1: $(srcdir)/configure.ac $(srcdir)/src/cpp-flex.skl $(srcdir)/src/options.c $(srcdir)/src/options.h - $(MAKE) $(AM_MAKEFLAGS) $(FLEX_FOR_DOC) - $(INSTALL) -m 700 $(FLEX_FOR_DOC) doc/flex$(EXEEXT) +if AUTO_BUILD_MAN_PAGE +doc/flex.1: $(FLEX_FOR_DOC)$(BUILD_EXEEXT) + $(MKDIR_P) doc $(HELP2MAN) \ --name='$(PACKAGE_NAME)' \ --section=1 \ --source='The Flex Project' \ --manual='Programming' \ --output=$@ \ - doc/flex + ./$(FLEX_FOR_DOC) +else +doc/flex.1: $(srcdir)/configure.ac $(srcdir)/src/cpp-flex.skl $(srcdir)/src/options.c $(srcdir)/src/options.h + @option_text=''; \ + { test '$(FLEX_FOR_DOC)' = flex || \ + : $${option_text=" with --enable-bootstrap'"}; }; \ + echo "error: flex man page outdated; please install help2man and rerun 'configure'$${option_text}" 1>&2; + @false +endif + +distclean-local: distclean-local-doc + +# Clean the man page in the build directory only if it is not the +# source directory. + +distclean-local-doc: + test '$(srcdir)' = . || { \ + if mv -f $(srcdir)/doc/flex.1 $(srcdir)/doc/flex.1.tmp; then \ + s=0; else s=$$? || :; fi; \ + rm -f doc/flex.1 || :; \ + test "$$s" -ne 0 || \ + mv -f $(srcdir)/doc/flex.1.tmp $(srcdir)/doc/flex.1; \ + } + +.PHONY: distclean-local-doc diff --git a/src/local.mk b/src/local.mk index 44b0e6922..51ff3d78c 100644 --- a/src/local.mk +++ b/src/local.mk @@ -7,8 +7,9 @@ pkgconfigdir = @pkgconfigdir@ m4 = @M4@ bin_PROGRAMS = flex + +EXTRA_PROGRAMS = stage1flex if ENABLE_BOOTSTRAP -noinst_PROGRAMS = stage1flex if !CROSS noinst_DATA = src/stage2compare endif @@ -31,24 +32,70 @@ nodist_stage1flex_SOURCES = \ $(SKELINCLUDES) if CROSS -stage1flex_LDADD = + stage1flex_SOURCES += \ lib/malloc.c \ lib/realloc.c -stage1flex_LINK = $(LIBTOOL) --tag=CC --mode=link $(CC_FOR_BUILD) \ - $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ - -$(stage1flex_OBJECTS): CC=$(CC_FOR_BUILD) -$(stage1flex_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD) -DUSE_CONFIG_FOR_BUILD -$(stage1flex_OBJECTS): CPP=$(CPP_FOR_BUILD) -$(stage1flex_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD) -$(stage1flex_OBJECTS): LDFLAGS=$(LDFLAGS_FOR_BUILD) + +stage1flex_CPPFLAGS = -DUSE_CONFIG_FOR_BUILD $(AM_CPPFLAGS) + +# This also overrides AM_LIBTOOLFLAGS and AM_LDFLAGS +stage1flex_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(LIBTOOLFLAGS) \ + --mode=link $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) \ + $(LDFLAGS_FOR_BUILD) -o $@ + +stage1flex_LDADD = + else + +stage1flex_CPPFLAGS = $(AM_CPPFLAGS) + +stage1flex_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ + stage1flex_LDADD = $(LDADD) -stage1flex_LINK = $(LINK) -stage1flex_CFLAGS = $(AM_CFLAGS) + endif +# Suppress build warnings when compiling and linking stage1flex. +stage1flex_CFLAGS = + +# Override the 'stage1flex$(EXEEXT)' target automake would generate. +# If the compiler is not $(CC_FOR_BUILD) when this target is invoked, +# delete the object files that would be linked to 'stage1flex' to force +# rebuild all of them. + +stage1flex$(EXEEXT): $(stage1flex_OBJECTS) $(stage1flex_DEPENDENCIES) $(EXTRA_stage1flex_DEPENDENCIES) + @rm -f stage1flex$(EXEEXT) + { test 'x$(CC)' = 'x$(CC_FOR_BUILD)' && \ + test 'x$(CPP)' = 'x$(CPP_FOR_BUILD)'; } || \ + { rm -f src/stage1flex-*.$(OBJEXT) \ + src/$(DEPDIR)/stage1flex-*.Po || :; } + @{ test 'x$(CC)' = 'x$(CC_FOR_BUILD)' && test 'x$(CPP)' = 'x$(CPP_FOR_BUILD)'; } || { \ + echo 'error: stage1flex must be built with a native compiler' 1>&2; \ + exit 1; \ + } + $(AM_V_CCLD)$(stage1flex_LINK) $(stage1flex_OBJECTS) $(stage1flex_LDADD) $(LIBS) + +# The 'stage1bin/flex$(BUILD_EXEEXT)' target is not managed by +# automake. We use a different file name from the automake-managed +# 'stage1flex$(EXEEXT)' target to avoid clashing. + +stage1bin/flex$(BUILD_EXEEXT): + @if test 'x$(EXEEXT)' != 'x$(BUILD_EXEEXT)'; then rm -f stage1flex$(EXEEXT); else :; fi + @if test 'x$(OBJEXT)' != 'x$(BUILD_OBJEXT)'; then rm -f src/stage1flex-*.$(OBJEXT); else :; fi + $(MAKE) $(AM_MAKEFLAGS) \ + CC='$(CC_FOR_BUILD)' \ + CPP='$(CPP_FOR_BUILD)' \ + CFLAGS='$(CFLAGS_FOR_BUILD)' \ + CPPFLAGS='$(CPPFLAGS_FOR_BUILD)' \ + LDFLAGS='$(LDFLAGS_FOR_BUILD)' \ + EXEEXT='$(BUILD_EXEEXT)' \ + OBJEXT='$(BUILD_OBJEXT)' \ + stage1flex$(BUILD_EXEEXT) + $(MKDIR_P) stage1bin + $(INSTALL) -m 700 stage1flex$(BUILD_EXEEXT) $@ + flex_SOURCES = \ $(COMMON_SOURCES) @@ -108,11 +155,15 @@ EXTRA_DIST += \ MOSTLYCLEANFILES += \ $(SKELINCLUDES) \ + src/stage1flex-*.$(BUILD_OBJEXT) \ src/stage1scan.c \ src/stage2scan.c \ src/stage2compare -CLEANFILES += stage1flex$(EXEEXT) +CLEANFILES += \ + stage1bin/flex$(BUILD_EXEEXT) \ + stage1flex$(BUILD_EXEEXT) \ + stage1flex$(EXEEXT) SKELINCLUDES = \ src/cpp-flex.h \ @@ -137,21 +188,20 @@ src/go-flex.h: src/go-flex.skl src/mkskel.sh # The input and output file names are fixed for deterministic scanner # generation. If scan.l is not modified by builders, stage1scan.c should # be bit-identical to the scan.c pregenerated on release. -src/stage1scan.c: src/scan.l stage1flex$(EXEEXT) - ( cd $(srcdir)/src && $(abs_builddir)/stage1flex$(EXEEXT) \ +src/stage1scan.c: src/scan.l stage1bin/flex$(BUILD_EXEEXT) + ( cd $(srcdir)/src && $(abs_builddir)/stage1bin/flex$(BUILD_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. -src/stage2scan.c: src/scan.l flex$(EXEEXT) src/stage1scan.c +src/stage2scan.c: src/scan.l flex$(EXEEXT) ( cd $(srcdir)/src && $(abs_builddir)/flex$(EXEEXT) \ $(AM_LFLAGS) $(LFLAGS) -o scan.c -t scan.l ) >$@ -src/stage2compare: src/stage1scan.c - @rm -f src/stage2scan.c; \ - $(MAKE) $(AM_MAKEFLAGS) src/stage2scan.c; \ - echo Comparing stage1scan.c and stage2scan.c; \ + +src/stage2compare: src/stage1scan.c src/stage2scan.c + @echo Comparing stage1scan.c and stage2scan.c; \ cmp src/stage1scan.c src/stage2scan.c || { \ s=$$?; \ echo "Bootstrap comparison failure!"; \ @@ -211,4 +261,4 @@ indentfiles += \ src/tables_shared.h \ src/tblcmp.c -.PHONY: dist-hook-src +.PHONY: dist-hook-src src/stage2scan.c