Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #37160] [PATCH] Make it easier to use a different compiler

1 view
Skip to first unread message

Andy Dougherty

unread,
Sep 13, 2005, 1:05:05 PM9/13/05
to bugs-bi...@rt.perl.org
# New Ticket Created by Andy Dougherty
# Please include the string: [perl #37160]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37160 >


This patch makes it easier to compile parrot with a compiler other than
the one used to compile perl5. It re-arranges the order in which various
defaults are set so that the user may override them either with hints
files or interactively, via ask. (For example, it used to be impossible
to set optimize and cc_shared.)

I have tested this on Solaris, where my perl is built with Sun's cc, but I
wanted to try building parrot with gcc. I also tested it on Linux, but
since I only have one compiler there, it wasn't much of a test.

The one user-visible enhancement that is relevant even if you're not
changing compilers is that you can now change the optimization:

perl Configure.pl --optimize

uses your perl5 $Config{optimize} value. Using

perl Configure.pl --optimize=-flags

uses -flags instead.

This patch does create one new file: config/inter/shlibs.pl. If anyone
applies this, be sure to include the appropriate svn commands to add a new
file.

diff -N -r -u parrot-orig/Configure.pl parrot-andy/Configure.pl
--- parrot-orig/Configure.pl Mon Jun 6 09:31:09 2005
+++ parrot-andy/Configure.pl Tue Sep 13 11:55:43 2005
@@ -76,7 +76,11 @@

=item C<--optimize>

-Tell the compiler to do an optimization phase.
+Add perl5's $Config{optimize} to the compiler flags.
+
+=item C<--optimize=flags>
+
+Add C<flags> to the compiler flags.

=item C<--inline>

@@ -314,6 +318,7 @@
--debugging=0 Disable debugging, default = 1
--profile Turn on profiled compile (gcc only for now)
--optimize Optimized compile
+ --optimize=flags Add given optimizer flags
--inline Compiler supports inline

--cc=(compiler) Use the given compiler
diff -N -r -u parrot-orig/MANIFEST parrot-andy/MANIFEST
--- parrot-orig/MANIFEST Mon Sep 12 09:38:54 2005
+++ parrot-andy/MANIFEST Tue Sep 13 11:41:12 2005
@@ -308,6 +308,7 @@
config/inter/exp.pl []
config/inter/ops.pl []
config/inter/pmc.pl []
+config/inter/shlibs.pl []
config/inter/progs.pl []
config/inter/types.pl []
docs/ROADMAP [devel]doc
diff -N -r -u parrot-orig/config/init/data.pl parrot-andy/config/init/data.pl
--- parrot-orig/config/init/data.pl Mon Sep 5 12:57:49 2005
+++ parrot-andy/config/init/data.pl Mon Sep 12 14:58:10 2005
@@ -37,7 +37,10 @@

