restructure configure so pkg-config derived SSL flags get used
[rofl0r-ixchat.git] / plugins / perl / generate_header
blob760bffaa810e913587931c43933288edb2386357
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use File::Basename;
6 use Cwd 'abs_path';
8 my $dir = dirname(abs_path($0));
11 sub header {
12 my $file = shift;
13 open my $input, "<", $file or die "Couldn't open '$file':$!";
14 my @file = <$input>;
15 close $file;
16 return toc(@file);
19 sub toc {
20 my @lines = @_;
21 for( @lines ) {
22 if( /^\s*$/s ) { $_ = qq{"\\n"\n}; next; }
23 if( /^\s*#/ ) { $_ = qq{"\\n"\n}; next; }
24 s/\\/\\\\/g; # double the number of \'s
25 s/"/\\"/g;
26 s/^\s*/"/;
27 s/\n/\\n"\n/;
29 return @lines;
32 for my $files (
34 $dir . "/xchat.pm.h", # output file
35 $dir . "/lib/Xchat.pm", # input files
36 $dir . "/lib/Xchat/Embed.pm",
37 $dir . "/lib/Xchat/List/Network.pm",
38 $dir . "/lib/Xchat/List/Network/Entry.pm",
39 $dir . "/lib/Xchat/List/Network/AutoJoin.pm",
42 $dir . "/irc.pm.h", # output file
43 $dir . "/lib/IRC.pm" # input file
45 ) {
46 my ($output,@inputs) = @$files;
48 open my $header, ">", $output or die "Couldn't open '$output': $!";
50 print $header qq["BEGIN {\\n"\n];
51 for my $input ( @inputs ) {
52 (my $trimmed = $input) =~ s{^lib/}{};
53 print $header qq["\$INC{'$trimmed'} = 'Compiled into the plugin.';\\n"\n];
55 print $header qq["}\\n"\n];
57 for my $input ( @inputs ) {
58 print $header qq["{\\n"\n];
59 print $header qq{"#line 1 \\"$input\\"\\n"\n};
60 print $header header( $input );
61 print $header qq["}\\n"\n];
63 close $header;