Debian Codegraph @

myConfig

raw
1 # -*- cperl -*-
2 require 5.00404;
3 my $path = "$Config{'archlibexp'}/CORE/perl.h";
4 die "Cannot find '$path' have you installed $^X?\n" unless (-r $path);
5 print "$^X is installed in $Config{'archlibexp'} okay\n";
6 use Config;
7 use Cwd;
8 use Tk::MMtry;
9 warn "No VERSION" unless (defined $VERSION);
10
11 my %define = ();
12
13 $inc = "";
14 $xlib = "";
15 $define = '';
16 $gccopt = "";
17 @macro = ( macro => {} );
18 $is_maintainer = 0;
19 eval{
20 $is_maintainer = (getpwuid($<))[6]
21 =~ /(Nick\s+Ing-Simmons|Slaven\s+Rezic)/;
22 };
23 if (defined $Config{'gccversion'})
24 {
25 $ver = $Config{'gccversion'};
26 if ($ver ge "2.8")
27 {
28 # retain author's favourite warnings if using gcc
29 $gccopt .= " -Wall -Wno-implicit-int -Wno-comment -Wno-unused -D__USE_FIXED_PROTOTYPES__";
30 eval
31 {
32 if (0 && $is_maintainer)
33 {
34 # This is the author - catch as many bugs as possible
35 # XXX libpng causes some warnings, so this is not enabled anymore
36 $gccopt .= " -MMD -Werror -Wno-format";
37 }
38 }
39 }
40 }
41
42 if ($] >= 5.005)
43 {
44 # Add PPM support stuff
45 push(@macro,
46 ABSTRACT => 'Tk - a Graphical User Interface Toolkit',
47 AUTHOR => '[email protected] (Nick Ing-Simmons)'
48 );
49 my $arch = ($^O eq 'MSWin32') ? $ENV{'PROCESSOR_ARCHITECTURE'} : $Config{'archname'};
50 my $binloc = "BINARY_LOCATION=$arch/Tk$VERSION-PPM.tar.gz";
51 if (!grep { $binloc eq $_ } @ARGV)
52 {
53 push(@ARGV,$binloc);
54 }
55 warn "PPM for perl$]\n";
56 }
57 else
58 {
59 warn "No PPM for perl$]\n";
60 }
61
62 $macro[1]->{WINARCH} = $win_arch;
63
64 #
65 # Convert perls Config info into -DXXXX for Tk
66 #
67
68 $define{'USE_PROTOTYPE'} = 1 if ($Config{'prototype'});
69 $define{'HAVE_INTTYPES_H'} = 1 if ($Config{'i_inttypes'});
70 $define{'HAVE_UNISTD_H'} = 1 if ($Config{'i_unistd'});
71 $define{'HAVE_SYS_SELECT_H'} = 1 if ($Config{'i_sysselct'});
72 $define{'NO_STDLIB_H'} = 1 unless ($Config{'i_stdlib'});
73 if ($Config{'i_systime'})
74 {
75 $define{'HAVE_SYS_TIME_H'} = 1;
76 if ($Config{'i_time'})
77 {
78 $define{'TIME_WITH_SYS_TIME'} = 1;
79 }
80 }
81 $define{'HAVE_LIMITS_H'} = 1 if ($Config{'i_limits'});
82 $define{'HAS_STDARG'} = 1 if ($Config{'i_stdarg'});
83 $define{'USE_BCOPY'} = 1 if (!$Config{'d_memmove'} && $Config{'d_bcopy'});
84
85 if (defined $Config{'selecttype'})
86 {
87 my $type = $Config{'selecttype'};
88 $type =~ s/\s*\*\s*$//;
89 $define{'SELECT_MASK'} = $type;
90 }
91
92 if (!$Config{'i_unistd'} && defined $Config{'lseektype'})
93 {
94 my $type = $Config{'lseektype'};
95 $type =~ s/\s*\*\s*$//;
96 $define{'LSEEK_TYPE'} =$type;
97 }
98
99 my $voidflags = $Config{'voidflags'};
100 my $voidused = $Config{'defvoidused'}+0;
101
102 $define{'NOVOID'} = 1 if (($voidflags & $voidused) != $voidused);
103 $define{'NOCONST'} = 1 unless ($Config{'d_const'});
104
105 #
106 # Hunt down X Library - first a function
107 #
108 sub lX11
109 {
110 my $user = shift;
111 foreach (@_)
112 {
113 # allow any of libX11.a libX11.so.* etc.
114 if (-d $_)
115 {
116 local ($lib);
117 my $pattern = "$_/libX11.*";
118 $pattern .= " $_/X11$Config::Config{lib_ext}"
119 if $Config::Config{osname} eq 'os2';
120 foreach $lib (reverse(<$ {pattern}>))
121 {
122 if (-r $lib)
123 {
124 print "Using -L$_ to find $lib\n";
125 return "-L$_"
126 }
127 }
128 }
129 }
130 print "No -lX11 in ",join(' ',@_),"\n" if (@_ && $user);
131 return undef;
132 }
133
134 sub IX11
135 {
136 foreach (@_)
137 {
138 if (-d $_ && -d "$_/X11" && -r "$_/X11/Xlib.h")
139 {
140 print "Using -I$_ to find $_/X11/Xlib.h\n";
141 return "-I$_";
142 }
143 }
144 return undef;
145 }
146
147 sub Ift
148 {
149 foreach (map { "$_/freetype2" } @_)
150 {
151 if (-r "$_/freetype.h") # location in Debian (since jessie) and in newer versions of the FreeBSD port
152 {
153 print "Using -I$_ to find $_/freetype/freetype.h\n";
154 return "-I$_";
155 }
156 if (-r "$_/freetype/freetype.h") # location in FreeBSD (older versions of freetype2 port) and Debian (up to wheezy)
157 {
158 print "Using -I$_ to find $_/freetype/freetype.h\n";
159 return "-I$_";
160 }
161 }
162 return undef;
163 }
164
165 my @args = ();
166 my $arg;
167 foreach $arg (@ARGV)
168 {
169 if ($arg =~ /^(X11\w*|XFT)=(.*)$/)
170 {
171 ${"$1"} = $2;
172 # Pushing these args to @ARGV will generate MakeMaker warnings
173 # ("... is not a known MakeMaker parameter name") but
174 # will asure that the parameters are reused when automatically
175 # re-building Makefiles.
176 }
177 elsif ($arg eq 'VERBOSE=1')
178 {
179 $Tk::MMtry::VERBOSE = 1;
180 }
181 else
182 {
183 $MakefileName = $1 if ($arg =~ /^MAKEFILE=(.*)$/);
184 }
185 push(@args,$arg);
186 }
187 @ARGV = @args;
188
189 # Now we have possibly $Tk::MMtry::VERBOSE set, we can
190 # use the try_compile stuff
191 if (try_compile("config/perlrx.c", ["-I$Config{'archlibexp'}/CORE"], undef, ["-c"]))
192 {
193 $define{'USE_NEWSTYLE_REGEXP_STRUCT'} = 1;
194 }
195
196 if (try_compile("config/pmop.c", ["-I$Config{'archlibexp'}/CORE"]))
197 {
198 $define{'HAS_PMOP_EXTRA_FLAGS'} = 1;
199 }
200
201 if (try_compile("config/pregcomp2.c", ["-I$Config{'archlibexp'}/CORE"], undef, ["-c"]))
202 {
203 $define{'USE_PREGCOMP_31027'} = 1; # pregcomp after perl change 31027
204 }
205
206 if (try_compile("config/regexp511.c", ["-I$Config{'archlibexp'}/CORE"], undef, ["-c"]))
207 {
208 $define{'USE_REGEXP_511'} = 1; # REGEXP in perl 5.11.x
209 }
210
211 if (try_compile("config/signedchar.c"))
212 {
213 $define{'ANSI_SIGNED_CHAR'} = 1;
214 }
215 else
216 {
217 if (try_run("config/unsigned.c"))
218 {
219 $define{'CHAR_UNSIGNED'} = 1;
220 }
221 }
222
223 if (!try_compile("config/Ksprintf.c") &&
224 try_compile("-DSPRINTF_RETURN_CHAR config/Ksprintf.c"))
225 {
226 $define{'SPRINTF_RETURN_CHAR'} = 1;
227 }
228
229 if (try_compile("config/svtrv.c", ["-I$Config{'archlibexp'}/CORE"], undef, ["-c"]))
230 {
231 $define{'HAS_REAL_SVT_RV'} = 1; # changed in perl 5.11.0, SVt_RV is since then defined as SVt_IV
232 }
233
234 if (try_compile("config/copstashset.c", ["-I$Config{'archlibexp'}/CORE"], undef, ["-c"]))
235 {
236 $define{'CAN_COPSTASH_SET_NULL'} = 1; # this seems to work since 5.17.x, and fails with older threaded perls
237 }
238
239 if ($] > 5.013002) # SvNV_nomg available
240 {
241 $define{'HAS_SVNV_NOMG'} = 1;
242 }
243 if ($] >= 5.009001 || ($] >= 5.008009 && $] < 5.009)) # SvIV_nomg available
244 {
245 $define{'HAS_SVIV_NOMG'} = 1;
246 }
247
248 if (!$IsWin32)
249 {
250 if (!try_compile("config/tod.c"))
251 {
252 my $d;
253 my $def;
254 foreach $d (qw(TZ NO_TZ DOTS))
255 {
256 if (try_compile("-DTIMEOFDAY_$d config/tod.c"))
257 {
258 $def = "TIMEOFDAY_$d";
259 print STDERR "$d gettimeofday()\n";
260 last;
261 }
262 }
263 if (defined $def)
264 {
265 $define{$def} = 1;
266 }
267 else
268 {
269 print STDERR "Problem gettimeofday()\n";
270 }
271 }
272 else
273 {
274 print STDERR "Generic gettimeofday()\n";
275 }
276 }
277
278 $win_arch or die '$win_arch not set in myConfig';
279
280 if ($win_arch eq 'x') {
281 @xdirs = ();
282
283 if (defined $X11)
284 {
285 my $dir = $X11;
286 if (-d $dir)
287 {
288 print "Looking for X in $dir\n";
289 push(@xdirs,$dir);
290 }
291 else
292 {
293 die "X11=$dir is not a directory";
294 }
295 }
296 else
297 {
298 # Find the X Library through xmkmf!
299 $xmkmf = undef;
300 my @exts = ("", ".cmd", ".bat");
301 LOOK:
302 foreach $dir (split($Config::Config{path_sep},$ENV{'PATH'})) {
303 foreach $ext (@exts) {
304 if (-x "$dir/xmkmf$ext" && -r "$dir/xmkmf$ext") {
305 $xmkmf = "$dir/xmkmf$ext";
306 last LOOK;
307 }
308 }
309 }
310 $uiline = undef;
311 if (defined $xmkmf) {
312 open(XMKMF,$xmkmf) || die("Can't open $xmkmf: $!\n");
313 while(<XMKMF>) {
314 next unless /UseInstalled/o;
315 warn ("Odd, two lines in the $xmkmf file that have UseInstalled on them:\n$uidir$_") if defined $uiline;
316 $uidir = $_;
317 }
318 close(XMKMF);
319 while (defined $uidir) {
320 last unless ($uidir =~ s!^.*-I(\S+)/lib/X11/config!!o);
321 $try = $1;
322 $try =~ s/'x11root'/$ENV{X11ROOT}/;
323 push(@xdirs,$try);
324 }
325 }
326 print "$xmkmf suggests ",join(' ',@xdirs),"\n" if (@xdirs);
327 }
328
329 undef $xlib; # Make sure
330
331 if (defined $X11LIB)
332 {
333 $xlib = &lX11(1,$X11LIB)
334 }
335 if (!defined($xlib) && defined($X11))
336 {
337 $xlib = &lX11(1,"$X11/lib")
338 }
339 $xlib = &lX11(0,map("$_/lib",@xdirs)) unless (defined $xlib);
340
341 # Special case for sun-machines
342 unless (defined $xlib)
343 {
344 if ($Config{'osname'} eq 'solaris' || $Config{'osname'} eq 'sunos')
345 {
346 $xlib = &lX11(0,'/usr/openwin/lib');
347 }
348 }
349
350 sub chooseX11
351 {
352 # Aim to prefer X11R5 over X11R4 over X11
353 (reverse(sort(@_)));
354 }
355
356 #
357 # Prefer 64bit libraries on certain architectures
358 #
359 if (!defined $xlib and $Config{'archname'} =~ m/x86_64/)
360 {
361 $xlib = &lX11(0, chooseX11(</usr/X11*/lib64>));
362 }
363
364 #
365 # If no luck there try "common" places
366 #
367 unless (defined $xlib)
368 {
369 $xlib = &lX11(0,chooseX11(</usr/X11*/lib>),chooseX11(</usr/lib/X11*>),</usr/Xfree*/lib>,'/usr/X386/lib',
370 '/opt/X11/lib')
371 }
372
373 #
374 # Try places perl looks for libraries
375 # This is now "last resort" as /lib and /usr/local/lib are so often
376 # full of dubious links
377 #
378 unless (defined $xlib)
379 {
380 $xlib = &lX11(0,split(/\s+/,$Config{'libpth'}))
381 }
382
383 unless(defined $xlib)
384 {
385 warn "Cannot find -lX11 anywhere --- cannot build Perl/Tk\n";
386 exit 0;
387 }
388
389 ($base) = $xlib =~ m#-L(.*)(?:/lib)$#x;
390 if (defined $X11INC)
391 {
392 $xinc = &IX11("$X11INC");
393 }
394
395 $xinc = &IX11("$base/include") unless (defined $xinc);
396
397 unless (defined $xinc)
398 {
399 warn "Cannot find X include files via $base/include\n";
400 $xinc = &IX11(map("$_/include",@xdirs),
401 '/usr/openwin/include',
402 chooseX11(</usr/X11*/include>),
403 chooseX11(</usr/include/X11*>),
404 </usr/Xfree*/include>,
405 '/usr/X386/include',
406 $Config{'usrinc'});
407 }
408
409 unless (defined $xinc)
410 {
411 warn <<EOF;
412 Cannot find X include files anywhere.
413 EOF
414 if ($^O eq 'linux')
415 {
416 warn <<EOF;
417 You probably need to install the X11 development package first.
418 On Debian or Ubuntu, this is the package libx11-dev.
419 On CentOS, RedHat, or Fedora, this is the package libX11-devel.
420 Please see README.linux for more information.
421 EOF
422 }
423 exit 0;
424 }
425
426 if (defined($Config{'gccversion'}) &&
427 $Config{'gccversion'} =~ /\S/ &&
428 $xinc =~ /^-I(.*openwin.*)$/)
429 {
430 $gccopt .= " -isystem $1";
431 }
432
433 $inc = ($xinc eq "-I/usr/include") ? "" : $xinc;
434
435 if (!defined $XFT)
436 {
437 $XFT = 1;
438 }
439 if ($XFT)
440 {
441 # Found basic X libraries now see if we can find -lXft
442
443 my $ftinc = Ift("/usr/include","/usr/local/include",$X11INC||(),"/opt/X11/include");
444 if ($ftinc)
445 {
446 print "xlib='$xlib' xinc='$xinc'\n";
447 my $success = 0;
448 # Including ft2build.h additionally seems to be necessary
449 # on an old RedHat 8.0 system
450 for my $def ([], ["-DNEED_FT2BUILD_H"])
451 {
452 my $ftlib = '-L/usr/local/lib'; # XXX needed if freetype and xlibs are in different lib directories, but should probably check if this is necessary
453 if (try_run("config/xft.c",[$xinc,$ftinc],[$xlib,$ftlib,'-lXft','-lfontconfig'],$def))
454 {
455 $inc .= " $ftinc";
456 warn "Seem to have -lXft\n";
457 $define{USE_XFT_FONTS} = 1;
458 $xlib .= " -lXft";
459 $xtra = " $ftlib -lfontconfig";
460 if (@$def)
461 {
462 for my $d (@$def)
463 {
464 $d =~ s{-D}{};
465 $define{$d} = 1;
466 }
467 }
468 $success = 1;
469 last;
470 }
471 }
472 if (!$success)
473 {
474 warn "Xft and/or fontconfig libraries and/or includes are missing" .
475 (!$Tk::MMtry::VERBOSE ? ",\ntry perl Makefile.PL VERBOSE=1 for more information" : "") .
476 ".\n";
477 }
478 }
479 else
480 {
481 warn "Cannot find freetype.h include file\n";
482 }
483 }
484 else
485 {
486 warn "XFT not requested\n";
487 }
488 } elsif ($win_arch eq 'open32') {
489 unless (defined $toolkit) {
490 my @path = split /;/, $ENV{PATH};
491 foreach (@path) {
492 next unless m:[\\/]toolkit[\\/]bin:i;
493 my $tlk = "$`/toolkit";
494 next unless -d "$tlk/H" and -f "$tlk/H/os2win.h";
495 $toolkit = $tlk;
496 $toolkit =~ s:\\:/:g ;
497 last;
498 }
499 }
500 die "Cannot find OS/2 toolkit" unless $toolkit;
501 $inc = "-I../pTk/mTk/xlib -I../../pTk/mTk/xlib -IpTk/mTk/xlib";
502 $inc .= " -I$toolkit/H -I../pTk/mTk/open32/h -IpTk/mTk/open32/h -ImTk/os2_rc";
503 $define .= " -D__WIN32__";
504 $xlib = "-L$toolkit/LIB -lpmwinx";
505 } elsif ($win_arch eq 'pm') {
506 $define .= " -D__PM__";
507 $inc = "-I../pTk/mTk/xlib -I../../pTk/mTk/xlib -IpTk/mTk/xlib -ImTk/os2_rc";
508 $xlib = ""; # No library is needed
509 } elsif ($IsWin32 or $^O eq 'cygwin') {
510 $inc = '-I$(TKDIR) -I$(TKDIR)/pTk/mTk/xlib';
511 }
512
513
514 if ($Config{'osname'} eq 'solaris' && $xlib =~ /\bopenwin\b/ )
515 {
516 $define{'NEED_PRELOAD'} = 1;
517 }
518
519 sub WriteIfChanged
520 {
521 my ($file,$string) = @_;
522 my ($dir) = $file =~ m#^(.*)/[^/]+$#;
523 if (defined($dir) && !-d $dir)
524 {
525 mkdir($dir,0777) || die "Cannot mkdir $dir:$!";
526 }
527 my $ok = -f $file;
528 if ($ok = open(IN,"$file"))
529 {
530 my $old = join('',<IN>);
531 close(IN);
532 $ok = $old eq $string;
533 print STDERR "$file has changed\n" unless ($ok);
534 }
535 unless ($ok)
536 {
537 open(OUT,">$file") || die "Cannot open $file:$!";
538 print STDERR "Writing $file\n";
539 print OUT $string;
540 close(OUT);
541 }
542 }
543
544 if (!defined($MakefileName) || $MakefileName eq 'Makefile')
545 {
546 my $config = "# DO NOT EDIT. CREATED AUTOMATICALLY BY myConfig\npackage Tk::Config;\nrequire Exporter;\nuse base qw(Exporter);\n";
547 my $sym;
548 my @export = ();
549 foreach $sym (qw(VERSION inc define xlib xinc gccopt win_arch))
550 {
551 my $val = ${$sym};
552 $val =~ s/([\\\'])/\\$1/g;
553 $config .= "\$$sym = '$val';\n";
554 push(@export,"\$$sym");
555 }
556 $config .= "\@EXPORT = qw(".join(' ',@export).");\n1;\n";
557 WriteIfChanged("Tk/Config.pm",$config);
558 $config = "#ifndef _TKCONFIG\n#define _TKCONFIG\n";
559 foreach $sym (sort keys %define)
560 {
561 $config .= "#define $sym $define{$sym}\n";
562 }
563 $config .= "#endif\n";
564 WriteIfChanged("pTk/tkConfig.h",$config);
565 }
566
567 1;