]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
autotools: use stamp file to build filter parser, improve portability
authorKarel Zak <kzak@redhat.com>
Mon, 13 Nov 2023 13:16:03 +0000 (14:16 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Nov 2023 21:25:47 +0000 (22:25 +0100)
* 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 <kzak@redhat.com>
libsmartcols/src/Makemodule.am

index c0f0dfaef9f2b7c7419742266a3b79bd62f5a1ab..377888e81ed944110509b78e598a1753c2235b5f 100644 (file)
@@ -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