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
|
# before running this script make sure you have 'tclsh' in your path,
# and this 'tcl' distribution is required one.
use strict;
use Getopt::Long;
use ExtUtils::MakeMaker;
use Config;
my $arch;
my $stub = "tclstub8.4";
# These need updating as more platforms are added to tcl-core/ area
if ($^O eq "MSWin32") {
$stub = "tclstub84";
$arch = "win32-x86" if ($Config{archname} =~ /-x86-/);
$arch = "win32-x64" if ($Config{archname} =~ /-x64-/);
} elsif ($^O eq "darwin") {
$arch = "darwin-universal";
} elsif ($^O eq "solaris") {
$arch = "$^O-x86" if ($Config{archname} =~ /86/);
$arch = "$^O-sparc" if ($Config{archname} =~ /sun4/);
} elsif ($^O eq "aix") {
$arch = "$^O";
} elsif ($^O eq "hpux") {
$arch = "$^O-ia64" if ($Config{archname} =~ /ia64/i);
$arch = "$^O-parisc" if ($Config{archname} =~ /pa-risc/i);
} elsif ($^O eq "linux" or $^O eq "cygwin") {
$arch = "$^O-i686" if ($Config{archname} =~ /i\d86/);
$arch = "$^O-ia64" if ($Config{archname} =~ /ia64/i);
$arch = "$^O-x86_64" if ($Config{archname} =~ /x86_64/);
}
sub _die ($) {
# CPAN smokers report FAIL if Makefile.PL dies, it should exit with status 0
my $err = shift;
warn $err;
exit 0;
}
my $tclsh_default = 'tclsh';
# for FreeBSD users, try to guess their name for tclsh; see ticket 6086
if ($^O eq 'freebsd') {
for my $ver (qw(8.9 8.8 8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0)) {
system "which tclsh$ver >/dev/null 2>&1";
if ($? == 0) {
$tclsh_default = "tclsh$ver"; # ok will use that as default
last;
}
}
}
GetOptions(
"tclsh=s", \(my $tclsh=$tclsh_default),
"tclconfig=s", \ my $tclconfig,
"usestubs!", \(my $usestubs = $^O =~ /^MSWin32|solaris|linux|hpux|darwin|cygwin|aix|freebsd|netbsd|openbsd$/? 1 : 0),
# we prefer usestubs, but on windows default is to not use them, because
# stubs lib that come with AS TCL is impossible to link with GCC which
# comes with strawberry perl; Have a ticket for this; (XXX) VKON 27-06-2018
#
# ... also any other $^O which we do not have in 'tcl-core' dir
# except for freebsd and netbsd and openbsd
"library=s", \ my $libpath,
"include=s", \ my $incpath,
"define=s", \(my $defs=''),
"hack1!", \(my $hack1=1),
"hack2!", \(my $hack2=1),
"help!", \ my $help,
) || usage();
usage() if $help;
sub usage {
_die <<'EOT';
Most common usage:
perl Makefile.PL
Customised usage:
perl Makefile.PL \
[--nousestubs] \ # (do not) use the Tcl stubs mechanism
[--tclsh <path>] \ # Use this tclsh executable as a base to find the lib info needed
[--tclconfig <path>] \ # Use this Tcl config file (not tclConfig.sh from the tclsh above)
[--library=...] \ # Use this specific Tcl library
[--include=...] \ # Use this specific include path
[--define=...] \ # Use this specific set of defines
[--nohack1] \ # internal usage, please RTFS word 'hack1'
[--help] \ # --help
[<makemaker opts>] # e.g. LINKTYPE=STATIC
For compilation against tcl at given specific location
perl Makefile.PL --library=-l/path/to/tcl(stub).a \
--include=-I/path/to/tcl/include \
--define="-DLIB_RUNTIME_DIR=... -DTCL_LIB_FILE=..."
--tclsh option is mostly for FreeBSD users, who have tclsh86 or alike;
however default autodetection should be fine with freebsd as well.
EOT
}
my @extraargs;
if ($usestubs) {
$defs .= " -DUSE_TCL_STUBS";
}
# If using stubs, we will set the LIB_RUNTIME_DIR and TCL_LIB_FILE
# to point to the install location as the default dll to load.
if (defined($libpath) && defined($incpath)) {
# do nothing - set on command line
} else {
# otherwise we *require* working tclsh; to avoid bogus FAIL reports
# even on $^O eq 'darwin'
# When user has its own tclConfig.sh with --tclconfig=..., then we
# overwrite values in %tclcfg
my $tclcfg = `$tclsh tclcfg.tcl`;
_die "error starting $tclsh: \$?=$?; \$!=$!\n" if $tclcfg eq ''; # can't check $?, BUG 133463
print $tclcfg;
my %tclcfg = $tclcfg =~ /^([^=]+)=(.*?)$/gm;
$defs .= " -DTCLSH_PATH=\\\"".([$tclcfg{tclsh}=~/^(.*)\//]->[0])."\\\""; #haack
if ($^O eq 'darwin' && !defined($tclconfig)) {
$tclconfig = $tclcfg{'tclConfig.sh'};
}
if ($^O eq 'MSWin32' && !defined($tclconfig) && (1 or !$usestubs)) {
$tclconfig = $tclcfg{'tclConfig.sh'};
}
if (!defined($tclconfig) && $arch && $usestubs) {
$incpath = "-Itcl-core/include";
$libpath = "-Ltcl-core/$arch -l$stub";
if ($^O eq 'darwin') {
# OS X also requires the Carbon framework by default
$libpath .= " -framework Carbon";
}
} elsif ($tclconfig) {
_die "Tcl config file '$tclconfig' not found\n" unless (-f $tclconfig);
# Retrieve all info based on tclConfig.sh
process_tclconfig($tclconfig, \%tclcfg);
if ($hack1 and q{
HACK1: on $^O eq 'MSWin32' activetcl 866 stub library could not be linked
with gcc which comes with strawberry;
860 is good.
}) { # hopefully this will be: if (0 and q{....})
if ($usestubs and $^O eq 'MSWin32') {
$stub = "tclstub84"; # use our stub, not their
$libpath = "-Ltcl-core/$arch -l$stub";
$incpath = "-Itcl-core/include";
$tclcfg{TCL_STUB_LIB_SPEC} = $libpath;
$tclcfg{TCL_LIB_FILE} = $tclcfg{TCL_DLL_FILE};
}
}
$libpath = $usestubs ? $tclcfg{TCL_STUB_LIB_SPEC} : $tclcfg{TCL_LIB_SPEC};
$incpath = $tclcfg{TCL_INCLUDE_SPEC};
# https://www.cpantesters.org/cpan/report/18397198-6bf4-1014-85e5-4e79f459b9c5
# Tcl.xs:32:10: fatal error: tcl.h: No such file or directory
if ($incpath) {
my @tclh = grep {-f "$_/tcl.h"} $incpath=~/-I(\S+)/g;
if ($#tclh==-1) {
_die "incpath $incpath from your tclconfig $tclconfig does not provide tcl.h"
}
} else {_die "can not figure out incpath from your tclconfig $tclconfig"}
if ($usestubs) {
if ($^O eq 'darwin' && $tclcfg{TCL_STUB_LIB_PATH} =~ /\.framework/ ) {
(my $fmk = $tclcfg{TCL_STUB_LIB_PATH}) =~ s/(?<=\.framework).*//;
$defs .= " -DLIB_RUNTIME_DIR=\\\"$fmk\\\"";
@extraargs = (dynamic_lib => {OTHERLDFLAGS => "-framework Carbon"});
} else {
$defs .= " -DLIB_RUNTIME_DIR=\\\"$tclcfg{TCL_EXEC_PREFIX}".($^O eq 'MSWin32'?'':'/lib')."\\\"";
}
$defs .= " -DTCL_LIB_FILE=\\\"$tclcfg{TCL_LIB_FILE}\\\"";
}
} else {
# no --tclconfig=... -> get values from ./tclcfg.tcl
my $tclver = $tclcfg{tcl_version};
if ($tclcfg{tcl_library} =~ /^(.*)[\\\/]lib[\\\/]/) {
$libpath = "-L$1/lib";
$incpath = "-I$1/include";
$defs .= " -DLIB_RUNTIME_DIR=\\\"$1/lib\\\"" if $usestubs;
}
if ($^O eq 'MSWin32') {
$tclver=~s/\.//;
$defs .= " -DTCL_LIB_FILE=\\\"tcl$tclver.$Config{so}\\\"" if $usestubs;
}
elsif ($^O eq 'freebsd' or $^O eq 'openbsd' or $^O eq 'netbsd') {
$tclver=~s/\.//;
$tclsh=~/([\d.]+)$/ and $incpath .= " -I/usr/local/include/tcl$1";
$defs .= " -DTCL_LIB_FILE=\\\"libtcl$tclver.$Config{so}\\\"" if $usestubs;
}
else {
$defs .= " -DTCL_LIB_FILE=\\\"libtcl$tclver.$Config{so}\\\"" if $usestubs;
}
$libpath .= " -ltcl" . ($usestubs?"stub":"") . $tclver;
}
# version must be 8.4+
_die "Tcl requires Tcl v8.4 or greater, found '$tclcfg{tcl_version}'\n"
if (defined $tclcfg{tcl_version} && $tclcfg{tcl_version} <8.4);
}
print "LIBS = $libpath\n";
print "INC = $incpath\n";
print "DEFINE = $defs\n";
print "tclConfig.sh = ", $tclconfig || "", "\n";
if ($^O eq 'darwin') {
# darwin has a broken ranlib that requires you to run it anytime
# you copy an archive file, so ensure ours it up-to-date
system("ranlib tcl-core/$arch/libtclstub8.4.a");
system("git update-index --assume-unchanged tcl-core/$arch/libtclstub8.4.a")
if -d ".git";
if ($libpath =~ /-framework/) {
# Frameworks require slightly different compile options
@extraargs = (dynamic_lib => {OTHERLDFLAGS => $libpath});
$libpath = "";
}
}
my $mm = WriteMakefile(
NAME => "Tcl",
VERSION_FROM => 'Tcl.pm',
LICENSE => 'perl',
MIN_PERL_VERSION => '5.006',
ABSTRACT_FROM => 'Tcl.pm',
META_MERGE => {
"meta-spec" => { version => 2 },
resources => {
repository => {
type => 'git',
web => 'https://github.com/gisle/tcl.pm',
url => 'https://github.com/gisle/tcl.pm.git',
},
MailingList => 'mailto:tcltk@perl.org',
}
},
LIBS => ["$libpath"],
INC => "$incpath",
DEFINE => $defs,
@extraargs,
);
if (0 and $mm->is_make_type('dmake')) { # Mmm. no. d-make welcome. problem was somewhere else
unlink('Makefile');
_die <<'EOS';
dmake prohibited. It does bla-bla-bla
EOS
}
sub process_tclconfig {
# Process a tclConfig.sh file for build info
my $tclconfig = shift;
my $hashref = shift;
open my $fh, $tclconfig or _die "error opening file '$tclconfig': $!\n";
print "Using config data in $tclconfig\n";
%$hashref = (join '', <$fh>) =~ /^(\w+)=['"]?(.*?)["']?$/gm;
for my $k (keys %$hashref) {
# Handle sh subs like ${TCL_DBGX}
$hashref->{$k} =~ s/\$\{(\w+)\}/(exists $hashref->{$1} ? $hashref->{$1} : $&)/eg;
# Handle any cygdrive-style paths
$hashref->{$k} =~ s{/cygdrive/(\w)/}{$1:/}ig;
}
$hashref->{tcl_version} = $hashref->{TCL_VERSION};
$hashref->{TCL_EXEC_PREFIX}=~y{\\}{/}; # hack for MSWin32; yet we don't go through \->\\ forest;
}
sub MY::libscan {
my($self, $path) =@_;
return '' if $path =~ /\.pl$/i;
return $path;
}
BEGIN {
# compatibility with older versions of MakeMaker
my $developer = -f ".git";
my %mm_req = (
LICENCE => 6.31,
META_MERGE => 6.45,
META_ADD => 6.45,
MIN_PERL_VERSION => 6.48,
);
undef(*WriteMakefile);
*WriteMakefile = sub {
my %arg = @_;
for (keys %mm_req) {
unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) {
warn "$_ $@" if $developer;
delete $arg{$_};
}
}
ExtUtils::MakeMaker::WriteMakefile(%arg);
};
}
|