]> git.imager.perl.org - imager.git/blame_incremental - Makefile.PL
Made TODO into a seperate file and removed it from the Changes file.
[imager.git] / Makefile.PL
... / ...
CommitLineData
1
2use ExtUtils::MakeMaker;
3use Cwd;
4use Config;
5
6$lext=$Config{'so'}; # Get extensions of libraries
7$aext=$Config{'_a'};
8
9#
10# IM_INCPATH colon seperated list of paths to extra include paths
11# IM_LIBPATH colon seperated list of paths to extra library paths
12#
13# IM_VERBOSE turns on verbose mode for the library finding and such
14# IM_MANUAL to manually select which libraries are used and which not
15# IM_ENABLE to programmatically select which libraries are used
16# and which are not
17# IM_NOLOG if true logging will not be compiled into the module
18# IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module
19# do not use IM_DEBUG_MALLOC in production - this slows
20# everything down by alot
21# IM_CFLAGS Extra flags to pass to the compiler
22# IM_LFLAGS Extra flags to pass to the linker
23# IM_DFLAGS Extra flags to pass to the preprocessor
24
25
26getenv(); # get environment variables
27init(); # initialize global data
28pathcheck(); # Check if directories exist
29
30# Pick what libraries are used
31if ($MANUAL) {
32 manual();
33} else {
34 automatic();
35 if (exists $ENV{IM_ENABLE}) {
36 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
37 for my $key (keys %formats) {
38 delete $formats{$key} unless $en{$key};
39 }
40 }
41}
42
43# Make sure there isn't a clash between the gif libraries.
44gifcheck();
45
46for $frm(values %formats) {
47 $F_DEFINE .= ' -D'.$frm->{def};
48 $F_LIBS .= ' ' .$frm->{libfiles};
49 $F_OBJECT .= ' ' .$frm->{objfiles};
50}
51
52$F_INC = join(" ",map { (exists $definc{$_})?'':'-I'.$_ } @incs);
53$F_LIBS = join(" ",map { '-L'.$_ } @libs).' '.$F_LIBS;
54
55$OSLIBS = '';
56$OSDEF = "-DOS_$^O";
57
58if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
59if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
60
61@objs = qw(Imager.o draw.o image.o io.o iolayer.o log.o
62 gaussian.o conv.o pnm.o raw.o feat.o font.o
63 filters.o dynaload.o stackmach.o datatypes.o
64 regmach.o trans2.o quant.o error.o convert.o
65 map.o);
66
67%opts=(
68 'NAME' => 'Imager',
69 'VERSION_FROM' => 'Imager.pm',
70 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
71 'DEFINE' => "$F_DEFINE $EXTDEF $OSDEF $CFLAGS",
72 'INC' => "$DFLAGS $F_INC",
73 'OBJECT' => join(' ', @objs, $F_OBJECT),
74 clean => { FILES=>'testout' },
75 );
76
77if ($] ge '5.005') {
78 $opts{AUTHOR} = 'Arnar M. Hrafnkelsson, addi@umich.edu';
79 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
80}
81
82if ($VERBOSE) { print Dumper(\%opts); }
83mkdir('testout',0777); # since we cannot include it in the archive.
84WriteMakefile(%opts);
85
86exit;
87
88
89sub MY::postamble {
90'
91dyntest.(MYEXTLIB) : dynfilt/Makefile
92 cd dynfilt && $(MAKE) $(PASTHRU)
93
94lib/Imager/Regops.pm : regmach.h regops.perl
95 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
96';
97}
98
99# manual configuration of helper libraries
100
101sub manual {
102 print <<EOF;
103
104 Please answer the following questions about
105 which formats are avaliable on your computer
106
107press <return> to continue
108EOF
109
110 <STDIN>; # eat one return
111
112 for $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
113 SWX:
114 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
115 print "Enable $frm support: ";
116 $gz=<STDIN>;
117 chomp($gz);
118 if ($gz =~ m/^(y|yes|n|no)/i) {
119 $gz=substr(lc($gz),0,1);
120 if ($gz eq 'n') {
121 delete $formats{$frm};
122 }
123 } else { goto SWX; }
124 }
125}
126
127
128# automatic configuration of helper libraries
129
130sub automatic {
131 for $frm(keys %formats) {
132 delete $formats{$frm} if !checkformat($frm);
133 }
134}
135
136
137sub gifcheck {
138 if ($formats{'gif'} and $formats{'ungif'}) {
139 print "ungif and gif can not coexist - removing ungif support\n";
140 delete $formats{'ungif'};
141 }
142 my @dirs;
143 for my $frm (grep $formats{$_}, qw(gif ungif)) {
144 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
145 }
146 my $minor = 0;
147 my $major = 0;
148 FILES: for my $dir (@dirs) {
149 my $h = "$dir/gif_lib.h";
150 open H, "< $h" or next;
151 while (<H>) {
152 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
153 $major = $1;
154 $minor = $2;
155 close H;
156 last FILES;
157 }
158 }
159 close H;
160 }
161
162 # we need the version in a #ifdefable form
163
164 $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor";
165}
166
167
168sub gd {
169 my($path,$chk)=@_;
170
171# print "checking path $path\n";
172 if ( !opendir(DH,$path) ) {
173 warn "Cannot open dir $path: $!\n";
174 return;
175 }
176 my @l=grep { $chk->($_) } readdir(DH);
177 # print @l;
178 close(DH);
179 return map $path, @l;
180}
181
182
183sub checkformat {
184 my $frm=shift;
185 my $libchk=$formats{$frm}{'libcheck'};
186 my $incchk=$formats{$frm}{'inccheck'};
187
188 my @l;
189 for my $lp (@libs) {
190 push(@l, gd($lp,$libchk));
191 }
192
193 my @i;
194 for my $ip (@incs) {
195 push(@i, gd($ip,$incchk));
196 }
197
198 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
199 $formats{$frm}{incdir} = \@i;
200 $formats{$frm}{libdir} = \@l;
201 return scalar(@i && @l);
202}
203
204
205
206
207sub pathcheck {
208 if ($VERBOSE) {
209 print "pathcheck\n";
210 print " Include paths:\n";
211 for (@incs) { print $_,"\n"; }
212 }
213 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @incs;
214
215 if ($VERBOSE) {
216 print "\nLibrary paths:\n";
217 for (@incs) { print $_,"\n"; }
218 }
219 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @libs;
220 print "\ndone.\n";
221}
222
223
224# Format data initialization
225
226# format definition is:
227# defines needed
228# default include path
229# files needed for include (boolean perl code)
230# default lib path
231# libs needed
232# files needed for link (boolean perl code)
233# object files needed for the format
234
235
236sub init {
237
238 @definc{'/usr/include'}=();
239 @incs=(qw(/usr/include /usr/local/include /usr/include/freetype /usr/local/include/freetype), split /:/, $INCPATH );
240 @libs=(split(/ /, $Config{'libpth'}), split(/:/, $LIBPATH) );
241 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
242 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
243 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
244 }
245
246 $formats{'jpeg'}={
247 order=>'21',
248 def=>'HAVE_LIBJPEG',
249 inccheck=>sub { $_[0] eq 'jpeglib.h' },
250 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
251 libfiles=>'-ljpeg',
252 objfiles=>'jpeg.o',
253 docs=>q{
254 In order to use jpeg with this module you need to have libjpeg
255 installed on your computer}
256 };
257
258 $formats{'tiff'}={
259 order=>'23',
260 def=>'HAVE_LIBTIFF',
261 inccheck=>sub { $_[0] eq 'tiffio.h' },
262 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
263 libfiles=>'-ltiff',
264 objfiles=>'tiff.o',
265 docs=>q{
266 In order to use tiff with this module you need to have libtiff
267 installed on your computer}
268 };
269
270 $formats{'png'}={
271 order=>'22',
272 def=>'HAVE_LIBPNG',
273 inccheck=>sub { $_[0] eq 'png.h' },
274 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
275 libfiles=>'-lpng -lz',
276 objfiles=>'png.o',
277 docs=>q{
278 Png stands for Portable Network Graphics and is intended as
279 a replacement for gif on the web. It is patent free and
280 is recommended by the w3c, you need libpng to use these formats}
281 };
282
283 $formats{'gif'}={
284 order=>'20',
285 def=>'HAVE_LIBGIF',
286 inccheck=>sub { $_[0] eq 'gif_lib.h' },
287 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
288 libfiles=>'-lgif',
289 objfiles=>'gif.o',
290 docs=>q{
291 gif is the de facto standard for webgraphics at the moment,
292 it does have some patent problems. If you have giflib and
293 are not in violation with the unisys patent you should use
294 this instead of the 'ungif' option. Note that they cannot
295 be in use at the same time}
296 };
297
298 $formats{'ungif'}={
299 order=>'21',
300 def=>'HAVE_LIBGIF',
301 inccheck=>sub { $_[0] eq 'gif_lib.h' },
302 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
303 libfiles=>'-lungif',
304 objfiles=>'gif.o',
305 docs=>q{
306 gif is the de facto standard for webgraphics at the moment,
307 it does have some patent problems. If you have libungif and
308 want to create images free from LZW patented compression you
309 should use this option instead of the 'gif' option}
310 };
311
312 $formats{'T1-fonts'}={
313 order=>'30',
314 def=>'HAVE_LIBT1',
315 inccheck=>sub { $_[0] eq 't1lib.h' },
316 libcheck=>sub { $_[0] eq 'libt1.a' or $_[0] eq "libt1.$lext" },
317 libfiles=>'-lt1',
318 objfiles=>'',
319 docs=>q{
320 postscript t1 fonts are scalable fonts. They can include
321 ligatures and kerning information and generally yield good
322 visual quality. We depend on libt1 to rasterize the fonts
323 for use in images.}
324 };
325
326 $formats{'TT-fonts'}={
327 order=>'31',
328 def=>'HAVE_LIBTT',
329 inccheck=>sub { $_[0] eq 'freetype.h' },
330 libcheck=>sub { $_[0] eq 'libttf.a' or $_[0] eq "libttf.$lext" },
331 libfiles=>'-lttf',
332 objfiles=>'',
333 docs=>q{
334 Truetype fonts are scalable fonts. They can include
335 kerning and hinting information and generally yield good
336 visual quality esp on low resultions. The freetype library is
337 used to rasterize for us. The only drawback is that there
338 are alot of badly designed fonts out there.}
339 };
340 # Make fix indent
341 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
342}
343
344
345
346sub gen {
347 my $V = $ENV{$_[0]};
348 defined($V) ? $V : "";
349}
350
351
352# Get information from environment variables
353
354sub getenv {
355
356 ($VERBOSE,
357 $INCPATH,
358 $LIBPATH,
359 $NOLOG,
360 $DEBUG_MALLOC,
361 $MANUAL,
362 $CFLAGS,
363 $LFLAGS,
364 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
365 IM_INCPATH
366 IM_LIBPATH
367 IM_NOLOG
368 IM_DEBUG_MALLOC
369 IM_MANUAL
370 IM_CFLAGS
371 IM_LFLAGS
372 IM_DFLAGS);
373
374 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
375
376 if ($NOLOG) { print "Logging not compiled into module\n"; }
377 else { $EXTDEF.=' -DIMAGER_LOG'; }
378
379 if ($DEBUG_MALLOC) {
380 $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
381 print "Malloc debugging enabled\n";
382 }
383
384}