my(%c)=(
debugging => $debugging ? 1 : 0,
- optimize => $optimize ? $Config{optimize} : '',
+ # A plain --optimize means use perl5's $Config{optimize}. If an argument is
+ # given, however, use that instead. This logic really belongs in the optimize
+ # unit.
+ optimize => $optimize ? ($optimize eq "1" ? $Config{optimize} : $optimize) : '',
verbose => $verbose,

build_dir => $FindBin::Bin,
diff -N -r -u parrot-orig/config/init/hints/solaris.pl parrot-andy/config/init/hints/solaris.pl
--- parrot-orig/config/init/hints/solaris.pl Mon Jun 6 09:12:44 2005
+++ parrot-andy/config/init/hints/solaris.pl Tue Sep 13 12:00:04 2005
@@ -1,5 +1,6 @@
# Copyright: 2005 The Perl Foundation. All Rights Reserved.
# $Id: solaris.pl 7612 2005-03-08 15:43:44Z leo $
+use Parrot::Configure::Step qw(cc_gen cc_run);

my $libs = Configure::Data->get('libs');
if ( $libs !~ /-lpthread/ ) {
@@ -13,24 +14,51 @@
);

################################################################
-my $link = Configure::Data->get('link');
-# Going to assume Sun's compiler
-# In which case we need to link with the C++ compiler (CC) rather than the
-# C compiler (cc)
-$link =~ s/\bcc\b/CC/;
-Configure::Data->set('link', $link);
-
-# if it turns out we're using gcc, then we need to make sure we're linking
-# with g++, not gcc. We can't make this decision until the gccversion test
-# has been run.
+# If we're going to be using ICU (or any other C++-compiled library) we
+# need to use the c++ compiler as a linker. As soon as the user
+# selects a compiler, we will run the gccversion test. (If we were to
+# wait till it's normally run, the linker question would have already
+# been asked.)
my $solaris_link_cb = sub {
- my ($key, $gccversion) = @_;
- if ($gccversion) {
- Configure::Data->set('link', 'g++');
- Configure::Data->deltrigger("gccversion", "solaris_link");
- }
+ use Carp;
+ my ($key, $cc) = @_;
+ my %gnuc;
+ my $link = Configure::Data->get('link');
+ cc_gen("config/auto/gcc/test_c.in");
+ # Can't call cc_build since we haven't set all the flags yet.
+ # This should suffice for this test.
+ Parrot::Configure::Step::_run_command("$cc -o test test.c", 'test.cco', 'test.cco')
+ and confess "C compiler failed (see test.cco)";
+ %gnuc=eval cc_run() or die "Can't run the test program: $!";
+ if (defined $gnuc{__GNUC__}) {
+ $link = 'g++';
+ }
+ else {
+ $link =~ s/\bcc\b/CC/;
+ }
+ Configure::Data->set('link', $link);
+ Configure::Data->deltrigger("cc", "solaris_link");
+};
+Configure::Data->settrigger("cc", "solaris_link", $solaris_link_cb);
+
+################################################################
+# cc_shared: Flags to instruct the compiler to use position-independent
+# code for use in shared libraries. -KPIC for Sun's compiler, -fPIC for
+# gcc. We don't know which compiler we're using till after the
+# gccversion test.
+# XXX Should this go into the shlibs.pl Configure.pl unit instead?
+my $solaris_cc_shared_cb = sub {
+ my ($key, $gccversion) = @_;
+ if ($gccversion) {
+ Configure::Data->set('cc_shared', '-fPIC');
+ }
+ else {
+ Configure::Data->set('cc_shared', '-KPIC');
+ }
+ Configure::Data->deltrigger("gccversion", "solaris_cc_shared");
};
-Configure::Data->settrigger("gccversion", "solaris_link", $solaris_link_cb);
+Configure::Data->settrigger("gccversion", "solaris_cc_shared",
+ $solaris_cc_shared_cb);

################################################################
# Parrot usually aims for IEEE-754 compliance.
diff -N -r -u parrot-orig/config/init/optimize.pl parrot-andy/config/init/optimize.pl
--- parrot-orig/config/init/optimize.pl Mon Jun 6 09:12:53 2005
+++ parrot-andy/config/init/optimize.pl Tue Sep 13 12:51:05 2005
@@ -1,4 +1,4 @@
-# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
+# Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
# $Id: optimize.pl 7613 2005-03-08 22:52:10Z bernhard $

=head1 NAME
@@ -9,6 +9,7 @@

Enables optimization by adding the appropriate flags for the local
platform to the C<CCFLAGS>.
+Should this be part of config/inter/progs.pl ? XXX

=cut

@@ -20,9 +21,10 @@

$description="Enabling optimization...";

-@args=qw(verbose);
+@args=qw(verbose optimize);

sub runstep {
+ my ($verbose, $optimize) = @_;
if (Configure::Data->get('optimize')) {
my($ccflags, $optimize) =
Configure::Data->get(qw(ccflags optimize));
@@ -33,7 +35,7 @@
);
}
else {
- print "(none requested) " if $_[0];
+ print "(none requested) " if $verbose;
}
}

