]> git.imager.perl.org - imager.git/blob - JPEG/Makefile.PL
update Changes
[imager.git] / JPEG / Makefile.PL
1 #!perl -w
2 use strict;
3 use ExtUtils::MakeMaker;
4 use Getopt::Long;
5 use Config;
6
7 my $verbose = $ENV{IM_VERBOSE};
8 my @libpaths;
9 my @incpaths;
10
11 GetOptions("incpath=s", \@incpaths,
12            "libpath=s" => \@libpaths,
13            "verbose|v" => \$verbose);
14
15 our $BUILDING_IMAGER;
16 our %IMAGER_LIBS;
17
18 my %opts = 
19   (
20    NAME => 'Imager::File::JPEG',
21    VERSION_FROM => 'JPEG.pm',
22    OBJECT => 'JPEG.o imjpeg.o',
23    clean => { FILES => 'testout' },
24   );
25
26 if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
27   $opts{LICENSE} = "perl_5";
28   $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
29   $opts{ABSTRACT} = 'JPEG Image file support for Imager';
30   $opts{META_MERGE} =
31     {
32      'meta-spec' =>
33      {
34       version => "2",
35       url => "https://metacpan.org/pod/CPAN::Meta::Spec",
36      },
37      resources =>
38      {
39       homepage => "http://imager.perl.org/",
40       repository =>
41       {
42        type => "git",
43        url => "git://github.com/tonycoz/imager.git",
44        web => "https://github.com/tonycoz/imager.git",
45       },
46       bugtracker =>
47       {
48        web => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
49        mailto => 'bug-Imager@rt.cpan.org',
50       },
51      },
52     };
53 }
54
55 my @inc;
56 if ($BUILDING_IMAGER) {
57   push @inc, "-I..";
58   unshift @INC, "../lib";
59 }
60 else {
61   unshift @INC, "inc";
62   print "JPEG: building independently\n";
63   require Imager::ExtUtils;
64   push @inc, Imager::ExtUtils->includes;
65   $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
66
67   # Imager required configure through use
68   my @Imager_req = ( Imager => "1.008" );
69   if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) {
70     $opts{META_MERGE}{prereqs} =
71       {
72        configure =>
73        {
74         requires =>
75         {
76          @Imager_req,
77         },
78        },
79        build =>
80        {
81         requires =>
82         {
83          @Imager_req,
84          "Test::More" => "0.47",
85         }
86        },
87        runtime =>
88        {
89         requires =>
90         {
91          @Imager_req,
92         }
93        },
94        test =>
95        {
96         requires =>
97         {
98          "Test::More" => "0.47",
99         }
100        },
101       };
102     $opts{PREREQ_PM} =
103       {
104        @Imager_req,
105        XSLoader => 0,
106       };
107   }
108 }
109
110 require Imager::Probe;
111
112 my %probe =
113   (
114    name => "JPEG",
115    inccheck => sub { -e File::Spec->catfile($_[0], "jpeglib.h") },
116    libbase => "jpeg",
117    testcode => _jpeg_test_code(),
118    testcodeheaders => [ "stdio.h", "stddef.h", "jpeglib.h" ],
119    incpath => \@incpaths,
120    libpath => \@libpaths,
121    verbose => $verbose,
122   );
123
124 my $probe_res = Imager::Probe->probe(\%probe);
125 if ($probe_res) {
126   $IMAGER_LIBS{JPEG} = 1;
127
128   push @inc, $probe_res->{INC};
129   $opts{LIBS} = $probe_res->{LIBS};
130   $opts{DEFINE} = $probe_res->{DEFINE};
131   $opts{INC} = "@inc";
132
133   WriteMakefile(%opts);
134 }
135 else {
136   $IMAGER_LIBS{JPEG} = 0;
137
138   if ($BUILDING_IMAGER) {
139     ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
140   }
141   else {
142     # fail in good way
143     die "OS unsupported: JPEG libraries or headers not found\n";
144   }
145 }
146
147 sub _jpeg_test_code {
148   return <<'CODE';
149 struct jpeg_decompress_struct cinfo;
150 struct jpeg_error_mgr jerr;
151
152 cinfo.err = jpeg_std_error(&jerr);
153 jpeg_create_decompress(&cinfo);
154
155 return 0;
156 CODE
157 }