PageRenderTime 134ms CodeModel.GetById 107ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/build-extras/2007-10Oct/Cairo-1.043/Makefile.PL

https://code.google.com/p/camelbox/
Perl | 375 lines | 315 code | 44 blank | 16 comment | 4 complexity | 3c8aedbeac10ba81a872f5ecf331dee2 MD5 | raw file
  1#
  2# Copyright (c) 2004-2006 by the cairo perl team (see the file README)
  3#
  4# Licensed under the LGPL, see LICENSE file for more information.
  5#
  6# $Header: /cvs/cairo/cairo-perl/Makefile.PL,v 1.28 2007-10-13 21:23:16 tsch Exp $
  7#
  8
  9BEGIN { require 5.006; }
 10
 11use strict;
 12use warnings;
 13use ExtUtils::MakeMaker;
 14use MakeHelper;
 15
 16my %extreqs = (
 17	'cairo' => '1.0.0',
 18);
 19
 20# Unfortunately we already need these prereqs for writing the Makefile ...
 21my %prereqs = (
 22	'ExtUtils::Depends'   => 0.2,
 23	'ExtUtils::PkgConfig' => 1.0,
 24);
 25
 26# ... thus we have to make sure they are installed.
 27while ((my $module, my $version) = each(%prereqs)) {
 28	unless (eval "use $module $version; 1" ) {
 29		print "This module requires $module to install itself.\n";
 30		my $yn = ExtUtils::MakeMaker::prompt("  Install $module from CPAN?", 'y');
 31
 32		unless ($yn =~ /^y/i) {
 33			die " *** Cannot install without $module.  Exiting ...\n";
 34		}
 35
 36		require Cwd;
 37		require File::Spec;
 38		require CPAN;
 39
 40		# Save this 'cause CPAN will chdir all over the place.
 41		my $cwd = Cwd::cwd();
 42		my $makefile = File::Spec->rel2abs($0);
 43
 44		CPAN::Shell->install($module);
 45
 46		chdir $cwd
 47			or die "Cannot chdir() back to $cwd: $!";
 48	}
 49	eval "use $module $version; 1" or die $@;
 50}
 51
 52# Add this now since it's not required to generate a Makefile.
 53$prereqs{'Test::Number::Delta'} = 1.00;
 54
 55my $autogen_dir = 'build';
 56mkdir $autogen_dir unless (-d $autogen_dir);
 57$MakeHelper::autogen_dir = $autogen_dir;
 58
 59my %cairo_cfg = ExtUtils::PkgConfig->find ("cairo >= $extreqs{cairo}");
 60
 61my %backend_guards = (
 62	'cairo_pdf_surface_t' => 'CAIRO_HAS_PDF_SURFACE',
 63	'cairo_ps_surface_t'  => 'CAIRO_HAS_PS_SURFACE',
 64	'cairo_svg_surface_t' => 'CAIRO_HAS_SVG_SURFACE',
 65);
 66
 67my %objects = (
 68	'cairo_t *'             => 'Cairo::Context',
 69	'cairo_font_face_t *'   => 'Cairo::FontFace',
 70	'cairo_pattern_t *'     => 'Cairo::Pattern',
 71	'cairo_scaled_font_t *' => 'Cairo::ScaledFont',
 72	'cairo_surface_t *'     => 'Cairo::Surface',
 73);
 74
 75my %structs = (
 76	'cairo_font_options_t *' => 'Cairo::FontOptions',
 77	'cairo_matrix_t *'       => 'Cairo::Matrix',
 78);
 79
 80my %enums = (
 81	cairo_antialias_t => [qw/
 82		CAIRO_ANTIALIAS_
 83		CAIRO_ANTIALIAS_DEFAULT
 84		CAIRO_ANTIALIAS_NONE
 85		CAIRO_ANTIALIAS_GRAY
 86		CAIRO_ANTIALIAS_SUBPIXEL
 87	/],
 88	cairo_content_t => [qw/
 89		CAIRO_CONTENT_
 90		CAIRO_CONTENT_COLOR
 91		CAIRO_CONTENT_ALPHA
 92		CAIRO_CONTENT_COLOR_ALPHA
 93	/],
 94	cairo_extend_t => [qw/
 95		CAIRO_EXTEND_
 96		CAIRO_EXTEND_NONE
 97		CAIRO_EXTEND_REPEAT
 98		CAIRO_EXTEND_REFLECT
 99	/],
100	cairo_fill_rule_t => [qw/
101		CAIRO_FILL_RULE_
102		CAIRO_FILL_RULE_WINDING
103		CAIRO_FILL_RULE_EVEN_ODD
104	/],
105	cairo_filter_t => [qw/
106		CAIRO_FILTER_
107		CAIRO_FILTER_FAST
108		CAIRO_FILTER_GOOD
109		CAIRO_FILTER_BEST
110		CAIRO_FILTER_NEAREST
111		CAIRO_FILTER_BILINEAR
112		CAIRO_FILTER_GAUSSIAN
113	/],
114	cairo_font_slant_t => [qw/
115		CAIRO_FONT_SLANT_
116		CAIRO_FONT_SLANT_NORMAL
117		CAIRO_FONT_SLANT_ITALIC
118		CAIRO_FONT_SLANT_OBLIQUE
119	/],
120	cairo_font_weight_t => [qw/
121		CAIRO_FONT_WEIGHT_
122		CAIRO_FONT_WEIGHT_NORMAL
123		CAIRO_FONT_WEIGHT_BOLD
124	/],
125	cairo_format_t => [qw/
126		CAIRO_FORMAT_
127		CAIRO_FORMAT_ARGB32
128		CAIRO_FORMAT_RGB24
129		CAIRO_FORMAT_A8
130		CAIRO_FORMAT_A1
131	/],
132	cairo_hint_metrics_t => [qw/
133		CAIRO_HINT_METRICS_
134		CAIRO_HINT_METRICS_DEFAULT
135		CAIRO_HINT_METRICS_OFF
136		CAIRO_HINT_METRICS_ON
137	/],
138	cairo_hint_style_t => [qw/
139		CAIRO_HINT_STYLE_
140		CAIRO_HINT_STYLE_DEFAULT
141		CAIRO_HINT_STYLE_NONE
142		CAIRO_HINT_STYLE_SLIGHT
143		CAIRO_HINT_STYLE_MEDIUM
144		CAIRO_HINT_STYLE_FULL
145	/],
146	cairo_line_cap_t => [qw/
147		CAIRO_LINE_CAP_
148		CAIRO_LINE_CAP_BUTT
149		CAIRO_LINE_CAP_ROUND
150		CAIRO_LINE_CAP_SQUARE
151	/],
152	cairo_line_join_t => [qw/
153		CAIRO_LINE_JOIN_
154		CAIRO_LINE_JOIN_MITER
155		CAIRO_LINE_JOIN_ROUND
156		CAIRO_LINE_JOIN_BEVEL
157	/],
158	cairo_operator_t => [qw/
159		CAIRO_OPERATOR_
160		CAIRO_OPERATOR_CLEAR
161		CAIRO_OPERATOR_SOURCE
162		CAIRO_OPERATOR_OVER
163		CAIRO_OPERATOR_IN
164		CAIRO_OPERATOR_OUT
165		CAIRO_OPERATOR_ATOP
166		CAIRO_OPERATOR_DEST
167		CAIRO_OPERATOR_DEST_OVER
168		CAIRO_OPERATOR_DEST_IN
169		CAIRO_OPERATOR_DEST_OUT
170		CAIRO_OPERATOR_DEST_ATOP
171		CAIRO_OPERATOR_XOR
172		CAIRO_OPERATOR_ADD
173		CAIRO_OPERATOR_SATURATE
174	/],
175	cairo_path_data_type_t => [qw/
176		CAIRO_PATH_
177		CAIRO_PATH_MOVE_TO
178		CAIRO_PATH_LINE_TO
179		CAIRO_PATH_CURVE_TO
180		CAIRO_PATH_CLOSE_PATH
181	/],
182	cairo_status_t => [qw/
183		CAIRO_STATUS_
184		CAIRO_STATUS_SUCCESS
185		CAIRO_STATUS_NO_MEMORY
186		CAIRO_STATUS_INVALID_RESTORE
187		CAIRO_STATUS_INVALID_POP_GROUP
188		CAIRO_STATUS_NO_CURRENT_POINT
189		CAIRO_STATUS_INVALID_MATRIX
190		CAIRO_STATUS_INVALID_STATUS
191		CAIRO_STATUS_NULL_POINTER
192		CAIRO_STATUS_INVALID_STRING
193		CAIRO_STATUS_INVALID_PATH_DATA
194		CAIRO_STATUS_READ_ERROR
195		CAIRO_STATUS_WRITE_ERROR
196		CAIRO_STATUS_SURFACE_FINISHED
197		CAIRO_STATUS_SURFACE_TYPE_MISMATCH
198		CAIRO_STATUS_PATTERN_TYPE_MISMATCH
199		CAIRO_STATUS_INVALID_CONTENT
200		CAIRO_STATUS_INVALID_FORMAT
201		CAIRO_STATUS_INVALID_VISUAL
202		CAIRO_STATUS_FILE_NOT_FOUND
203		CAIRO_STATUS_INVALID_DASH
204	/],
205	cairo_subpixel_order_t => [qw/
206		CAIRO_SUBPIXEL_ORDER_
207		CAIRO_SUBPIXEL_ORDER_DEFAULT
208		CAIRO_SUBPIXEL_ORDER_RGB
209		CAIRO_SUBPIXEL_ORDER_BGR
210		CAIRO_SUBPIXEL_ORDER_VRGB
211		CAIRO_SUBPIXEL_ORDER_VBGR
212	/],
213);
214
215# --------------------------------------------------------------------------- #
216
217my $have_cairo_1_2 = ExtUtils::PkgConfig->atleast_version("cairo", "1.2.0");
218my $have_cairo_1_4 = ExtUtils::PkgConfig->atleast_version("cairo", "1.4.0");
219
220if ($have_cairo_1_2) {
221	my %new = (
222		cairo_extend_t => [qw/CAIRO_EXTEND_PAD/],
223		cairo_format_t => [qw/CAIRO_FORMAT_RGB16_565/],
224		cairo_status_t => [qw/CAIRO_STATUS_INVALID_DSC_COMMENT/],
225	);
226
227	foreach my $enum (keys %new) {
228		foreach my $value (@{$new{$enum}}) {
229			push @{$enums{$enum}}, $value;
230		}
231	}
232
233	$enums{cairo_font_type_t} = [qw/
234		CAIRO_FONT_TYPE_
235		CAIRO_FONT_TYPE_TOY
236		CAIRO_FONT_TYPE_FT
237		CAIRO_FONT_TYPE_WIN32
238		CAIRO_FONT_TYPE_ATSUI
239	/];
240
241	$enums{cairo_pattern_type_t} = [qw/
242		CAIRO_PATTERN_TYPE_
243		CAIRO_PATTERN_TYPE_SOLID
244		CAIRO_PATTERN_TYPE_SURFACE
245		CAIRO_PATTERN_TYPE_LINEAR
246		CAIRO_PATTERN_TYPE_RADIAL
247	/];
248
249	$enums{cairo_surface_type_t} = [qw/
250		CAIRO_SURFACE_TYPE_
251		CAIRO_SURFACE_TYPE_IMAGE
252		CAIRO_SURFACE_TYPE_PDF
253		CAIRO_SURFACE_TYPE_PS
254		CAIRO_SURFACE_TYPE_XLIB
255		CAIRO_SURFACE_TYPE_XCB
256		CAIRO_SURFACE_TYPE_GLITZ
257		CAIRO_SURFACE_TYPE_QUARTZ
258		CAIRO_SURFACE_TYPE_WIN32
259		CAIRO_SURFACE_TYPE_BEOS
260		CAIRO_SURFACE_TYPE_DIRECTFB
261		CAIRO_SURFACE_TYPE_SVG
262	/];
263
264	$enums{cairo_svg_version_t} = [qw/
265		CAIRO_SVG_VERSION_
266		CAIRO_SVG_VERSION_1_1
267		CAIRO_SVG_VERSION_1_2
268	/];
269} else {
270	# We need to create empty enum entries for new types so that typemaps
271	# are generated for them.  xsubpp demands typemaps even if the code is
272	# #if'd out.
273	$enums{cairo_font_type_t} = [];
274	$enums{cairo_pattern_type_t} = [];
275	$enums{cairo_surface_type_t} = [];
276	$enums{cairo_svg_version_t} = [];
277}
278
279if ($have_cairo_1_4) {
280	my %new = (
281		cairo_status_t => [qw/CAIRO_STATUS_INVALID_INDEX
282		                      CAIRO_STATUS_CLIP_NOT_REPRESENTABLE/],
283	);
284
285	foreach my $enum (keys %new) {
286		foreach my $value (@{$new{$enum}}) {
287			push @{$enums{$enum}}, $value;
288		}
289	}
290}
291
292# --------------------------------------------------------------------------- #
293
294my %enum_guards = (
295	cairo_svg_version_t => $backend_guards{cairo_svg_surface_t},
296);
297
298MakeHelper::do_enums (\%enums, \%enum_guards);
299
300my @xs_files = <*.xs>;
301
302MakeHelper::write_boot (
303	xs_files => \@xs_files,
304	ignore => '^Cairo$',
305);
306
307my @typemaps = MakeHelper::do_typemaps (\%objects, \%structs, \%enums,
308                                        \%backend_guards, \%enum_guards);
309push @typemaps, 'cairo-perl.typemap';
310
311my $dep = ExtUtils::Depends->new ('Cairo');
312$dep->set_inc ('-I. -I'.$autogen_dir.' '.$cairo_cfg{cflags});
313$dep->set_libs ($cairo_cfg{libs});
314$dep->add_xs (@xs_files);
315$dep->add_c ('cairo-perl-enums.c');
316$dep->add_pm ('Cairo.pm' => '$(INST_LIBDIR)/Cairo.pm');
317$dep->add_typemaps (@typemaps);
318
319$dep->install (qw(cairo-perl.h
320                  cairo-perl.typemap
321                  doctypes
322                  build/cairo-perl-auto.h
323                  build/cairo-perl-auto.typemap));
324$dep->save_config ('build/IFiles.pm');
325
326my @exports = qw(
327    cairo_font_type_from_sv
328    cairo_font_type_to_sv
329	cairo_object_from_sv
330	cairo_object_to_sv
331	cairo_pattern_to_sv
332	cairo_struct_from_sv
333	cairo_struct_to_sv
334	cairo_surface_to_sv
335	newSVCairoFontExtents
336	newSVCairoTextExtents
337	newSVCairoGlyph
338	SvCairoGlyph
339	newSVCairoPath
340	SvCairoPath
341
342);
343
344WriteMakefile (
345	NAME          => 'Cairo',
346	VERSION_FROM  => 'Cairo.pm',
347	ABSTRACT_FROM => 'Cairo.pm',
348	PREREQ_PM     => \%prereqs,
349	XSPROTOARG    => '-noprototypes',
350	FUNCLIST      => \@exports,
351	DL_FUNCS      => { Cairo=> [] },
352
353	$dep->get_makefile_vars,
354
355	EXTRA_META => qq(
356configure_requires:
357    ExtUtils::Depends: $prereqs{'ExtUtils::Depends'}
358    ExtUtils::PkgConfig: $prereqs{'ExtUtils::PkgConfig'}
359
360build_requires:
361    Test::Number::Delta: $prereqs{'Test::Number::Delta'}
362
363no_index:
364    file:
365    - MakeHelper.pm
366),
367);
368
369sub MY::postamble
370{
371	my $autogen_dir = $MakeHelper::autogen_dir;
372
373	"realclean ::
374	-\$(RM_RF) $autogen_dir cairo-perl-enums.*";
375}