Simon Cozens:
# One of the items on the Parrot TODO is to build a Configure
# system. I don't want to spark up the old metaconfig-versus-autoconf
# debate again, so I'll clarify what I mean.
...
# You'll notice that the Parrot build process currently depends on the
# existence of Perl 5 to build certain header files and preprocess the
# opcode table. So if we know we've got Perl 5 hanging around, we know
# we've already got a config file which tells us things like how big IVs
# are, what header files we have around, and so on. Furthermore, we
# can write a Perl program which uses Config.pm to give us this
# information in a hash, and hence we can use that to produce a
# config.h
# specific to a given machine.
#
# So I'd like to see a patch which consists of a program to
# automatically generate Parrot's config.h from Perl's Config.pm. You
# could be really clever, and also have it conditionally include some
# of the header files mentioned in parrot.h depending on whether the
# i_... values in Config.pm say we have them. (You may need to move the
# "#include"s of the system header files from parrot.h to config.h)
# No prizes will be awarded for using Perl's config.h, or C preprocessor
# abuse. :)

I'm starting to do some hacking on this.  (Hey, I can't sleep... :^) )
Since Perl 5 already has this stuff, it seems like it should be pretty
easy.  (Famous last words?)  The $64,000 question is, what do I have to
copy over?  A simple "autogenerate what's already in Parrot's config.h"
is easy--I've already written a prototype (pasted after my sig)--but
seems like it's too easy considering what you're talking about.  What
else does it need to do?

The prototype below properly defines IV and NV (most of the time) based
on Perl 5's IV and NV.  It also sets up HAS_HEADER_FOO for each of the
i_ symbols in Config.pm.  Let me know if I should change the symbol I
define.  (If the comment line with my name in it seems improper, feel
free to remove it.)

I'm on Win32, so I don't have the tools to make a diff (I'm trying to
get PPT working) so you'll have to turn it into a patch yourself.
Sorry.

--Brent Dax
[EMAIL PROTECTED]

"...and if the answers are inadequate, the pumpqueen will be overthrown
in a bloody coup by programmers flinging dead Java programs over the
walls with a trebuchet."

~~~~~~~~~~~

#!/usr/bin/perl -w
#we want -w on

#Configure.pl, written by Brent Dax

use strict;
use Config;

print <<"END";
Parrot Configure
Copyright (C) 2001 Yet Another Society

Since you're running this script, you obviously have
Perl 5--I'll be pulling some defaults from its configuration.

Rules are the same as Perl 5's Configure--defaults are in
square brackets, and you can hit enter to accept them.
END

#Some versions don't seem to have ivtype or nvtype--provide
#defaults for them.
#XXX Figure out better defaults
my($iv, $nv)=(($Config{ivtype}||'long'), ($Config{nvtype}||'long
double'));
my $input;

print "How big would you like integers to be? [$iv] ";
chomp($input=<STDIN>);
$iv=$input||$iv;

print "How about your floats? [$nv] ";
chomp($input=<STDIN>);
$nv=$input||$nv;

my($config_h)=<<"END_OF_CONFIG_H";
/* config.h
 *
 * Platform-specific config file
 *
 * DO NOT EDIT THIS FILE!
 * This file was autogenerated by Configure.pl--please
 * rerun that!  Changes to this file may be lost!
 *
 */

#if !defined(PARROT_CONFIG_H_GUARD)
#define PARROT_CONFIG_H_GUARD
typedef $iv IV
typedef $nv NV;

typedef struct _vtable VTABLE;
typedef void DPOINTER;
typedef void SYNC;

//typedef IV *(*opcode_funcs)(void *, void *) OPFUNC;

#define FRAMES_PER_CHUNK 16

#define FRAMES_PER_PMC_REG_CHUNK FRAMES_PER_CHUNK
#define FRAMES_PER_NUM_REG_CHUNK FRAMES_PER_CHUNK
#define FRAMES_PER_INT_REG_CHUNK FRAMES_PER_CHUNK
#define FRAMES_PER_STR_REG_CHUNK FRAMES_PER_CHUNK

#define MASK_CHUNK_LOW_BITS 0xfffff000

END_OF_CONFIG_H


print <<"END";
Okay.  Now I'm gonna probe Perl 5's configuration to see
what headers you have around.  This could take a bit on slow
machines...
END


#set up HAS_HEADER_
foreach(grep {/^i_/} keys %Config) {
        $config_h.=defineifdef((/^i_(.*)$/));
}


$config_h.="\n#endif";

open(CONFIG_H, ">config.h");

print CONFIG_H $config_h;


print <<"END";

Okay, we're done!
You can now use `make test_prog' (or your platform's equivalent to
`make')
to build your Parrot.  Happy Hacking,
        The Parrot Team
END


sub defineifdef {
        my $thing=shift;

        if($Config{"i_$thing"}) {
                return "#define HAS_HEADER_\U$thing\E\n";
        }
        else {
                return "#undef HAS_HEADER_\U$thing\E\n"; #XXX do we want this?
        }
}

Reply via email to