add test code for the JPEG probe
[imager.git] / JPEG / Makefile.PL
CommitLineData
797a9f9c
TC
1#!perl -w
2use strict;
3use ExtUtils::MakeMaker qw(WriteMakefile WriteEmptyMakefile);
4use Getopt::Long;
5use Config;
6
7my $verbose = $ENV{IM_VERBOSE};
8my @libpaths;
9my @incpaths;
10
11GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
14
15our $BUILDING_IMAGER;
16
17my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
18
19my %opts =
20 (
21 NAME => 'Imager::File::JPEG',
22 VERSION_FROM => 'JPEG.pm',
23 OBJECT => 'JPEG.o imjpeg.o imexif.o',
24 );
25
26my @inc;
27if ($BUILDING_IMAGER) {
28 push @inc, "-I..";
29 unshift @INC, "../lib";
30}
31else {
32 unshift @INC, "inc";
33 print "JPEG: building independently\n";
34 require Imager::ExtUtils;
35 push @inc, Imager::ExtUtils->includes;
36 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
37
38 # Imager required configure through use
39 my @Imager_req = ( Imager => "0.77" );
40 if ($MM_ver >= 6.46) {
41 $opts{META_MERGE} =
42 {
43 configure_requires =>
44 {
45 @Imager_req,
46 },
47 build_requires =>
48 {
49 @Imager_req,
50 "Test::More" => "0.47",
51 },
52 resources =>
53 {
54 homepage => "http://imager.perl.org/",
55 repository =>
56 {
57 url => "http://imager.perl.org/svn/trunk/Imager-File-JPEG",
58 web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager-File-JPEG",
59 type => "svn",
60 },
61 },
62 };
63 $opts{PREREQ_PM} =
64 {
65 @Imager_req,
66 };
67 }
68}
69
70require Imager::Probe;
71
72my %probe =
73 (
74 name => "JPEG",
75 inccheck => sub { -e File::Spec->catfile($_[0], "jpeglib.h") },
76 libbase => "jpeg",
cb4f51d6
TC
77 testcode => _jpeg_test_code(),
78 testcodeheaders => [ "stdio.h", "stddef.h", "jpeglib.h" ],
797a9f9c
TC
79 incpath => join($Config{path_sep}, @incpaths),
80 libpath => join($Config{path_sep}, @libpaths),
81 );
82
83my $probe_res = Imager::Probe->probe(\%probe);
84if ($probe_res) {
85 push @inc, $probe_res->{INC};
86 $opts{LIBS} = $probe_res->{LIBS};
87
88 $opts{INC} = "@inc";
89
90 if ($MM_ver > 6.06) {
91 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
92 $opts{ABSTRACT} = 'JPEG Image file support';
93 }
94
95 WriteMakefile(%opts);
96}
97else {
98 if ($BUILDING_IMAGER) {
99 WriteEmptyMakefile(%opts);
100 }
101 else {
102 # fail in good way
103 die "OS unsupported: JPEG libraries or headers not found\n";
104 }
105}
106
107sub _jpeg_test_code {
108 return <<'CODE';
cb4f51d6
TC
109struct jpeg_decompress_struct cinfo;
110struct jpeg_error_mgr jerr;
111
112cinfo.err = jpeg_std_error(&jerr);
113jpeg_create_decompress(&cinfo);
797a9f9c 114
797a9f9c
TC
115return 0;
116CODE
117}