Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 377 lines (309 sloc) 10.003 kb
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
1
2 use ExtUtils::MakeMaker;
3 use Cwd;
4 use Config;
5
6 $lext=$Config{'so'}; # Get extensions of libraries
88a763e libpng support for Win32
Tony Cook authored
7 $aext=$Config{'_a'};
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
8
9 #
10 # IM_INCPATH colon seperated list of paths to extra include paths
11 # IM_LIBPATH colon seperated list of paths to extra library paths
12 #
13 # IM_VERBOSE turns on verbose mode for the library finding and such
14 # IM_MANUAL to manually select which libraries are used and which not
15 # IM_ENABLE to programmatically select which libraries are used
16 # and which are not
17 # IM_NOLOG if true logging will not be compiled into the module
18 # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module
19 # do not use IM_DEBUG_MALLOC in production - this slows
20 # everything down by alot
21 # IM_CFLAGS Extra flags to pass to the compiler
22 # IM_LFLAGS Extra flags to pass to the linker
23 # IM_DFLAGS Extra flags to pass to the preprocessor
24
25
26 getenv(); # get environment variables
27 init(); # initialize global data
28 pathcheck(); # Check if directories exist
29
30 # Pick what libraries are used
31 if ($MANUAL) {
32 manual();
33 } else {
34 automatic();
35 if (exists $ENV{IM_ENABLE}) {
36 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
37 for my $key (keys %formats) {
38 delete $formats{$key} unless $en{$key};
39 }
40 }
41 }
42
43 # Make sure there isn't a clash between the gif libraries.
44 gifcheck();
45
46 for $frm(values %formats) {
47 $F_DEFINE .= ' -D'.$frm->{def};
48 $F_LIBS .= ' ' .$frm->{libfiles};
49 $F_OBJECT .= ' ' .$frm->{objfiles};
50 }
51
52 $F_INC = join(" ",map { (exists $definc{$_})?'':'-I'.$_ } @incs);
53 $F_LIBS = join(" ",map { '-L'.$_ } @libs).' '.$F_LIBS;
54
55 $OSLIBS = '';
56 $OSDEF = "-DOS_$^O";
57
58 if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
59 if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
60
61 @objs = qw(Imager.o draw.o image.o io.o iolayer.o log.o
62 gaussian.o conv.o pnm.o raw.o feat.o font.o
63 filters.o dynaload.o stackmach.o datatypes.o
64 regmach.o trans2.o quant.o);
65
66 %opts=(
67 'NAME' => 'Imager',
68 'VERSION_FROM' => 'Imager.pm',
69 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
70 'DEFINE' => "$F_DEFINE $EXTDEF $OSDEF $CFLAGS",
71 'INC' => "$DFLAGS $F_INC",
72 'OBJECT' => join(' ', @objs, $F_OBJECT)
73 );
74
75 if ($VERBOSE) { print Dumper(\%opts); }
76 mkdir('testout',0777); # since we cannot include it in the archive.
77 WriteMakefile(%opts);
78 exit;
79
80
81 sub MY::postamble {
82 '
83 dyntest.(MYEXTLIB) : dynfilt/Makefile
84 cd dynfilt && $(MAKE) $(PASTHRU)
85
86 lib/Imager/Regops.pm : regmach.h regops.perl
87 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
88 ';
89 }
90
91 # manual configuration of helper libraries
92
93 sub manual {
94 print <<EOF;
95
96 Please answer the following questions about
97 which formats are avaliable on your computer
98
99 press <return> to continue
100 EOF
101
102 <STDIN>; # eat one return
103
104 for $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
105 SWX:
106 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
107 print "Enable $frm support: ";
108 $gz=<STDIN>;
109 chomp($gz);
110 if ($gz =~ m/^(y|yes|n|no)/i) {
111 $gz=substr(lc($gz),0,1);
112 if ($gz eq 'n') {
113 delete $formats{$frm};
114 }
115 } else { goto SWX; }
116 }
117 }
118
119
120 # automatic configuration of helper libraries
121
122 sub automatic {
123 for $frm(keys %formats) {
124 delete $formats{$frm} if !checkformat($frm);
125 }
126 }
127
128
129 sub gifcheck {
130 if ($formats{'gif'} and $formats{'ungif'}) {
131 print "ungif and gif can not coexist - removing ungif support\n";
132 delete $formats{'ungif'};
133 }
134 my @dirs;
135 for my $frm (grep $formats{$_}, qw(gif ungif)) {
136 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
137 }
138 my $minor = 0;
139 my $major = 0;
140 FILES: for my $dir (@dirs) {
141 my $h = "$dir/gif_lib.h";
142 open H, "< $h" or next;
143 while (<H>) {
144 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
145 $major = $1;
146 $minor = $2;
147 close H;
148 last FILES;
149 }
150 }
151 close H;
152 }
153
154 # we need the version in a #ifdefable form
155
156 $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor";
157 }
158
159
160 sub gd {
161 my($path,$chk)=@_;
162
163 # print "checking path $path\n";
164 if ( !opendir(DH,$path) ) {
165 warn "Cannot open dir $path: $!\n";
166 return;
167 }
168 my @l=grep { $chk->($_) } readdir(DH);
169 # print @l;
170 close(DH);
171 return map $path, @l;
172 }
173
174
175 sub checkformat {
176 my $frm=shift;
177 my $libchk=$formats{$frm}{'libcheck'};
178 my $incchk=$formats{$frm}{'inccheck'};
179
180 my @l;
181 for my $lp (@libs) {
182 push(@l, gd($lp,$libchk));
183 }
184
185 my @i;
186 for my $ip (@incs) {
187 push(@i, gd($ip,$incchk));
188 }
189
190 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
191 $formats{$frm}{incdir} = \@i;
192 $formats{$frm}{libdir} = \@l;
193 return scalar(@i && @l);
194 }
195
196
197
198
199 sub pathcheck {
200 if ($VERBOSE) {
201 print "pathcheck\n";
202 print " Include paths:\n";
203 for (@incs) { print $_,"\n"; }
204 }
205 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @incs;
206
207 if ($VERBOSE) {
208 print "\nLibrary paths:\n";
209 for (@incs) { print $_,"\n"; }
210 }
211 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @libs;
212 print "\ndone.\n";
213 }
214
215
216 # Format data initialization
217
218 # format definition is:
219 # defines needed
220 # default include path
221 # files needed for include (boolean perl code)
222 # default lib path
223 # libs needed
224 # files needed for link (boolean perl code)
225 # object files needed for the format
226
227
228 sub init {
229
230 @definc{'/usr/include'}=();
231 @incs=(qw(/usr/include /usr/local/include /usr/include/freetype /usr/local/include/freetype), split /:/, $INCPATH );
232 @libs=(split(/ /, $Config{'libpth'}), split(/:/, $LIBPATH) );
88a763e libpng support for Win32
Tony Cook authored
233 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
234 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
235 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
236 }
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
237
238 $formats{'jpeg'}={
239 order=>'21',
240 def=>'HAVE_LIBJPEG',
241 inccheck=>sub { $_[0] eq 'jpeglib.h' },
242 libcheck=>sub { $_[0] eq 'libjpeg.a' or $_ eq "libjpeg.$lext" },
243 libfiles=>'-ljpeg',
244 objfiles=>'jpeg.o',
245 docs=>q{
246 In order to use jpeg with this module you need to have libjpeg
247 installed on your computer}
248 };
249
250 $formats{'tiff'}={
251 order=>'23',
252 def=>'HAVE_LIBTIFF',
253 inccheck=>sub { $_[0] eq 'tiffio.h' },
254 libcheck=>sub { $_[0] eq 'libtiff.a' or $_ eq "libtiff.$lext" },
255 libfiles=>'-ltiff',
256 objfiles=>'tiff.o',
257 docs=>q{
258 In order to use tiff with this module you need to have libtiff
259 installed on your computer}
260 };
261
262 $formats{'png'}={
263 order=>'22',
264 def=>'HAVE_LIBPNG',
265 inccheck=>sub { $_[0] eq 'png.h' },
88a763e libpng support for Win32
Tony Cook authored
266 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
267 libfiles=>'-lpng -lz',
268 objfiles=>'png.o',
269 docs=>q{
270 Png stands for Portable Network Graphics and is intended as
271 a replacement for gif on the web. It is patent free and
272 is recommended by the w3c, you need libpng to use these formats}
273 };
274
275 $formats{'gif'}={
276 order=>'20',
277 def=>'HAVE_LIBGIF',
278 inccheck=>sub { $_[0] eq 'gif_lib.h' },
279 libcheck=>sub { $_[0] eq 'libgif.a' or $_[0] eq "libgif.$lext" },
280 libfiles=>'-lgif',
281 objfiles=>'gif.o',
282 docs=>q{
283 gif is the de facto standard for webgraphics at the moment,
284 it does have some patent problems. If you have giflib and
285 are not in violation with the unisys patent you should use
286 this instead of the 'ungif' option. Note that they cannot
287 be in use at the same time}
288 };
289
290 $formats{'ungif'}={
291 order=>'21',
292 def=>'HAVE_LIBGIF',
293 inccheck=>sub { $_[0] eq 'gif_lib.h' },
294 libcheck=>sub { $_[0] eq 'libungif.a' or $_[0] eq "libungif.$lext" },
295 libfiles=>'-lungif',
296 objfiles=>'gif.o',
297 docs=>q{
298 gif is the de facto standard for webgraphics at the moment,
299 it does have some patent problems. If you have libungif and
300 want to create images free from LZW patented compression you
301 should use this option instead of the 'gif' option}
302 };
303
304 $formats{'T1-fonts'}={
305 order=>'30',
306 def=>'HAVE_LIBT1',
307 inccheck=>sub { $_[0] eq 't1lib.h' },
308 libcheck=>sub { $_[0] eq 'libt1.a' or $_[0] eq "libt1.$lext" },
309 libfiles=>'-lt1',
310 objfiles=>'',
311 docs=>q{
312 postscript t1 fonts are scalable fonts. They can include
313 ligatures and kerning information and generally yield good
314 visual quality. We depend on libt1 to rasterize the fonts
315 for use in images.}
316 };
317
318 $formats{'TT-fonts'}={
319 order=>'31',
320 def=>'HAVE_LIBTT',
321 inccheck=>sub { $_[0] eq 'freetype.h' },
322 libcheck=>sub { $_[0] eq 'libttf.a' or $_[0] eq "libttf.$lext" },
323 libfiles=>'-lttf',
324 objfiles=>'',
325 docs=>q{
326 Truetype fonts are scalable fonts. They can include
327 kerning and hinting information and generally yield good
328 visual quality esp on low resultions. The freetype library is
329 used to rasterize for us. The only drawback is that there
330 are alot of badly designed fonts out there.}
331 };
332 # Make fix indent
333 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
334 }
335
336
337
338 sub gen {
339 my $V = $ENV{$_[0]};
340 defined($V) ? $V : "";
341 }
342
343
344 # Get information from environment variables
345
346 sub getenv {
347
348 ($VERBOSE,
349 $INCPATH,
350 $LIBPATH,
351 $NOLOG,
352 $DEBUG_MALLOC,
353 $MANUAL,
354 $CFLAGS,
355 $LFLAGS,
356 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
357 IM_INCPATH
358 IM_LIBPATH
359 IM_NOLOG
360 IM_DEBUG_MALLOC
361 IM_MANUAL
362 IM_CFLAGS
363 IM_LFLAGS
364 IM_DFLAGS);
365
366 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
367
368 if ($NOLOG) { print "Logging not compiled into module\n"; }
369 else { $EXTDEF.=' -DIMAGER_LOG'; }
370
371 if ($DEBUG_MALLOC) {
372 $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
373 print "Malloc debugging enabled\n";
374 }
375
376 }
Something went wrong with that request. Please try again.