[BACK]Return to configure CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / macos

Annotation of OpenXM_contrib/gmp/macos/configure, Revision 1.1.1.2

1.1       maekawa     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.
                      4:
1.1.1.2 ! ohara       5: # Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
1.1       maekawa     6: #
                      7: # This file is part of the GNU MP Library.
                      8: #
                      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.
                     13: #
                     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.
                     18: #
                     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,
                     22: # MA 02111-1307, USA.
                     23:
                     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 **************************************
                     30:
                     31: use strict;
                     32:
                     33: ###########################################################################
                     34: #
                     35: #  Platform dependent
                     36: #
                     37: ###########################################################################
                     38:
                     39: $/ = "\012"                    # Input files use Unix end-of-line chars
                     40:   if $^O eq 'MacOS';
                     41:
                     42: ###########################################################################
                     43: #
                     44: #  Constants
                     45: #
                     46: ###########################################################################
                     47:
                     48: # Directories to create
                     49:
                     50: my @dirs =
                     51:   (
                     52:    'MpfObj',
                     53:    'MpnObj',
                     54:    'MpqObj',
                     55:    'MpzObj',
                     56:    'CmnObj',
                     57:    'AsmObj',
                     58:    'Asm',
                     59:    'MpfBin',
                     60:    'MpqBin',
                     61:    'MpzBin',
                     62:   );
                     63:
                     64: my $cfg;                       # Will point to %cfg_apple or %cfg_cw
                     65:
                     66: my %cfg_apple =
                     67:   (
                     68:    'cc'          =>  'MrC',
                     69:    'coptions'    => ['-ansi on -i : -i :: -i ::mpn:powerpc32 -i ::mpz',
1.1.1.2 ! ohara      70:                     '-opt speed -inline on'],
1.1       maekawa    71:    'link'        => 'PPCLink',
                     72:    'linkoptions' => '-sym on -xm library',
                     73:    'tooloptions' => "-t 'MPST' -c 'MPS'",
                     74:    'asm'         => 'PPCAsm',
                     75:    'aoptions'    => '-sym on',
                     76:    'syslibs'     => [
                     77:                     '"{SharedLibraries}"StdCLib',
                     78:                     '"{SharedLibraries}"InterfaceLib',
                     79:                     '"{SharedLibraries}"MathLib',
                     80:                     '"{PPCLibraries}"StdCRuntime.o',
                     81:                     '"{PPCLibraries}"PPCCRuntime.o',
                     82:                    ],
                     83:   );
                     84:
                     85: my %cfg_cw =
                     86:   (
                     87:    'cc'          =>  'MWCPPC',
                     88:    'coptions'    => [
                     89:                     '-opt all -w nounusedvar,noextended',
                     90:                     '-i :: -i ::mpn:powerpc32 -i ::mpz',
1.1.1.2 ! ohara      91:                     '-sym full',
1.1       maekawa    92:                    ],
                     93:    'link'        => 'MWLinkPPC',
                     94:    'linkoptions' => '-sym fullpath -library',
                     95:    'tooloptions' => '-mpwtool',
                     96:    'asm'         => 'PPCAsm',
                     97:    'aoptions'    => '-sym on',
                     98:    'syslibs'     => [
                     99:                     '"{SharedLibraries}"InterfaceLib',
                    100:                     '"{MWPPCLibraries}MSL MPWCRuntime.Lib"',
                    101:                     '"{MWPPCLibraries}MSL C.PPC MPW(NL).Lib"',
                    102:                     '"{SharedLibraries}"MathLib',
                    103:                    ],
                    104:   );
                    105:
1.1.1.2 ! ohara     106: # We only set the variables that have a value
        !           107: my %vars =
        !           108:   (
        !           109:    'BITS_PER_MP_LIMB' => 32,
        !           110:    'HAVE_HOST_CPU_FAMILY_power' => 0,
        !           111:    'HAVE_HOST_CPU_FAMILY_powerpc' => 1,
        !           112:    'GMP_NAIL_BITS' => 0,
        !           113:    'DEFN_LONG_LONG_LIMB' => '',
        !           114:    'LIBGMP_DLL' => 0,
        !           115:   );
1.1       maekawa   116:
                    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");
1.1.1.2 ! ohara     122: my $gmp_h        = mf('../gmp.h');
        !           123: my $gmp_h_in     = mf('../gmp-h.in');
