# Copyright (C) 2004-2007, The Perl Foundation. # $Id: configuration.pod 23427 2007-12-04 00:55:49Z jkeenan $ =pod =head1 NAME docs/configuration.pod - Parrot Configuration System =head1 DESCRIPTION Parrot configuration is broken up into I. Each step contains several related I, I, or I. Steps should be mostly of a single type, though some overlap is allowed (for example, allowing a probe to ask the user what to do in an exceptional situation). The directory F contains subdirectories for each type of step. Each step should consist of I F<.pm> file and any number of supporting F<.c>, F<.in>, etc. files. Any supporting files should be in a folder whose name is the same as the basename of the step's F<.pm> file; for example, if F uses F, F should be in a directory called F; the full path might be F. Generally, when adding a new component to the configuration process you should add a new step unless that component I belongs in a current step. For example, if you added a new user-configurable type called C, you would add the code used to determine its size in F. However, if you were determining what dynaloading capabilities are available, you would create a new step. =head2 Initialization Steps I are run before any other steps. They do tasks such as preparing the configuration system's data structures and checking the F. New initialization steps will only be added when the configuration system is getting significant new capabilities. They're kept in the directory F. =head2 Prompts Prompts ask the user for some information. These should be used sparingly. A step containing prompts is an I. Interactive steps should be in the F folder. Interactive steps often include simple probes to determine good guesses of what the user will answer. See L for more information. Note that, by default, these prompts are turned off. To enable them run F with the C<--ask> option. =head2 Probes Probes are automated tests of some feature of the computer. These should be used wherever a value will not need to be modified often by the user. A step containing probes is an I. Automatic steps should be in the F folder. =head2 Generations Generations create files needed after configuration has completed, such as Makefiles and configuration headers. A step containing generations is a I. Generation steps should be in the F folder. Templates for files to be generated usually have the extension F<.in>. There are variable substitutes and funny macros like 'CONDITIONED_LINE' and 'INVERSE_CONDITIONED_LINE'. =head2 Prompt or Probe? It can sometimes be hard to decide whether a given step should be an automatic or an interactive step. The guiding question is I, or conversely, I A step figuring out what the compiler's command is would probably be an interactive step; conversely, a step figuring out if that command is connected to a specific compiler (like F) would be an automatic step. =head2 Configuring Configuration The configuration system gets its own configuration data from, and is invoked via, the F script. The system is invoked by instantiating a L object, registering one or more steps with that object, and then calling C. =head2 Adding New Steps New steps should be added in one of the four folders mentioned above. All steps are really classes; each exists in a unique namespace. The namespace used depends on the step's relative path in the source tree sans the F prefix. For example, the step F uses the C namespace. Each step inherits its constructor and some other methods from F. Each step needs to define only two methods: C<_init()> and C. The C<_init()> method should follow the following example, defining three elements within an internal hash: sub _init { my $self = shift; my %data; $data{description} = q{This is the step description}; $data{args} = [ qw( optional arguments ) ]; $data{result} = q{}; return \%data; } =over 4 =item C Of these three elements, C is the most important as it is used extensively within C. Returns a short descriptive message that should be printed before the step executes. Usually, interactive steps have long, friendly descriptions and other steps have terse descriptions ending in "...". Some example descriptions: =over 4 =item F Determining if your compiler supports computed goto... =item F Generating config.h... =back Note that on non-interactive steps, the text I will be printed after the description when the step finishes executing; for example, the user will see: Determining if your compiler supports computed goto...done. =item C Returns a list of the names of any command-line arguments the step cares about. Command-line arguments are standardized in F; this will be described L in more detail. I Note that this method is currently unused but will be used in the futher to register acceptable CLI parameters. New steps should continue to define this method. =item C The C is initialized to an empty string mainly to quiet 'uninitialized variable' warnings. Most configuration steps override the C value inside their C method. =item L<_run_this_step> This method is called to actually execute the step. The return value should be C<1> if the step accomplishes what it is intended to do. Otherwise, the step should simply C, I, return an undefined value. I In the near future there will be a means of passing additional parameters. =back The configuration system won't execute your step by default unless it's specifically told to. To do this, edit F. Steps are run in the order in which that are registered with the L object. Various utility functions for configuration steps are provided by the L module. A template for a new step might look like this: package auto::newstep; use strict; use warnings; use vars qw($description $result @args); use base qw(Parrot::Configure::Step::Base); use Parrot::Configure::Step; sub _init { my $self = shift; my %data; $data{description} = q{This is the step description}; $data{args} = [ qw( optional arguments ) ]; $data{result} = q{}; return \%data; } sub runstep { my ($self, $conf) = @_ ... if ($success) { $self->set_result('yes'); return 1; } else { $self->set_result('no'); return; } } The step's C method should return C<1> upon success and do a bare return on failure (thereby returning an undefined value). =head2 Command-line Arguments Command-line arguments look like C; the equals sign separates the name and the value. If the value is omitted, it's assumed to be 1. The options C<--help> and C<--version> are built in to Configure; any others are defined by steps. Command-line arguments are now processed by C, a subroutine exported by L. If you add a new option, don't forget to add it to this documentation and to two locations in F: =over 4 =item * the list of valid command-line arguments in C; and =item * the description of command-line arguments found in C. =back Arguments passed to F are held in a L object stored inside the L object. The options data object may be accessed via the L method. Steps use the C method to list any options they're interested in. They should be listed without the dashes. =head2 Building Up Configuration Data The second step is F, which sets up some defaults in a L object contained by the main L object. It can be accessed via the Lmethod. You get and set configuration system's data by interacting with this object. Some of its methods are summarized below. =over 4 =item C Returns the values for the given keys. =item C Sets the given keys to the given values. =item C Sets the given keys to the given values or appends values delimited by I to existing keys. =item C Returns a list of all keys. =item C Returns a string that can be Ced by Perl to create a hash representing the configuration system's data. See the L documentation for further details. =back =head2 Special Configuration Items Some configuration items, by convention, have a special meaning (mainly prefixes) and are handled with some magic internally. =over 4 =item C include files defines or undefs PARROT_HAS_HEADER_XXX in F =item C features defines PARROT_HAS_XXX in F =item C temporary settings These settings are deleted before F is written. These entries are only used e.g. for Makefile creation. =back =head2 Accessing Configuration Information via Perl 5 Variables Parrot configuration is currently jump-started by extracting considerable information from variables associated with the instance of Perl 5 which the user is using to run F. These variables are largely looked up in the C<%Config> found in the Perl 5 F, but may also be sought in Perl 5 special variables such as C<$^O>. All such lookups should be done in configuration step C and B in that step. Special accessors are available for working with such variables; see F and F. =head1 HISTORY The Parrot configuration system was created by Brent Dax and has been heavily mangled by Joshua Hoblitt. =head1 SEE ALSO L, L, L, L =cut