blob: af6c00192dfd4b3868ec75f87845d99a9a0169b9 [file] [log] [blame]
cristy16af1cb2009-12-11 21:38:29 +00001# Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization
cristy3ed852e2009-09-05 21:47:34 +00002# dedicated to making software imaging solutions freely available.
3#
4# You may not use this file except in compliance with the License. You may
5# obtain a copy of the License at
6#
7# http://www.imagemagick.org/script/license.php
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15# Exercise all regression tests:
cristy6b1a5722010-10-08 17:35:00 +000016#
cristy3ed852e2009-09-05 21:47:34 +000017# make test
18#
19# Exersise one regression test:
20#
21# make TEST_VERBOSE=1 TEST_FILES=t/filter.t test
22#
23
24use ExtUtils::MakeMaker;
25use Config;
cristye9d0a412009-10-09 01:49:39 +000026use File::Spec::Functions qw/catfile catdir devnull catpath splitpath/;
27use Cwd;
28
29sub AutodetectWin32gcc {
30 my $wrkdir = getcwd();
31 my $devnull = devnull();
cristy6b1a5722010-10-08 17:35:00 +000032
cristye9d0a412009-10-09 01:49:39 +000033 my @incdir = ();
34 my @libdir = ($wrkdir);
35 my @bindir = ();
cristy6b1a5722010-10-08 17:35:00 +000036
cristye9d0a412009-10-09 01:49:39 +000037 #try to get configuration info via identify or convert utilities
38 my $conf = `identify -list Configure 2>$devnull` || `convert -list Configure 2>$devnull`;
39 foreach my $line (split '\n', $conf) {
40 if ($line =~ /^Path:\s+(.*)/) {
41 my ($vol,$dir,$file) = splitpath($1);
42 next unless $dir;
43 my $dirpath = catpath( $vol, $dir);
44 my (@l,@b,@i) = ( (),(),() );
45
46 # try to detect 'lib' dir
47 push @l, catfile($dirpath,'..','lib');
48 push @l, catfile($dirpath,'..','..','lib');
49 push @l, catfile($dirpath,'..','..','..','lib');
50 foreach (@l) { push @libdir, $_ if (-d $_) };
51
52 # try to detect 'bin' dir
53 push @b, catfile($dirpath,'..');
54 push @b, catfile($dirpath,'..','bin');
55 push @b, catfile($dirpath,'..','..');
56 push @b, catfile($dirpath,'..','..','bin');
57 push @b, catfile($dirpath,'..','..','..');
58 push @b, catfile($dirpath,'..','..','..','bin');
59 foreach (@b) { push @bindir, $_ if (-e "$_/convert.exe" || -e "$_/identify.exe") };
60
61 # try to detect 'include' dir
62 push @i, catfile($dirpath,'..','include');
63 push @i, catfile($dirpath,'..','include','ImageMagick');
64 push @i, catfile($dirpath,'..','..','include');
65 push @i, catfile($dirpath,'..','..','include','ImageMagick');
66 push @i, catfile($dirpath,'..','..','..','include');
67 push @i, catfile($dirpath,'..','..','..','include','ImageMagick');
68 foreach (@i) { push @incdir, $_ if (-e "$_/magick/MagickCore.h") };
69 }
70 };
cristy6b1a5722010-10-08 17:35:00 +000071
cristye9d0a412009-10-09 01:49:39 +000072 foreach my $bin (@bindir) {
73 opendir(my $bindir, $bin) or die qq{Cannot opendir $bin: $!};
74 my @dlls = map {catfile($bin, $_)} grep /^\S*magick[^\+]\S*?\.dll$/i, readdir $bindir;
75 foreach my $d (@dlls) {
76 unlink "$wrkdir/libMagickCore.def", "$wrkdir/libMagickCore.a";
77 system("pexports \"$d\" >\"$wrkdir/libMagickCore.def\" 2>$devnull");
78 open(DEF, "<$wrkdir/libMagickCore.def");
cristy93ebefb2009-12-08 00:51:55 +000079 my @found = grep(/MagickCoreGenesis/, <DEF>); #checking if we have taken the right DLL
cristye9d0a412009-10-09 01:49:39 +000080 close(DEF);
81 next unless(@found);
82 print STDERR "Gonna create 'libMagickCore.a' from '$d'\n";
83 system("dlltool -D \"$d\" -d \"$wrkdir/libMagickCore.def\" -l \"$wrkdir/libMagickCore.a\" 2>$devnull");
84 last if -s "$wrkdir/libMagickCore.a";
85 }
86 last if -s "$wrkdir/libMagickCore.a";
87 }
cristy6b1a5722010-10-08 17:35:00 +000088
cristye9d0a412009-10-09 01:49:39 +000089 unless(@incdir && @libdir && @bindir && (-s "$wrkdir/libMagickCore.a")) {
90 print STDERR <<EOF
91################################### WARNING! ###################################
92# It seems that you are trying to install Perl::Magick on a MS Windows box with
93# perl + gcc compiler (e.g. strawberry perl), however we cannot find ImageMagick
94# binaries installed on your system.
95#
96# Please check the following prerequisites:
97#
98# 1) You need to have installed ImageMagick Windows binaries from
99# http://www.imagemagick.org/script/binary-releases.php#windows
100#
101# 2) We only support dynamic (DLL) ImageMagick binaries
102# note: it is not possible to mix 32/64-bit binaries of perl and ImageMagick
103#
104# 3) During installation select that you want to install ImageMagick's
105# development files (libraries+headers)
106#
107# 4) You also need to have ImageMagick's directory in your PATH
108# note: we are checking the presence of convert.exe and/or identify.exe tools
109#
110# 5) You might need Visual C++ Redistributable Package installed on your system
111# see instructions on ImageMagick's Binary Release webpage
112#
113# We are gonna continue, but chances for successful build are very low!
114################################################################################
115EOF
116 }
cristy6b1a5722010-10-08 17:35:00 +0000117
cristye9d0a412009-10-09 01:49:39 +0000118 my $inc = join ' ', map "-I\"$_\"", @incdir;
119 my $lib = join ' ', map "-L\"$_\"", @libdir;
cristye9d0a412009-10-09 01:49:39 +0000120
cristy739df912009-10-24 16:10:18 +0000121 return ($inc, $lib);
cristye9d0a412009-10-09 01:49:39 +0000122}
123
cristy6b1a5722010-10-08 17:35:00 +0000124sub AutodetectDelegates {
125 #try to get configuration info via identify or convert utilities
126 my $conf = `identify -list format 2>$devnull` || `convert -list format 2>$devnull`;
127 foreach my $line (split '\n', $conf) {
128 next unless $line =~ /^DELEGATES\s+/;
129 my (undef, @delegates) = split /\s+/, $line;
130 last;
131 };
132 return @delegates;
133}
cristy3ed852e2009-09-05 21:47:34 +0000134
135# Compute test specification
136my $delegate_tests='t/*.t';
cristy6b1a5722010-10-08 17:35:00 +0000137my @tested_delegates = qw/bzlib djvu fftw fontconfig freetype jpeg jng jp2 lcms mpeg png rsvg tiff x11 xml wmf zlib/;
138my @supported_delegates = AutodetectDelegates();
139# find the intersection of tested and supported delegates
140my %seen_delegates = ();
141$seen_delegates{$_}++ for @supported_delegates;
142foreach my $delegate (@tested_delegates) {
143 if ( $seen_delegates{$_} ) {
144 if ( -d "t/$delegate" ) {
145 if ( defined($ENV{'DISPLAY'}) && ($^O ne 'MSWin32') ) {
146 if ( defined $ENV{'DISPLAY'} ) {
147 $delegate_tests .= " t/$delegate/*.t";
148 }
149 next;
cristy3ed852e2009-09-05 21:47:34 +0000150 }
cristy6b1a5722010-10-08 17:35:00 +0000151 $delegate_tests .= " t/$delegate/*.t";
cristy3ed852e2009-09-05 21:47:34 +0000152 }
cristy3ed852e2009-09-05 21:47:34 +0000153 }
154}
155
cristye9d0a412009-10-09 01:49:39 +0000156# defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
cristy0d1c56b2010-10-08 14:34:37 +0000157my $INC_magick = '-I../ -I.. -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/freetype2 -I/usr/include/libxml2 -I"' . $Config{'usrinc'} . '/ImageMagick"';
cristy6bf78be2009-10-16 20:13:48 +0000158my $LIBS_magick = '-L../magick/.libs -lMagickCore -lperl -lm';
cristy0d1c56b2010-10-08 14:34:37 +0000159my $CCFLAGS_magick = "$Config{'ccflags'} -fopenmp -g -O2 -Wall -pthread";
cristye8939e72010-02-03 17:05:25 +0000160my $LDFLAGS_magick = "-L../magick/.libs -lMagickCore $Config{'ldflags'} ";
161my $LDDLFLAGS_magick = "-L../magick/.libs -lMagickCore $Config{'lddlflags'} ";
cristye9d0a412009-10-09 01:49:39 +0000162
163if (($^O eq 'MSWin32') && ($Config{cc} =~ /gcc/)) {
cristy739df912009-10-24 16:10:18 +0000164 my($Ipaths, $Lpaths) = AutodetectWin32gcc();
165
166 #
167 # Setup for strawberry perl.
168 #
169 $INC_magick = "$Ipaths";
170 $LIBS_magick = "-lMagickCore";
171 $CCFLAGS_magick = "$Config{'ccflags'}";
172 $LDFLAGS_magick = "$Config{'ldflags'} $Lpaths ";
173 $LDDLFLAGS_magick = "$Config{'lddlflags'} $Lpaths ";
cristye9d0a412009-10-09 01:49:39 +0000174}
175
cristy3ed852e2009-09-05 21:47:34 +0000176# See lib/ExtUtils/MakeMaker.pm for details of how to influence
177# the contents of the Makefile that is written.
178WriteMakefile
179 (
180 # Module description
181 'ABSTRACT' => 'ImageMagick PERL Extension',
182
183 # Perl module name is Image::Magick
184 'NAME' => 'Image::Magick',
185
186 # Module author
187 'AUTHOR' => 'ImageMagick Studio LLC',
188
189 # Module version
cristyc5baf4f2010-08-31 15:05:33 +0000190 'VERSION' => '6.6.4',
cristy3ed852e2009-09-05 21:47:34 +0000191
192 # Preprocessor defines
cristy6b1a5722010-10-08 17:35:00 +0000193 'DEFINE' => ' -D_LARGE_FILES=1 -DHAVE_CONFIG_H', # e.g., '-DHAVE_SOMETHING'
cristy3ed852e2009-09-05 21:47:34 +0000194
195 # Header search specfication and preprocessor flags
cristye9d0a412009-10-09 01:49:39 +0000196 'INC' => $INC_magick,
cristy3ed852e2009-09-05 21:47:34 +0000197
198 # C compiler
cristy40e685d2010-04-23 14:44:08 +0000199 #'CC' => 'gcc -std=gnu99 -std=gnu99',
cristy3ed852e2009-09-05 21:47:34 +0000200
201 # C pre-processor flags (e.g. -I & -D options)
cristy0d1c56b2010-10-08 14:34:37 +0000202 # 'CPPFLAGS' => "$Config{'cppflags'} -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/freetype2 -I/usr/include/libxml2",
cristy3ed852e2009-09-05 21:47:34 +0000203
204 # C compiler flags (e.g. -O -g)
cristye9d0a412009-10-09 01:49:39 +0000205 'CCFLAGS' => $CCFLAGS_magick,
cristy3ed852e2009-09-05 21:47:34 +0000206
207 # Linker
cristy40e685d2010-04-23 14:44:08 +0000208 #'LD' => $Config{'ld'} == $Config{'cc'} ? 'gcc -std=gnu99 -std=gnu99' : $Config{'ld'},
cristy3ed852e2009-09-05 21:47:34 +0000209
210 # Linker flags for building an executable
cristy739df912009-10-24 16:10:18 +0000211 'LDFLAGS' => $LDFLAGS_magick,
cristy3ed852e2009-09-05 21:47:34 +0000212
213 # Linker flags for building a dynamically loadable module
cristy739df912009-10-24 16:10:18 +0000214 'LDDLFLAGS' => $LDDLFLAGS_magick,
cristy3ed852e2009-09-05 21:47:34 +0000215
216 # Install PerlMagick binary into ImageMagick bin directory
217 'INSTALLBIN' => '/usr/local/bin',
218
219 # Library specification
cristye9d0a412009-10-09 01:49:39 +0000220 'LIBS' => [ $LIBS_magick ],
cristy3ed852e2009-09-05 21:47:34 +0000221
222 # Perl binary name (if a Perl binary is built)
223 'MAP_TARGET' => 'PerlMagick',
224
225 # Let CFLAGS drive optimization flags by setting OPTIMIZE to empty
226 # 'OPTIMIZE' => '',
227
228 # Use same compiler as ImageMagick
cristy55bf91c2010-09-24 00:29:41 +0000229 'PERLMAINCC' => ' -fopenmp',
cristy3ed852e2009-09-05 21:47:34 +0000230
231 # Set Perl installation prefix to ImageMagick installation prefix
232# 'PREFIX' => '/usr/local',
233
234 # Include delegate directories in tests
235 test => { TESTS => $delegate_tests},
236
237 ($Config{'archname'} =~ /-object$/i ? ('CAPI' => 'TRUE') : ()),
238);
239
240
241#
242# Substitutions for "makeaperl" section.
243#
244sub MY::makeaperl {
245 package MY; # so that "SUPER" works right
246 my $inherited = shift->SUPER::makeaperl(@_);
247
248 # Stinky ExtUtils::MM_Unix likes to append its own library path to $(CC),
249 # prior to any user-specified library path so that an installed library is
250 # used rather than the library just built. This substitution function
251 # tries to insert our library path first. Also, use the same compiler used
252 # to build perlmain.c to link so that a C++ compiler may be used if
253 # necessary.
254 $inherited =~ s:MAP_LINKCMD\s.*\s*\$\(CC\):MAP_LINKCMD = \$(PERLMAINCC) -L/usr/local/lib: ;
255 $inherited;
256 }