[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.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:
        !             5: # Copyright (C) 2000 Free Software Foundation, Inc.
        !             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',
        !            70:                     '-opt speed -inline on -d random=rand -d srandom=srand'],
        !            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',
        !            91:                     '-sym full -d random=rand -d srandom=srand',
        !            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:
        !           106:
        !           107: my $make_in      = 'Makefile.in';
        !           108: my $make         = 'Makefile';
        !           109: my $configure    = mf("../configure");
        !           110: my $configure_in = mf("../configure.in");
        !           111: my $config_in    = mf("../config.in");
        !           112: my $mpn_asm_dir  = "../mpn/powerpc32";
        !           113: my $mpn_gen_dir  = "../mpn/generic";
        !           114: my $config_h     = 'config.h';
        !           115:
        !           116: my $asm_start    = "\ttoc";    # No dot, like ".dot"?
        !           117:
        !           118: ###########################################################################
        !           119: #
        !           120: #  Read command line
        !           121: #
        !           122: ###########################################################################
        !           123:
        !           124: $cfg = \%cfg_apple;            # Default
        !           125:
        !           126: if (@ARGV and $ARGV[0] =~ /^cw|co/) {
        !           127:   $cfg = \%cfg_cw;
        !           128:   $make .= '.cw';
        !           129: }
        !           130:
        !           131: ###########################################################################
        !           132: #
        !           133: #  Parse top configure file for mpn files
        !           134: #
        !           135: ###########################################################################
        !           136:
        !           137: my ($files,$optional,$package,$version) = parse_top_configure($configure);
        !           138: my %mpn_objects = map {$_ => 1} (@$files,@$optional);
        !           139: my %mpn_optional = map {$_ => 1} @$optional;
        !           140:
        !           141: ###########################################################################
        !           142: #
        !           143: #  Create config.h from ../config.in
        !           144: #
        !           145: ###########################################################################
        !           146:
        !           147: my @asm_files;
        !           148:
        !           149: open(CONFIG_IN, $config_in)
        !           150:   or die "Can't open \"$config_in\"\n";
        !           151: open(CONFIG_H, ">$config_h")
        !           152:   or die "Can't create \"$config_h\"\n";
        !           153:
        !           154: while (<CONFIG_IN>) {
        !           155:   chomp;
        !           156:
        !           157:   if (/^\s*#\s*undef\s+HAVE_NATIVE_mpn_(\w+)/ and
        !           158:       -r mf("$mpn_asm_dir/$1.asm")) {
        !           159:
        !           160:     if (defined delete $mpn_objects{$1}) {
        !           161:       push(@asm_files, $1);
        !           162:       print CONFIG_H "\#define HAVE_NATIVE_mpn_$1 1\n";
        !           163:     } else {
        !           164:       print STDERR "Warning: Found asm file \"$1\" but no corresponding C file - ignoring\n";
        !           165:     }
        !           166:
        !           167:   } elsif (/^\s*#\s*undef\s+PACKAGE/) {
        !           168:     print CONFIG_H "\#define PACKAGE \"$package\"\n";
        !           169:   } elsif (/^\s*#\s*undef\s+VERSION/) {
        !           170:     print CONFIG_H "\#define VERSION \"$version\"\n";
        !           171:   } elsif (/^\s*#\s*undef\s+STDC_HEADERS/) {
        !           172:     print CONFIG_H "\#define STDC_HEADERS 1\n";
        !           173:   } else {                     # Blank line, leave it
        !           174:     print CONFIG_H "$_\n";
        !           175:   }
        !           176: }
        !           177:
        !           178: close CONFIG_H;
        !           179: close CONFIG_IN;
        !           180:
        !           181: ###########################################################################
        !           182: #
        !           183: #  Create directories
        !           184: #
        !           185: ###########################################################################
        !           186:
        !           187: foreach (@dirs) {
        !           188:   -d $_ or mkdir $_, 0775
        !           189:     or die "Can't create directory \"$_\"\n";
        !           190: }
        !           191:
        !           192: ###########################################################################
        !           193: #
        !           194: #  Parse the *.asm files found and convert them to MPW format
        !           195: #
        !           196: ###########################################################################
        !           197:
        !           198: my $file;
        !           199:
        !           200: foreach $file (@asm_files) {
        !           201:   my $ifile = mf("$mpn_asm_dir/$file.asm");
        !           202:   my $ofile = mf("Asm/$file.s");
        !           203:
        !           204:   open(ASM, $ifile)
        !           205:     or die "Can't read file \"$ifile\"\n";
        !           206:   open(NEW, ">$ofile")
        !           207:     or die "Can't create file \"$ofile\"\n";
        !           208:
        !           209:   while (<ASM>) {
        !           210:     chomp;                     # Remove whatever ending it was
        !           211:
        !           212:     s/\bdnl\b/;/ or s/\bC\b/;/;        # Use ; comments
        !           213:
        !           214:     s/include\s*\(.*?\)//;     # Don't use include macro
        !           215:
        !           216:     s/ASM_START\s*\(.*?\)/$asm_start/;
        !           217:
        !           218:     s/PROLOGUE\s*\(\s*(.*?)\s*\)/asm_prologue($1)/e;
        !           219:
        !           220:     s/EPILOGUE\s*\(\s*(.*?)\s*\)/asm_epilogue($1)/e;
        !           221:
        !           222:     s/\n/\x0D/g;
        !           223:     print NEW "$_\x0D";                # Use MacOS end-of-line character
        !           224:   }
        !           225:
        !           226:   close ASM;
        !           227:   close NEW;
        !           228: }
        !           229:
        !           230:
        !           231: ###########################################################################
        !           232: #
        !           233: #  Parse the Makefile.in and produce the Makefile
        !           234: #
        !           235: ###########################################################################
        !           236:
        !           237: # Check if we have optional left in C directory
        !           238:
        !           239: foreach (keys %mpn_objects) {
        !           240:   delete $mpn_objects{$_}
        !           241:     if $mpn_optional{$_} and !-r mf("$mpn_gen_dir/$_.c");
        !           242: }
        !           243:
        !           244: my $mpn_objects = join(' ', map {"{MpnObjDir}$_.o"}  sort keys %mpn_objects);
        !           245: $mpn_objects =~ s/(.{1,66})\s/$1 \xB6\x0D\t/g;
        !           246:
        !           247: my @asm_objects = @asm_files;
        !           248: my @asm_sources = @asm_files;
        !           249:
        !           250: # Adjust configuration
        !           251:
        !           252: foreach (keys %{$cfg}) {
        !           253:   $$cfg{$_} = join(" \xB6\x0D\t\t", @{$$cfg{$_}})
        !           254:     if ref $$cfg{$_};
        !           255: }
        !           256:
        !           257: my %config =
        !           258:   (
        !           259:    'version' => $version,
        !           260:    'package' => $package,
        !           261:    'c'       => "\xB6",
        !           262:    'dep'     => "\xC4",
        !           263:    'wildcard'=> "\xC5",
        !           264:    'asm_objects' =>
        !           265:        join(" \xB6\x0D\t",map {$_ = "{AsmObjDir}$_.o"} sort @asm_objects),
        !           266:    'asm_sources' =>
        !           267:        join(" \xB6\x0D\t",map {$_ = "{AsmSrcDir}$_.s"} sort @asm_sources),
        !           268:    'mpn_objects' => $mpn_objects,
        !           269:    'mpz_objects' => what_objects("mpz","../mpz","{MpzObjDir}"),
        !           270:    'mpf_objects' => what_objects("mpf","../mpf","{MpfObjDir}"),
        !           271:    'mpq_objects' => what_objects("mpq","../mpq","{MpqObjDir}"),
        !           272:    'gmp_objects' => what_objects("gmp","..",    "{CmnObjDir}"),
        !           273:    %{$cfg},
        !           274:   );
        !           275:
        !           276:
        !           277: open(IN, $make_in)
        !           278:   or die "Can't read file \"$make_in\"\n";
        !           279: open(OUT, ">$make")
        !           280:   or die "Can't create file \"$make\"\n";
        !           281:
        !           282: while (<IN>) {
        !           283:   chomp;                       # Remove whatever ending it was
        !           284:
        !           285:   # Do the variable substitution
        !           286:
        !           287:   s/\@([^\@]+)\@/exists $config{$1} ? $config{$1} : ''/ge;
        !           288:
        !           289:   print OUT "$_\x0D";          # Use MacOS end-of-line character
        !           290: }
        !           291:
        !           292: close IN;
        !           293: close OUT;
        !           294:
        !           295: ###########################################################################
        !           296: #
        !           297: #  Parse the configure.in file to find the mpn files to compile and link
        !           298: #  Find package name and version
        !           299: #
        !           300: ###########################################################################
        !           301:
        !           302: sub parse_top_configure {
        !           303:   my $cfg = shift;
        !           304:
        !           305:   open(CONFIGURE, $cfg)
        !           306:     or die "Can't open \"$cfg\"\n";
        !           307:   my $old_eol = $/;
        !           308:   undef $/;
        !           309:   my $text = <CONFIGURE>;
        !           310:   $/ = $old_eol;
        !           311:   close CONFIGURE;
        !           312:
        !           313:   my ($package) = $text =~ /(?:\n|\r)PACKAGE\s*=\s*(\S+)/;
        !           314:   my ($version) = $text =~ /(?:\n|\r)VERSION\s*=\s*(\S+)/;
        !           315:
        !           316:   my $files = join(' ',$text =~ /(?:\n|\r)gmp_mpn_functions\s*=\s*\"([^\"]+)/);
        !           317:   $files =~ s/\\/ /g;
        !           318:   $files =~ s/\$\{?\w*\}?//g;
        !           319:   my @files = sort split(' ',$files);
        !           320:
        !           321:   $files = join(' ',$text =~ /(?:\n|\r)gmp_mpn_functions_optional\s*=\s*\"([^\"]+)/);
        !           322:   $files =~ s/\\/ /g;
        !           323:   $files =~ s/\$\{?\w*\}?//g;
        !           324:   my @optional = sort split(' ',$files);
        !           325:
        !           326:   @files > 30 or die "Can't find mpn files in \"$cfg\"\n";
        !           327:   defined $package or die "Can't find package name in \"$cfg\"\n";
        !           328:   defined $version or die "Can't find version name in \"$cfg\"\n";
        !           329:   return (\@files,\@optional,$package,$version);
        !           330: }
        !           331:
        !           332: ###########################################################################
        !           333: #
        !           334: #  Find the C files for mpz, mpf .....
        !           335: #
        !           336: ###########################################################################
        !           337:
        !           338: sub what_objects {
        !           339:   my $part   = shift;
        !           340:   my $srcdir = shift;
        !           341:   my $dstdir = shift;
        !           342:
        !           343:   my $makefile_am = mf("$srcdir/Makefile.am");
        !           344:
        !           345:   # We look in the Makefile.am file
        !           346:   open(MAKEFILE_AM, $makefile_am)
        !           347:     or die "Can't open file \"$makefile_am\"\n";
        !           348:
        !           349:   # I had as short version of this using more advanced
        !           350:   # regular expressions on the whole file content but
        !           351:   # MacPerl freezes my Mac every time..... :-(
        !           352:
        !           353:   my $line;
        !           354:   my $text = '';
        !           355:
        !           356:   while (defined($line = <MAKEFILE_AM>) ) {
        !           357:     chomp $line;
        !           358:
        !           359:     if ($line =~ s/^lib${part}_la_SOURCES\s*=//) {
        !           360:       do {
        !           361:        chomp $line;
        !           362:        if ($line =~ s/\\\s*$//) {
        !           363:          $text .= " $line";
        !           364:        } else {
        !           365:          $text .= " $line";
        !           366:          next;
        !           367:        }
        !           368:       } while (defined($line = <MAKEFILE_AM>));
        !           369:     }
        !           370:
        !           371:     if ($line =~ s/^nodist_lib${part}_la_SOURCES\s*=//) {
        !           372:       do {
        !           373:        chomp $line;
        !           374:        if ($line =~ s/\\\s*$//) {
        !           375:          $text .= " $line";
        !           376:        } else {
        !           377:          $text .= " $line";
        !           378:          last;
        !           379:        }
        !           380:       } while (defined($line = <MAKEFILE_AM>));
        !           381:     }
        !           382:   }
        !           383:   close MAKEFILE_AM;
        !           384:
        !           385:   my @ofiles = split(' ',$text);
        !           386:   @ofiles > 10 or die "Can't find $part files in \"$makefile_am\"\n";
        !           387:   my $ofiles = join(' ', map {/^(.+)\.c$/ and $_ = "$dstdir$1.o"} @ofiles);
        !           388:   $ofiles =~ s/(.{1,66})\s/$1 \xB6\x0D\t/g;
        !           389:
        !           390:   return $ofiles;
        !           391: }
        !           392:
        !           393: ###########################################################################
        !           394: #
        !           395: #  Assembler
        !           396: #
        !           397: ###########################################################################
        !           398:
        !           399: sub asm_epilogue {
        !           400:     my $func = shift;
        !           401:     return "\tcsect .__g$func\[pr]";
        !           402: }
        !           403:
        !           404: sub asm_prologue {
        !           405:     my $func = shift;
        !           406:
        !           407:     my $asm = <<HERE;
        !           408:        EXPORT __g$func\[DS]
        !           409:        EXPORT .__g$func\[PR]
        !           410:
        !           411:        TC __g$func\[TC], __g$func\[DS]
        !           412:
        !           413:        CSECT __g$func\[DS]
        !           414:        DC.L .__g$func\[PR]
        !           415:        DC.L TOC[tc0]
        !           416:
        !           417:        CSECT .__g$func\[PR]
        !           418:        FUNCTION .__g$func\[PR]
        !           419: HERE
        !           420:     return $asm;
        !           421: }
        !           422:
        !           423:
        !           424: ###########################################################################
        !           425: #
        !           426: #  Platform dependent filename conversion
        !           427: #
        !           428: ###########################################################################
        !           429:
        !           430: sub mf {
        !           431:   my $path = shift;
        !           432:
        !           433:   return $path unless $^O eq 'MacOS';
        !           434:
        !           435:   $path =~ /:/ and die "File name already converted to mac format: $path\n";
        !           436:
        !           437:   if ($path =~ s&^/&&) {
        !           438:     # Absolute path
        !           439:     unless ($path =~ s&/&:&g) {
        !           440:       # This is a drive name
        !           441:       $path .= ':';
        !           442:     }
        !           443:   } else {
        !           444:     # Relative path
        !           445:     if ($path =~ s&/&:&g) {
        !           446:       # Contains slash
        !           447:       $path = ":$path";
        !           448:       $path =~ s&\.\.:&:&g;
        !           449:     } else {
        !           450:       # Plain file name, no directory part
        !           451:     }
        !           452:   }
        !           453:   return $path;
        !           454: }

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