]> git.imager.perl.org - imager.git/blobdiff - Makefile.PL
- added samp-form.cgi and samp-image.cgi to the samples directory to
[imager.git] / Makefile.PL
index 5cb36ccdc71bfe69ced28e536f17dc10afb6de8d..444842d44254432972805ab0ef20a59697168cf5 100644 (file)
@@ -3,6 +3,7 @@ use ExtUtils::MakeMaker;
 use Cwd;
 use Config;
 use File::Spec;
+use Getopt::Long;
 
 #
 # IM_INCPATH      colon seperated list of paths to extra include paths
@@ -21,30 +22,64 @@ use File::Spec;
 # IM_DFLAGS       Extra flags to pass to the preprocessor
 # IM_SUPPRESS_PROMPT  Suppress the prompt asking about gif support
 
+my $help;
+my @enable;
+my @disable;
+my @incpaths;
+my @libpaths;
+my $noprobe;
+GetOptions("help" => \$help,
+           "enable=s" => \@enable,
+           "disable=s" => \@disable,
+           "incpath=s", \@incpaths,
+           "libpath=s" => \@libpaths,
+           "noprobe" => \$noprobe);
+
+if ($help) {
+  usage();
+}
+
+if (@enable && @disable) {
+  print STDERR "Only --enable or --disable can be used, not both, try --help\n";
+  exit 1;
+}
 
 getenv();     # get environment variables
 init();       # initialize global data
 pathcheck();  # Check if directories exist
 
+if (exists $ENV{IM_ENABLE}) {
+  my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
+  for my $key (keys %formats) {
+    delete $formats{$key} unless $en{$key};
+  }
+}
+if (@enable) {
+  my %en = map { $_ => 1 } map { split /,/ } @enable;
+  for my $key (keys %formats) {
+    delete $formats{$key} unless $en{$key};
+  }
+}
+elsif (@disable) {
+  delete @formats{map { split /,/ } @disable};
+}
+
+my @defines;
+
 # Pick what libraries are used
 if ($MANUAL) {
   manual();
 } else {
   automatic();
-  if (exists $ENV{IM_ENABLE}) {
-    my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
-    for my $key (keys %formats) {
-      delete $formats{$key} unless $en{$key};
-    }
-  }
 }
 
 # Make sure there isn't a clash between the gif libraries.
 gifcheck();
 
 my $lib_cflags = '';
-for $frm(values %formats) {
-  $F_DEFINE .= ' -D'.$frm->{def};
+for my $frmkey (keys %formats) {
+  my $frm = $formats{$frmkey};
+  push @defines, [ $frm->{def}, 1, "$frmkey available" ];
   $F_LIBS   .= ' '  .$frm->{libfiles};
   $F_OBJECT .= ' '  .$frm->{objfiles};
   $lib_cflags   .= ' '  .$frm->{cflags} if $frm->{cflags};
@@ -71,7 +106,7 @@ if (defined $Config{'d_dlsymun'}) { $OSDEF  .= ' -DDLSYMUN'; }
        'NAME'         => 'Imager',
        'VERSION_FROM' => 'Imager.pm',
        'LIBS'         => "$LFLAGS -lm $OSLIBS $F_LIBS",
-       'DEFINE'       => "$F_DEFINE $EXTDEF $OSDEF $CFLAGS",
+       'DEFINE'       => "$OSDEF $CFLAGS",
        'INC'          => "$lib_cflags $DFLAGS $F_INC",
        'OBJECT'       => join(' ', @objs, $F_OBJECT),
        clean          => { FILES=>'testout' },
@@ -85,6 +120,8 @@ if ($ExtUtils::MakeMaker::VERSION > 6.10) {
   $opts{NO_META} = 1;
 }
 
+make_imconfig(\@defines);
+
 if ($VERBOSE) { print Dumper(\%opts); }
 mkdir('testout',0777); # since we cannot include it in the archive.
 WriteMakefile(%opts);
@@ -99,6 +136,11 @@ dyntest.$(MYEXTLIB) : dynfilt/Makefile
 
 lib/Imager/Regops.pm : regmach.h regops.perl
        $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
+
+imconfig.h: Makefile.PL
+       $(ECHO) "imconfig.h out-of-date with respect to $?"
+       $(PERLRUN) Makefile.PL
+       $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
 ';
 }
 
@@ -198,7 +240,8 @@ EOFF
 
   # we need the version in a #ifdefable form
 
-  $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor";
+  push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ];
+  push @defines, [ IM_GIFMINOR, $minor ];
 }
 
 