diff -N -r -u parrot-orig/config/inter/progs.pl parrot-andy/config/inter/progs.pl
--- parrot-orig/config/inter/progs.pl Mon Jun 6 09:12:33 2005
+++ parrot-andy/config/inter/progs.pl Tue Sep 13 12:51:51 2005
@@ -1,4 +1,4 @@
-# Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
+# Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
# $Id: progs.pl 7613 2005-03-08 22:52:10Z bernhard $

=head1 NAME
@@ -29,20 +29,9 @@
@args{@args}=@_;

my($cc, $cxx, $link, $ld, $ccflags, $ccwarn, $linkflags, $ldflags, $libs, $lex,
- $yacc) =
- Configure::Data->get(qw(cc cxx link ld ccflags ccwarn linkflags ldflags
- libs lex yacc));
- $ccflags =~ s/-D((PERL|HAVE)_\w+\s*|USE_PERLIO)//g;
- $ccflags =~ s/-fno-strict-aliasing//g;
- $ccflags =~ s/-fnative-struct//g;
- $linkflags =~ s/-libpath:\S+//g;
- $ldflags =~ s/-libpath:\S+//g;
- my $debug='n';
-
- $libs=join ' ',
- grep { $^O=~/VMS|MSWin/ || !/^-l(c|gdbm(_compat)?|dbm|ndbm|db)$/ }
- split(' ', $libs);
+ $yacc);

+ # Find a working version of a program:
# Try each alternative, until one works.
# If none work, then set to null command.
# XXX need config support for a null command.
@@ -54,20 +43,6 @@
}
return $null;
};
- if ($args{'maintainer'}) {
- $lex = &$first_working($lex, 'flex', 'lex' );
- $yacc = &$first_working($yacc, 'bison -v -y', 'yacc', 'byacc');
- }
- else {
- $lex = $yacc = $null;
- }
-
- for my $var(qw(cc cxx link ld ccflags linkflags ldflags libs ccwarn lex yacc)) {
- #Symrefs to lexicals are a no-no, so we have to use eval STRING. %MY, anyone?
- eval qq{ \$$var=integrate(\$$var, \$args{$var}) if defined \$args{$var} };
- }
-
- $debug='y' if $args{debugging};

if($args{ask}) {
print <<'END';
@@ -80,20 +55,74 @@
configuration.

END
+ }

