cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 1 | # Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2 | # 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: |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 16 | # |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | # make test |
| 18 | # |
| 19 | # Exersise one regression test: |
| 20 | # |
| 21 | # make TEST_VERBOSE=1 TEST_FILES=t/filter.t test |
| 22 | # |
| 23 | |
| 24 | use ExtUtils::MakeMaker; |
| 25 | use Config; |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 26 | use File::Spec::Functions qw/catfile catdir devnull catpath splitpath/; |
| 27 | use Cwd; |
| 28 | |
| 29 | sub AutodetectWin32gcc { |
| 30 | my $wrkdir = getcwd(); |
| 31 | my $devnull = devnull(); |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 32 | |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 33 | my @incdir = (); |
| 34 | my @libdir = ($wrkdir); |
| 35 | my @bindir = (); |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 36 | |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 37 | #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'); |
cristy | 3dc6469 | 2011-07-02 01:24:25 +0000 | [diff] [blame] | 68 | foreach (@i) { push @incdir, $_ if (-e "$_/MagickCore/MagickCore.h") }; |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 69 | } |
| 70 | }; |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 71 | |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 72 | 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"); |
cristy | 93ebefb | 2009-12-08 00:51:55 +0000 | [diff] [blame] | 79 | my @found = grep(/MagickCoreGenesis/, <DEF>); #checking if we have taken the right DLL |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 80 | 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 | } |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 88 | |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 89 | 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 | ################################################################################ |
| 115 | EOF |
| 116 | } |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 117 | |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 118 | my $inc = join ' ', map "-I\"$_\"", @incdir; |
| 119 | my $lib = join ' ', map "-L\"$_\"", @libdir; |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 120 | |
cristy | f912c45 | 2009-10-20 12:33:26 +0000 | [diff] [blame] | 121 | return ($inc, $lib); |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 122 | } |
| 123 | |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 124 | sub AutodetectDelegates { |
| 125 | #try to get configuration info via identify or convert utilities |
cristy | 409306f | 2010-10-08 17:39:19 +0000 | [diff] [blame] | 126 | my $devnull = devnull(); |
cristy | 3a5962c | 2010-10-10 01:07:26 +0000 | [diff] [blame] | 127 | my $conf = `identify -list Configure 2>$devnull` || `convert -list Configure 2>$devnull`; |
| 128 | my @delegates = (); |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 129 | foreach my $line (split '\n', $conf) { |
| 130 | next unless $line =~ /^DELEGATES\s+/; |
cristy | 3a5962c | 2010-10-10 01:07:26 +0000 | [diff] [blame] | 131 | (undef, @delegates) = split /\s+/, $line; |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 132 | last; |
| 133 | }; |
| 134 | return @delegates; |
| 135 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | |
| 137 | # Compute test specification |
| 138 | my $delegate_tests='t/*.t'; |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 139 | my @tested_delegates = qw/bzlib djvu fftw fontconfig freetype jpeg jng jp2 lcms mpeg png rsvg tiff x11 xml wmf zlib/; |
| 140 | my @supported_delegates = AutodetectDelegates(); |
| 141 | # find the intersection of tested and supported delegates |
| 142 | my %seen_delegates = (); |
| 143 | $seen_delegates{$_}++ for @supported_delegates; |
| 144 | foreach my $delegate (@tested_delegates) { |
cristy | 3a5962c | 2010-10-10 01:07:26 +0000 | [diff] [blame] | 145 | if ( $seen_delegates{$delegate} ) { |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 146 | if ( -d "t/$delegate" ) { |
| 147 | if ( defined($ENV{'DISPLAY'}) && ($^O ne 'MSWin32') ) { |
| 148 | if ( defined $ENV{'DISPLAY'} ) { |
| 149 | $delegate_tests .= " t/$delegate/*.t"; |
| 150 | } |
| 151 | next; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | } |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 153 | $delegate_tests .= " t/$delegate/*.t"; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 154 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 158 | # defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile |
| 159 | my $INC_magick = '-I../ -I@top_srcdir@ @CPPFLAGS@ -I"' . $Config{'usrinc'} . '/ImageMagick"'; |
cristy | 3dc6469 | 2011-07-02 01:24:25 +0000 | [diff] [blame] | 160 | my $LIBS_magick = '-L../MagickCore/.libs -lMagickCore -lperl @MATH_LIBS@'; |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 161 | my $CCFLAGS_magick = "$Config{'ccflags'} @CFLAGS@"; |
cristy | 3dc6469 | 2011-07-02 01:24:25 +0000 | [diff] [blame] | 162 | my $LDFLAGS_magick = "-L../MagickCore/.libs -lMagickCore $Config{'ldflags'} @LDFLAGS@"; |
| 163 | my $LDDLFLAGS_magick = "-L../MagickCore/.libs -lMagickCore $Config{'lddlflags'} @LDFLAGS@"; |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 164 | |
| 165 | if (($^O eq 'MSWin32') && ($Config{cc} =~ /gcc/)) { |
cristy | 5b67587 | 2009-10-21 13:12:00 +0000 | [diff] [blame] | 166 | my($Ipaths, $Lpaths) = AutodetectWin32gcc(); |
| 167 | |
| 168 | # |
| 169 | # Setup for strawberry perl. |
| 170 | # |
cristy | f912c45 | 2009-10-20 12:33:26 +0000 | [diff] [blame] | 171 | $INC_magick = "$Ipaths"; |
| 172 | $LIBS_magick = "-lMagickCore"; |
| 173 | $CCFLAGS_magick = "$Config{'ccflags'}"; |
| 174 | $LDFLAGS_magick = "$Config{'ldflags'} $Lpaths "; |
| 175 | $LDDLFLAGS_magick = "$Config{'lddlflags'} $Lpaths "; |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 176 | } |
| 177 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 178 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
| 179 | # the contents of the Makefile that is written. |
| 180 | WriteMakefile |
| 181 | ( |
| 182 | # Module description |
| 183 | 'ABSTRACT' => 'ImageMagick PERL Extension', |
| 184 | |
| 185 | # Perl module name is Image::Magick |
| 186 | 'NAME' => 'Image::Magick', |
| 187 | |
cristy | 5b67587 | 2009-10-21 13:12:00 +0000 | [diff] [blame] | 188 | # Module author |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 189 | 'AUTHOR' => 'ImageMagick Studio LLC', |
| 190 | |
| 191 | # Module version |
cristy | 878c2f1 | 2011-08-19 00:25:19 +0000 | [diff] [blame] | 192 | 'VERSION' => '@PACKAGE_PERL_VERSION@', |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 193 | |
| 194 | # Preprocessor defines |
cristy | 6b1a572 | 2010-10-08 17:35:00 +0000 | [diff] [blame] | 195 | 'DEFINE' => '@LFS_CPPFLAGS@ @DEFS@', # e.g., '-DHAVE_SOMETHING' |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 196 | |
| 197 | # Header search specfication and preprocessor flags |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 198 | 'INC' => $INC_magick, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 199 | |
| 200 | # C compiler |
cristy | e610759 | 2009-09-26 23:04:25 +0000 | [diff] [blame] | 201 | #'CC' => '@CC@', |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | |
| 203 | # C pre-processor flags (e.g. -I & -D options) |
| 204 | # 'CPPFLAGS' => "$Config{'cppflags'} @CPPFLAGS@", |
| 205 | |
| 206 | # C compiler flags (e.g. -O -g) |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 207 | 'CCFLAGS' => $CCFLAGS_magick, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 208 | |
| 209 | # Linker |
cristy | e610759 | 2009-09-26 23:04:25 +0000 | [diff] [blame] | 210 | #'LD' => $Config{'ld'} == $Config{'cc'} ? '@CC@' : $Config{'ld'}, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | |
| 212 | # Linker flags for building an executable |
cristy | f912c45 | 2009-10-20 12:33:26 +0000 | [diff] [blame] | 213 | 'LDFLAGS' => $LDFLAGS_magick, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 214 | |
| 215 | # Linker flags for building a dynamically loadable module |
cristy | f912c45 | 2009-10-20 12:33:26 +0000 | [diff] [blame] | 216 | 'LDDLFLAGS' => $LDDLFLAGS_magick, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 217 | |
| 218 | # Install PerlMagick binary into ImageMagick bin directory |
| 219 | 'INSTALLBIN' => '@BIN_DIR@', |
| 220 | |
| 221 | # Library specification |
cristy | e9d0a41 | 2009-10-09 01:49:39 +0000 | [diff] [blame] | 222 | 'LIBS' => [ $LIBS_magick ], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 223 | |
| 224 | # Perl binary name (if a Perl binary is built) |
| 225 | 'MAP_TARGET' => 'PerlMagick', |
| 226 | |
| 227 | # Let CFLAGS drive optimization flags by setting OPTIMIZE to empty |
| 228 | # 'OPTIMIZE' => '', |
| 229 | |
| 230 | # Use same compiler as ImageMagick |
| 231 | 'PERLMAINCC' => '@PERLMAINCC@ @OPENMP_CFLAGS@', |
cristy | ca142db | 2012-05-08 11:35:55 +0000 | [diff] [blame] | 232 | 'AR' => '@AR@', |
| 233 | 'LD' => '@PERLMAINCC@', |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | |
| 235 | # Set Perl installation prefix to ImageMagick installation prefix |
| 236 | # 'PREFIX' => '@prefix@', |
| 237 | |
| 238 | # Include delegate directories in tests |
| 239 | test => { TESTS => $delegate_tests}, |
| 240 | |
| 241 | ($Config{'archname'} =~ /-object$/i ? ('CAPI' => 'TRUE') : ()), |
| 242 | ); |
| 243 | |
| 244 | |
| 245 | # |
| 246 | # Substitutions for "makeaperl" section. |
| 247 | # |
| 248 | sub MY::makeaperl { |
| 249 | package MY; # so that "SUPER" works right |
| 250 | my $inherited = shift->SUPER::makeaperl(@_); |
| 251 | |
| 252 | # Stinky ExtUtils::MM_Unix likes to append its own library path to $(CC), |
| 253 | # prior to any user-specified library path so that an installed library is |
| 254 | # used rather than the library just built. This substitution function |
| 255 | # tries to insert our library path first. Also, use the same compiler used |
| 256 | # to build perlmain.c to link so that a C++ compiler may be used if |
| 257 | # necessary. |
| 258 | $inherited =~ s:MAP_LINKCMD\s.*\s*\$\(CC\):MAP_LINKCMD = \$(PERLMAINCC) -L@MAGICKCORE_PATH@: ; |
| 259 | $inherited; |
| 260 | } |