@@ -219,9 +262,9 @@ sub gd {
 
 sub checkformat {
   my $frm=shift;
-
+  
   my $code = $formats{$frm}{'code'};
-  if ($code) {
+  if ($code && !$noprobe) {
     return 1 if $code->($formats{$frm}, $frm);
   }
 
@@ -235,7 +278,7 @@ sub checkformat {
 
   my @i;
   for my $ip (@incs) {
-    push(@i, gd($ip,$incchk));
+    push(@i, $ip) if $incchk->($ip,$frm);
   }
 
   printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
@@ -245,8 +288,6 @@ sub checkformat {
 }
 
 
-
-
 sub pathcheck {
   if ($VERBOSE) {
     print "pathcheck\n";
@@ -279,7 +320,8 @@ sub pathcheck {
 sub init {
 
   @definc{'/usr/include'}=();
-  @incs=(split(/\Q$Config{path_sep}/, $INCPATH));
+  @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
+        map { split /\Q$Config{path_sep}/} @incpaths );
   if ($Config{locincpth}) {
     push @incs, grep -d, split ' ', $Config{locincpth};
   }
@@ -291,10 +333,11 @@ sub init {
          /usr/include/freetype2
          /usr/local/include/freetype2
          /usr/local/include/freetype1/freetype
-         /usr/include /usr/local/include /usr/include/freetype 
+         /usr/include /usr/local/include /usr/include/freetype
          /usr/local/include/freetype);
 
-  @libs= split(/\Q$Config{path_sep}/,$LIBPATH);
+  @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
+    map { split /\Q$Config{path_sep}/} @libpaths );
   if ($Config{loclibpth}) {
     push @libs, grep -d, split ' ', $Config{loclibpth};
   }
@@ -313,7 +356,7 @@ sub init {
   $formats{'jpeg'}={
                    order=>'21',
                    def=>'HAVE_LIBJPEG',
-                   inccheck=>sub { $_[0] eq 'jpeglib.h' },
+                   inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
                    libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
                    libfiles=>'-ljpeg',
                    objfiles=>'jpeg.o',
@@ -325,7 +368,7 @@ sub init {
   $formats{'tiff'}={
                    order=>'23',
                    def=>'HAVE_LIBTIFF',
-                   inccheck=>sub { $_[0] eq 'tiffio.h' },
+                   inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
                    libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
                    libfiles=>'-ltiff',
                    objfiles=>'tiff.o',
@@ -337,7 +380,7 @@ sub init {
   $formats{'png'}={
                   order=>'22',
                   def=>'HAVE_LIBPNG',
-                  inccheck=>sub { $_[0] eq 'png.h' },
+                  inccheck=>sub { -e catfile($_[0], 'png.h') },
                   libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
                   libfiles=>'-lpng -lz',
                   objfiles=>'png.o',
@@ -351,7 +394,7 @@ sub init {
   $formats{'gif'}={
                   order=>'20',
                   def=>'HAVE_LIBGIF',
-                  inccheck=>sub { $_[0] eq 'gif_lib.h' },
+                  inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
                   libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
                   libfiles=>'-lgif',
                   objfiles=>'gif.o',
@@ -366,7 +409,7 @@ sub init {
   $formats{'ungif'}={
                     order=>'21',
                     def=>'HAVE_LIBGIF',
-                    inccheck=>sub { $_[0] eq 'gif_lib.h' },
+                    inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
                     libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
                     libfiles=>'-lungif',
                     objfiles=>'gif.o',
@@ -380,7 +423,7 @@ sub init {
   $formats{'T1-fonts'}={
                        order=>'30',
                        def=>'HAVE_LIBT1',
-                       inccheck=>sub { $_[0] eq 't1lib.h' },
+                       inccheck=>sub { -e catfile($_[0], 't1lib.h') },
                        libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
                        libfiles=>'-lt1',
                        objfiles=>'',
@@ -391,24 +434,26 @@ sub init {
                                for use in images.}
                       };
 
-  $formats{'TT-fonts'}={
-                       order=>'31',
-                       def=>'HAVE_LIBTT',
-                       inccheck=>sub { $_[0] eq 'freetype.h' },
-                       libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
-                       libfiles=>'-lttf',
-                       objfiles=>'',
-                       docs=>q{
-                               Truetype fonts are scalable fonts. They can include 
-                               kerning and hinting information and generally yield good
-                               visual quality esp on low resultions. The freetype library is
-                               used to rasterize for us. The only drawback is that there
-                               are alot of badly designed fonts out there.}
+  $formats{'TT-fonts'}=
+    {
+     order=>'31',
+     def=>'HAVE_LIBTT',
+     inccheck=>sub { -e catfile($_[0], 'freetype.h')
+                       && !-e catfile($_[0], 'fterrors.h') },
+     libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
+     libfiles=>'-lttf',
+     objfiles=>'',
+     docs=>q{
+Truetype fonts are scalable fonts. They can include 
+kerning and hinting information and generally yield good
+visual quality esp on low resultions. The freetype library is
+used to rasterize for us. The only drawback is that there
+are alot of badly designed fonts out there.}
                       };
   $formats{'w32'} = {
                     order=>40,
                     def=>'HAVE_WIN32',
-                    inccheck=>sub { lc $_[0] eq 'windows.h' },
+                    inccheck=>sub { -e catfile($_[0], 'windows.h') },
                     libcheck=>sub { lc $_[0] eq 'gdi32.lib' 
                                       || lc $_[0] eq 'libgdi32.a' },
                     libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
@@ -422,13 +467,13 @@ DOCS
   $formats{'freetype2'} = {
                            order=>'29',
                            def=>'HAVE_FT2',
-                           inccheck=>sub { lc $_[0] eq 'ft2build.h' },
+                           inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
                            libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
                            libfiles=>'-lfreetype',
                            objfiles=>'freetyp2.o',
                            docs=><<DOCS,
 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
-scalable.
+scalable.  It also supports a variety of other fonts.
 DOCS
                            code => \&freetype2_probe,
                           };
@@ -469,15 +514,39 @@ sub getenv {
   if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
 
   if ($NOLOG)   { print "Logging not compiled into module\n"; }
-  else { $EXTDEF.=' -DIMAGER_LOG'; }
+  else { 
+    push @defines, [ IMAGER_LOG => 1, "Logging system" ];
+  }
 
   if ($DEBUG_MALLOC) {
-    $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
+    push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
     print "Malloc debugging enabled\n";
   }
 
 }
 
+sub make_imconfig {
+  my ($defines) = @_;
+
+  open CONFIG, "> imconfig.h"
+    or die "Cannot create imconfig.h: $!\n";
+  print CONFIG <<EOS;
+/* This file is automatically generated by Makefile.PL.
+   Don't edit this file, since any changes will be lost */
+
+#ifndef IMAGER_IMCONFIG_H
+#define IMAGER_IMCONFIG_H
+EOS
+  for my $define (@$defines) {
+    if ($define->[2]) {
+      print CONFIG "\n/*\n  $define->[2]\n*/\n\n";
+    }
+    print CONFIG "#define $define->[0] $define->[1]\n";
+  }
+  print CONFIG "\n#endif\n";
+  close CONFIG;
+}
+
 # probes for freetype2 by trying to run freetype-config
 sub freetype2_probe {
   my ($frm, $frmkey) = @_;
@@ -543,3 +612,15 @@ sub is_exe {
 
   return;
 }
+
+sub usage {
+  print STDERR <<EOS;
+Usage: $0 [--enable feature1,feature2,...] [--incpath ...] [--libpath ...]
+       $0 [--disable feature1,feature2,...] [--incpath ...] [--libpath ...]
+       $0 --help
+Possible feature names are:
+  png gif ungif jpeg tiff T1-fonts TT-fonts freetype2
+EOS
+  exit 1;
+
+}