- $cc=prompt("What C compiler do you want to use?", $cc);
- $link=prompt("How about your linker?", $link);
- $ld=prompt("What program do you want to use to build shared libraries?",
- $ld);
- $ccflags=prompt("What flags should your C compiler receive?", $ccflags);
- $linkflags=prompt("And your linker?", $linkflags);
- $ldflags=prompt("And your $ld for building shared libraries?", $ldflags);
- $libs=prompt("What libraries should your C compiler use?", $libs);
- $cxx=prompt("What C++ compiler do you want to use?", $cxx);
- $debug=prompt("Do you want a debugging build of Parrot?", $debug);
- $lex=prompt("Do you have a lexical analyzer generator, like flex or lex?",$lex);
- $yacc=prompt("Do you have a parser generator, like bison or yacc?",$yacc);
- }
+ # Set each variable individually so that hints files can use them as
+ # triggers to help pick the correct defaults for later answers.
+
+ $cc = integrate(Configure::Data->get('cc'), $args{cc});
+ $cc = prompt("What C compiler do you want to use?", $cc) if $args{ask};
+ Configure::Data->set(cc => $cc);
+
+ $link = integrate(Configure::Data->get('link'), $args{link});
+ $link = prompt("How about your linker?", $link) if $args{ask};
+ Configure::Data->set(link => $link);
+
+ $ld = integrate(Configure::Data->get('ld'), $args{ld});
+ $ld = prompt("What program do you want to use to build shared libraries?", $ld) if $args{ask};
+ Configure::Data->set(ld => $ld);
+
+ $ccflags = Configure::Data->get('ccflags');
+ # Remove some perl5-isms.
+ $ccflags =~ s/-D((PERL|HAVE)_\w+\s*|USE_PERLIO)//g;
+ $ccflags =~ s/-fno-strict-aliasing//g;
+ $ccflags =~ s/-fnative-struct//g;
+ $ccflags = integrate($ccflags, $args{ccflags});
+ $ccflags = prompt("What flags should your C compiler receive?", $ccflags) if $args{ask};
+ Configure::Data->set(ccflags => $ccflags);
+
+ $linkflags = Configure::Data->get('linkflags');
+ $linkflags =~ s/-libpath:\S+//g; # XXX No idea why.
+ $linkflags = integrate($linkflags, $args{linkflags});
+ $linkflags = prompt("And your linker?", $linkflags) if $args{ask};
+ Configure::Data->set(linkflags => $linkflags);
+
+ $ldflags = Configure::Data->get('ldflags');
+ $ldflags =~ s/-libpath:\S+//g; # XXX No idea why.
+ $ldflags = integrate($ldflags, $args{ldflags});
+ $ldflags = prompt("And your $ld for building shared libraries?", $ldflags) if $args{ask};
+ Configure::Data->set(ldflags => $ldflags);
+
+ $libs = Configure::Data->get('libs');
+ $libs=join ' ',
+ grep { $^O=~/VMS|MSWin/ || !/^-l(c|gdbm(_compat)?|dbm|ndbm|db)$/ }
+ split(' ', $libs);
+ $libs = integrate($libs, $args{libs});
+ $libs = prompt("What libraries should your C compiler use?", $libs) if $args{ask};
+ Configure::Data->set(libs => $libs);
+
+ $cxx = integrate(Configure::Data->get('cxx'), $args{cxx});
+ $cxx = prompt("What C++ compiler do you want to use?", $cxx) if $args{ask};
+ Configure::Data->set(cxx => $cxx);
+
+ my $debug='n';
+ $debug='y' if $args{debugging};
+ $debug = prompt("Do you want a debugging build of Parrot?", $debug) if $args{ask};
+
+ if ($args{'maintainer'}) {
+ $lex = integrate(Configure::Data->get('lex'), $args{lex});
+ $lex = &$first_working($lex, 'flex', 'lex');
+ $yacc = integrate(Configure::Data->get('yacc'), $args{yacc});
+ $yacc = &$first_working($yacc, 'bison -v -y', 'yacc', 'byacc');
+ }
+ else {
+ $lex = $yacc = $null;
+ }
+ $lex = prompt("Do you have a lexical analyzer generator, like flex or lex?",$lex) if $args{ask};
+ Configure::Data->set(lex => $lex);
+
+ $yacc = prompt("Do you have a parser generator, like bison or yacc?",$yacc) if $args{ask};
+ Configure::Data->set(yacc => $yacc);

if(!$debug || $debug =~ /n/i) {
Configure::Data->set(
@@ -103,19 +132,9 @@
);
}

- Configure::Data->set(
- cc => $cc,
- cxx => $cxx,
- link => $link,
- ld => $ld,
- ccflags => $ccflags,
- linkflags => $linkflags,
- ldflags => $ldflags,
- libs => $libs,
- ccwarn => $ccwarn,
- lex => $lex,
- yacc => $yacc,
- );
+ # This one isn't prompted for above. I don't know why.
+ $ccwarn = integrate(Configure::Data->get('ccwarn'), $args{ccwarn});
+ Configure::Data->set(ccwarn => $ccwarn);
}

