blob: d07b7c7d4f7f911720c60690a8521dc0d645c84d [file] [log] [blame]
Cristy7ce65e72015-12-12 18:03:16 -05001# Copyright 1999-2016 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
cristy1ddea982012-12-16 00:01:56 +000047 push @l, catfile($dirpath,'lib');
cristye9d0a412009-10-09 01:49:39 +000048 push @l, catfile($dirpath,'..','lib');
49 push @l, catfile($dirpath,'..','..','lib');
50 push @l, catfile($dirpath,'..','..','..','lib');
51 foreach (@l) { push @libdir, $_ if (-d $_) };
52
53 # try to detect 'bin' dir
cristy6e882972012-12-16 00:04:58 +000054 push @b, catfile($dirpath);
55 push @b, catfile($dirpath,'bin');
cristye9d0a412009-10-09 01:49:39 +000056 push @b, catfile($dirpath,'..');
57 push @b, catfile($dirpath,'..','bin');
58 push @b, catfile($dirpath,'..','..');
59 push @b, catfile($dirpath,'..','..','bin');
60 push @b, catfile($dirpath,'..','..','..');
61 push @b, catfile($dirpath,'..','..','..','bin');
62 foreach (@b) { push @bindir, $_ if (-e "$_/convert.exe" || -e "$_/identify.exe") };
63
64 # try to detect 'include' dir
cristy1ddea982012-12-16 00:01:56 +000065 push @i, catfile($dirpath,'include');
cristy6e882972012-12-16 00:04:58 +000066 push @i, catfile($dirpath,'include','ImageMagick');
cristye9d0a412009-10-09 01:49:39 +000067 push @i, catfile($dirpath,'..','include');
68 push @i, catfile($dirpath,'..','include','ImageMagick');
69 push @i, catfile($dirpath,'..','..','include');
70 push @i, catfile($dirpath,'..','..','include','ImageMagick');
71 push @i, catfile($dirpath,'..','..','..','include');
72 push @i, catfile($dirpath,'..','..','..','include','ImageMagick');
cristy3dc64692011-07-02 01:24:25 +000073 foreach (@i) { push @incdir, $_ if (-e "$_/MagickCore/MagickCore.h") };
cristye9d0a412009-10-09 01:49:39 +000074 }
75 };
cristy6b1a5722010-10-08 17:35:00 +000076
cristye9d0a412009-10-09 01:49:39 +000077 foreach my $bin (@bindir) {
78 opendir(my $bindir, $bin) or die qq{Cannot opendir $bin: $!};
79 my @dlls = map {catfile($bin, $_)} grep /^\S*magick[^\+]\S*?\.dll$/i, readdir $bindir;
80 foreach my $d (@dlls) {
81 unlink "$wrkdir/libMagickCore.def", "$wrkdir/libMagickCore.a";
82 system("pexports \"$d\" >\"$wrkdir/libMagickCore.def\" 2>$devnull");
83 open(DEF, "<$wrkdir/libMagickCore.def");
cristy93ebefb2009-12-08 00:51:55 +000084 my @found = grep(/MagickCoreGenesis/, <DEF>); #checking if we have taken the right DLL
cristye9d0a412009-10-09 01:49:39 +000085 close(DEF);
86 next unless(@found);
87 print STDERR "Gonna create 'libMagickCore.a' from '$d'\n";
88 system("dlltool -D \"$d\" -d \"$wrkdir/libMagickCore.def\" -l \"$wrkdir/libMagickCore.a\" 2>$devnull");
89 last if -s "$wrkdir/libMagickCore.a";
90 }
91 last if -s "$wrkdir/libMagickCore.a";
92 }
cristy6b1a5722010-10-08 17:35:00 +000093
cristye9d0a412009-10-09 01:49:39 +000094 unless(@incdir && @libdir && @bindir && (-s "$wrkdir/libMagickCore.a")) {
95 print STDERR <<EOF
96################################### WARNING! ###################################
97# It seems that you are trying to install Perl::Magick on a MS Windows box with
98# perl + gcc compiler (e.g. strawberry perl), however we cannot find ImageMagick
99# binaries installed on your system.
100#
101# Please check the following prerequisites:
102#
103# 1) You need to have installed ImageMagick Windows binaries from
104# http://www.imagemagick.org/script/binary-releases.php#windows
105#
106# 2) We only support dynamic (DLL) ImageMagick binaries
107# note: it is not possible to mix 32/64-bit binaries of perl and ImageMagick
108#
109# 3) During installation select that you want to install ImageMagick's
110# development files (libraries+headers)
111#
112# 4) You also need to have ImageMagick's directory in your PATH
113# note: we are checking the presence of convert.exe and/or identify.exe tools
114#
115# 5) You might need Visual C++ Redistributable Package installed on your system
116# see instructions on ImageMagick's Binary Release webpage
117#
118# We are gonna continue, but chances for successful build are very low!
119################################################################################
120EOF
121 }
cristy6b1a5722010-10-08 17:35:00 +0000122
cristye9d0a412009-10-09 01:49:39 +0000123 my $inc = join ' ', map "-I\"$_\"", @incdir;
124 my $lib = join ' ', map "-L\"$_\"", @libdir;
cristye9d0a412009-10-09 01:49:39 +0000125
cristyf912c452009-10-20 12:33:26 +0000126 return ($inc, $lib);
cristye9d0a412009-10-09 01:49:39 +0000127}
128
cristy6b1a5722010-10-08 17:35:00 +0000129sub AutodetectDelegates {
130 #try to get configuration info via identify or convert utilities
cristy409306f2010-10-08 17:39:19 +0000131 my $devnull = devnull();
cristy3a5962c2010-10-10 01:07:26 +0000132 my $conf = `identify -list Configure 2>$devnull` || `convert -list Configure 2>$devnull`;
133 my @delegates = ();
cristy6b1a5722010-10-08 17:35:00 +0000134 foreach my $line (split '\n', $conf) {
135 next unless $line =~ /^DELEGATES\s+/;
cristy3a5962c2010-10-10 01:07:26 +0000136 (undef, @delegates) = split /\s+/, $line;
cristy6b1a5722010-10-08 17:35:00 +0000137 last;
138 };
139 return @delegates;
140}
cristy3ed852e2009-09-05 21:47:34 +0000141
142# Compute test specification
143my $delegate_tests='t/*.t';
cristye4dc56a2015-04-15 21:26:47 +0000144my @tested_delegates = qw/bzlib djvu fftw fontconfig freetype jpeg jng openjp2 lcms png rsvg tiff x11 xml wmf zlib/;
cristy6b1a5722010-10-08 17:35:00 +0000145my @supported_delegates = AutodetectDelegates();
146# find the intersection of tested and supported delegates
147my %seen_delegates = ();
148$seen_delegates{$_}++ for @supported_delegates;
149foreach my $delegate (@tested_delegates) {
cristy3a5962c2010-10-10 01:07:26 +0000150 if ( $seen_delegates{$delegate} ) {
cristy6b1a5722010-10-08 17:35:00 +0000151 if ( -d "t/$delegate" ) {
152 if ( defined($ENV{'DISPLAY'}) && ($^O ne 'MSWin32') ) {
153 if ( defined $ENV{'DISPLAY'} ) {
154 $delegate_tests .= " t/$delegate/*.t";
155 }
156 next;
cristy3ed852e2009-09-05 21:47:34 +0000157 }
cristy6b1a5722010-10-08 17:35:00 +0000158 $delegate_tests .= " t/$delegate/*.t";
cristy3ed852e2009-09-05 21:47:34 +0000159 }
cristy3ed852e2009-09-05 21:47:34 +0000160 }
161}
162
cristye9d0a412009-10-09 01:49:39 +0000163# defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
164my $INC_magick = '-I../ -I@top_srcdir@ @CPPFLAGS@ -I"' . $Config{'usrinc'} . '/ImageMagick"';
cristyee35eb42013-02-14 02:06:22 +0000165my $LIBS_magick = '-L../MagickCore/.libs -lMagickCore-@MAGICK_MAJOR_VERSION@.@MAGICK_ABI_SUFFIX@ -lperl @MATH_LIBS@';
cristye9d0a412009-10-09 01:49:39 +0000166my $CCFLAGS_magick = "$Config{'ccflags'} @CFLAGS@";
cristyee35eb42013-02-14 02:06:22 +0000167my $LDFLAGS_magick = "-L../MagickCore/.libs -lMagickCore-@MAGICK_MAJOR_VERSION@.@MAGICK_ABI_SUFFIX@ $Config{'ldflags'} @LDFLAGS@";
168my $LDDLFLAGS_magick = "-L../MagickCore/.libs -lMagickCore-@MAGICK_MAJOR_VERSION@.@MAGICK_ABI_SUFFIX@ $Config{'lddlflags'} @LDFLAGS@";
cristye9d0a412009-10-09 01:49:39 +0000169
170if (($^O eq 'MSWin32') && ($Config{cc} =~ /gcc/)) {
cristy5b675872009-10-21 13:12:00 +0000171 my($Ipaths, $Lpaths) = AutodetectWin32gcc();
172
173 #
174 # Setup for strawberry perl.
175 #
cristyf912c452009-10-20 12:33:26 +0000176 $INC_magick = "$Ipaths";
cristyee35eb42013-02-14 02:06:22 +0000177 $LIBS_magick = "-lMagickCore-@MAGICK_MAJOR_VERSION@.@MAGICK_ABI_SUFFIX@";
cristyf912c452009-10-20 12:33:26 +0000178 $CCFLAGS_magick = "$Config{'ccflags'}";
179 $LDFLAGS_magick = "$Config{'ldflags'} $Lpaths ";
180 $LDDLFLAGS_magick = "$Config{'lddlflags'} $Lpaths ";
cristye9d0a412009-10-09 01:49:39 +0000181}
182
cristy3ed852e2009-09-05 21:47:34 +0000183# See lib/ExtUtils/MakeMaker.pm for details of how to influence
184# the contents of the Makefile that is written.
185WriteMakefile
186 (
187 # Module description
cristy5aec9f92013-02-14 01:48:51 +0000188 'ABSTRACT' => 'ImageMagick PERL Extension',
cristy3ed852e2009-09-05 21:47:34 +0000189
190 # Perl module name is Image::Magick
cristy5aec9f92013-02-14 01:48:51 +0000191 'NAME' => 'Image::Magick',
cristy3ed852e2009-09-05 21:47:34 +0000192
cristy5b675872009-10-21 13:12:00 +0000193 # Module author
cristy3ed852e2009-09-05 21:47:34 +0000194 'AUTHOR' => 'ImageMagick Studio LLC',
195
196 # Module version
cristy878c2f12011-08-19 00:25:19 +0000197 'VERSION' => '@PACKAGE_PERL_VERSION@',
cristy3ed852e2009-09-05 21:47:34 +0000198
cristy7cabfab2013-02-14 15:20:47 +0000199 # Prerequisite version
200 'PREREQ_PM' => {'parent' => '0'},
201
cristy3ed852e2009-09-05 21:47:34 +0000202 # Preprocessor defines
cristy6b1a5722010-10-08 17:35:00 +0000203 'DEFINE' => '@LFS_CPPFLAGS@ @DEFS@', # e.g., '-DHAVE_SOMETHING'
cristy3ed852e2009-09-05 21:47:34 +0000204
205 # Header search specfication and preprocessor flags
cristye9d0a412009-10-09 01:49:39 +0000206 'INC' => $INC_magick,
cristy3ed852e2009-09-05 21:47:34 +0000207
208 # C compiler
cristye6107592009-09-26 23:04:25 +0000209 #'CC' => '@CC@',
cristy3ed852e2009-09-05 21:47:34 +0000210
211 # C pre-processor flags (e.g. -I & -D options)
212 # 'CPPFLAGS' => "$Config{'cppflags'} @CPPFLAGS@",
213
214 # C compiler flags (e.g. -O -g)
cristye9d0a412009-10-09 01:49:39 +0000215 'CCFLAGS' => $CCFLAGS_magick,
cristy3ed852e2009-09-05 21:47:34 +0000216
217 # Linker
cristye6107592009-09-26 23:04:25 +0000218 #'LD' => $Config{'ld'} == $Config{'cc'} ? '@CC@' : $Config{'ld'},
cristy3ed852e2009-09-05 21:47:34 +0000219
220 # Linker flags for building an executable
cristyf912c452009-10-20 12:33:26 +0000221 'LDFLAGS' => $LDFLAGS_magick,
cristy3ed852e2009-09-05 21:47:34 +0000222
223 # Linker flags for building a dynamically loadable module
cristyf912c452009-10-20 12:33:26 +0000224 'LDDLFLAGS' => $LDDLFLAGS_magick,
cristy3ed852e2009-09-05 21:47:34 +0000225
226 # Install PerlMagick binary into ImageMagick bin directory
227 'INSTALLBIN' => '@BIN_DIR@',
228
229 # Library specification
cristye9d0a412009-10-09 01:49:39 +0000230 'LIBS' => [ $LIBS_magick ],
cristy3ed852e2009-09-05 21:47:34 +0000231
232 # Perl binary name (if a Perl binary is built)
233 'MAP_TARGET' => 'PerlMagick',
234
235 # Let CFLAGS drive optimization flags by setting OPTIMIZE to empty
236 # 'OPTIMIZE' => '',
237
238 # Use same compiler as ImageMagick
239 'PERLMAINCC' => '@PERLMAINCC@ @OPENMP_CFLAGS@',
cristyca142db2012-05-08 11:35:55 +0000240 'AR' => '@AR@',
241 'LD' => '@PERLMAINCC@',
cristy3ed852e2009-09-05 21:47:34 +0000242
243 # Set Perl installation prefix to ImageMagick installation prefix
244# 'PREFIX' => '@prefix@',
245
246 # Include delegate directories in tests
247 test => { TESTS => $delegate_tests},
248
249 ($Config{'archname'} =~ /-object$/i ? ('CAPI' => 'TRUE') : ()),
cristy3e049f82013-02-13 13:26:53 +0000250
cristy5aec9f92013-02-14 01:48:51 +0000251 # sane version
cristy3e049f82013-02-13 13:26:53 +0000252 depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }
cristy3ed852e2009-09-05 21:47:34 +0000253);
254
255
256#
257# Substitutions for "makeaperl" section.
258#
259sub MY::makeaperl {
260 package MY; # so that "SUPER" works right
261 my $inherited = shift->SUPER::makeaperl(@_);
262
263 # Stinky ExtUtils::MM_Unix likes to append its own library path to $(CC),
264 # prior to any user-specified library path so that an installed library is
265 # used rather than the library just built. This substitution function
266 # tries to insert our library path first. Also, use the same compiler used
267 # to build perlmain.c to link so that a C++ compiler may be used if
268 # necessary.
269 $inherited =~ s:MAP_LINKCMD\s.*\s*\$\(CC\):MAP_LINKCMD = \$(PERLMAINCC) -L@MAGICKCORE_PATH@: ;
270 $inherited;
271 }