1
# This is a simple configure script for MacOS and MPW.
2
# Note that this script can't be run directly from MPW perl
3
# because it has the wrong end-of-line characters. See README.
5
# Copyright 2000, 2001 Free Software Foundation, Inc.
7
# This file is part of the GNU MP Library.
9
# The GNU MP Library is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU Lesser General Public License as published by
11
# the Free Software Foundation; either version 2.1 of the License, or (at your
12
# option) any later version.
14
# The GNU MP Library is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
# License for more details.
19
# You should have received a copy of the GNU Lesser General Public License
20
# along with the GNU MP Library; see the file COPYING.LIB. If not, write to
21
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24
# ***************************** NOTE **************************************
25
# This script try to figure out things about this release but has a hard
26
# time doing it. It reads some lines in "configure", "Makefile.am" and
27
# "mp*/Makefile.am" and try to guess things. With every new release
28
# this script has to be tested.
29
# ***************************** NOTE **************************************
33
###########################################################################
37
###########################################################################
39
$/ = "\012" # Input files use Unix end-of-line chars
42
###########################################################################
46
###########################################################################
48
# Directories to create
64
my $cfg; # Will point to %cfg_apple or %cfg_cw
69
'coptions' => ['-ansi on -i : -i :: -i ::mpn:powerpc32 -i ::mpz',
70
'-opt speed -inline on'],
72
'linkoptions' => '-sym on -xm library',
73
'tooloptions' => "-t 'MPST' -c 'MPS'",
75
'aoptions' => '-sym on',
77
'"{SharedLibraries}"StdCLib',
78
'"{SharedLibraries}"InterfaceLib',
79
'"{SharedLibraries}"MathLib',
80
'"{PPCLibraries}"StdCRuntime.o',
81
'"{PPCLibraries}"PPCCRuntime.o',
89
'-opt all -w nounusedvar,noextended',
90
'-i :: -i ::mpn:powerpc32 -i ::mpz',
93
'link' => 'MWLinkPPC',
94
'linkoptions' => '-sym fullpath -library',
95
'tooloptions' => '-mpwtool',
97
'aoptions' => '-sym on',
99
'"{SharedLibraries}"InterfaceLib',
100
'"{MWPPCLibraries}MSL MPWCRuntime.Lib"',
101
'"{MWPPCLibraries}MSL C.PPC MPW(NL).Lib"',
102
'"{SharedLibraries}"MathLib',
106
# We only set the variables that have a value
109
'__GMP_BITS_PER_MP_LIMB' => 32,
110
'__GMP_HAVE_HOST_CPU_FAMILY_power' => 0,
111
'__GMP_HAVE_HOST_CPU_FAMILY_powerpc' => 1,
112
'DEFN_LONG_LONG_LIMB' => '',
113
'__GMP_LIBGMP_STATIC' => 0,
114
'__GMP_LIBGMP_SHARED' => 0,
117
my $make_in = 'Makefile.in';
118
my $make = 'Makefile';
119
my $configure = mf("../configure");
120
my $configure_in = mf("../configure.in");
121
my $config_in = mf("../config.in");
122
my $gmp_h = mf('../gmp.h');
123
my $gmp_h_in = mf('../gmp-h.in');
124
my $mpn_asm_dir = "../mpn/powerpc32";
125
my $mpn_gen_dir = "../mpn/generic";
126
my $config_h = 'config.h';
128
my $asm_start = "\ttoc"; # No dot, like ".dot"?
130
###########################################################################
134
###########################################################################
136
$cfg = \%cfg_apple; # Default
138
if (@ARGV and $ARGV[0] =~ /^cw|co/) {
143
###########################################################################
145
# Parse top configure file for mpn files
147
###########################################################################
149
my ($files,$optional,$package,$version) = parse_top_configure($configure);
150
my %mpn_objects = map {$_ => 1} (@$files,@$optional);
151
my %mpn_optional = map {$_ => 1} @$optional;
153
###########################################################################
155
# Create config.h from ../config.in
157
###########################################################################
161
open(CONFIG_IN, $config_in)
162
or die "Can't open \"$config_in\"\n";
163
open(CONFIG_H, ">$config_h")
164
or die "Can't create \"$config_h\"\n";
166
while (<CONFIG_IN>) {
169
if (/^\s*#\s*undef\s+HAVE_NATIVE_mpn_(\w+)/ and
170
-r mf("$mpn_asm_dir/$1.asm")) {
172
if (defined delete $mpn_objects{$1}) {
173
push(@asm_files, $1);
174
print CONFIG_H "\#define HAVE_NATIVE_mpn_$1 1\n";
176
print STDERR "Warning: Found asm file \"$1\" but no corresponding C file - ignoring\n";
179
} elsif (/^\s*#\s*undef\s+inline\b/) {
180
print CONFIG_H "\#define inline\n";
181
} elsif (/^\s*#\s*undef\s+HAVE_STDARG\b/) {
182
print CONFIG_H "\#define HAVE_STDARG 1\n";
183
} elsif (/^\s*#\s*undef\s+HAVE_STRCHR\b/) {
184
print CONFIG_H "\#define HAVE_STRCHR 1\n";
185
} elsif (/^\s*#\s*undef\s+HAVE_HOST_CPU_FAMILY_powerpc\b/) {
186
print CONFIG_H "\#define HAVE_HOST_CPU_FAMILY_powerpc 1\n";
187
} elsif (/^\s*#\s*undef\s+WANT_TMP_NOTREENTRANT\b/) {
188
print CONFIG_H "\#define WANT_TMP_NOTREENTRANT 1\n";
189
} elsif (/^\s*#\s*undef\s+PACKAGE\b/) {
190
print CONFIG_H "\#define PACKAGE \"$package\"\n";
191
} elsif (/^\s*#\s*undef\s+VERSION\b/) {
192
print CONFIG_H "\#define VERSION \"$version\"\n";
193
} elsif (/^\s*#\s*undef\s+STDC_HEADERS\b/) {
194
print CONFIG_H "\#define STDC_HEADERS 1\n";
195
} else { # Blank line, leave it
196
print CONFIG_H "$_\n";
203
###########################################################################
205
# Create gmp.h from ../gmp-h.in
207
###########################################################################
209
open(GMP_H_IN, $gmp_h_in)
210
or die "Can't open \"$gmp_h_in\"\n";
211
open(GMP_H, ">$gmp_h")
212
or die "Can't create \"$gmp_h\"\n";
215
chomp; # Remove whatever ending it was
217
# Do the variable substitution
219
s/\@([^\@]+)\@/exists $vars{$1} ? $vars{$1} : ''/ge;
227
###########################################################################
231
###########################################################################
234
-d $_ or mkdir $_, 0775
235
or die "Can't create directory \"$_\"\n";
238
###########################################################################
240
# Parse the *.asm files found and convert them to MPW format
242
###########################################################################
246
foreach $file (@asm_files) {
247
my $ifile = mf("$mpn_asm_dir/$file.asm");
248
my $ofile = mf("Asm/$file.s");
251
or die "Can't read file \"$ifile\"\n";
253
or die "Can't create file \"$ofile\"\n";
256
chomp; # Remove whatever ending it was
258
s/\bdnl\b/;/ or s/\bC\b/;/; # Use ; comments
260
s/include\s*\(.*?\)//; # Don't use include macro
262
s/ASM_START\s*\(.*?\)/$asm_start/;
264
s/PROLOGUE\s*\(\s*(.*?)\s*\)/asm_prologue($1)/e;
266
s/EPILOGUE\s*\(\s*(.*?)\s*\)/asm_epilogue($1)/e;
269
print NEW "$_\x0D"; # Use MacOS end-of-line character
277
###########################################################################
279
# Parse the Makefile.in and produce the Makefile
281
###########################################################################
283
# Check if we have optional left in C directory
285
foreach (keys %mpn_objects) {
286
delete $mpn_objects{$_}
287
if $mpn_optional{$_} and !-r mf("$mpn_gen_dir/$_.c");
290
my $mpn_objects = join(' ', map {"{MpnObjDir}$_.o"} sort keys %mpn_objects);
291
$mpn_objects =~ s/(.{1,66})\s/$1 \xB6\x0D\t/g;
293
my @asm_objects = @asm_files;
294
my @asm_sources = @asm_files;
296
# Adjust configuration
298
foreach (keys %{$cfg}) {
299
$$cfg{$_} = join(" \xB6\x0D\t\t", @{$$cfg{$_}})
305
'version' => $version,
306
'package' => $package,
311
join(" \xB6\x0D\t",map {$_ = "{AsmObjDir}$_.o"} sort @asm_objects),
313
join(" \xB6\x0D\t",map {$_ = "{AsmSrcDir}$_.s"} sort @asm_sources),
314
'mpn_objects' => $mpn_objects,
315
'mpz_objects' => what_objects("mpz","../mpz","{MpzObjDir}"),
316
'mpf_objects' => what_objects("mpf","../mpf","{MpfObjDir}"),
317
'mpq_objects' => what_objects("mpq","../mpq","{MpqObjDir}"),
318
'gmp_objects' => what_objects("gmp","..", "{CmnObjDir}"),
324
or die "Can't read file \"$make_in\"\n";
326
or die "Can't create file \"$make\"\n";
329
chomp; # Remove whatever ending it was
331
# Do the variable substitution
333
s/\@([^\@]+)\@/exists $config{$1} ? $config{$1} : ''/ge;
335
print OUT "$_\x0D"; # Use MacOS end-of-line character
341
###########################################################################
343
# Parse the configure.in file to find the mpn files to compile and link
344
# Find package name and version
346
###########################################################################
348
sub parse_top_configure {
351
open(CONFIGURE, $cfg)
352
or die "Can't open \"$cfg\"\n";
355
my $text = <CONFIGURE>;
359
my ($package) = $text =~ /(?:\n|\r)PACKAGE\s*=\s*(\S+)/;
360
my ($version) = $text =~ /(?:\n|\r)VERSION\s*=\s*(\S+)/;
362
my $files = join(' ',$text =~ /(?:\n|\r)gmp_mpn_functions\s*=\s*\"([^\"]+)/);
364
$files =~ s/\$\{?\w*\}?//g;
365
my @files = sort split(' ',$files);
367
$files = join(' ',$text =~ /(?:\n|\r)gmp_mpn_functions_optional\s*=\s*\"([^\"]+)/);
369
$files =~ s/\$\{?\w*\}?//g;
370
my @optional = sort split(' ',$files);
372
@files > 30 or die "Can't find mpn files in \"$cfg\"\n";
373
defined $package or die "Can't find package name in \"$cfg\"\n";
374
defined $version or die "Can't find version name in \"$cfg\"\n";
375
return (\@files,\@optional,$package,$version);
378
###########################################################################
380
# Find the C files for mpz, mpf .....
382
###########################################################################
389
my $makefile_am = mf("$srcdir/Makefile.am");
391
# We look in the Makefile.am file
392
open(MAKEFILE_AM, $makefile_am)
393
or die "Can't open file \"$makefile_am\"\n";
395
# I had as short version of this using more advanced
396
# regular expressions on the whole file content but
397
# MacPerl freezes my Mac every time..... :-(
402
while (defined($line = <MAKEFILE_AM>) ) {
405
if ($line =~ s/^lib${part}_la_SOURCES\s*=//) {
408
if ($line =~ s/\\\s*$//) {
414
} while (defined($line = <MAKEFILE_AM>));
417
if ($line =~ s/^nodist_lib${part}_la_SOURCES\s*=//) {
420
if ($line =~ s/\\\s*$//) {
426
} while (defined($line = <MAKEFILE_AM>));
431
my @ofiles = split(' ',$text);
432
@ofiles > 10 or die "Can't find $part files in \"$makefile_am\"\n";
433
my $ofiles = join(' ', map {/^(.+)\.c$/ and $_ = "$dstdir$1.o"} @ofiles);
434
$ofiles =~ s/(.{1,66})\s/$1 \xB6\x0D\t/g;
439
###########################################################################
443
###########################################################################
447
return "\tcsect .__g$func\[pr]";
455
EXPORT .__g$func\[PR]
457
TC __g$func\[TC], __g$func\[DS]
464
FUNCTION .__g$func\[PR]
470
###########################################################################
472
# Platform dependent filename conversion
474
###########################################################################
479
return $path unless $^O eq 'MacOS';
481
$path =~ /:/ and die "File name already converted to mac format: $path\n";
483
if ($path =~ s&^/&&) {
485
unless ($path =~ s&/&:&g) {
486
# This is a drive name
491
if ($path =~ s&/&:&g) {
494
$path =~ s&\.\.:&:&g;
496
# Plain file name, no directory part