PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/PerlMagick/Makefile.PL

https://github.com/trevor/ImageMagick
Perl | 271 lines | 136 code | 41 blank | 94 comment | 20 complexity | bd83cb1a128232a5b85e6be0c1e59dff MD5 | raw file
  1. # Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization
  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:
  16. #
  17. # make test
  18. #
  19. # Exersise one regression test:
  20. #
  21. # make TEST_VERBOSE=1 TEST_FILES=t/filter.t test
  22. #
  23. use ExtUtils::MakeMaker;
  24. use Config;
  25. use File::Spec::Functions qw/catfile catdir devnull catpath splitpath/;
  26. use Cwd;
  27. sub AutodetectWin32gcc {
  28. my $wrkdir = getcwd();
  29. my $devnull = devnull();
  30. my @incdir = ();
  31. my @libdir = ($wrkdir);
  32. my @bindir = ();
  33. #try to get configuration info via identify or convert utilities
  34. my $conf = `identify -list Configure 2>$devnull` || `convert -list Configure 2>$devnull`;
  35. foreach my $line (split '\n', $conf) {
  36. if ($line =~ /^Path:\s+(.*)/) {
  37. my ($vol,$dir,$file) = splitpath($1);
  38. next unless $dir;
  39. my $dirpath = catpath( $vol, $dir);
  40. my (@l,@b,@i) = ( (),(),() );
  41. # try to detect 'lib' dir
  42. push @l, catfile($dirpath,'lib');
  43. push @l, catfile($dirpath,'..','lib');
  44. push @l, catfile($dirpath,'..','..','lib');
  45. push @l, catfile($dirpath,'..','..','..','lib');
  46. foreach (@l) { push @libdir, $_ if (-d $_) };
  47. # try to detect 'bin' dir
  48. push @b, catfile($dirpath);
  49. push @b, catfile($dirpath,'bin');
  50. push @b, catfile($dirpath,'..');
  51. push @b, catfile($dirpath,'..','bin');
  52. push @b, catfile($dirpath,'..','..');
  53. push @b, catfile($dirpath,'..','..','bin');
  54. push @b, catfile($dirpath,'..','..','..');
  55. push @b, catfile($dirpath,'..','..','..','bin');
  56. foreach (@b) { push @bindir, $_ if (-e "$_/convert.exe" || -e "$_/identify.exe") };
  57. # try to detect 'include' dir
  58. push @i, catfile($dirpath,'include');
  59. push @i, catfile($dirpath,'include','ImageMagick');
  60. push @i, catfile($dirpath,'..','include');
  61. push @i, catfile($dirpath,'..','include','ImageMagick');
  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. foreach (@i) { push @incdir, $_ if (-e "$_/MagickCore/MagickCore.h") };
  67. }
  68. };
  69. foreach my $bin (@bindir) {
  70. opendir(my $bindir, $bin) or die qq{Cannot opendir $bin: $!};
  71. my @dlls = map {catfile($bin, $_)} grep /^\S*magick[^\+]\S*?\.dll$/i, readdir $bindir;
  72. foreach my $d (@dlls) {
  73. unlink "$wrkdir/libMagickCore.def", "$wrkdir/libMagickCore.a";
  74. system("pexports \"$d\" >\"$wrkdir/libMagickCore.def\" 2>$devnull");
  75. open(DEF, "<$wrkdir/libMagickCore.def");
  76. my @found = grep(/MagickCoreGenesis/, <DEF>); #checking if we have taken the right DLL
  77. close(DEF);
  78. next unless(@found);
  79. print STDERR "Gonna create 'libMagickCore.a' from '$d'\n";
  80. system("dlltool -D \"$d\" -d \"$wrkdir/libMagickCore.def\" -l \"$wrkdir/libMagickCore.a\" 2>$devnull");
  81. last if -s "$wrkdir/libMagickCore.a";
  82. }
  83. last if -s "$wrkdir/libMagickCore.a";
  84. }
  85. unless(@incdir && @libdir && @bindir && (-s "$wrkdir/libMagickCore.a")) {
  86. print STDERR <<EOF
  87. ################################### WARNING! ###################################
  88. # It seems that you are trying to install Perl::Magick on a MS Windows box with
  89. # perl + gcc compiler (e.g. strawberry perl), however we cannot find ImageMagick
  90. # binaries installed on your system.
  91. #
  92. # Please check the following prerequisites:
  93. #
  94. # 1) You need to have installed ImageMagick Windows binaries from
  95. # http://www.imagemagick.org/script/binary-releases.php#windows
  96. #
  97. # 2) We only support dynamic (DLL) ImageMagick binaries
  98. # note: it is not possible to mix 32/64-bit binaries of perl and ImageMagick
  99. #
  100. # 3) During installation select that you want to install ImageMagick's
  101. # development files (libraries+headers)
  102. #
  103. # 4) You also need to have ImageMagick's directory in your PATH
  104. # note: we are checking the presence of convert.exe and/or identify.exe tools
  105. #
  106. # 5) You might need Visual C++ Redistributable Package installed on your system
  107. # see instructions on ImageMagick's Binary Release webpage
  108. #
  109. # We are gonna continue, but chances for successful build are very low!
  110. ################################################################################
  111. EOF
  112. }
  113. my $inc = join ' ', map "-I\"$_\"", @incdir;
  114. my $lib = join ' ', map "-L\"$_\"", @libdir;
  115. return ($inc, $lib);
  116. }
  117. sub AutodetectDelegates {
  118. #try to get configuration info via identify or convert utilities
  119. my $devnull = devnull();
  120. my $conf = `identify -list Configure 2>$devnull` || `convert -list Configure 2>$devnull`;
  121. my @delegates = ();
  122. foreach my $line (split '\n', $conf) {
  123. next unless $line =~ /^DELEGATES\s+/;
  124. (undef, @delegates) = split /\s+/, $line;
  125. last;
  126. };
  127. return @delegates;
  128. }
  129. # Compute test specification
  130. my $delegate_tests='t/*.t';
  131. my @tested_delegates = qw/bzlib djvu fftw fontconfig freetype jpeg jng openjp2 lcms mpeg png rsvg tiff x11 xml wmf zlib/;
  132. my @supported_delegates = AutodetectDelegates();
  133. # find the intersection of tested and supported delegates
  134. my %seen_delegates = ();
  135. $seen_delegates{$_}++ for @supported_delegates;
  136. foreach my $delegate (@tested_delegates) {
  137. if ( $seen_delegates{$delegate} ) {
  138. if ( -d "t/$delegate" ) {
  139. if ( defined($ENV{'DISPLAY'}) && ($^O ne 'MSWin32') ) {
  140. if ( defined $ENV{'DISPLAY'} ) {
  141. $delegate_tests .= " t/$delegate/*.t";
  142. }
  143. next;
  144. }
  145. $delegate_tests .= " t/$delegate/*.t";
  146. }
  147. }
  148. }
  149. # defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
  150. my $INC_magick = '-I../ -I.. -pthread -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libpng16 -I/usr/include/freetype2 -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/libxml2 -I"' . $Config{'usrinc'} . '/ImageMagick"';
  151. my $LIBS_magick = '-L../MagickCore/.libs -lMagickCore-7.Q16HDRI -lperl -lm';
  152. my $CCFLAGS_magick = "$Config{'ccflags'} -pthread -I/usr/include/OpenEXR -I/usr/include/libdrm -I/usr/include/freetype2 -fopenmp -g -O2 -Wall -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16";
  153. my $LDFLAGS_magick = "-L../MagickCore/.libs -lMagickCore-7.Q16HDRI $Config{'ldflags'} ";
  154. my $LDDLFLAGS_magick = "-L../MagickCore/.libs -lMagickCore-7.Q16HDRI $Config{'lddlflags'} ";
  155. if (($^O eq 'MSWin32') && ($Config{cc} =~ /gcc/)) {
  156. my($Ipaths, $Lpaths) = AutodetectWin32gcc();
  157. #
  158. # Setup for strawberry perl.
  159. #
  160. $INC_magick = "$Ipaths";
  161. $LIBS_magick = "-lMagickCore-7.Q16HDRI";
  162. $CCFLAGS_magick = "$Config{'ccflags'}";
  163. $LDFLAGS_magick = "$Config{'ldflags'} $Lpaths ";
  164. $LDDLFLAGS_magick = "$Config{'lddlflags'} $Lpaths ";
  165. }
  166. # See lib/ExtUtils/MakeMaker.pm for details of how to influence
  167. # the contents of the Makefile that is written.
  168. WriteMakefile
  169. (
  170. # Module description
  171. 'ABSTRACT' => 'ImageMagick PERL Extension',
  172. # Perl module name is Image::Magick
  173. 'NAME' => 'Image::Magick',
  174. # Module author
  175. 'AUTHOR' => 'ImageMagick Studio LLC',
  176. # Module version
  177. 'VERSION' => '7.00',
  178. # Prerequisite version
  179. 'PREREQ_PM' => {'parent' => '0'},
  180. # Preprocessor defines
  181. 'DEFINE' => ' -D_LARGE_FILES=1 -DHAVE_CONFIG_H', # e.g., '-DHAVE_SOMETHING'
  182. # Header search specfication and preprocessor flags
  183. 'INC' => $INC_magick,
  184. # C compiler
  185. #'CC' => 'gcc -std=gnu99 -std=gnu99',
  186. # C pre-processor flags (e.g. -I & -D options)
  187. # 'CPPFLAGS' => "$Config{'cppflags'} -pthread -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libpng16 -I/usr/include/freetype2 -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/libxml2",
  188. # C compiler flags (e.g. -O -g)
  189. 'CCFLAGS' => $CCFLAGS_magick,
  190. # Linker
  191. #'LD' => $Config{'ld'} == $Config{'cc'} ? 'gcc -std=gnu99 -std=gnu99' : $Config{'ld'},
  192. # Linker flags for building an executable
  193. 'LDFLAGS' => $LDFLAGS_magick,
  194. # Linker flags for building a dynamically loadable module
  195. 'LDDLFLAGS' => $LDDLFLAGS_magick,
  196. # Install PerlMagick binary into ImageMagick bin directory
  197. 'INSTALLBIN' => '/usr/local/bin',
  198. # Library specification
  199. 'LIBS' => [ $LIBS_magick ],
  200. # Perl binary name (if a Perl binary is built)
  201. 'MAP_TARGET' => 'PerlMagick',
  202. # Let CFLAGS drive optimization flags by setting OPTIMIZE to empty
  203. # 'OPTIMIZE' => '',
  204. # Use same compiler as ImageMagick
  205. 'PERLMAINCC' => 'g++ -fopenmp',
  206. 'AR' => 'ar',
  207. 'LD' => 'g++',
  208. # Set Perl installation prefix to ImageMagick installation prefix
  209. # 'PREFIX' => '/usr/local',
  210. # Include delegate directories in tests
  211. test => { TESTS => $delegate_tests},
  212. ($Config{'archname'} =~ /-object$/i ? ('CAPI' => 'TRUE') : ()),
  213. # sane version
  214. depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }
  215. );
  216. #
  217. # Substitutions for "makeaperl" section.
  218. #
  219. sub MY::makeaperl {
  220. package MY; # so that "SUPER" works right
  221. my $inherited = shift->SUPER::makeaperl(@_);
  222. # Stinky ExtUtils::MM_Unix likes to append its own library path to $(CC),
  223. # prior to any user-specified library path so that an installed library is
  224. # used rather than the library just built. This substitution function
  225. # tries to insert our library path first. Also, use the same compiler used
  226. # to build perlmain.c to link so that a C++ compiler may be used if
  227. # necessary.
  228. $inherited =~ s:MAP_LINKCMD\s.*\s*\$\(CC\):MAP_LINKCMD = \$(PERLMAINCC) -L/usr/local/lib: ;
  229. $inherited;
  230. }