From 8521d131941be5a177270bc428fa8e684cd645b5 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 11 Oct 2012 06:57:04 -0400 Subject: [PATCH] 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. --- contrib/cube/Makefile | 14 -------------- contrib/seg/Makefile | 14 -------------- src/Makefile.global.in | 16 ++++++++++++++++ src/backend/bootstrap/Makefile | 16 ---------------- src/backend/parser/Makefile | 20 ++++---------------- src/backend/replication/Makefile | 14 -------------- src/backend/utils/misc/Makefile | 7 ------- src/bin/psql/Makefile | 11 ++--------- src/interfaces/ecpg/preproc/Makefile | 15 +-------------- src/pl/plpgsql/src/Makefile | 9 +-------- src/test/isolation/Makefile | 14 -------------- 11 files changed, 24 insertions(+), 126 deletions(-) diff --git a/contrib/cube/Makefile b/contrib/cube/Makefile index 19fd7dc658..b5cd5d0f33 100644 --- a/contrib/cube/Makefile +++ b/contrib/cube/Makefile @@ -27,20 +27,6 @@ endif # cubescan is compiled as part of cubeparse 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 maintainer-clean: diff --git a/contrib/seg/Makefile b/contrib/seg/Makefile index d84934c67f..fb9c5765c3 100644 --- a/contrib/seg/Makefile +++ b/contrib/seg/Makefile @@ -25,20 +25,6 @@ endif # segscan is compiled as part of segparse 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 maintainer-clean: diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 000bfd772a..fbaaaf995b 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -500,6 +500,22 @@ TAS = @TAS@ # # Global targets and rules +%.c: %.l +ifdef FLEX + $(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $< + @$(if $(FLEX_NO_BACKUP),if [ `wc -l &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 $(CPP) $(CPPFLAGS) -o $@ $< diff --git a/src/backend/bootstrap/Makefile b/src/backend/bootstrap/Makefile index a77d864800..672bc8b6d7 100644 --- a/src/backend/bootstrap/Makefile +++ b/src/backend/bootstrap/Makefile @@ -16,24 +16,8 @@ OBJS= bootparse.o bootstrap.o include $(top_srcdir)/src/backend/common.mk - # bootscanner is compiled as part of bootparse 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 # they are not cleaned here. diff --git a/src/backend/parser/Makefile b/src/backend/parser/Makefile index 1f48e16a76..0395bd5934 100644 --- a/src/backend/parser/Makefile +++ b/src/backend/parser/Makefile @@ -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_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 @@ -40,22 +38,12 @@ endif gram.h: gram.c ; -gram.c: gram.y - $(PERL) $(srcdir)/check_keywords.pl $< $(top_srcdir)/src/include/parser/kwlist.h -ifdef BISON - $(BISON) -d $(BISONFLAGS) -o $@ $< -else - @$(missing) bison $< $@ -endif +gram.c: BISONFLAGS += -d +gram.c: BISON_CHECK_CMD = $(PERL) $(srcdir)/check_keywords.pl $< $(top_srcdir)/src/include/parser/kwlist.h -scan.c: scan.l -ifdef FLEX - $(FLEX) $(FLEXFLAGS) -o'$@' $< - @if [ `wc -l $@ diff --git a/src/pl/plpgsql/src/Makefile b/src/pl/plpgsql/src/Makefile index 0db0dc5692..852b0c7ae4 100644 --- a/src/pl/plpgsql/src/Makefile +++ b/src/pl/plpgsql/src/Makefile @@ -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 # See notes in src/backend/parser/Makefile about the following two rules - pl_gram.h: pl_gram.c ; - -pl_gram.c: pl_gram.y -ifdef BISON - $(BISON) -d $(BISONFLAGS) -o $@ $< -else - @$(missing) bison $< $@ -endif +pl_gram.c: BISONFLAGS += -d # generate plerrcodes.h from src/backend/utils/errcodes.txt plerrcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-plerrcodes.pl diff --git a/src/test/isolation/Makefile b/src/test/isolation/Makefile index 482ac3ecb9..6579be148c 100644 --- a/src/test/isolation/Makefile +++ b/src/test/isolation/Makefile @@ -43,20 +43,6 @@ specparse.h: specparse.c ; # specscanner is compiled as part of specparse 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, # so do not clean them here clean distclean: