--- meander.pl 2004-03-06 23:24:02.000000000 -0500 +++ meander-mup.pl 2004-03-06 23:28:42.000000000 -0500 @@ -29,22 +29,65 @@ use constant pi=>4*atan2(1,1); -my @packages; -my @incs; -my @libs; +my %mfvars; # Makefile Vars +my $typemap; # dirty hack, see below BEGIN { - @packages=qw[glib-2.0 gtk+-2.0]; - @incs=map qx[pkg-config $_ --cflags], @packages; - @libs=map qx[pkg-config $_ --libs], @packages; - chomp (@incs, @libs); - push @incs, "-I/usr/lib/perl5/Glib/Install"; # ewww + # ExtUtils::Depends knows how to find the typemaps and headers for the + # Gtk2 module and the ones on which it depends (Glib, basically). + # use it to get the INC, LIBS, and TYPEMAPS information we need to give + # to Inline::C so we can use gtk2-perl functions and such. + use ExtUtils::Depends; + my $dep = ExtUtils::Depends->new ('Meander', 'Gtk2'); + %mfvars = $dep->get_makefile_vars; + + # Inline::C's manpage claims that it takes the same value for TYPEMAPS as + # MakeMaker, but this is an evil lie --- it takes only a filename string, + # whereas MakeMaker takes a string or an array of strings. We'll have to + # consolidate the many typemap files from the depends object into one to + # appease the fickle Inline. This bites. + my %typemap_info; + use strict; + foreach my $f (@{$mfvars{TYPEMAPS}}) { + open IN, $f or die "can't open $f: $!\n"; + my $cur = ''; + while () { + if ($cur eq '') { + next unless /^TYPEMAP/; + $cur = 'TYPEMAP'; + } elsif (/^(INPUT|OUTPUT)/) { + $cur = $1; + } else { + push @{$typemap_info{$cur}}, $_; + } + } + close IN; + } + use File::Temp ':mktemp'; + $typemap = mktemp ("/tmp/".$0."XXXXXX"); + open OUT, ">$typemap" or die "can't write temp typemap file: $!"; + print OUT "# generated by $0 from ".join(" ", @{$mfvars{TYPEMAPS}})."\n\n"; + foreach my $section (qw(TYPEMAP INPUT OUTPUT)) { + print OUT "$section\n"; + foreach (@{$typemap_info{$section}}) { + print OUT $_; + } + } + close OUT; +} +END { + unlink $typemap; } -use Inline C => <<'EOF', CCFLAGS => '-O3', INC => "@incs", LIBS => "@libs"; +use Inline (C => Config => + CCFLAGS => '-O3', + INC => $mfvars{INC}, + LIBS => $mfvars{LIBS}, + TYPEMAPS => $typemap, #$mfvars{TYPEMAPS}, # $% ^ Inline, see above +); +use Inline C => <<'EOF'; -#include -#include +#include #define THRESH 0.5 @@ -119,7 +162,7 @@ } } -int draw_meander (SV *points_ref, SV *area, int xstart, int ystart, int dx, int dy, int maxiter, int l) { +int draw_meander (SV *points_ref, GtkWidget *area, int xstart, int ystart, int dx, int dy, int maxiter, int l) { AV *points; int len; double *ptr; @@ -150,7 +193,7 @@ *ptr++=(double)SvNV(*val); } - da = gperl_get_object_check (area, GTK_TYPE_WIDGET); + da = area; bufptr = buf; count = 0;