1.1       maekawa   124: my $mpn_asm_dir  = "../mpn/powerpc32";
                    125: my $mpn_gen_dir  = "../mpn/generic";
                    126: my $config_h     = 'config.h';
                    127:
                    128: my $asm_start    = "\ttoc";    # No dot, like ".dot"?
                    129:
                    130: ###########################################################################
                    131: #
                    132: #  Read command line
                    133: #
                    134: ###########################################################################
                    135:
                    136: $cfg = \%cfg_apple;            # Default
                    137:
                    138: if (@ARGV and $ARGV[0] =~ /^cw|co/) {
                    139:   $cfg = \%cfg_cw;
                    140:   $make .= '.cw';
                    141: }
                    142:
                    143: ###########################################################################
                    144: #
                    145: #  Parse top configure file for mpn files
                    146: #
                    147: ###########################################################################
                    148:
                    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;
                    152:
                    153: ###########################################################################
                    154: #
                    155: #  Create config.h from ../config.in
                    156: #
                    157: ###########################################################################
                    158:
                    159: my @asm_files;
                    160:
                    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";
                    165:
                    166: while (<CONFIG_IN>) {
                    167:   chomp;
                    168:
                    169:   if (/^\s*#\s*undef\s+HAVE_NATIVE_mpn_(\w+)/ and
                    170:       -r mf("$mpn_asm_dir/$1.asm")) {
                    171:
                    172:     if (defined delete $mpn_objects{$1}) {
                    173:       push(@asm_files, $1);
                    174:       print CONFIG_H "\#define HAVE_NATIVE_mpn_$1 1\n";
                    175:     } else {
                    176:       print STDERR "Warning: Found asm file \"$1\" but no corresponding C file - ignoring\n";
                    177:     }
                    178:
1.1.1.2 ! ohara     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/) {
1.1       maekawa   190:     print CONFIG_H "\#define PACKAGE \"$package\"\n";
1.1.1.2 ! ohara     191:   } elsif (/^\s*#\s*undef\s+VERSION\b/) {
1.1       maekawa   192:     print CONFIG_H "\#define VERSION \"$version\"\n";
1.1.1.2 ! ohara     193:   } elsif (/^\s*#\s*undef\s+STDC_HEADERS\b/) {
1.1       maekawa   194:     print CONFIG_H "\#define STDC_HEADERS 1\n";
                    195:   } else {                     # Blank line, leave it
                    196:     print CONFIG_H "$_\n";
                    197:   }
                    198: }
                    199:
                    200: close CONFIG_H;
                    201: close CONFIG_IN;
1.1.1.2 ! ohara     202:
        !           203: ###########################################################################
        !           204: #
        !           205: #  Create gmp.h from ../gmp-h.in
        !           206: #
        !           207: ###########################################################################
        !           208:
        !           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";
        !           213:
        !           214: while (<GMP_H_IN>) {
        !           215:   chomp;                       # Remove whatever ending it was
        !           216:
        !           217:   # Do the variable substitution
        !           218:
        !           219:   s/\@([^\@]+)\@/exists $vars{$1} ? $vars{$1} : ''/ge;
        !           220:
        !           221:   print GMP_H "$_\n";
        !           222: }
        !           223:
        !           224: close GMP_H;
        !           225: close GMP_H_IN;
