From: Karel Zak Date: Mon, 13 Nov 2023 13:16:03 +0000 (+0100) Subject: autotools: use stamp file to build filter parser, improve portability X-Git-Tag: v2.40-rc1~151^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55a460055204047a196efdc2826b3493ee0b6194;p=thirdparty%2Futil-linux.git autotools: use stamp file to build filter parser, improve portability * use .stamp files to generate .c and .h by only one flex and bison call * use bison --defines=HEADER rather than --header=, the --header is supported also by old bison version (like common bison 3.0.4) * make sure there is defined dependence between the scanner and parser .c and .h files (scanner need header from parser and vice-versa) * distribute .stamp files to avoid flex and bison for people who use sources from tarball (we distribute generated source files) Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/Makemodule.am b/libsmartcols/src/Makemodule.am index c0f0dfaef9..377888e81e 100644 --- a/libsmartcols/src/Makemodule.am +++ b/libsmartcols/src/Makemodule.am @@ -39,11 +39,49 @@ BUILT_SOURCES += libsmartcols/src/filter-parser.c \ EXTRA_DIST += libsmartcols/src/filter-parser.y \ libsmartcols/src/filter-scanner.l -libsmartcols/src/filter-parser.h libsmartcols/src/filter-parser.c: libsmartcols/src/filter-parser.y libsmartcols/src/filter-scanner.h - $(AM_V_YACC) $(BISON) $< --output=${basename $@}.c --header=${basename $@}.h +## Generate filter parser (YACC) and tokenizer (LEX) .c and .h files. +# +# Note that we need advanced bison and flex features and configuration +# directives to generated thread safe parser (usable in stared library), so +# it's probably a bad idea to use "-y" (posix compatible) as default in +# autotools. We also need to generate .c and .h files in the same time to avoid +# duplicate stuff. +# +SCOLS_YACC_BASENAME = libsmartcols/src/filter-parser +SCOLS_YACC_STEMP = $(SCOLS_YACC_BASENAME).stamp + +SCOLS_LEX_BASENAME = libsmartcols/src/filter-scanner +SCOLS_LEX_STEMP = $(SCOLS_LEX_BASENAME).stamp + + +$(SCOLS_YACC_STEMP): $(SCOLS_YACC_BASENAME).y + @rm -f $(SCOLS_YACC_STEMP).tmp + @touch -f $(SCOLS_YACC_STEMP).tmp + $(AM_V_YACC) $(BISON) $< --output=${basename $@}.c --defines=${basename $@}.h + @mv -f $(SCOLS_YACC_STEMP).tmp $@ + +$(SCOLS_YACC_BASENAME).c $(SCOLS_YACC_BASENAME).h: $(SCOLS_YACC_STEMP) + @test -f $@ || rm -f $(SCOLS_YACC_STEMP) + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(SCOLS_YACC_STEMP) + + +$(SCOLS_LEX_STEMP): $(SCOLS_LEX_BASENAME).l + @rm -f $(SCOLS_LEX_STEMP).tmp + @touch -f $(SCOLS_LEX_STEMP).tmp + $(AM_V_GEN) $(FLEX) --header-file=${basename $@}.h --outfile=${basename $@}.c $< + @mv -f $(SCOLS_LEX_STEMP).tmp $@ + +$(SCOLS_LEX_BASENAME).c $(SCOLS_LEX_BASENAME).h: $(SCOLS_LEX_STEMP) + @test -f $@ || rm -f $(SCOLS_LEX_STEMP) + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) $(SCOLS_LEX_STEMP) + +# Each part of the parser depends on the header files +$(SCOLS_LEX_BASENAME).c: $(SCOLS_YACC_BASENAME).h +$(SCOLS_YACC_BASENAME).c: $(SCOLS_LEX_BASENAME).h + +# Don't re-generate parser when use sources from tarball +EXTRA_DIST += $(SCOLS_YACC_STEMP) $(SCOLS_LEX_STEMP) -libsmartcols/src/filter-scanner.h libsmartcols/src/filter-scanner.c: libsmartcols/src/filter-scanner.l - $(AM_V_LEX) $(FLEX) --header-file=${basename $@}.h --outfile=${basename $@}.c $< libsmartcols_la_LIBADD = $(LDADD) libcommon.la