X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/3e6d8b86de3de73f9968b8e5699e1cc19a87c36d..3063ecbb7e74c693653fa31ca5974892946d1f64:/Makefile.PL diff --git a/Makefile.PL b/Makefile.PL index ce37cf0f..2b14c27f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -5,9 +5,18 @@ use Cwd; use Config; use File::Spec; use Getopt::Long; -use vars qw(%Recommends); 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 @@ -24,7 +33,23 @@ use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CF # 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 @@ -36,9 +61,9 @@ 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 $noexif; # non-zero to disable EXIF parsing of JPEGs -my $no_gif_set_version; # disable calling EGifSetGifVersion 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, @@ -46,9 +71,15 @@ GetOptions("help" => \$help, "libpath=s" => \@libpaths, "verbose|v" => \$VERBOSE, "nolog" => \$NOLOG, - "noexif" => \$noexif, - "nogifsetversion" => \$no_gif_set_version, - 'coverage' => \$coverage); + 'coverage' => \$coverage, + "assert|a" => \$assert, + "tracecontext" => \$trace_context); + +setenv(); + +if ($ENV{AUTOMATED_TESTING}) { + $assert = 1; +} if ($VERBOSE) { print "Verbose mode\n"; @@ -67,6 +98,10 @@ 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"; @@ -85,20 +120,20 @@ 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; } # Pick what libraries are used @@ -108,89 +143,175 @@ if ($MANUAL) { automatic(); } -# Make sure there isn't a clash between the gif libraries. -gifcheck(); +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_cflags = ''; -my $lib_lflags = ''; -my $F_LIBS = ''; -my $F_OBJECT = ''; +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_OBJECT .= ' ' .$frm->{objfiles}; - if ($frm->{cflags}) { - $lib_cflags .= ' ' .$frm->{cflags}; - ++$definc{$_} for map { /^-I(.*)$/ ? ($1) : () } - grep /^-I./, split ' ', $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}; } - if ($frm->{lflags}) { - $lib_lflags .= ' ' . $frm->{lflags}; +} + +my $OSLIBS = ''; +my $OSDEF = "-DOS_$^O"; + +if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } +if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } + +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 { - $F_LIBS .= ' ' .$frm->{libfiles}; + print "Unsupported threading model\n"; + push @objs, "mutexnull.o"; + if ($ENV{AUTOMATED_TESTING}) { + die "OS unsupported: no threading support code for this platform\n"; + } } - } - -unless ($noexif) { - print "EXIF support enabled\n"; - push @defines, [ 'IMEXIF_ENABLE', 1, "Enable experimental EXIF support" ]; - $F_OBJECT .= ' imexif.o'; +else { + print "No threads\n"; + push @objs, "mutexnull.o"; } -my $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_, - grep !$definc{$_}, @incs; -$F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, - grep !$deflib{$_}++, @libs) . $F_LIBS; +my @typemaps = qw(typemap.local typemap); +if ($] < 5.008) { + unshift @typemaps, "typemap.oldperl"; +} -my $OSLIBS = ''; -my $OSDEF = "-DOS_$^O"; +if ($trace_context) { + $CFLAGS .= " -DIMAGER_TRACE_CONTEXT"; +} -if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } -if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } +my $tests = 't/*.t t/*/*.t'; +if (-d "xt" && scalar(() = glob("xt/*.t"))) { + $tests .= " xt/*.t"; +} -my @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 color.o fills.o imgdouble.o limits.o hlines.o - imext.o scale.o rubthru.o render.o paste.o compose.o); - -$Recommends{Imager} = - { 'Parse::RecDescent' => 0 }; - -my %opts=( - 'NAME' => 'Imager', - 'VERSION_FROM' => 'Imager.pm', - 'LIBS' => "$LFLAGS -lm $lib_lflags $OSLIBS $F_LIBS", - 'DEFINE' => "$OSDEF $CFLAGS", - 'INC' => "$lib_cflags $DFLAGS $F_INC", - 'OBJECT' => join(' ', @objs, $F_OBJECT), - clean => { FILES=>'testout meta.tmp rubthru.c scale.c conv.c filters.c gaussian.c render.c rubthru.c' }, - PM => gen_PM(), - PREREQ_PM => { 'Test::More' => 0.47 }, - ); +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'; - #$opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' }; + 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'; +if (eval { ExtUtils::MakeMaker->VERSION('6.06'); 1 }) { + $opts{AUTHOR} = 'Tony Cook , Arnar M. Hrafnkelsson'; $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; } -if ($MM_ver > 6.10) { - $opts{NO_META} = 1; + +if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { + $opts{LICENSE} = "perl_5"; + $opts{META_MERGE} = + { + 'meta-spec' => + { + version => "2", + url => "https://metacpan.org/pod/CPAN::Meta::Spec", + }, + prereqs => + { + runtime => + { + recommends => + { + "Parse::RecDescent" => 0 + }, + requires => + { + 'Scalar::Util' => "1.00", + XSLoader => 0, + }, + }, + build => + { + requires => + { + XSLoader => 0, + }, + }, + test => + { + requires => + { + 'Test::More' => "0.99", + }, + }, + }, + dynamic_config => 0, + no_index => + { + directory => + [ + "PNG", + "GIF", + "TIFF", + "JPEG", + "W32", + "FT2", + "T1", + ], + }, + resources => + { + homepage => "http://imager.perl.org/", + repository => + { + url => "git://git.imager.perl.org/imager.git", + web => "http://git.imager.perl.org/imager.git", + type => "git", + }, + bugtracker => + { + web => "https://rt.cpan.org/Dist/Display.html?Name=Imager", + mailto => 'bug-Imager@rt.cpan.org', + }, + }, + }; } make_imconfig(\@defines); @@ -198,10 +319,27 @@ make_imconfig(\@defines); if ($VERBOSE) { print Dumper(\%opts); } mkdir('testout',0777); # since we cannot include it in the archive. -make_metafile(\%opts); +-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; @@ -223,7 +361,7 @@ imconfig.h : Makefile.PL $(PERLRUN) Makefile.PL $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <==" '.qq! -lib/Imager/APIRef.pod : \$(C_FILES) apidocs.perl +lib/Imager/APIRef.pod : \$(C_FILES) \$(H_FILES) apidocs.perl $perl apidocs.perl lib/Imager/APIRef.pod !.join('', map _im_rule($perl, $_), @ims) @@ -251,6 +389,10 @@ sub manual { Please answer the following questions about which formats are avaliable on your computer + Warning: if you use manual configuration you are responsible for + configuring extra include/library directories as necessary using + INC and LIBS command-line assignments. + press to continue EOF @@ -263,9 +405,9 @@ EOF 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; } } @@ -276,109 +418,35 @@ EOF sub automatic { print "Automatic probing:\n" if $VERBOSE; - for my $frm (sort { $formats{$a}{order} <=> $formats{$b}{order} } 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'}; - } - - 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; - } - } - close H; - } - - # we need the version in a #ifdefable form - - push @defines, [ IM_GIFMAJOR => $major, "Parsed giflib version" ]; - push @defines, [ IM_GIFMINOR => $minor ]; - push @defines, [ IM_NO_SET_GIF_VERSION => 1, "Disable EGifSetGifVersion" ] - if $no_gif_set_version; -} - - -sub grep_directory { - 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; - - print " checkformat($frm)\n" if $VERBOSE; - - my $probe_array = $formats{$frm}{'code'}; - if ($probe_array) { - print " Calling probe function\n" if $VERBOSE; - if (ref $probe_array ne 'ARRAY') { - $probe_array = [ $probe_array ]; - } - for my $func (@$probe_array) { - return 1 if $func->($formats{$frm}, $frm); + 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/}; } } - - my $lib_check=$formats{$frm}{'libcheck'}; - my $inc_check=$formats{$frm}{'inccheck'}; - - if ($lib_check) { - my @l; - for my $lp (@libs) { - push(@l, grep_directory($lp,$lib_check)); - } - - my @i; - for my $ip (@incs) { - push(@i, $ip) if $inc_check->($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 1 if scalar(@i && @l); - } - else { - printf("%10s: not available\n", $frm); - } - - return 0; } - sub pathcheck { if ($VERBOSE) { print "pathcheck\n"; @@ -466,138 +534,18 @@ sub init { } push @libs, grep -d, qw(/usr/local/lib); - $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=>$^O eq 'MSWin32' ? '-lpng -lzlib' : '-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=>'', - code => \&freetype1_probe, + 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.} - }; - $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', - # we always use a probe function - #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_ftconfig, - \&freetype2_probe_scan - ], - }; +Freetype 1.x supports Truetype fonts and is obsoleted by Freetype 2.x. +It's probably insecure. +} + }; # Make fix indent for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } } @@ -606,6 +554,8 @@ DOCS sub gen { my $V = $ENV{$_[0]}; + print " $_[0]: '$V'\n" + if $VERBOSE && defined $V; defined($V) ? $V : ""; } @@ -614,16 +564,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 @@ -631,7 +583,13 @@ sub getenv { IM_CFLAGS IM_LFLAGS IM_DFLAGS); +} +# 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 { @@ -652,237 +610,47 @@ EOS } print CONFIG "#define $define->[0] $define->[1]\n"; } - print CONFIG "\n#endif\n"; - close CONFIG; -} - -# use pkg-config to probe for libraries -# works around the junk that pkg-config dumps on FreeBSD -sub _pkg_probe { - my ($pkg) = @_; - - is_exe('pkg-config') or return; - - my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null'; - - !system("pkg-config $pkg --exists $redir"); -} - -# probes for freetype1 by scanning @incs for the includes and -# @libs for the libs. This is done separately because freetype's headers -# are stored in a freetype or freetype1 directory under PREFIX/include. -# -# we could find the files with the existing mechanism, but it won't set -# -I flags correctly. -# -# This could be extended to freetype2 too, but freetype-config catches -# that -sub freetype1_probe { - my ($frm, $frmkey) = @_; - - my $found_inc; - INCS: - for my $inc (@incs) { - for my $subdir (qw/freetype freetype1/) { - my $path = File::Spec->catfile($inc, $subdir, 'freetype.h'); - -e $path or next; - $path = File::Spec->catfile($inc, $subdir, 'fterrors.h'); - -e $path and next; - - $found_inc = File::Spec->catdir($inc, $subdir); - last INCS; - } - } + if ($Config{gccversion} && $Config{gccversion} =~ /^([0-9]+)/ && $1 > 3) { + print CONFIG <catfile($lib, "libttf$aext"); - my $l_path = File::Spec->catfile($lib, "libttf.$lext"); - if (-e $a_path || -e $l_path) { - $found_lib = $lib; - last LIBS; - } - } +Compiler supports the GCC __attribute__((format...)) syntax. - return unless $found_inc && $found_lib; - printf("%10s: includes %s - libraries %s\n", $frmkey, - ($found_inc ? 'found' : 'not found'), - ($found_lib ? 'found' : 'not found')); +*/ - $frm->{cflags} = "-I$found_inc"; - $frm->{libfiles} = "-lttf"; +#define IMAGER_FORMAT_ATTR 1 - return 1; -} - -# probes for freetype2 by trying to run freetype-config -sub freetype2_probe_ftconfig { - my ($frm, $frmkey) = @_; - - is_exe('freetype-config') or return; - - my $cflags = `freetype-config --cflags` - and !$? or return; - chomp $cflags; - - my $lflags = `freetype-config --libs` - and !$? or return; - chomp $lflags; - - # before 2.1.5 freetype-config --cflags could output - # the -I options in the wrong order, causing a conflict with - # freetype1.x installed with the same --prefix - # - # can happen iff: - # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags - # in that order - # - freetype 1.x headers are in prefix/include/freetype - my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags; - if (@incdirs == 2 - && $incdirs[1] eq "$incdirs[0]/freetype2" - && -e "$incdirs[0]/freetype/freetype.h" - && -e "$incdirs[0]/freetype/fterrid.h") { - print "** freetype-config provided -I options out of order, correcting\n" - if $VERBOSE; - $cflags = join(' ', grep(!/-I/, split ' ', $cflags), - map "-I$_", reverse @incdirs); +EOS } - $frm->{cflags} = $cflags; - $frm->{lflags} = $lflags; - - printf "%10s: configured via freetype-config\n", $frmkey; - return 1; -} - -# attempt to probe for freetype2 by scanning directories -# we can't use the normal scan since we need to find the directory -# containing most of the includes -sub freetype2_probe_scan { - my ($frm, $frmkey) = @_; - - my $found_inc; - my $found_inc2; - INCS: - for my $inc (@incs) { - my $path = File::Spec->catfile($inc, 'ft2build.h'); - -e $path or next; - - # try to find what it's including - my $ftheader; - open FT2BUILD, "< $path" - or next; - while () { - if (m!^\s*\#\s*include\s+<([\w/.]+)>! - || m!^\s*\#\s*include\s+"([\w/.]+)"!) { - $ftheader = $1; - last; - } - } - close FT2BUILD; - $ftheader - or next; - # non-Unix installs put this directly under the same directory in - # theory - if (-e File::Spec->catfile($inc, $ftheader)) { - $found_inc = $inc; - last INCS; - } - for my $subdir (qw/freetype2 freetype/) { - $path = File::Spec->catfile($inc, $subdir, 'fterrors.h'); - -e $path and next; - - $found_inc = $inc; - $found_inc2 = File::Spec->catdir($inc, $subdir); - last INCS; - } - } + if ($Config{d_snprintf}) { + print CONFIG <catfile($lib, "libfreetype$aext"); - my $l_path = File::Spec->catfile($lib, "libfreetype.$lext"); - if (-e $a_path || -e $l_path) { - $found_lib = $lib; - last LIBS; - } +EOS } - printf("%10s: includes %s - libraries %s\n", $frmkey, - ($found_inc ? 'found' : 'not found'), - ($found_lib ? 'found' : 'not found')); - - return unless $found_inc && $found_lib; - - $frm->{cflags} = _make_I($found_inc); - $frm->{cflags} .= " " . _make_I($found_inc2) if $found_inc2; - $frm->{libfiles} = "-lfreetype"; - - return 1; -} - -sub _make_I { - my ($inc_dir) = @_; - - $definc{$inc_dir} - and return ''; - - $inc_dir =~ / / ? qq!-I"$inc_dir"! : "-I$inc_dir"; -} + if ($Config{d_vsnprintf}) { + print CONFIG <{cflags} = $cflags; - $frm->{lflags} = $lflags; - - printf "%10s: configured via `pkg-config $config ...`\n", $frmkey; - - return 1; -} - -sub catfile { - return File::Spec->catfile(@_); -} - -sub is_exe { - my ($name) = @_; - - my @exe_suffix = $Config{_exe}; - if ($^O eq 'MSWin32') { - push @exe_suffix, qw/.bat .cmd/; - } + print CONFIG <path) { - for my $suffix (@exe_suffix) { - -x catfile($dir, "$name$suffix") - and return 1; - } - } + This is intended for formatting i_img_dim values. +*/ +typedef $Config{ivtype} i_dim_format_t; +#define i_DF $Config{ivdformat} +EOS - return; + print CONFIG "\n#endif\n"; + close CONFIG; } sub usage { @@ -891,7 +659,7 @@ Usage: $0 [--enable feature1,feature2,...] [other options] $0 [--disable feature1,feature2,...] [other options] $0 --help Possible feature names are: - png gif ungif jpeg tiff T1-fonts TT-fonts freetype2 + T1-fonts Other options: --verbose | -v Verbose library probing (or set IM_VERBOSE in the environment) @@ -901,6 +669,10 @@ Other options: Add to the include search path --libpath dir Add to the library search path + --coverage + Build for coverage testing. + --assert + Build with assertions active. EOS exit 1; @@ -941,70 +713,6 @@ sub gen_PM { \%pm; } -sub make_metafile { - my ($opts) = @_; - - # extract the version - my $version = MM->parse_version($opts->{VERSION_FROM}) - or die "Could not extract version number from $opts->{VERSION_FROM}\n"; - - # we don't set this on older EU::MM and it corrupts META.yml - # so don't generate it - return unless $opts->{AUTHOR}; - - my $meta = <{NAME} -version: $version -version_from: $opts->{VERSION_FROM} -author: -YAML - for my $author (split /,\s*/, $opts->{AUTHOR}) { - $meta .= " - $author\n"; - } - $meta .= <{ABSTRACT} -installdirs: site -YAML - if (keys %{$Recommends{$opts->{NAME}}}) { - $meta .= "recommends:\n"; - while (my ($module, $version) = each %{$Recommends{$opts->{NAME}}}) { - $meta .= " $module: $version\n"; - } - } - if ($opts->{PREREQ_PM}) { - $meta .= "requires:\n"; - while (my ($module, $version) = each %{$opts->{PREREQ_PM}}) { - $meta .= " $module: $version\n"; - } - } - $meta .= <{NAME} version $version -YAML - my $save_meta; - if (open META, "< META.yml") { - my $old_meta = do { local $/; }; - close META; - - $save_meta = $old_meta ne $meta; - } - else { - ++$save_meta; - } - if ($save_meta) { - print "Updating META.yml\n"; - open META, "> META.yml" or die "Cannot create META.yml: $!"; - print META $meta; - close META; - } -} - my $home; sub _tilde_expand { my ($path) = @_; @@ -1026,9 +734,34 @@ sub _tilde_expand { $path; } -# This isn't a module, but some broken tools, like -# Module::Depends::Instrusive insist on treating it like one. -# -# http://rt.cpan.org/Public/Bug/Display.html?id=21229 +sub _ft1_test_code { + return <<'CODE'; +TT_Engine engine; +TT_Error error; + +error = TT_Init_FreeType(&engine); +if (error) { + printf("FT1: Could not initialize engine\n"); + exit(1); +} + +return 0; +CODE +} + +sub map_bundled { + my (@names) = @_; + + @names = map { split /,/ } @names; + + my @outnames; + for my $name (@names) { + push @outnames, $name; + push @outnames, $bundled_names{$name} + if $bundled_names{$name}; + } + + @outnames; +} 1;