1.1       maekawa   226:
                    227: ###########################################################################
                    228: #
                    229: #  Create directories
                    230: #
                    231: ###########################################################################
                    232:
                    233: foreach (@dirs) {
                    234:   -d $_ or mkdir $_, 0775
                    235:     or die "Can't create directory \"$_\"\n";
                    236: }
                    237:
                    238: ###########################################################################
                    239: #
                    240: #  Parse the *.asm files found and convert them to MPW format
                    241: #
                    242: ###########################################################################
                    243:
                    244: my $file;
                    245:
                    246: foreach $file (@asm_files) {
                    247:   my $ifile = mf("$mpn_asm_dir/$file.asm");
                    248:   my $ofile = mf("Asm/$file.s");
                    249:
                    250:   open(ASM, $ifile)
                    251:     or die "Can't read file \"$ifile\"\n";
                    252:   open(NEW, ">$ofile")
                    253:     or die "Can't create file \"$ofile\"\n";
                    254:
                    255:   while (<ASM>) {
                    256:     chomp;                     # Remove whatever ending it was
                    257:
                    258:     s/\bdnl\b/;/ or s/\bC\b/;/;        # Use ; comments
                    259:
                    260:     s/include\s*\(.*?\)//;     # Don't use include macro
                    261:
                    262:     s/ASM_START\s*\(.*?\)/$asm_start/;
                    263:
                    264:     s/PROLOGUE\s*\(\s*(.*?)\s*\)/asm_prologue($1)/e;
                    265:
                    266:     s/EPILOGUE\s*\(\s*(.*?)\s*\)/asm_epilogue($1)/e;
                    267:
                    268:     s/\n/\x0D/g;
                    269:     print NEW "$_\x0D";                # Use MacOS end-of-line character
                    270:   }
                    271:
                    272:   close ASM;
                    273:   close NEW;
                    274: }
                    275:
                    276:
                    277: ###########################################################################
                    278: #
                    279: #  Parse the Makefile.in and produce the Makefile
                    280: #
                    281: ###########################################################################
                    282:
                    283: # Check if we have optional left in C directory
                    284:
                    285: foreach (keys %mpn_objects) {
                    286:   delete $mpn_objects{$_}
                    287:     if $mpn_optional{$_} and !-r mf("$mpn_gen_dir/$_.c");
                    288: }
                    289:
                    290: my $mpn_objects = join(' ', map {"{MpnObjDir}$_.o"}  sort keys %mpn_objects);
                    291: $mpn_objects =~ s/(.{1,66})\s/$1 \xB6\x0D\t/g;
                    292:
                    293: my @asm_objects = @asm_files;
                    294: my @asm_sources = @asm_files;
                    295:
                    296: # Adjust configuration
                    297:
                    298: foreach (keys %{$cfg}) {
                    299:   $$cfg{$_} = join(" \xB6\x0D\t\t", @{$$cfg{$_}})
                    300:     if ref $$cfg{$_};
                    301: }
                    302:
                    303: my %config =
                    304:   (
                    305:    'version' => $version,
                    306:    'package' => $package,
                    307:    'c'       => "\xB6",
                    308:    'dep'     => "\xC4",
                    309:    'wildcard'=> "\xC5",
                    310:    'asm_objects' =>
                    311:        join(" \xB6\x0D\t",map {$_ = "{AsmObjDir}$_.o"} sort @asm_objects),
                    312:    'asm_sources' =>
                    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}"),
                    319:    %{$cfg},
                    320:   );
                    321:
                    322:
                    323: open(IN, $make_in)
                    324:   or die "Can't read file \"$make_in\"\n";
                    325: open(OUT, ">$make")
                    326:   or die "Can't create file \"$make\"\n";
                    327:
                    328: while (<IN>) {
                    329:   chomp;                       # Remove whatever ending it was
                    330:
                    331:   # Do the variable substitution
                    332:
                    333:   s/\@([^\@]+)\@/exists $config{$1} ? $config{$1} : ''/ge;
                    334:
                    335:   print OUT "$_\x0D";          # Use MacOS end-of-line character
                    336: }
                    337:
                    338: close IN;
                    339: close OUT;
                    340:
                    341: ###########################################################################
                    342: #
                    343: #  Parse the configure.in file to find the mpn files to compile and link
                    344: #  Find package name and version
                    345: #
                    346: ###########################################################################
                    347:
                    348: sub parse_top_configure {
                    349:   my $cfg = shift;
                    350:
                    351:   open(CONFIGURE, $cfg)
                    352:     or die "Can't open \"$cfg\"\n";
                    353:   my $old_eol = $/;
                    354:   undef $/;
                    355:   my $text = <CONFIGURE>;
                    356:   $/ = $old_eol;
                    357:   close CONFIGURE;
                    358:
                    359:   my ($package) = $text =~ /(?:\n|\r)PACKAGE\s*=\s*(\S+)/;
                    360:   my ($version) = $text =~ /(?:\n|\r)VERSION\s*=\s*(\S+)/;
                    361:
                    362:   my $files = join(' ',$text =~ /(?:\n|\r)gmp_mpn_functions\s*=\s*\"([^\"]+)/);
                    363:   $files =~ s/\\/ /g;
                    364:   $files =~ s/\$\{?\w*\}?//g;
                    365:   my @files = sort split(' ',$files);
                    366:
                    367:   $files = join(' ',$text =~ /(?:\n|\r)gmp_mpn_functions_optional\s*=\s*\"([^\"]+)/);
                    368:   $files =~ s/\\/ /g;
                    369:   $files =~ s/\$\{?\w*\}?//g;
                    370:   my @optional = sort split(' ',$files);
                    371:
                    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);
                    376: }
                    377:
                    378: ###########################################################################
                    379: #
                    380: #  Find the C files for mpz, mpf .....
                    381: #
                    382: ###########################################################################
                    383:
                    384: sub what_objects {
                    385:   my $part   = shift;
                    386:   my $srcdir = shift;
                    387:   my $dstdir = shift;
                    388:
                    389:   my $makefile_am = mf("$srcdir/Makefile.am");
                    390:
                    391:   # We look in the Makefile.am file
                    392:   open(MAKEFILE_AM, $makefile_am)
                    393:     or die "Can't open file \"$makefile_am\"\n";
                    394:
                    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..... :-(
                    398:
                    399:   my $line;
                    400:   my $text = '';
                    401:
                    402:   while (defined($line = <MAKEFILE_AM>) ) {
                    403:     chomp $line;
                    404:
                    405:     if ($line =~ s/^lib${part}_la_SOURCES\s*=//) {
                    406:       do {
                    407:        chomp $line;
                    408:        if ($line =~ s/\\\s*$//) {
                    409:          $text .= " $line";
                    410:        } else {
                    411:          $text .= " $line";
                    412:          next;
                    413:        }
                    414:       } while (defined($line = <MAKEFILE_AM>));
                    415:     }
                    416:
                    417:     if ($line =~ s/^nodist_lib${part}_la_SOURCES\s*=//) {
                    418:       do {
                    419:        chomp $line;
                    420:        if ($line =~ s/\\\s*$//) {
                    421:          $text .= " $line";
                    422:        } else {
                    423:          $text .= " $line";
                    424:          last;
                    425:        }
                    426:       } while (defined($line = <MAKEFILE_AM>));
                    427:     }
                    428:   }
                    429:   close MAKEFILE_AM;
                    430:
                    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;
                    435:
                    436:   return $ofiles;
                    437: }
                    438:
                    439: ###########################################################################
                    440: #
                    441: #  Assembler
                    442: #
                    443: ###########################################################################
                    444:
                    445: sub asm_epilogue {
                    446:     my $func = shift;
                    447:     return "\tcsect .__g$func\[pr]";
                    448: }
                    449:
                    450: sub asm_prologue {
                    451:     my $func = shift;
                    452:
                    453:     my $asm = <<HERE;
                    454:        EXPORT __g$func\[DS]
                    455:        EXPORT .__g$func\[PR]
                    456:
                    457:        TC __g$func\[TC], __g$func\[DS]
                    458:
                    459:        CSECT __g$func\[DS]
                    460:        DC.L .__g$func\[PR]
                    461:        DC.L TOC[tc0]
                    462:
                    463:        CSECT .__g$func\[PR]
                    464:        FUNCTION .__g$func\[PR]
                    465: HERE
                    466:     return $asm;
                    467: }
                    468:
                    469:
                    470: ###########################################################################
                    471: #
                    472: #  Platform dependent filename conversion
                    473: #
                    474: ###########################################################################
                    475:
                    476: sub mf {
                    477:   my $path = shift;
                    478:
                    479:   return $path unless $^O eq 'MacOS';
                    480:
                    481:   $path =~ /:/ and die "File name already converted to mac format: $path\n";
                    482:
                    483:   if ($path =~ s&^/&&) {
                    484:     # Absolute path
                    485:     unless ($path =~ s&/&:&g) {
                    486:       # This is a drive name
                    487:       $path .= ':';
                    488:     }
                    489:   } else {
                    490:     # Relative path
                    491:     if ($path =~ s&/&:&g) {
                    492:       # Contains slash
                    493:       $path = ":$path";
                    494:       $path =~ s&\.\.:&:&g;
                    495:     } else {
                    496:       # Plain file name, no directory part
                    497:     }
                    498:   }
                    499:   return $path;
                    500: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>