1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

psql: Output dir and dependency generation for sql_help

This is in preparation for building postgres with meson / ninja.

When building with meson, commands are run at the root of the build tree. Add
an option to put build output into the appropriate place. This can be utilized
by src/tools/msvc/ for a minor simplification, which also provides some
coverage for the new option.

To deal with dependencies to the variable set of input files to this script,
add an option to generate a dependency file (which meson / ninja can consume).

Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/5e216522-ba3c-f0e6-7f97-5276d0270029@enterprisedb.com
This commit is contained in:
Andres Freund
2022-07-18 11:57:31 -07:00
parent a91242b1bc
commit 7c3c2cb9ae
3 changed files with 32 additions and 19 deletions

View File

@ -56,7 +56,7 @@ sql_help.c: sql_help.h
touch $@ touch $@
sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml) sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
$(PERL) $< $(REFDOCDIR) $* $(PERL) $< --docdir $(REFDOCDIR) --basename $*
psqlscanslash.c: FLEXFLAGS = -Cfe -p -p psqlscanslash.c: FLEXFLAGS = -Cfe -p -p
psqlscanslash.c: FLEX_NO_BACKUP=yes psqlscanslash.c: FLEX_NO_BACKUP=yes

View File

@ -21,21 +21,24 @@
use strict; use strict;
use warnings; use warnings;
use Getopt::Long;
my $docdir = $ARGV[0] or die "$0: missing required argument: docdir\n"; my $docdir = '';
my $hfile = $ARGV[1] . '.h' my $outdir = '.';
or die "$0: missing required argument: output file\n"; my $depfile = '';
my $cfile = $ARGV[1] . '.c'; my $hfilebasename = '';
my $hfilebasename; GetOptions(
if ($hfile =~ m!.*/([^/]+)$!) 'docdir=s' => \$docdir,
{ 'outdir=s' => \$outdir,
$hfilebasename = $1; 'basename=s' => \$hfilebasename,
} 'depfile=s' => \$depfile,) or die "$0: wrong arguments";
else
{ $docdir or die "$0: missing required argument: docdir\n";
$hfilebasename = $hfile; $hfilebasename or die "$0: missing required argument: basename\n";
}
my $hfile = $hfilebasename . '.h';
my $cfile = $hfilebasename . '.c';
my $define = $hfilebasename; my $define = $hfilebasename;
$define =~ tr/a-z/A-Z/; $define =~ tr/a-z/A-Z/;
@ -43,11 +46,18 @@ $define =~ s/\W/_/g;
opendir(DIR, $docdir) opendir(DIR, $docdir)
or die "$0: could not open documentation source dir '$docdir': $!\n"; or die "$0: could not open documentation source dir '$docdir': $!\n";
open(my $hfile_handle, '>', $hfile) open(my $hfile_handle, '>', "$outdir/$hfile")
or die "$0: could not open output file '$hfile': $!\n"; or die "$0: could not open output file '$hfile': $!\n";
open(my $cfile_handle, '>', $cfile) open(my $cfile_handle, '>', "$outdir/$cfile")
or die "$0: could not open output file '$cfile': $!\n"; or die "$0: could not open output file '$cfile': $!\n";
my $depfile_handle;
if ($depfile)
{
open($depfile_handle, '>', $depfile)
or die "$0: could not open output file '$depfile': $!\n";
}
print $hfile_handle "/* print $hfile_handle "/*
* *** Do not change this file by hand. It is automatically * *** Do not change this file by hand. It is automatically
* *** generated from the DocBook documentation. * *** generated from the DocBook documentation.
@ -98,6 +108,9 @@ foreach my $file (sort readdir DIR)
my ($cmdid, @cmdnames, $cmddesc, $cmdsynopsis); my ($cmdid, @cmdnames, $cmddesc, $cmdsynopsis);
$file =~ /\.sgml$/ or next; $file =~ /\.sgml$/ or next;
print $depfile_handle "$outdir/$cfile $outdir/$hfile: $docdir/$file\n"
if ($depfile);
open(my $fh, '<', "$docdir/$file") or next; open(my $fh, '<', "$docdir/$file") or next;
my $filecontent = join('', <$fh>); my $filecontent = join('', <$fh>);
close $fh; close $fh;
@ -216,4 +229,5 @@ print $hfile_handle "
close $cfile_handle; close $cfile_handle;
close $hfile_handle; close $hfile_handle;
close $depfile_handle if ($depfile);
closedir DIR; closedir DIR;

View File

@ -692,9 +692,8 @@ sub GenerateFiles
if (IsNewer('src/bin/psql/sql_help.h', 'src/bin/psql/create_help.pl')) if (IsNewer('src/bin/psql/sql_help.h', 'src/bin/psql/create_help.pl'))
{ {
print "Generating sql_help.h...\n"; print "Generating sql_help.h...\n";
chdir('src/bin/psql'); my $psql = 'src/bin/psql';
system("perl create_help.pl ../../../doc/src/sgml/ref sql_help"); system("perl $psql/create_help.pl --docdir doc/src/sgml/ref --outdir $psql --basename sql_help");
chdir('../../..');
} }
if (IsNewer('src/common/kwlist_d.h', 'src/include/parser/kwlist.h')) if (IsNewer('src/common/kwlist_d.h', 'src/include/parser/kwlist.h'))