Commit | Line | Data |
---|---|---|
ea9e6c3f | 1 | #!perl -w |
02d1d628 AMH |
2 | use ExtUtils::MakeMaker; |
3 | use Cwd; | |
4 | use Config; | |
07ea6c21 | 5 | use File::Spec; |
02d1d628 | 6 | |
02d1d628 AMH |
7 | # |
8 | # IM_INCPATH colon seperated list of paths to extra include paths | |
9 | # IM_LIBPATH colon seperated list of paths to extra library paths | |
10 | # | |
11 | # IM_VERBOSE turns on verbose mode for the library finding and such | |
12 | # IM_MANUAL to manually select which libraries are used and which not | |
13 | # IM_ENABLE to programmatically select which libraries are used | |
14 | # and which are not | |
15 | # IM_NOLOG if true logging will not be compiled into the module | |
16 | # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module | |
17 | # do not use IM_DEBUG_MALLOC in production - this slows | |
18 | # everything down by alot | |
19 | # IM_CFLAGS Extra flags to pass to the compiler | |
20 | # IM_LFLAGS Extra flags to pass to the linker | |
21 | # IM_DFLAGS Extra flags to pass to the preprocessor | |
f4dbac50 | 22 | # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support |
02d1d628 AMH |
23 | |
24 | ||
25 | getenv(); # get environment variables | |
26 | init(); # initialize global data | |
27 | pathcheck(); # Check if directories exist | |
28 | ||
e11d297f TC |
29 | my @defines; |
30 | ||
02d1d628 AMH |
31 | # Pick what libraries are used |
32 | if ($MANUAL) { | |
33 | manual(); | |
34 | } else { | |
35 | automatic(); | |
36 | if (exists $ENV{IM_ENABLE}) { | |
37 | my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE}; | |
38 | for my $key (keys %formats) { | |
39 | delete $formats{$key} unless $en{$key}; | |
40 | } | |
41 | } | |
42 | } | |
43 | ||
44 | # Make sure there isn't a clash between the gif libraries. | |
45 | gifcheck(); | |
46 | ||
07ea6c21 | 47 | my $lib_cflags = ''; |
e11d297f TC |
48 | for my $frmkey (keys %formats) { |
49 | my $frm = $formats{$frmkey}; | |
50 | push @defines, [ $frm->{def}, 1, "$frmkey available" ]; | |
02d1d628 AMH |
51 | $F_LIBS .= ' ' .$frm->{libfiles}; |
52 | $F_OBJECT .= ' ' .$frm->{objfiles}; | |
07ea6c21 | 53 | $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags}; |
02d1d628 AMH |
54 | } |
55 | ||
ea9e6c3f TC |
56 | $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_, |
57 | grep !exists $definc{$_}, @incs; | |
58 | $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS; | |
02d1d628 AMH |
59 | |
60 | $OSLIBS = ''; | |
61 | $OSDEF = "-DOS_$^O"; | |
62 | ||
63 | if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } | |
64 | if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } | |
65 | ||
9982a307 AMH |
66 | @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o |
67 | log.o gaussian.o conv.o pnm.o raw.o feat.o font.o | |
02d1d628 | 68 | filters.o dynaload.o stackmach.o datatypes.o |
2df3535a | 69 | regmach.o trans2.o quant.o error.o convert.o |
261f91c5 | 70 | map.o tags.o palimg.o maskimg.o img16.o rotate.o |
737a830c | 71 | bmp.o tga.o rgb.o color.o fills.o imgdouble.o); |
02d1d628 AMH |
72 | |
73 | %opts=( | |
74 | 'NAME' => 'Imager', | |
75 | 'VERSION_FROM' => 'Imager.pm', | |
76 | 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS", | |
e11d297f | 77 | 'DEFINE' => "$OSDEF $CFLAGS", |
07ea6c21 | 78 | 'INC' => "$lib_cflags $DFLAGS $F_INC", |
de2b8bae TC |
79 | 'OBJECT' => join(' ', @objs, $F_OBJECT), |
80 | clean => { FILES=>'testout' }, | |
02d1d628 AMH |
81 | ); |
82 | ||
29316bdb TC |
83 | if ($ExtUtils::MakeMaker::VERSION > 6.06) { |
84 | $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson'; | |
ca508100 TC |
85 | $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; |
86 | } | |
29316bdb TC |
87 | if ($ExtUtils::MakeMaker::VERSION > 6.10) { |
88 | $opts{NO_META} = 1; | |
89 | } | |
ca508100 | 90 | |
e11d297f TC |
91 | make_imconfig(\@defines); |
92 | ||
02d1d628 AMH |
93 | if ($VERBOSE) { print Dumper(\%opts); } |
94 | mkdir('testout',0777); # since we cannot include it in the archive. | |
95 | WriteMakefile(%opts); | |
4dce694d | 96 | |
02d1d628 AMH |
97 | exit; |
98 | ||
99 | ||
100 | sub MY::postamble { | |
101 | ' | |
faa9b3e7 | 102 | dyntest.$(MYEXTLIB) : dynfilt/Makefile |
02d1d628 AMH |
103 | cd dynfilt && $(MAKE) $(PASTHRU) |
104 | ||
105 | lib/Imager/Regops.pm : regmach.h regops.perl | |
106 | $(PERL) regops.perl regmach.h lib/Imager/Regops.pm | |
e11d297f TC |
107 | |
108 | imconfig.h: Makefile.PL | |
109 | $(ECHO) "imconfig.h out-of-date with respect to $?" | |
110 | $(PERLRUN) Makefile.PL | |
111 | $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <==" | |
02d1d628 AMH |
112 | '; |
113 | } | |
114 | ||
115 | # manual configuration of helper libraries | |
116 | ||
117 | sub manual { | |
118 | print <<EOF; | |
119 | ||
120 | Please answer the following questions about | |
121 | which formats are avaliable on your computer | |
122 | ||
123 | press <return> to continue | |
124 | EOF | |
125 | ||
126 | <STDIN>; # eat one return | |
127 | ||
2646b26c | 128 | for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) { |
02d1d628 AMH |
129 | SWX: |
130 | if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; } | |
131 | print "Enable $frm support: "; | |
09fd3468 | 132 | $gz = <STDIN>; |
02d1d628 AMH |
133 | chomp($gz); |
134 | if ($gz =~ m/^(y|yes|n|no)/i) { | |
135 | $gz=substr(lc($gz),0,1); | |
136 | if ($gz eq 'n') { | |
137 | delete $formats{$frm}; | |
138 | } | |
139 | } else { goto SWX; } | |
140 | } | |
141 | } | |
142 | ||
143 | ||
144 | # automatic configuration of helper libraries | |
145 | ||
146 | sub automatic { | |
147 | for $frm(keys %formats) { | |
148 | delete $formats{$frm} if !checkformat($frm); | |
149 | } | |
150 | } | |
151 | ||
152 | ||
153 | sub gifcheck { | |
5f5fe73e | 154 | if ($formats{'gif'} and $formats{'ungif'}) { |
02d1d628 AMH |
155 | print "ungif and gif can not coexist - removing ungif support\n"; |
156 | delete $formats{'ungif'}; | |
157 | } | |
5f5fe73e AMH |
158 | |
159 | RETR: | |
f4dbac50 | 160 | if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) { |
5f5fe73e AMH |
161 | print <<EOFF; |
162 | ||
163 | You have libgif or libungif installed. They are both known to have | |
164 | bugs. Imager can crash or display other strange behaviour after | |
165 | reading or writing gif images. Some of the gif tests can even fail | |
166 | since they stress some parts of the buggy code. | |
167 | ||
f1967c11 TC |
168 | libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one |
169 | patch to have all the bugs fixed, see README for details. | |
170 | ||
171 | Of course it's possible your operating system distributor has patched | |
172 | all of these problems and you have nothing to worry about. | |
0b836ff8 | 173 | |
5f5fe73e AMH |
174 | Do you want to remove gif support? [Y/n] |
175 | EOFF | |
176 | my $resp = <STDIN>; | |
177 | chomp($resp); | |
178 | if ($resp ne "n") { | |
179 | delete $formats{'gif'}; | |
180 | delete $formats{'ungif'}; | |
09fd3468 | 181 | return; |
5f5fe73e AMH |
182 | } |
183 | } | |
09fd3468 AMH |
184 | |
185 | for my $frm (qw(gif ungif)) { | |
186 | checkformat($frm) if ($MANUAL and $formats{$frm}); | |
187 | } | |
188 | ||
02d1d628 AMH |
189 | my @dirs; |
190 | for my $frm (grep $formats{$_}, qw(gif ungif)) { | |
191 | push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir}; | |
192 | } | |
193 | my $minor = 0; | |
194 | my $major = 0; | |
195 | FILES: for my $dir (@dirs) { | |
196 | my $h = "$dir/gif_lib.h"; | |
197 | open H, "< $h" or next; | |
198 | while (<H>) { | |
199 | if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) { | |
200 | $major = $1; | |
201 | $minor = $2; | |
202 | close H; | |
203 | last FILES; | |
204 | } | |
205 | } | |
206 | close H; | |
207 | } | |
208 | ||
209 | # we need the version in a #ifdefable form | |
4dce694d | 210 | |
e11d297f TC |
211 | push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ]; |
212 | push @defines, [ IM_GIFMINOR, $minor ]; | |
02d1d628 AMH |
213 | } |
214 | ||
215 | ||
216 | sub gd { | |
217 | my($path,$chk)=@_; | |
218 | ||
219 | # print "checking path $path\n"; | |
220 | if ( !opendir(DH,$path) ) { | |
221 | warn "Cannot open dir $path: $!\n"; | |
222 | return; | |
223 | } | |
224 | my @l=grep { $chk->($_) } readdir(DH); | |
225 | # print @l; | |
226 | close(DH); | |
227 | return map $path, @l; | |
228 | } | |
229 | ||
230 | ||
231 | sub checkformat { | |
232 | my $frm=shift; | |
2646b26c | 233 | |
07ea6c21 TC |
234 | my $code = $formats{$frm}{'code'}; |
235 | if ($code) { | |
236 | return 1 if $code->($formats{$frm}, $frm); | |
237 | } | |
238 | ||
02d1d628 AMH |
239 | my $libchk=$formats{$frm}{'libcheck'}; |
240 | my $incchk=$formats{$frm}{'inccheck'}; | |
241 | ||
242 | my @l; | |
243 | for my $lp (@libs) { | |
244 | push(@l, gd($lp,$libchk)); | |
245 | } | |
246 | ||
247 | my @i; | |
248 | for my $ip (@incs) { | |
f8e9bc07 | 249 | push(@i, $ip) if $incchk->($ip,$frm); |
02d1d628 AMH |
250 | } |
251 | ||
252 | printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found')); | |
253 | $formats{$frm}{incdir} = \@i; | |
254 | $formats{$frm}{libdir} = \@l; | |
255 | return scalar(@i && @l); | |
256 | } | |
257 | ||
258 | ||
259 | ||
260 | ||
261 | sub pathcheck { | |
262 | if ($VERBOSE) { | |
263 | print "pathcheck\n"; | |
264 | print " Include paths:\n"; | |
265 | for (@incs) { print $_,"\n"; } | |
266 | } | |
3a6bb91b | 267 | @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs; |
02d1d628 AMH |
268 | |
269 | if ($VERBOSE) { | |
270 | print "\nLibrary paths:\n"; | |
271 | for (@incs) { print $_,"\n"; } | |
272 | } | |
3a6bb91b | 273 | @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs; |
02d1d628 AMH |
274 | print "\ndone.\n"; |
275 | } | |
276 | ||
277 | ||
278 | # Format data initialization | |
279 | ||
280 | # format definition is: | |
281 | # defines needed | |
282 | # default include path | |
283 | # files needed for include (boolean perl code) | |
284 | # default lib path | |
285 | # libs needed | |
286 | # files needed for link (boolean perl code) | |
287 | # object files needed for the format | |
288 | ||
289 | ||
290 | sub init { | |
291 | ||
292 | @definc{'/usr/include'}=(); | |
2646b26c TC |
293 | @incs=(split(/\Q$Config{path_sep}/, $INCPATH)); |
294 | if ($Config{locincpth}) { | |
6552acfe | 295 | push @incs, grep -d, split ' ', $Config{locincpth}; |
2646b26c | 296 | } |
88a763e2 TC |
297 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
298 | push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE}; | |
2646b26c | 299 | } |
6552acfe | 300 | push @incs, grep -d, |
2646b26c TC |
301 | qw(/sw/include |
302 | /usr/include/freetype2 | |
303 | /usr/local/include/freetype2 | |
304 | /usr/local/include/freetype1/freetype | |
305 | /usr/include /usr/local/include /usr/include/freetype | |
306 | /usr/local/include/freetype); | |
307 | ||
308 | @libs= split(/\Q$Config{path_sep}/,$LIBPATH); | |
309 | if ($Config{loclibpth}) { | |
6552acfe | 310 | push @libs, grep -d, split ' ', $Config{loclibpth}; |
2646b26c | 311 | } |
6552acfe | 312 | push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'}); |
2646b26c | 313 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
88a763e2 TC |
314 | push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB}; |
315 | } | |
faa9b3e7 TC |
316 | if ($^O eq 'cygwin') { |
317 | push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api'; | |
318 | push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api'; | |
319 | } | |
02d1d628 | 320 | |
2646b26c TC |
321 | my $lext=$Config{'so'}; # Get extensions of libraries |
322 | my $aext=$Config{'_a'}; | |
323 | ||
02d1d628 AMH |
324 | $formats{'jpeg'}={ |
325 | order=>'21', | |
326 | def=>'HAVE_LIBJPEG', | |
f8e9bc07 | 327 | inccheck=>sub { -e catfile($_[0], 'jpeglib.h') }, |
50ee6f9c | 328 | libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" }, |
02d1d628 AMH |
329 | libfiles=>'-ljpeg', |
330 | objfiles=>'jpeg.o', | |
331 | docs=>q{ | |
332 | In order to use jpeg with this module you need to have libjpeg | |
333 | installed on your computer} | |
334 | }; | |
335 | ||
336 | $formats{'tiff'}={ | |
337 | order=>'23', | |
338 | def=>'HAVE_LIBTIFF', | |
f8e9bc07 | 339 | inccheck=>sub { -e catfile($_[0], 'tiffio.h') }, |
76c8a0a4 | 340 | libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" }, |
02d1d628 AMH |
341 | libfiles=>'-ltiff', |
342 | objfiles=>'tiff.o', | |
343 | docs=>q{ | |
344 | In order to use tiff with this module you need to have libtiff | |
345 | installed on your computer} | |
346 | }; | |
347 | ||
348 | $formats{'png'}={ | |
349 | order=>'22', | |
350 | def=>'HAVE_LIBPNG', | |
f8e9bc07 | 351 | inccheck=>sub { -e catfile($_[0], 'png.h') }, |
88a763e2 | 352 | libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" }, |
02d1d628 AMH |
353 | libfiles=>'-lpng -lz', |
354 | objfiles=>'png.o', | |
355 | docs=>q{ | |
356 | Png stands for Portable Network Graphics and is intended as | |
357 | a replacement for gif on the web. It is patent free and | |
07ea6c21 TC |
358 | is recommended by the w3c, you need libpng to use these formats}, |
359 | code => \&png_probe, | |
02d1d628 AMH |
360 | }; |
361 | ||
362 | $formats{'gif'}={ | |
363 | order=>'20', | |
364 | def=>'HAVE_LIBGIF', | |
f8e9bc07 | 365 | inccheck=>sub { -e catfile($_[0], 'gif_lib.h') }, |
e02451e0 | 366 | libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" }, |
02d1d628 AMH |
367 | libfiles=>'-lgif', |
368 | objfiles=>'gif.o', | |
369 | docs=>q{ | |
370 | gif is the de facto standard for webgraphics at the moment, | |
371 | it does have some patent problems. If you have giflib and | |
372 | are not in violation with the unisys patent you should use | |
373 | this instead of the 'ungif' option. Note that they cannot | |
374 | be in use at the same time} | |
375 | }; | |
376 | ||
377 | $formats{'ungif'}={ | |
378 | order=>'21', | |
379 | def=>'HAVE_LIBGIF', | |
f8e9bc07 | 380 | inccheck=>sub { -e catfile($_[0], 'gif_lib.h') }, |
e02451e0 | 381 | libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" }, |
02d1d628 AMH |
382 | libfiles=>'-lungif', |
383 | objfiles=>'gif.o', | |
384 | docs=>q{ | |
385 | gif is the de facto standard for webgraphics at the moment, | |
386 | it does have some patent problems. If you have libungif and | |
387 | want to create images free from LZW patented compression you | |
388 | should use this option instead of the 'gif' option} | |
389 | }; | |
390 | ||
391 | $formats{'T1-fonts'}={ | |
392 | order=>'30', | |
393 | def=>'HAVE_LIBT1', | |
f8e9bc07 | 394 | inccheck=>sub { -e catfile($_[0], 't1lib.h') }, |
faa9b3e7 | 395 | libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" }, |
02d1d628 AMH |
396 | libfiles=>'-lt1', |
397 | objfiles=>'', | |
398 | docs=>q{ | |
399 | postscript t1 fonts are scalable fonts. They can include | |
400 | ligatures and kerning information and generally yield good | |
401 | visual quality. We depend on libt1 to rasterize the fonts | |
402 | for use in images.} | |
403 | }; | |
404 | ||
f8e9bc07 TC |
405 | $formats{'TT-fonts'}= |
406 | { | |
407 | order=>'31', | |
408 | def=>'HAVE_LIBTT', | |
409 | inccheck=>sub { -e catfile($_[0], 'freetype.h') | |
410 | && !-e catfile($_[0], 'fterrors.h') }, | |
411 | libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" }, | |
412 | libfiles=>'-lttf', | |
413 | objfiles=>'', | |
414 | docs=>q{ | |
415 | Truetype fonts are scalable fonts. They can include | |
416 | kerning and hinting information and generally yield good | |
417 | visual quality esp on low resultions. The freetype library is | |
418 | used to rasterize for us. The only drawback is that there | |
419 | are alot of badly designed fonts out there.} | |
02d1d628 | 420 | }; |
faa9b3e7 TC |
421 | $formats{'w32'} = { |
422 | order=>40, | |
423 | def=>'HAVE_WIN32', | |
f8e9bc07 | 424 | inccheck=>sub { -e catfile($_[0], 'windows.h') }, |
faa9b3e7 TC |
425 | libcheck=>sub { lc $_[0] eq 'gdi32.lib' |
426 | || lc $_[0] eq 'libgdi32.a' }, | |
427 | libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '', | |
428 | objfiles=>'win32.o', | |
429 | docs => <<DOCS | |
430 | Uses the Win32 GDI for rendering text. | |
431 | ||
432 | This currently only works on under normal Win32 and cygwin. | |
433 | DOCS | |
434 | }; | |
435 | $formats{'freetype2'} = { | |
436 | order=>'29', | |
437 | def=>'HAVE_FT2', | |
f8e9bc07 | 438 | inccheck=>sub { -e catfile($_[0], 'ft2build.h') }, |
faa9b3e7 TC |
439 | libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" }, |
440 | libfiles=>'-lfreetype', | |
441 | objfiles=>'freetyp2.o', | |
07ea6c21 | 442 | docs=><<DOCS, |
faa9b3e7 | 443 | Freetype 2 supports both Truetype and Type 1 fonts, both of which are |
f8e9bc07 | 444 | scalable. It also supports a variety of other fonts. |
faa9b3e7 | 445 | DOCS |
07ea6c21 | 446 | code => \&freetype2_probe, |
faa9b3e7 | 447 | }; |
02d1d628 AMH |
448 | # Make fix indent |
449 | for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } | |
450 | } | |
451 | ||
452 | ||
453 | ||
454 | sub gen { | |
455 | my $V = $ENV{$_[0]}; | |
456 | defined($V) ? $V : ""; | |
457 | } | |
458 | ||
459 | ||
460 | # Get information from environment variables | |
461 | ||
462 | sub getenv { | |
463 | ||
464 | ($VERBOSE, | |
465 | $INCPATH, | |
466 | $LIBPATH, | |
467 | $NOLOG, | |
468 | $DEBUG_MALLOC, | |
469 | $MANUAL, | |
470 | $CFLAGS, | |
471 | $LFLAGS, | |
472 | $DFLAGS) = map { gen $_ } qw(IM_VERBOSE | |
473 | IM_INCPATH | |
474 | IM_LIBPATH | |
475 | IM_NOLOG | |
476 | IM_DEBUG_MALLOC | |
477 | IM_MANUAL | |
478 | IM_CFLAGS | |
479 | IM_LFLAGS | |
480 | IM_DFLAGS); | |
481 | ||
482 | if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);} | |
483 | ||
484 | if ($NOLOG) { print "Logging not compiled into module\n"; } | |
e11d297f TC |
485 | else { |
486 | push @defines, [ IMAGER_LOG => 1, "Logging system" ]; | |
487 | } | |
02d1d628 AMH |
488 | |
489 | if ($DEBUG_MALLOC) { | |
e11d297f | 490 | push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ]; |
02d1d628 AMH |
491 | print "Malloc debugging enabled\n"; |
492 | } | |
493 | ||
494 | } | |
07ea6c21 | 495 | |
e11d297f TC |
496 | sub make_imconfig { |
497 | my ($defines) = @_; | |
498 | ||
499 | open CONFIG, "> imconfig.h" | |
500 | or die "Cannot create imconfig.h: $!\n"; | |
501 | print CONFIG <<EOS; | |
502 | /* This file is automatically generated by Makefile.PL. | |
503 | Don't edit this file, since any changes will be lost */ | |
504 | ||
505 | #ifndef IMAGER_IMCONFIG_H | |
506 | #define IMAGER_IMCONFIG_H | |
507 | EOS | |
508 | for my $define (@$defines) { | |
509 | if ($define->[2]) { | |
510 | print CONFIG "\n/*\n $define->[2]\n*/\n\n"; | |
511 | } | |
512 | print CONFIG "#define $define->[0] $define->[1]\n"; | |
513 | } | |
514 | print CONFIG "\n#endif\n"; | |
515 | close CONFIG; | |
516 | } | |
517 | ||
07ea6c21 TC |
518 | # probes for freetype2 by trying to run freetype-config |
519 | sub freetype2_probe { | |
520 | my ($frm, $frmkey) = @_; | |
521 | ||
522 | is_exe('freetype-config') or return; | |
523 | ||
524 | my $cflags = `freetype-config --cflags` | |
525 | and !$? or return; | |
526 | chomp $cflags; | |
527 | ||
528 | $frm->{cflags} = $cflags; | |
529 | my $lflags = `freetype-config --libs` | |
530 | and !$? or return; | |
531 | chomp $lflags; | |
532 | $frm->{libfiles} = $lflags; | |
533 | ||
534 | printf "%10s: configured via freetype-config\n", $frmkey; | |
535 | ||
536 | return 1; | |
537 | } | |
538 | ||
539 | # probes for libpng via pkg-config | |
540 | sub png_probe { | |
541 | my ($frm, $frmkey) = @_; | |
542 | ||
543 | is_exe('pkg-config') or return; | |
544 | ||
545 | my $cflags; | |
546 | my $config; | |
547 | for my $check_conf (qw(libpng libpng12 libpng10)) { | |
548 | $cflags = `pkg-config $check_conf --cflags`; | |
549 | if ($cflags && !$?) { | |
550 | $config = $check_conf; | |
551 | last; | |
552 | } | |
553 | } | |
554 | $config or return; | |
555 | ||
556 | my $lflags = `pkg-config $config --libs` | |
557 | and !$? or return; | |
558 | ||
559 | chomp $cflags; | |
560 | chomp $lflags; | |
561 | $frm->{cflags} = $cflags; | |
562 | $frm->{libfiles} = $lflags; | |
563 | ||
564 | printf "%10s: configured via `pkg-config $config ...`\n", $frmkey; | |
565 | ||
566 | return 1; | |
567 | } | |
568 | ||
569 | sub catfile { | |
570 | return File::Spec->catfile(@_); | |
571 | } | |
572 | ||
573 | sub is_exe { | |
574 | my ($name) = @_; | |
575 | ||
576 | for my $dir (File::Spec->path) { | |
577 | -x catfile($dir, "$name$Config{_exe}") | |
578 | and return 1; | |
579 | } | |
580 | ||
581 | return; | |
582 | } |