-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.PL
126 lines (100 loc) · 2.97 KB
/
Makefile.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Makefile.PL -- Makefile for eps2png
# Author : Johan Vromans
# Created On : Sat Jun 6 16:08:33 1998
# Last Modified By: Johan Vromans
# Last Modified On: Thu Mar 27 16:21:55 2008
# Update Count : 51
# Status : Released
use strict;
use warnings;
use Config;
use ExtUtils::MakeMaker;
my @scripts = qw (eps2png);
my $usrbin = "/usr/bin";
my $installscript = $Config{installscript};
print STDERR <<EOD unless $installscript eq $usrbin;
WARNING: This Makefile will install user accessible scripts.
The location for these scripts is $installscript.
You may consider to pass INSTALLSCRIPT=$usrbin (or some other
convenient location) to "make install".
EOD
print STDERR <<EOD;
IMPORTANT: This program requires Ghostscript and may require the
Portable Bitmap package (PBM) for additional conversions.
IMPORTANT: Due to ongoing development of the Ghostscript output
drivers, some tests may fail. See README for details.
EOD
$ENV{LC_ALL} = "C";
my $gs = `gs --help`;
unless ( $gs =~ /^available devices:/im ) {
warn("Ghostscript not found. Cannot continue\n");
exit 0;
}
foreach my $type ( qw(pngmono pnggray png16 png256 pngalpha jpeggray) ) {
next if $gs =~ / $type( |$)/m;
warn("No Ghostscript driver for $type. You won't be able to use these.\n");
}
foreach my $type ( qw(png16m jpeg) ) {
next if $gs =~ / $type( |$)/m;
warn("No Ghostscript driver for $type. Some tests will fail.\n");
}
my $needpbm = 0;
foreach my $type ( qw(gif gifmono) ) {
next if $gs =~ / $type( |$)/m;
warn("No Ghostscript driver for $type. PBM fallback required.\n");
$needpbm = 1;
}
my $x =
WriteMakefile
(
NAME => "$scripts[0]",
VERSION_FROM => "src/$scripts[0].pl",
($] >= 5.005) ?
( AUTHOR => 'Johan Vromans ([email protected])',
ABSTRACT => 'Convert EPS files to PNG, JPG or GIF' ) : (),
PREREQ_PM => { 'Getopt::Long' => 2.1 },
EXE_FILES => [ map { "script/$_" } @scripts ],
);
warn("Creating script\n");
open(my $src, "<", "src/eps2png.pl")
or die("src/eps2png.pl: $!\n");
open(my $dst, ">", "script/eps2png")
or die("script/eps2png: $!\n");
while ( <$src> ) {
s/my \$use_pbm = .;/my \$use_pbm = $needpbm;/;
print { $dst } $_;
}
close($dst);
close($src);
WriteSpecfile($x->{NAME}, $x->{VERSION});
1;
sub WriteSpecfile {
my $name = shift;
my $version = shift;
vcopy( _tag => "RPM spec file",
_dst => "$name.spec",
pkgname => $name,
version => $version,
);
}
sub vcopy {
my (%ctrl) = @_;
$ctrl{_src} ||= $ctrl{_dst} . ".in";
return unless open(my $fh, "<", $ctrl{_src});
print("Writing ", $ctrl{_tag}, "...\n") if $ctrl{_tag};
my $newfh;
open ($newfh, ">", $ctrl{_dst})
or die($ctrl{_dst}, ": $!\n");
my $pat = "(";
foreach ( grep { ! /^_/ } keys(%ctrl) ) {
$pat .= quotemeta($_) . "|";
}
chop($pat);
$pat .= ")";
$pat = qr/\[\%\s+$pat\s+\%\]/;
while ( <$fh> ) {
s/$pat/$ctrl{$1}/ge;
print { $newfh } $_;
}
close($newfh);
}