Hi all, When working on extensions or packaging, one can do some grep-ing on pg_config.h to get PG_VERSION_NUM to do version-related operations. An example of that is the Makefile of plv8 using --include-dir with perl and a regex: https://github.com/plv8/plv8/blob/master/Makefile Wouldn't it be more simple to expose PG_VERSION_NUM in pg_config with a new option? Like that for example: $ pg_config --version-num 90500
Attached is a patch implementing the idea. Regards, -- Michael
diff --git a/doc/src/sgml/ref/pg_config-ref.sgml b/doc/src/sgml/ref/pg_config-ref.sgml index 0210f63..6297f02 100644 --- a/doc/src/sgml/ref/pg_config-ref.sgml +++ b/doc/src/sgml/ref/pg_config-ref.sgml @@ -275,6 +275,15 @@ </varlistentry> <varlistentry> + <term><option>--version-num</option></> + <listitem> + <para> + Print the version of <productname>PostgreSQL</> as a number. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-?</></term> <term><option>--help</></term> <listitem> diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c index 9b1f95d..8b261d4 100644 --- a/src/bin/pg_config/pg_config.c +++ b/src/bin/pg_config/pg_config.c @@ -382,6 +382,14 @@ show_version(bool all) printf("PostgreSQL " PG_VERSION "\n"); } +static void +show_version_num(bool all) +{ + if (all) + printf("VERSION_NUM = "); + printf("%d\n", PG_VERSION_NUM); +} + /* * Table of known information items @@ -418,6 +426,7 @@ static const InfoItem info_items[] = { {"--ldflags_sl", show_ldflags_sl}, {"--libs", show_libs}, {"--version", show_version}, + {"--version-num", show_version_num}, {NULL, NULL} }; @@ -454,6 +463,7 @@ help(void) printf(_(" --ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built\n")); printf(_(" --libs show LIBS value used when PostgreSQL was built\n")); printf(_(" --version show the PostgreSQL version\n")); + printf(_(" --version-num show the PostgreSQL version as a number\n")); printf(_(" -?, --help show this help, then exit\n")); printf(_("\nWith no arguments, all known items are shown.\n\n")); printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers