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