]> git.imager.perl.org - imager.git/commitdiff
- Makefile.PL now builds imconfig.h with #defines for libraries
authorTony Cook <tony@develop=help.com>
Thu, 6 Jan 2005 09:43:43 +0000 (09:43 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 6 Jan 2005 09:43:43 +0000 (09:43 +0000)
  present (and for the GIF library version) rather than putting them
  into CFLAGS

.cvsignore
Changes
Makefile.PL
image.h
log.c

index 4be0832c846f4efd6031b9fef43db7e4c5336e51..ea87bc7f05d784c51cb442566d89bcf1cad9d7e3 100644 (file)
@@ -6,3 +6,4 @@ Imager.c
 pm_to_blib
 Imager.bs
 t1lib.log
 pm_to_blib
 Imager.bs
 t1lib.log
+imconfig.h
diff --git a/Changes b/Changes
index 54ffffeeb4769d1a626efd0717626153d716613d..f1bf40acccb97ce1a7ac5e1d1fad763dcba4bd26 100644 (file)
--- a/Changes
+++ b/Changes
@@ -990,6 +990,9 @@ Revision history for Perl extension Imager.
   and pkg-config to configure libpng.
 - avoid complaining about include/lib directories we pull from 
   perl's config or we have built-in
   and pkg-config to configure libpng.
 - avoid complaining about include/lib directories we pull from 
   perl's config or we have built-in
+- Makefile.PL now builds imconfig.h with #defines for libraries
+  present (and for the GIF library version) rather than putting them
+  into CFLAGS
 
 =================================================================
 
 
 =================================================================
 
index 5cb36ccdc71bfe69ced28e536f17dc10afb6de8d..a3e08042e59722b9e29561f2c609bf316f89b90a 100644 (file)
@@ -26,6 +26,8 @@ getenv();     # get environment variables
 init();       # initialize global data
 pathcheck();  # Check if directories exist
 
 init();       # initialize global data
 pathcheck();  # Check if directories exist
 
+my @defines;
+
 # Pick what libraries are used
 if ($MANUAL) {
   manual();
 # Pick what libraries are used
 if ($MANUAL) {
   manual();
@@ -43,8 +45,9 @@ if ($MANUAL) {
 gifcheck();
 
 my $lib_cflags = '';
 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};
   $F_LIBS   .= ' '  .$frm->{libfiles};
   $F_OBJECT .= ' '  .$frm->{objfiles};
   $lib_cflags   .= ' '  .$frm->{cflags} if $frm->{cflags};
@@ -71,7 +74,7 @@ if (defined $Config{'d_dlsymun'}) { $OSDEF  .= ' -DDLSYMUN'; }
        'NAME'         => 'Imager',
        'VERSION_FROM' => 'Imager.pm',
        'LIBS'         => "$LFLAGS -lm $OSLIBS $F_LIBS",
        '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' },
        'INC'          => "$lib_cflags $DFLAGS $F_INC",
        'OBJECT'       => join(' ', @objs, $F_OBJECT),
        clean          => { FILES=>'testout' },
@@ -85,6 +88,8 @@ if ($ExtUtils::MakeMaker::VERSION > 6.10) {
   $opts{NO_META} = 1;
 }
 
   $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);
 if ($VERBOSE) { print Dumper(\%opts); }
 mkdir('testout',0777); # since we cannot include it in the archive.
 WriteMakefile(%opts);
@@ -99,6 +104,11 @@ dyntest.$(MYEXTLIB) : dynfilt/Makefile
 
 lib/Imager/Regops.pm : regmach.h regops.perl
        $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
 
 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 +208,8 @@ EOFF
 
   # we need the version in a #ifdefable form
 
 
   # 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 ];
 }
 
 
 }
 
 
@@ -469,15 +480,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"; }
   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) {
 
   if ($DEBUG_MALLOC) {
-    $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
+    push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
     print "Malloc debugging enabled\n";
   }
 
 }
 
     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) = @_;
 # probes for freetype2 by trying to run freetype-config
 sub freetype2_probe {
   my ($frm, $frmkey) = @_;
diff --git a/image.h b/image.h
index 5278c09a0e94af1ae10477c83cfd9ff0cd3623f0..52f507177013a294815862bb3e22c0ec81cdfea3 100644 (file)
--- a/image.h
+++ b/image.h
@@ -1,6 +1,7 @@
 #ifndef _IMAGE_H_
 #define _IMAGE_H_
 
 #ifndef _IMAGE_H_
 #define _IMAGE_H_
 
+#include "imconfig.h"
 #include "imio.h"
 #include "iolayer.h"
 #include "log.h"
 #include "imio.h"
 #include "iolayer.h"
 #include "log.h"
diff --git a/log.c b/log.c
index 04e225a7d97f2e397323f02cdc01ca9ca91fb4ba..c2b23e62a2bd04753fdd8ed1fc38b093ab18e5c3 100644 (file)
--- a/log.c
+++ b/log.c
@@ -1,3 +1,4 @@
+#include "imconfig.h"
 #include "log.h"
 
 #define DTBUFF 50
 #include "log.h"
 
 #define DTBUFF 50