Refactor flex and bison make rules

Numerous flex and bison make rules have appeared in the source tree
over time, and they are all virtually identical, so we can replace
them by pattern rules with some variables for customization.

Users of pgxs will also be able to benefit from this.
This commit is contained in:
Peter Eisentraut 2012-10-11 06:57:04 -04:00
parent ab112068b6
commit 8521d13194
11 changed files with 24 additions and 126 deletions

View File

@ -27,20 +27,6 @@ endif
# cubescan is compiled as part of cubeparse # cubescan is compiled as part of cubeparse
cubeparse.o: cubescan.c cubeparse.o: cubescan.c
cubeparse.c: cubeparse.y
ifdef BISON
$(BISON) $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
cubescan.c: cubescan.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
distprep: cubeparse.c cubescan.c distprep: cubeparse.c cubescan.c
maintainer-clean: maintainer-clean:

View File

@ -25,20 +25,6 @@ endif
# segscan is compiled as part of segparse # segscan is compiled as part of segparse
segparse.o: segscan.c segparse.o: segscan.c
segparse.c: segparse.y
ifdef BISON
$(BISON) $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
segscan.c: segscan.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
distprep: segparse.c segscan.c distprep: segparse.c segscan.c
maintainer-clean: maintainer-clean:

View File

@ -500,6 +500,22 @@ TAS = @TAS@
# #
# Global targets and rules # Global targets and rules
%.c: %.l
ifdef FLEX
$(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $<
@$(if $(FLEX_NO_BACKUP),if [ `wc -l <lex.backup` -eq 1 ]; then rm lex.backup; else echo "Scanner requires backup; see lex.backup." 1>&2; exit 1; fi)
else
@$(missing) flex $< '$@'
endif
%.c: %.y
$(if $(BISON_CHECK_CMD),$(BISON_CHECK_CMD))
ifdef BISON
$(BISON) $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
%.i: %.c %.i: %.c
$(CPP) $(CPPFLAGS) -o $@ $< $(CPP) $(CPPFLAGS) -o $@ $<

View File

@ -16,24 +16,8 @@ OBJS= bootparse.o bootstrap.o
include $(top_srcdir)/src/backend/common.mk include $(top_srcdir)/src/backend/common.mk
# bootscanner is compiled as part of bootparse # bootscanner is compiled as part of bootparse
bootparse.o: bootscanner.c bootparse.o: bootscanner.c
bootparse.c: bootparse.y
ifdef BISON
$(BISON) $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
bootscanner.c: bootscanner.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
# bootparse.c and bootscanner.c are in the distribution tarball, so # bootparse.c and bootscanner.c are in the distribution tarball, so
# they are not cleaned here. # they are not cleaned here.

View File

@ -17,8 +17,6 @@ OBJS= analyze.o gram.o keywords.o kwlookup.o parser.o \
parse_expr.o parse_func.o parse_node.o parse_oper.o parse_param.o \ parse_expr.o parse_func.o parse_node.o parse_oper.o parse_param.o \
parse_relation.o parse_target.o parse_type.o parse_utilcmd.o scansup.o parse_relation.o parse_target.o parse_type.o parse_utilcmd.o scansup.o
FLEXFLAGS = -CF -b -p -p
include $(top_srcdir)/src/backend/common.mk include $(top_srcdir)/src/backend/common.mk
@ -40,22 +38,12 @@ endif
gram.h: gram.c ; gram.h: gram.c ;
gram.c: gram.y gram.c: BISONFLAGS += -d
$(PERL) $(srcdir)/check_keywords.pl $< $(top_srcdir)/src/include/parser/kwlist.h gram.c: BISON_CHECK_CMD = $(PERL) $(srcdir)/check_keywords.pl $< $(top_srcdir)/src/include/parser/kwlist.h
ifdef BISON
$(BISON) -d $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
scan.c: scan.l scan.c: FLEXFLAGS = -CF -p -p
ifdef FLEX scan.c: FLEX_NO_BACKUP=yes
$(FLEX) $(FLEXFLAGS) -o'$@' $<
@if [ `wc -l <lex.backup` -eq 1 ]; then rm lex.backup; else echo "Scanner requires backup, see lex.backup."; exit 1; fi
else
@$(missing) flex $< $@
endif
# Force these dependencies to be known even without dependency info built: # Force these dependencies to be known even without dependency info built:

View File

@ -22,19 +22,5 @@ include $(top_srcdir)/src/backend/common.mk
# repl_scanner is compiled as part of repl_gram # repl_scanner is compiled as part of repl_gram
repl_gram.o: repl_scanner.c repl_gram.o: repl_scanner.c
repl_gram.c: repl_gram.y
ifdef BISON
$(BISON) $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
repl_scanner.c: repl_scanner.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
# repl_gram.c and repl_scanner.c are in the distribution tarball, so # repl_gram.c and repl_scanner.c are in the distribution tarball, so
# they are not cleaned here. # they are not cleaned here.

View File

@ -28,13 +28,6 @@ include $(top_srcdir)/src/backend/common.mk
# guc-file is compiled as part of guc # guc-file is compiled as part of guc
guc.o: guc-file.c guc.o: guc-file.c
guc-file.c: guc-file.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
# Note: guc-file.c is not deleted by 'make clean', # Note: guc-file.c is not deleted by 'make clean',
# since we want to ship it in distribution tarballs. # since we want to ship it in distribution tarballs.
clean: clean:

View File

@ -26,8 +26,6 @@ OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
sql_help.o \ sql_help.o \
$(WIN32RES) $(WIN32RES)
FLEXFLAGS = -Cfe -b -p -p
all: psql all: psql
@ -49,13 +47,8 @@ sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
# psqlscan is compiled as part of mainloop # psqlscan is compiled as part of mainloop
mainloop.o: psqlscan.c mainloop.o: psqlscan.c
psqlscan.c: psqlscan.l psqlscan.c: FLEXFLAGS = -Cfe -p -p
ifdef FLEX psqlscan.c: FLEX_NO_BACKUP=yes
$(FLEX) $(FLEXFLAGS) -o'$@' $<
@if [ `wc -l <lex.backup` -eq 1 ]; then rm lex.backup; else echo "Scanner requires backup, see lex.backup."; exit 1; fi
else
@$(missing) flex $< $@
endif
distprep: sql_help.h psqlscan.c distprep: sql_help.h psqlscan.c

View File

@ -42,20 +42,7 @@ ecpg: $(OBJS) | submake-libpgport
preproc.o: pgc.c preproc.o: pgc.c
preproc.h: preproc.c ; preproc.h: preproc.c ;
preproc.c: BISONFLAGS += -d
preproc.c: preproc.y
ifdef BISON
$(BISON) -d $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
pgc.c: pgc.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
$(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@ $(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@

View File

@ -55,15 +55,8 @@ uninstall-headers:
pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o: plpgsql.h pl_gram.h plerrcodes.h pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o: plpgsql.h pl_gram.h plerrcodes.h
# See notes in src/backend/parser/Makefile about the following two rules # See notes in src/backend/parser/Makefile about the following two rules
pl_gram.h: pl_gram.c ; pl_gram.h: pl_gram.c ;
pl_gram.c: BISONFLAGS += -d
pl_gram.c: pl_gram.y
ifdef BISON
$(BISON) -d $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
# generate plerrcodes.h from src/backend/utils/errcodes.txt # generate plerrcodes.h from src/backend/utils/errcodes.txt
plerrcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-plerrcodes.pl plerrcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-plerrcodes.pl

View File

@ -43,20 +43,6 @@ specparse.h: specparse.c ;
# specscanner is compiled as part of specparse # specscanner is compiled as part of specparse
specparse.o: specscanner.c specparse.o: specscanner.c
specparse.c: specparse.y
ifdef BISON
$(BISON) $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
specscanner.c: specscanner.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
# specparse.c and specscanner.c are in the distribution tarball, # specparse.c and specscanner.c are in the distribution tarball,
# so do not clean them here # so do not clean them here
clean distclean: clean distclean: