X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/855c5808a2661ad4b3b13a552dc05feb949012a7..6f1cbfedd211c64b2e6b7b140fd17efddf51068d:/Makefile.PL diff --git a/Makefile.PL b/Makefile.PL index 89c124d7..835ecb6f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,9 +1,22 @@ #!perl -w +use strict; use ExtUtils::MakeMaker; use Cwd; use Config; use File::Spec; use Getopt::Long; +use ExtUtils::Manifest qw(maniread); +use ExtUtils::Liblist; +use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS); +use lib 'inc', 'lib'; +use Imager::Probe; + +# EU::MM runs Makefile.PL all in the same process, so sub-modules will +# see this +our $BUILDING_IMAGER = 1; + +# used to display a summary after we've probed the world +our %IMAGER_LIBS; # # IM_INCPATH colon seperated list of paths to extra include paths @@ -20,23 +33,53 @@ use Getopt::Long; # IM_CFLAGS Extra flags to pass to the compiler # IM_LFLAGS Extra flags to pass to the linker # IM_DFLAGS Extra flags to pass to the preprocessor -# IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support + +my $KEEP_FILES = $ENV{IMAGER_KEEP_FILES}; + +# make sure --verbose will dump environment settings +if (grep $_ =~ /^--?v(?:erbose)?$/, @ARGV) { + $VERBOSE = 1; +} + +# modules/features bundled with Imager that can be enabled/disabled +# withs --enable/--disable +my @bundled = qw(FT1 FT2 GIF JPEG PNG T1 TIFF W32); + +# extra modules bundled with Imager not available on CPAN +my @extras = qw(CountColor DynTest ICO SGI Mandelbrot Flines); + +# alternate names for modules +my %bundled_names = qw(win32 w32 tt ft1); getenv(); # get environment variables -my $help; -my @enable; -my @disable; -my @incpaths; -my @libpaths; -my $noprobe; +my $lext=$Config{'so'}; # Get extensions of libraries +my $aext=$Config{'_a'}; + +my $help; # display help if set +my @enable; # list of drivers to enable +my @disable; # or list of drivers to disable +my @incpaths; # places to look for headers +my @libpaths; # places to look for libraries +my $coverage; # build for coverage testing +my $assert; # build with assertions +my $trace_context; # trace context management to stderr GetOptions("help" => \$help, "enable=s" => \@enable, "disable=s" => \@disable, "incpath=s", \@incpaths, "libpath=s" => \@libpaths, - "noprobe" => \$noprobe, - "verbose|v" => \$VERBOSE); + "verbose|v" => \$VERBOSE, + "nolog" => \$NOLOG, + 'coverage' => \$coverage, + "assert|a" => \$assert, + "tracecontext" => \$trace_context); + +setenv(); + +if ($ENV{AUTOMATED_TESTING}) { + $assert = 1; +} if ($VERBOSE) { print "Verbose mode\n"; @@ -48,31 +91,50 @@ if ($help) { usage(); } +my @defines; + +if ($NOLOG) { print "Logging not compiled into module\n"; } +else { + push @defines, [ IMAGER_LOG => 1, "Logging system" ]; +} + +if ($assert) { + push @defines, [ IM_ASSERT => 1, "im_assert() are effective" ]; +} + +if ($DEBUG_MALLOC) { + push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ]; + print "Malloc debugging enabled\n"; +} + if (@enable && @disable) { print STDERR "Only --enable or --disable can be used, not both, try --help\n"; exit 1; } +my %definc; +my %deflib; +my @incs; # all the places to look for headers +my @libs; # all the places to look for libraries + init(); # initialize global data pathcheck(); # Check if directories exist +my @enabled_bundled; if (exists $ENV{IM_ENABLE}) { - my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE}; - for my $key (keys %formats) { - delete $formats{$key} unless $en{$key}; - } + push @enable, split ' ', $ENV{IM_ENABLE}; } if (@enable) { - my %en = map { $_ => 1 } map { split /,/ } @enable; - for my $key (keys %formats) { - delete $formats{$key} unless $en{$key}; - } + my %en = map { lc $_ => 1 } map_bundled(@enable); + @enabled_bundled = grep $en{lc $_}, @bundled; } elsif (@disable) { - delete @formats{map { split /,/ } @disable}; + my %dis = map { lc $_ => 1 } map_bundled(@disable); + @enabled_bundled = grep !$dis{lc $_}, @bundled; +} +else { + @enabled_bundled = @bundled; } - -my @defines; # Pick what libraries are used if ($MANUAL) { @@ -81,62 +143,177 @@ if ($MANUAL) { automatic(); } -# Make sure there isn't a clash between the gif libraries. -gifcheck(); - -my $lib_cflags = ''; -my $F_LIBS = ''; -my $F_OBJECT = ''; -for my $frmkey (keys %formats) { +my @objs = qw(Imager.o context.o draw.o polygon.o image.o io.o iolayer.o + log.o gaussian.o conv.o pnm.o raw.o feat.o combine.o + filters.o dynaload.o stackmach.o datatypes.o + regmach.o trans2.o quant.o error.o convert.o + map.o tags.o palimg.o maskimg.o img8.o img16.o rotate.o + bmp.o tga.o color.o fills.o imgdouble.o limits.o hlines.o + imext.o scale.o rubthru.o render.o paste.o compose.o flip.o + perlio.o); + +my $lib_define = ''; +my $lib_inc = ''; +my $lib_libs = ''; +for my $frmkey (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) { my $frm = $formats{$frmkey}; - push @defines, [ $frm->{def}, 1, "$frmkey available" ]; - $F_LIBS .= ' ' .$frm->{libfiles}; - $F_OBJECT .= ' ' .$frm->{objfiles}; - $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags}; + if ($frm->{enabled}) { + push @defines, [ $frm->{def}, 1, "$frmkey available" ]; + push @objs, $frm->{objfiles}; + $lib_define .= " $frm->{DEFINE}" if $frm->{DEFINE}; + $lib_inc .= " $frm->{INC}" if $frm->{INC}; + $lib_libs .= " $frm->{LIBS}" if $frm->{LIBS}; + } } -$F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_, - grep !exists $definc{$_}, @incs; -$F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS; - -$OSLIBS = ''; -$OSDEF = "-DOS_$^O"; +my $OSLIBS = ''; +my $OSDEF = "-DOS_$^O"; if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } -@objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o - log.o gaussian.o conv.o pnm.o raw.o feat.o font.o - filters.o dynaload.o stackmach.o datatypes.o - regmach.o trans2.o quant.o error.o convert.o - map.o tags.o palimg.o maskimg.o img16.o rotate.o - bmp.o tga.o rgb.o color.o fills.o imgdouble.o limits.o); - -%opts=( - 'NAME' => 'Imager', - 'VERSION_FROM' => 'Imager.pm', - 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS", - 'DEFINE' => "$OSDEF $CFLAGS", - 'INC' => "$lib_cflags $DFLAGS $F_INC", - 'OBJECT' => join(' ', @objs, $F_OBJECT), - clean => { FILES=>'testout meta.tmp' }, - ); +if ($Config{useithreads}) { + if ($Config{i_pthread}) { + print "POSIX threads\n"; + push @objs, "mutexpthr.o"; + } + elsif ($^O eq 'MSWin32') { + print "Win32 threads\n"; + push @objs, "mutexwin.o"; + } + else { + print "Unsupported threading model\n"; + push @objs, "mutexnull.o"; + if ($ENV{AUTOMATED_TESTING}) { + die "OS unsupported: no threading support code for this platform\n"; + } + } +} +else { + print "No threads\n"; + push @objs, "mutexnull.o"; +} + +my @typemaps = qw(typemap.local typemap); +if ($] < 5.008) { + unshift @typemaps, "typemap.oldperl"; +} + +if ($trace_context) { + $CFLAGS .= " -DIMAGER_TRACE_CONTEXT"; +} + +my $tests = 't/*.t t/*/*.t'; +if (-d "xt" && scalar(() = glob("xt/*.t"))) { + $tests .= " xt/*.t"; +} -if ($ExtUtils::MakeMaker::VERSION > 6.06) { - $opts{AUTHOR} = 'Tony Cook , Arnar M. Hrafnkelsson'; +my %opts= + ( + NAME => 'Imager', + VERSION_FROM => 'Imager.pm', + LIBS => "$LFLAGS -lm $lib_libs $OSLIBS", + DEFINE => "$OSDEF $lib_define $CFLAGS", + INC => "$lib_inc $DFLAGS", + OBJECT => join(' ', @objs), + DIR => [ sort grep -d, @enabled_bundled, @extras ], + clean => { FILES=>'testout rubthru.c scale.c conv.c filters.c gaussian.c render.c rubthru.c' }, + PM => gen_PM(), + PREREQ_PM => + { + 'Test::More' => 0.99, + 'Scalar::Util' => 1.00, + 'XSLoader' => 0, + }, + TYPEMAPS => \@typemaps, + test => { TESTS => $tests }, + ); + +if ($coverage) { + if ($Config{gccversion}) { + push @ARGV, 'OPTIMIZE=-ftest-coverage -fprofile-arcs -g'; + $opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' }; + } + else { + die "Don't know the coverage C flags for your compiler\n"; + } +} + +# eval to prevent warnings about versions with _ in them +my $MM_ver = eval $ExtUtils::MakeMaker::VERSION; +if ($MM_ver > 6.06) { + $opts{AUTHOR} = 'Tony Cook , Arnar M. Hrafnkelsson'; $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; } -make_imconfig(\@defines); +if ($MM_ver >= 6.46) { + $opts{META_MERGE} = + { + recommends => + { + "Parse::RecDescent" => 0 + }, + license => "perl", + dynamic_config => 1, + no_index => + { + directory => + [ + "PNG", + "GIF", + "TIFF", + "JPEG", + "W32", + "FT2", + "T1", + ], + }, + resources => + { + homepage => "http://imager.perl.org/", + repository => "git://git.imager.perl.org/imager.git", + bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager", + }, + }; +} + +my $ivdformat = probe_ivdformat(); + +make_imconfig(\@defines, $ivdformat); if ($VERBOSE) { print Dumper(\%opts); } mkdir('testout',0777); # since we cannot include it in the archive. + +-d "probe" and rmdir "probe"; + WriteMakefile(%opts); +my @good; +my @bad; +for my $name (sort { lc $a cmp lc $b } keys %IMAGER_LIBS) { + if ($IMAGER_LIBS{$name}) { + push @good, $name; + } + else { + push @bad, $name; + } +} + +print "\n"; +print "Libraries found:\n" if @good; +print " $_\n" for @good; +print "Libraries *not* found:\n" if @bad; +print " $_\n" for @bad; + exit; sub MY::postamble { + my $self = shift; + my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)'; + my $mani = maniread; + + my @ims = grep /\.im$/, keys %$mani; ' dyntest.$(MYEXTLIB) : dynfilt/Makefile cd dynfilt && $(MAKE) $(PASTHRU) @@ -144,36 +321,29 @@ dyntest.$(MYEXTLIB) : dynfilt/Makefile lib/Imager/Regops.pm : regmach.h regops.perl $(PERL) regops.perl regmach.h lib/Imager/Regops.pm -imconfig.h: Makefile.PL +imconfig.h : Makefile.PL $(ECHO) "imconfig.h out-of-date with respect to $?" $(PERLRUN) Makefile.PL $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <==" -'; -} - -sub MY::metafile { - my ($self) = @_; - - my $meta = <{VERSION} -version_from: $self->{VERSION_FROM} -author: $self->{AUTHOR} -abstract: $self->{ABSTRACT} -installdirs: $self->{INSTALLDIRS} -recommends: - Parse::RecDescent: 0 -license: perl -dynamic_config: 1 -distribution_type: module -generated_by: Imager version $self->{VERSION} -YAML - open META, "> meta.tmp" or die "Cannot create meta.tmp: $!"; - print META $meta; - close META; - - return sprintf "metafile :\n\t\$(CP) meta.tmp META.yml\n"; +'.qq! +lib/Imager/APIRef.pod : \$(C_FILES) \$(H_FILES) apidocs.perl + $perl apidocs.perl lib/Imager/APIRef.pod + +!.join('', map _im_rule($perl, $_), @ims) + +} + +sub _im_rule { + my ($perl, $im) = @_; + + (my $c = $im) =~ s/\.im$/.c/; + return < to continue EOF @@ -193,12 +367,12 @@ EOF SWX: if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; } print "Enable $frm support: "; - $gz = ; + my $gz = ; chomp($gz); if ($gz =~ m/^(y|yes|n|no)/i) { - $gz=substr(lc($gz),0,1); - if ($gz eq 'n') { - delete $formats{$frm}; + if ($gz =~ /y/i) { + $formats{$frm}{enabled} = 1; + $IMAGER_LIBS{$frm} = 1; } } else { goto SWX; } } @@ -208,118 +382,36 @@ EOF # automatic configuration of helper libraries sub automatic { - for $frm(keys %formats) { - delete $formats{$frm} if !checkformat($frm); - } -} - - -sub gifcheck { - if ($formats{'gif'} and $formats{'ungif'}) { - print "ungif and gif can not coexist - removing ungif support\n"; - delete $formats{'ungif'}; - } - - RETR: - if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) { - print <; - chomp($resp); - if ($resp ne "n") { - delete $formats{'gif'}; - delete $formats{'ungif'}; - return; - } - } - - for my $frm (qw(gif ungif)) { - checkformat($frm) if ($MANUAL and $formats{$frm}); - } - - my @dirs; - for my $frm (grep $formats{$_}, qw(gif ungif)) { - push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir}; - } - my $minor = 0; - my $major = 0; - FILES: for my $dir (@dirs) { - my $h = "$dir/gif_lib.h"; - open H, "< $h" or next; - while () { - if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) { - $major = $1; - $minor = $2; - close H; - last FILES; - } + print "Automatic probing:\n" if $VERBOSE; + + if (grep $_ eq "FT1", @enabled_bundled) { + my %probe = + ( + name => "FT1", + inccheck => sub { -e File::Spec->catfile($_[0], "ftnameid.h") }, + libbase => "ttf", + testcode => _ft1_test_code(), + testcodeheaders => [ "freetype.h", "stdio.h" ], + incpaths => \@incpaths, + libpaths => \@libpaths, + alternatives => + [ + { + incsuffix => "freetype", + } + ], + verbose => $VERBOSE, + ); + my $probe_res = Imager::Probe->probe(\%probe); + $IMAGER_LIBS{FT1} = defined $probe_res; + if ($probe_res) { + $formats{FT1}{enabled} = 1; + @{$formats{FT1}}{qw/DEFINE INC LIBS/} = + @$probe_res{qw/DEFINE INC LIBS/}; } - close H; - } - - # we need the version in a #ifdefable form - - push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ]; - push @defines, [ IM_GIFMINOR, $minor ]; -} - - -sub gd { - my($path,$chk)=@_; - -# print "checking path $path\n"; - if ( !opendir(DH,$path) ) { - warn "Cannot open dir $path: $!\n"; - return; - } - my @l=grep { $chk->($_) } readdir(DH); - # print @l; - close(DH); - return map $path, @l; -} - - -sub checkformat { - my $frm=shift; - - my $code = $formats{$frm}{'code'}; - if ($code && !$noprobe) { - return 1 if $code->($formats{$frm}, $frm); - } - - my $libchk=$formats{$frm}{'libcheck'}; - my $incchk=$formats{$frm}{'inccheck'}; - - my @l; - for my $lp (@libs) { - push(@l, gd($lp,$libchk)); } - - my @i; - for my $ip (@incs) { - push(@i, $ip) if $incchk->($ip,$frm); - } - - printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found')); - $formats{$frm}{incdir} = \@i; - $formats{$frm}{libdir} = \@l; - return scalar(@i && @l); } - sub pathcheck { if ($VERBOSE) { print "pathcheck\n"; @@ -351,15 +443,22 @@ sub pathcheck { sub init { - @definc{'/usr/include'}=(); - @incs=(split(/\Q$Config{path_sep}/, $INCPATH), - map { split /\Q$Config{path_sep}/} @incpaths ); + my @definc = qw(/usr/include); + @definc{@definc}=(1) x @definc; + @incs= + ( + split(/\Q$Config{path_sep}/, $INCPATH), + map _tilde_expand($_), map { split /\Q$Config{path_sep}/ } @incpaths + ); if ($Config{locincpth}) { push @incs, grep -d, split ' ', $Config{locincpth}; } if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE}; } + if ($Config{incpath}) { + push @incs, grep -d, split /\Q$Config{path_sep}/, $Config{incpath}; + } push @incs, grep -d, qw(/sw/include /usr/include/freetype2 @@ -367,148 +466,51 @@ sub init { /usr/local/include/freetype1/freetype /usr/include /usr/local/include /usr/include/freetype /usr/local/include/freetype); + if ($Config{ccflags}) { + my @hidden = map { /^-I(.*)$/ ? ($1) : () } split ' ', $Config{ccflags}; + push @incs, @hidden; + @definc{@hidden} = (1) x @hidden; + } @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH), - map { split /\Q$Config{path_sep}/} @libpaths ); + map _tilde_expand($_), map { split /\Q$Config{path_sep}/} @libpaths ); if ($Config{loclibpth}) { push @libs, grep -d, split ' ', $Config{loclibpth}; } + push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'}); + push @libs, grep -d, split / /, $Config{libspath} if $Config{libspath}; if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB}; } if ($^O eq 'cygwin') { push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api'; - push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api'; + push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api'; } + if ($Config{ldflags}) { + # some builds of perl put -Ldir into ldflags without putting it in + # loclibpth, let's extract them + my @hidden = grep -d, map { /^-L(.*)$/ ? ($1) : () } + split ' ', $Config{ldflags}; + push @libs, @hidden; + # don't mark them as seen - EU::MM will remove any libraries + # it can't find and it doesn't look for -L in ldflags + #@deflib{@hidden} = @hidden; + } + push @libs, grep -d, qw(/usr/local/lib); - my $lext=$Config{'so'}; # Get extensions of libraries - my $aext=$Config{'_a'}; - - $formats{'jpeg'}={ - order=>'21', - def=>'HAVE_LIBJPEG', - inccheck=>sub { -e catfile($_[0], 'jpeglib.h') }, - libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" }, - libfiles=>'-ljpeg', - objfiles=>'jpeg.o', - docs=>q{ - In order to use jpeg with this module you need to have libjpeg - installed on your computer} - }; - - $formats{'tiff'}={ - order=>'23', - def=>'HAVE_LIBTIFF', - inccheck=>sub { -e catfile($_[0], 'tiffio.h') }, - libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" }, - libfiles=>'-ltiff', - objfiles=>'tiff.o', - docs=>q{ - In order to use tiff with this module you need to have libtiff - installed on your computer} - }; - - $formats{'png'}={ - order=>'22', - def=>'HAVE_LIBPNG', - inccheck=>sub { -e catfile($_[0], 'png.h') }, - libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" }, - libfiles=>'-lpng -lz', - objfiles=>'png.o', - docs=>q{ - Png stands for Portable Network Graphics and is intended as - a replacement for gif on the web. It is patent free and - is recommended by the w3c, you need libpng to use these formats}, - code => \&png_probe, - }; - - $formats{'gif'}={ - order=>'20', - def=>'HAVE_LIBGIF', - inccheck=>sub { -e catfile($_[0], 'gif_lib.h') }, - libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" }, - libfiles=>'-lgif', - objfiles=>'gif.o', - docs=>q{ - gif is the de facto standard for webgraphics at the moment, - it does have some patent problems. If you have giflib and - are not in violation with the unisys patent you should use - this instead of the 'ungif' option. Note that they cannot - be in use at the same time} - }; - - $formats{'ungif'}={ - order=>'21', - def=>'HAVE_LIBGIF', - inccheck=>sub { -e catfile($_[0], 'gif_lib.h') }, - libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" }, - libfiles=>'-lungif', - objfiles=>'gif.o', - docs=>q{ - gif is the de facto standard for webgraphics at the moment, - it does have some patent problems. If you have libungif and - want to create images free from LZW patented compression you - should use this option instead of the 'gif' option} - }; - - $formats{'T1-fonts'}={ - order=>'30', - def=>'HAVE_LIBT1', - inccheck=>sub { -e catfile($_[0], 't1lib.h') }, - libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" }, - libfiles=>'-lt1', - objfiles=>'', - docs=>q{ - postscript t1 fonts are scalable fonts. They can include - ligatures and kerning information and generally yield good - visual quality. We depend on libt1 to rasterize the fonts - for use in images.} - }; - - $formats{'TT-fonts'}= + $formats{FT1}= { order=>'31', def=>'HAVE_LIBTT', - inccheck=>sub { -e catfile($_[0], 'freetype.h') - && !-e catfile($_[0], 'fterrors.h') }, - libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" }, - libfiles=>'-lttf', - objfiles=>'', + objfiles=>'fontft1.o', + LIBS => "-lttf", docs=>q{ -Truetype fonts are scalable fonts. They can include -kerning and hinting information and generally yield good -visual quality esp on low resultions. The freetype library is -used to rasterize for us. The only drawback is that there -are alot of badly designed fonts out there.} +Freetype 1.x supports Truetype fonts and is obsoleted by Freetype 2.x. + +It's probably insecure. +} }; - $formats{'w32'} = { - order=>40, - def=>'HAVE_WIN32', - inccheck=>sub { -e catfile($_[0], 'windows.h') }, - libcheck=>sub { lc $_[0] eq 'gdi32.lib' - || lc $_[0] eq 'libgdi32.a' }, - libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '', - objfiles=>'win32.o', - docs => <'29', - def=>'HAVE_FT2', - inccheck=>sub { -e catfile($_[0], 'ft2build.h') }, - libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" }, - libfiles=>'-lfreetype', - objfiles=>'freetyp2.o', - docs=>< \&freetype2_probe, - }; # Make fix indent for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } } @@ -517,6 +519,8 @@ DOCS sub gen { my $V = $ENV{$_[0]}; + print " $_[0]: '$V'\n" + if $VERBOSE && defined $V; defined($V) ? $V : ""; } @@ -525,16 +529,18 @@ sub gen { sub getenv { - ($VERBOSE, - $INCPATH, + $VERBOSE ||= gen("IM_VERBOSE"); + + print "Environment config:\n" if $VERBOSE; + + ($INCPATH, $LIBPATH, $NOLOG, $DEBUG_MALLOC, $MANUAL, $CFLAGS, $LFLAGS, - $DFLAGS) = map { gen $_ } qw(IM_VERBOSE - IM_INCPATH + $DFLAGS) = map { gen $_ } qw(IM_INCPATH IM_LIBPATH IM_NOLOG IM_DEBUG_MALLOC @@ -542,21 +548,17 @@ sub getenv { IM_CFLAGS IM_LFLAGS IM_DFLAGS); +} - if ($NOLOG) { print "Logging not compiled into module\n"; } - else { - push @defines, [ IMAGER_LOG => 1, "Logging system" ]; - } - - if ($DEBUG_MALLOC) { - push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ]; - print "Malloc debugging enabled\n"; - } - +# populate the environment so that sub-modules get the same info +sub setenv { + $ENV{IM_VERBOSE} = 1 if $VERBOSE; + $ENV{IM_INCPATH} = join $Config{path_sep}, @incpaths if @incpaths; + $ENV{IM_LIBPATH} = join $Config{path_sep}, @libpaths if @libpaths; } sub make_imconfig { - my ($defines) = @_; + my ($defines, $ivdformat) = @_; open CONFIG, "> imconfig.h" or die "Cannot create imconfig.h: $!\n"; @@ -573,97 +575,201 @@ EOS } print CONFIG "#define $define->[0] $define->[1]\n"; } - print CONFIG "\n#endif\n"; - close CONFIG; -} + if ($Config{gccversion} && $Config{gccversion} =~ /^([0-9]+)/ && $1 > 3) { + print CONFIG </dev/null'; +#define IMAGER_FORMAT_ATTR 1 - !system("pkg-config $pkg --exists $redir"); -} +EOS + } -# probes for freetype2 by trying to run freetype-config -sub freetype2_probe { - my ($frm, $frmkey) = @_; + if ($Config{d_snprintf}) { + print CONFIG <{cflags} = $cflags; - my $lflags = `freetype-config --libs` - and !$? or return; - chomp $lflags; - $frm->{libfiles} = $lflags; +EOS + } - printf "%10s: configured via freetype-config\n", $frmkey; + print CONFIG < $VERBOSE, + LIBS => [], + INC => "", + header => \@headers, + function => <{cflags} = $cflags; - $frm->{libfiles} = $lflags; + my $mani = maniread(); - printf "%10s: configured via `pkg-config $config ...`\n", $frmkey; + for my $filename (keys %$mani) { + if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) { + (my $work = $filename) =~ s/^lib//; + $pm{$filename} = $instbase . $work; + } + } - return 1; -} + # need the typemap + $pm{typemap} = $instbase . '/Imager/typemap'; -sub catfile { - return File::Spec->catfile(@_); + # and the core headers + for my $filename (keys %$mani) { + if ($filename =~ /^\w+\.h$/) { + $pm{$filename} = $instbase . '/Imager/include/' . $filename; + } + } + + # and the generated header + $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h'; + + \%pm; } -sub is_exe { - my ($name) = @_; +my $home; +sub _tilde_expand { + my ($path) = @_; - for my $dir (File::Spec->path) { - -x catfile($dir, "$name$Config{_exe}") - and return 1; + if ($path =~ m!^~[/\\]!) { + defined $home or $home = $ENV{HOME}; + if (!defined $home && $^O eq 'MSWin32' + && defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) { + $home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH}; + } + unless (defined $home) { + $home = eval { (getpwuid($<))[7] }; + } + defined $home or die "You supplied $path, but I can't find your home directory\n"; + $path =~ s/^~//; + $path = File::Spec->catdir($home, $path); } - return; + $path; } -sub usage { - print STDERR <