| 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 |
warn "No VERSION" unless (defined $VERSION); |
| 9 |
|
| 10 |
my %define = (); |
| 11 |
|
| 12 |
$inc = ""; |
| 13 |
$xlib = ""; |
| 14 |
$define = ''; |
| 15 |
$gccopt = ""; |
| 16 |
@macro = ( macro => {} ); |
| 17 |
|
| 18 |
|
| 19 |
if (defined $Config{'gccversion'}) |
| 20 |
{ |
| 21 |
$ver = $Config{'gccversion'}; |
| 22 |
if( $ver ge "2.8" ) |
| 23 |
{ |
| 24 |
# retain author's favourite warnings if using gcc |
| 25 |
$gccopt .= " -ggdb -Wall -Wno-implicit-int -Wno-comment -Wno-unused -D__USE_FIXED_PROTOTYPES__"; |
| 26 |
eval |
| 27 |
{ |
| 28 |
if ((getpwuid($<))[6] =~ /Nick\s+Ing-Simmons/) |
| 29 |
{ |
| 30 |
# This is the author - catch as many bugs as possible |
| 31 |
$gccopt .= " -MMD -Werror"; |
| 32 |
@macro = ( macro => { INSTALLDIRS => 'perl' }); |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
} |
| 37 |
# else{ $define .= ' -g ' } |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
if ($] >= 5.005) |
| 42 |
{ |
| 43 |
# Add PPM support stuff |
| 44 |
push(@macro, |
| 45 |
ABSTRACT => 'Tk::tkTable - a Spreadsheet/Table Widget', |
| 46 |
AUTHOR => '[email protected] (John Cerney)' |
| 47 |
); |
| 48 |
my $arch = ($^O eq 'MSWin32') ? $ENV{'PROCESSOR_ARCHITECTURE'} : $Config{'archname'}; |
| 49 |
push(@ARGV,"BINARY_LOCATION=$arch/Tk$VERSION-PPM.tar.gz"); |
| 50 |
warn "PPM for perl$]\n"; |
| 51 |
} |
| 52 |
else |
| 53 |
{ |
| 54 |
warn "No PPM for perl$]\n"; |
| 55 |
} |
| 56 |
|
| 57 |
$macro[1]->{WINARCH} = $win_arch; |
| 58 |
|
| 59 |
# |
| 60 |
# Convert perls Config info into -DXXXX for Tk |
| 61 |
# |
| 62 |
|
| 63 |
$define{'USE_PROTOTYPE'} = 1 if ($Config{'prototype'}); |
| 64 |
$define{'HAVE_UNISTD_H'} = 1 if ($Config{'i_unistd'}); |
| 65 |
$define{'HAVE_SYS_SELECT_H'} = 1 if ($Config{'i_sysselct'}); |
| 66 |
$define{'NO_STDLIB_H'} = 1 unless ($Config{'i_stdlib'}); |
| 67 |
$define{'HAVE_SYS_TIME_H'} = 1 if ($Config{'i_systime'}); |
| 68 |
$define{'HAVE_LIMITS_H'} = 1 if ($Config{'i_limits'}); |
| 69 |
$define{'HAS_STDARG'} = 1 if ($Config{'i_stdarg'}); |
| 70 |
$define{'USE_BCOPY'} = 1 if (!$Config{'d_memmove'} && $Config{'d_bcopy'}); |
| 71 |
|
| 72 |
if (defined $Config{'selecttype'}) |
| 73 |
{ |
| 74 |
my $type = $Config{'selecttype'}; |
| 75 |
$type =~ s/\s*\*\s*$//; |
| 76 |
$define{'SELECT_MASK'} = $type; |
| 77 |
} |
| 78 |
|
| 79 |
if (!$Config{'i_unistd'} && defined $Config{'lseektype'}) |
| 80 |
{ |
| 81 |
my $type = $Config{'lseektype'}; |
| 82 |
$type =~ s/\s*\*\s*$//; |
| 83 |
$define{'LSEEK_TYPE'} =$type; |
| 84 |
} |
| 85 |
|
| 86 |
my $voidflags = $Config{'voidflags'}; |
| 87 |
my $voidused = $Config{'defvoidused'}+0; |
| 88 |
|
| 89 |
$define{'NOVOID'} = 1 if (($voidflags & $voidused) != $voidused); |
| 90 |
$define{'NOCONST'} = 1 unless ($Config{'d_const'}); |
| 91 |
|
| 92 |
|
| 93 |
# |
| 94 |
# Hunt down X Library - first a function |
| 95 |
# |
| 96 |
sub lX11 |
| 97 |
{ |
| 98 |
my $user = shift; |
| 99 |
foreach (@_) |
| 100 |
{ |
| 101 |
# allow any of libX11.a libX11.so.* etc. |
| 102 |
if (-d $_) |
| 103 |
{ |
| 104 |
local ($lib); |
| 105 |
my $pattern = "$_/libX11.*"; |
| 106 |
$pattern .= " $_/X11$Config::Config{lib_ext}" if $Config::Config{osname} eq 'os2'; |
| 107 |
foreach $lib (reverse(<$ {pattern}>)) |
| 108 |
{ |
| 109 |
if (-r $lib) |
| 110 |
{ |
| 111 |
print "Using -L$_ to find $lib\n"; |
| 112 |
return "-L$_"; |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
print "No -lX11 in ",join(' ',@_),"\n" if (@_ && $user); |
| 118 |
return undef; |
| 119 |
} |
| 120 |
|
| 121 |
sub IX11 |
| 122 |
{ |
| 123 |
foreach (@_) |
| 124 |
{ |
| 125 |
if (-d $_ && -d "$_/X11" && -r "$_/X11/Xlib.h") |
| 126 |
{ |
| 127 |
print "Using -I$_ to find $_/X11/Xlib.h\n"; |
| 128 |
return "-I$_"; |
| 129 |
} |
| 130 |
} |
| 131 |
return undef; |
| 132 |
} |
| 133 |
|
| 134 |
my @args = (); |
| 135 |
my $arg; |
| 136 |
foreach $arg (@ARGV) |
| 137 |
{ |
| 138 |
if ($arg =~ /^(X11\w*)=(.*)$/) |
| 139 |
{ |
| 140 |
${"$1"} = $2; |
| 141 |
} |
| 142 |
else |
| 143 |
{ |
| 144 |
$MakefileName = $1 if ($arg =~ /^MAKEFILE=(.*)$/); |
| 145 |
push(@args,$arg); |
| 146 |
} |
| 147 |
} |
| 148 |
@ARGV = @args; |
| 149 |
|
| 150 |
$win_arch or die '$win_arch not set in myConfig'; |
| 151 |
|
| 152 |
if ($win_arch eq 'x') |
| 153 |
{ |
| 154 |
|
| 155 |
@xdirs = (); |
| 156 |
|
| 157 |
if (defined $X11) |
| 158 |
{ |
| 159 |
my $dir = $X11; |
| 160 |
if (-d $dir) |
| 161 |
{ |
| 162 |
print "Looking for X in $dir\n"; |
| 163 |
push(@xdirs,$dir); |
| 164 |
} |
| 165 |
else |
| 166 |
{ |
| 167 |
die "X11=$dir is not a directory"; |
| 168 |
} |
| 169 |
} |
| 170 |
else |
| 171 |
{ |
| 172 |
# Find the X Library through xmkmf! |
| 173 |
$xmkmf = undef; |
| 174 |
my @exts = ("", ".cmd", ".bat"); |
| 175 |
|
| 176 |
LOOK: |
| 177 |
foreach $dir (split($Config::Config{path_sep},$ENV{'PATH'})) |
| 178 |
{ |
| 179 |
foreach $ext (@exts) |
| 180 |
{ |
| 181 |
if (-x "$dir/xmkmf$ext" && -r "$dir/xmkmf$ext") |
| 182 |
{ |
| 183 |
$xmkmf = "$dir/xmkmf$ext"; |
| 184 |
last LOOK; |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
$uiline = undef; |
| 190 |
if (defined $xmkmf) |
| 191 |
{ |
| 192 |
open(XMKMF,$xmkmf) || die("Can't open $xmkmf: $!\n"); |
| 193 |
while(<XMKMF>) |
| 194 |
{ |
| 195 |
next unless /UseInstalled/o; |
| 196 |
warn ("Odd, two lines in the $xmkmf file that have UseInstalled on them:\n$uidir$_") if defined $uiline; |
| 197 |
$uidir = $_; |
| 198 |
} |
| 199 |
close(XMKMF); |
| 200 |
while (defined $uidir) |
| 201 |
{ |
| 202 |
last unless ($uidir =~ s!^.*-I(\S+)/lib/X11/config!!o); |
| 203 |
$try = $1; |
| 204 |
$try =~ s/'x11root'/$ENV{X11ROOT}/; |
| 205 |
push(@xdirs,$try); |
| 206 |
} |
| 207 |
} |
| 208 |
print "$xmkmf suggests ",join(' ',@xdirs),"\n" if (@xdirs); |
| 209 |
} |
| 210 |
|
| 211 |
undef $xlib; # Make sure |
| 212 |
|
| 213 |
if (defined $X11LIB) |
| 214 |
{ |
| 215 |
$xlib = &lX11(1,$X11LIB) |
| 216 |
} |
| 217 |
if (!defined($xlib) && defined($X11)) |
| 218 |
{ |
| 219 |
$xlib = &lX11(1,"$X11/lib") |
| 220 |
} |
| 221 |
$xlib = &lX11(0,map("$_/lib",@xdirs)) unless (defined $xlib); |
| 222 |
|
| 223 |
# Special case for sun-machines |
| 224 |
unless (defined $xlib) |
| 225 |
{ |
| 226 |
if ($Config{'osname'} eq 'solaris' || $Config{'osname'} eq 'sunos') |
| 227 |
{ |
| 228 |
$xlib = &lX11(0,'/usr/openwin/lib'); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
sub chooseX11 |
| 233 |
{ |
| 234 |
# Aim to prefer X11R5 over X11R4 over X11 |
| 235 |
(reverse(sort(@_))); |
| 236 |
} |
| 237 |
|
| 238 |
# |
| 239 |
# If no luck there try "common" places |
| 240 |
# |
| 241 |
unless (defined $xlib) |
| 242 |
{ |
| 243 |
$xlib = &lX11(0,chooseX11(</usr/X11*/lib>),chooseX11(</usr/lib/X11*>),</usr/Xfree*/lib>,'/usr/X386/lib') |
| 244 |
} |
| 245 |
|
| 246 |
# |
| 247 |
# Try places perl looks for libraries |
| 248 |
# This is now "last resort" as /lib and /usr/local/lib are so often |
| 249 |
# full of dubious links |
| 250 |
# |
| 251 |
unless (defined $xlib) |
| 252 |
{ |
| 253 |
$xlib = &lX11(0,split(/\s+/,$Config{'libpth'})) |
| 254 |
} |
| 255 |
|
| 256 |
unless (defined $xlib) |
| 257 |
{ |
| 258 |
warn "Cannot find -lX11 anywhere --- cannot build Tk::TableMatrix\n"; |
| 259 |
exit 0; |
| 260 |
} |
| 261 |
|
| 262 |
($base) = $xlib =~ m#-L(.*)(?:/lib)$#x; |
| 263 |
if (defined $X11INC) |
| 264 |
{ |
| 265 |
$xinc = &IX11("$X11INC"); |
| 266 |
} |
| 267 |
|
| 268 |
$xinc = &IX11("$base/include") unless (defined $xinc); |
| 269 |
|
| 270 |
unless (defined $xinc) |
| 271 |
{ |
| 272 |
warn "Cannot find X include files via $base/include\n"; |
| 273 |
$xinc = &IX11(map("$_/include",@xdirs), |
| 274 |
'/usr/openwin/include', |
| 275 |
chooseX11(</usr/X11*/include>), |
| 276 |
chooseX11(</usr/include/X11*>), |
| 277 |
</usr/Xfree*/include>, |
| 278 |
'/usr/X386/include', |
| 279 |
$Config{'usrinc'}); |
| 280 |
} |
| 281 |
|
| 282 |
die "Cannot find X include files anywhere" unless (defined $xinc); |
| 283 |
|
| 284 |
if (defined($Config{'gccversion'}) && $Config{'gccversion'} =~ /\S/ && $xinc =~ /^-I(.*openwin.*)$/) |
| 285 |
{ |
| 286 |
$gccopt .= " -isystem $1"; |
| 287 |
} |
| 288 |
|
| 289 |
$inc = ($xinc eq "-I/usr/include") ? "" : $xinc; |
| 290 |
|
| 291 |
} |
| 292 |
elsif ($win_arch eq 'open32') |
| 293 |
{ |
| 294 |
|
| 295 |
unless (defined $toolkit) |
| 296 |
{ |
| 297 |
my @path = split /;/, $ENV{PATH}; |
| 298 |
foreach (@path) |
| 299 |
{ |
| 300 |
next unless m:[\\/]toolkit[\\/]bin:i; |
| 301 |
my $tlk = "$`/toolkit"; |
| 302 |
next unless -d "$tlk/H" and -f "$tlk/H/os2win.h"; |
| 303 |
$toolkit = $tlk; |
| 304 |
$toolkit =~ s:\\:/:g ; |
| 305 |
last; |
| 306 |
} |
| 307 |
} |
| 308 |
die "Cannot find OS/2 toolkit" unless $toolkit; |
| 309 |
$inc = "-I../pTk/mTk/xlib -I../../pTk/mTk/xlib -IpTk/mTk/xlib"; |
| 310 |
$inc .= " -I$toolkit/H -I../pTk/mTk/open32/h -IpTk/mTk/open32/h -ImTk/os2_rc"; |
| 311 |
$define .= " -D__WIN32__"; |
| 312 |
$xlib = "-L$toolkit/LIB -lpmwinx"; |
| 313 |
|
| 314 |
} |
| 315 |
elsif ($win_arch eq 'pm') |
| 316 |
{ |
| 317 |
|
| 318 |
$define .= " -D__PM__"; |
| 319 |
$inc = "-I../pTk/mTk/xlib -I../../pTk/mTk/xlib -IpTk/mTk/xlib -ImTk/os2_rc"; |
| 320 |
$xlib = ""; # No library is needed |
| 321 |
|
| 322 |
} |
| 323 |
elsif ($IsWin32) |
| 324 |
{ |
| 325 |
$inc = '-I$(TKDIR)/pTk/mTk/xlib'; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
if ($Config{'osname'} eq 'solaris' && $xlib =~ /\bopenwin\b/ ) |
| 330 |
{ |
| 331 |
$define{'NEED_PRELOAD'} = 1; |
| 332 |
} |
| 333 |
|
| 334 |
sub WriteIfChanged |
| 335 |
{ |
| 336 |
my ($file,$string) = @_; |
| 337 |
my ($dir) = $file =~ m#^(.*)/[^/]+$#; |
| 338 |
if (defined($dir) && !-d $dir) |
| 339 |
{ |
| 340 |
mkdir($dir,0777) || die "Cannot mkdir $dir:$!"; |
| 341 |
} |
| 342 |
my $ok = -f $file; |
| 343 |
if ($ok = open(IN,"$file")) |
| 344 |
{ |
| 345 |
my $old = join('',<IN>); |
| 346 |
close(IN); |
| 347 |
$ok = $old eq $string; |
| 348 |
print STDERR "$file has changed\n" unless ($ok); |
| 349 |
} |
| 350 |
unless ($ok) |
| 351 |
{ |
| 352 |
open(OUT,">$file") || die "Cannot open $file:$!"; |
| 353 |
print STDERR "Writing $file\n"; |
| 354 |
print OUT $string; |
| 355 |
close(OUT); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
# Config File Write ( Not Needed when building tkTable ) |
| 360 |
# if (!defined($MakefileName) || $MakefileName eq 'Makefile') |
| 361 |
if(0) |
| 362 |
{ |
| 363 |
my $config = "package Tk::Config;\nrequire Exporter;\nuse base qw(Exporter);\n"; |
| 364 |
my $sym; |
| 365 |
my @export = (); |
| 366 |
foreach $sym (qw(VERSION inc define xlib xinc gccopt win_arch)) |
| 367 |
{ |
| 368 |
my $val = ${$sym}; |
| 369 |
$val =~ s/([\\\'])/\\$1/g; |
| 370 |
$config .= "\$$sym = '$val';\n"; |
| 371 |
push(@export,"\$$sym"); |
| 372 |
} |
| 373 |
$config .= "\@EXPORT = qw(".join(' ',@export).");\n1;\n"; |
| 374 |
WriteIfChanged("Tk/Config.pm",$config); |
| 375 |
$config = "#ifndef _TKCONFIG\n#define _TKCONFIG\n"; |
| 376 |
foreach $sym (sort keys %define) |
| 377 |
{ |
| 378 |
$config .= "#define $sym $define{$sym}\n"; |
| 379 |
} |
| 380 |
$config .= "#endif\n"; |
| 381 |
WriteIfChanged("pTk/tkConfig.h",$config); |
| 382 |
} |
| 383 |
|
| 384 |
1; |