xref: /openbsd-src/gnu/usr.bin/perl/utils/json_pp.PL (revision 256a93a44f36679bee503f12e49566c2183f6181)
1898184e3Ssthen#!/usr/local/bin/perl
2898184e3Ssthen
3898184e3Ssthenuse Config;
4898184e3Ssthenuse File::Basename qw(&basename &dirname);
5898184e3Ssthenuse Cwd;
6898184e3Ssthen
7898184e3Ssthen# List explicitly here the variables you want Configure to
8898184e3Ssthen# generate.  Metaconfig only looks for shell variables, so you
9898184e3Ssthen# have to mention them as if they were shell variables, not
10898184e3Ssthen# %Config entries.  Thus you write
11898184e3Ssthen#  $startperl
12898184e3Ssthen# to ensure Configure will look for $Config{startperl}.
13898184e3Ssthen
14898184e3Ssthen# This forces PL files to create target in same directory as PL file.
15898184e3Ssthen# This is so that make depend always knows where to find PL derivatives.
16898184e3Ssthenmy $origdir = cwd;
17898184e3Ssthenchdir dirname($0);
18898184e3Ssthenmy $file = basename($0, '.PL');
19898184e3Ssthen$file .= '.com' if $^O eq 'VMS';
20898184e3Ssthen
215759b3d2Safresh1open OUT, '>', $file or die "Can't create $file: $!";
22898184e3Ssthen
23898184e3Ssthenprint "Extracting $file (with variable substitutions)\n";
24898184e3Ssthen
25898184e3Ssthen# In this section, perl variables will be expanded during extraction.
26898184e3Ssthen# You can use $Config{...} to use Configure variables.
27898184e3Ssthen
28898184e3Ssthenprint OUT <<"!GROK!THIS!";
29898184e3Ssthen$Config{startperl}
30898184e3Ssthen    eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
31*256a93a4Safresh1	if 0; # ^ Run only under a shell
32898184e3Ssthen!GROK!THIS!
33898184e3Ssthen
34898184e3Ssthenuse File::Spec;
35898184e3Ssthen
36898184e3Ssthenmy $script = File::Spec->catfile(
37898184e3Ssthen            File::Spec->catdir(
38898184e3Ssthen                File::Spec->updir, qw[cpan JSON-PP bin]
39898184e3Ssthen            ), "json_pp");
40898184e3Ssthen
415759b3d2Safresh1if (open(IN, '<', $script)) {
42898184e3Ssthen    print OUT <IN>;
43898184e3Ssthen    close IN;
44898184e3Ssthen} else {
45898184e3Ssthen    die "$0: cannot find '$script'\n";
46898184e3Ssthen}
47898184e3Ssthen
48898184e3Ssthenclose OUT or die "Can't close $file: $!";
49898184e3Ssthenchmod 0755, $file or die "Can't reset permissions for $file: $!\n";
50898184e3Ssthenexec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
51898184e3Ssthenchdir $origdir;
52