From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 10 Nov 2009 23:12:13 +0000 (+0000)
Subject: Do not build psql's flex module on its own, but instead include it in
X-Git-Tag: REL8_5_ALPHA3~139
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90bfe99963aaf22830c4a9b989c525858bf7ff46;p=postgresql

Do not build psql's flex module on its own, but instead include it in
mainloop.c.  This ensures that postgres_fe.h is read before including
any system headers, which is necessary to avoid problems on some platforms
where we make nondefault selections of feature macros for stdio.h or
other headers.  We have had this policy for flex modules in the backend
for many years, but for some reason it was not applied to psql.
Per trouble report from Alexandra Roy and diagnosis by Albe Laurenz.
---

diff --git a/src/bin/psql/Makefile b/src/bin/psql/Makefile
index 9a5feadba4..27445d635b 100644
--- a/src/bin/psql/Makefile
+++ b/src/bin/psql/Makefile
@@ -5,7 +5,7 @@
 # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.66 2009/09/18 05:00:42 petere Exp $
+# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.67 2009/11/10 23:12:13 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -21,7 +21,7 @@ override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/p
 
 OBJS=	command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
 	startup.o prompt.o variables.o large_obj.o print.o describe.o \
-	psqlscan.o tab-complete.o mbprint.o dumputils.o keywords.o kwlookup.o \
+	tab-complete.o mbprint.o dumputils.o keywords.o kwlookup.o \
 	sql_help.o \
 	$(WIN32RES)
 
@@ -45,6 +45,9 @@ sql_help.c: sql_help.h ;
 sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
 	$(PERL) $< $(REFDOCDIR) $*
 
+# psqlscan is compiled as part of mainloop
+mainloop.o: psqlscan.c
+
 psqlscan.c: psqlscan.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
index c63219bd13..b39b2a44e5 100644
--- a/src/bin/psql/mainloop.c
+++ b/src/bin/psql/mainloop.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2009, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.95 2009/06/11 14:49:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/mainloop.c,v 1.96 2009/11/10 23:12:13 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "mainloop.h"
@@ -407,3 +407,13 @@ MainLoop(FILE *source)
 
 	return successResult;
 }	/* MainLoop() */
+
+
+/*
+ * psqlscan.c is #include'd here instead of being compiled on its own.
+ * This is because we need postgres_fe.h to be read before any system
+ * include files, else things tend to break on platforms that have
+ * multiple infrastructures for stdio.h and so on.  flex is absolutely
+ * uncooperative about that, so we can't compile psqlscan.c on its own.
+ */
+#include "psqlscan.c"