diff --git a/configure b/configure
index 930ee945be40c2e9506debd75708f545a52e6353..5d502ddc46eb46ed913bfd17c768f66531fdaf01 100755
--- a/configure
+++ b/configure
@@ -3244,7 +3244,7 @@ cat >>confdefs.h <<\_ACEOF
 #define PROFILE_PID_DIR 1
 _ACEOF
 
-    CFLAGS="$CFLAGS -pg"
+    CFLAGS="$CFLAGS -pg $PLATFORM_PROFILE_FLAGS"
   else
     { { echo "$as_me:$LINENO: error: --enable-profiling is supported only when using GCC" >&5
 echo "$as_me: error: --enable-profiling is supported only when using GCC" >&2;}
diff --git a/configure.in b/configure.in
index 10a87348b4d23f7ab37a5728fd99defc24a117d2..c4c0d8f4ba88a41f5da625d93d757878f607aa19 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $PostgreSQL: pgsql/configure.in,v 1.526 2007/09/12 14:28:55 tgl Exp $
+dnl $PostgreSQL: pgsql/configure.in,v 1.527 2007/09/21 02:33:46 tgl Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -307,8 +307,8 @@ fi
 if test "$enable_profiling" = yes && test "$ac_cv_prog_cc_g" = yes; then
   if test "$GCC" = yes; then
     AC_DEFINE([PROFILE_PID_DIR], 1, 
-           [Define to 1 to enable profiling. (--enable-profiling)])
-    CFLAGS="$CFLAGS -pg"
+           [Define to 1 to allow profiling output to be saved separately for each process.])
+    CFLAGS="$CFLAGS -pg $PLATFORM_PROFILE_FLAGS"
   else
     AC_MSG_ERROR([--enable-profiling is supported only when using GCC])
   fi
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index a0e451b0e0c5ff2bf6da24c2a49fb2741b1b1ec4..0f5839537691fcfacfb9b42174ffed6a7c362abc 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -617,7 +617,8 @@
 /* A string containing the version number, platform, and C compiler */
 #undef PG_VERSION_STR
 
-/* Define to 1 to enable profiling. (--enable-profiling) */
+/* Define to 1 to allow profiling output to be saved separately for each
+   process. */
 #undef PROFILE_PID_DIR
 
 /* Define to the necessary symbol if this constant uses a non-standard name on
diff --git a/src/template/linux b/src/template/linux
index dff0eca6f105854f8975cf1ef10654f0db7e3861..ed800d23f12933d83a96a7bbf20f6609b2715948 100644
--- a/src/template/linux
+++ b/src/template/linux
@@ -1,4 +1,7 @@
-# $PostgreSQL: pgsql/src/template/linux,v 1.29 2006/12/12 19:43:19 petere Exp $
+# $PostgreSQL: pgsql/src/template/linux,v 1.30 2007/09/21 02:33:46 tgl Exp $
 
 # Force _GNU_SOURCE on; plperl is broken with Perl 5.8.0 otherwise
 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+
+# If --enable-profiling is specified, we need -DLINUX_PROFILE
+PLATFORM_PROFILE_FLAGS="-DLINUX_PROFILE"