1;
diff -N -r -u parrot-orig/config/inter/shlibs.pl parrot-andy/config/inter/shlibs.pl
--- parrot-orig/config/inter/shlibs.pl Wed Dec 31 19:00:00 1969
+++ parrot-andy/config/inter/shlibs.pl Tue Sep 13 12:51:58 2005
@@ -0,0 +1,39 @@
+# Copyright: 2005 The Perl Foundation. All Rights Reserved.
+# $Id: cc_shared.pl $
+
+=head1 NAME
+
+config/inter/shlibs.pl - Flags for shared libraries.
+
+=head1 DESCRIPTION
+
+Asks the user which flags are needed for compiling position-independent
+code for use in shared libraries. Eventually, other
+shared-library-related prompts may end up here.
+
+This is a separate unit from config/inter/progs.pl because the answers
+depend on which compiler is in use. Thus it should come after the
+gccversion test.
+
+=cut
+
+package Configure::Step;
+
+use strict;
+use vars qw($description @args);
+use Parrot::Configure::Step ':inter';
+
+$description = 'Determining flags for building shared libraries...';
+
+@args = qw(ask verbose cc_shared);
+
+sub runstep {
+ my ($ask, $verbose, $cc_shared) = @_;
+ $cc_shared = integrate(Configure::Data->get('cc_shared'), $cc_shared);
+ $cc_shared=prompt(
+ "\nWhat flags instruct your compiler to compile code suitable for use in a shared library?",
+ $cc_shared) if $ask;
+ Configure::Data->set(cc_shared => $cc_shared);
+ $Configure::Step::result = $cc_shared;
+}
+1;
diff -N -r -u parrot-orig/lib/Parrot/Configure/RunSteps.pm parrot-andy/lib/Parrot/Configure/RunSteps.pm
--- parrot-orig/lib/Parrot/Configure/RunSteps.pm Mon Jun 6 09:05:07 2005
+++ parrot-andy/lib/Parrot/Configure/RunSteps.pm Tue Sep 13 11:25:33 2005
@@ -33,6 +33,7 @@
inter/progs.pl
auto/gcc.pl
init/optimize.pl
+ inter/shlibs.pl
inter/charset.pl
inter/encoding.pl
inter/types.pl
diff -N -r -u parrot-orig/lib/Parrot/Configure/Step.pm parrot-andy/lib/Parrot/Configure/Step.pm
--- parrot-orig/lib/Parrot/Configure/Step.pm Mon Sep 5 12:57:12 2005
+++ parrot-andy/lib/Parrot/Configure/Step.pm Mon Sep 12 12:29:09 2005
@@ -49,7 +49,8 @@

=item C<integrate($orig, $new)>

-Integrates C<$new> into C<$orig>.
+Integrates C<$new> into C<$orig>. Returns C<$orig> if C<$new>
+is undefined.

=cut

@@ -57,7 +58,11 @@
my($orig, $new) = @_;

unless(defined $new) {
- warn "String to be integrated in to '$orig' undefined";
+ # Rather than sprinkling "if defined(...)", everywhere,
+ # config/inter/progs.pl just passes in potentially undefined
+ # strings. Just pass back the original in that case. Don't
+ # bother warning. --AD, 12 Sep 2005
+ # warn "String to be integrated in to '$orig' undefined";
return $orig;
}

--
Andy Dougherty doug...@lafayette.edu

Bernhard Schmalhofer via RT

unread,
Sep 14, 2005, 2:33:09 PM9/14/05
to perl6-i...@perl.org
> [doughera - Di 13. Sep 2005, 10:05:04]:

>
> This patch makes it easier to compile parrot with a compiler other
> than
> the one used to compile perl5. It re-arranges the order in which
> various
> defaults are set so that the user may override them either with hints
> files or interactively, via ask. (For example, it used to be
> impossible
> to set optimize and cc_shared.)

I have submittes this patch. I have only tried it under Linux, Andy has
run it under Solaris and Linux.
Please holler, when there are problems.

CU, Bernhard

0 new messages