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