Next: GPRconfig variable substitution, Previous: Compiler description, Up: The GPRconfig knowledge base [Contents][Index]
A number of the XML nodes described above can contain one or more children,
and specify how to query a value from an executable. Here is the list of
valid contents for these nodes. The <directory>
and <external>
children can be repeated multiple times, and the <filter>
and
<must_match>
nodes will be applied to each of these. The final
value of the external value is the concatenation of the computation for each
of the <directory>
and <external>
nodes.
A simple string given in the node indicates a constant. For instance, the list of supported languages might be defined as:
<compiler_description> <name>GNAT</name> <executable>gnatmake</executable> <languages>Ada</languages> </compiler_description>
for the GNAT compiler, since this is an Ada-only compiler.
Variables can be referenced in simple strings.
<getenv name="variable" />
If the contents of the node is a <getenv>
child, the value of
the environment variable variable
is returned. If the variable is
not defined, this is an error and the compiler is ignored.
<compiler_description> <name>GCC-WRS</name> <executable prefix="1">cc(arm|pentium)</executable> <version> <getenv name="WIND_BASE" /> </version> </compile_description>
<external>command</external>
If the contents of the node is an <external>
child, this indicates
that a command should be run on the system.
When the command is run, the current directory (i.e., the one that contains
the executable found through the <executable>
node), is placed first
on the PATH
. The output of the command is returned and may be later
filtered. The command is not executed through a shell; therefore you cannot
use output redirection, pipes, or other advanced features.
For instance, extracting the target processor from gcc
can be done
with:
<version> <external>gcc -dumpmachine</external> </version>
Since the PATH
has been modified, we know that the gcc
command
that is executed is the one from the same directory as the <external>
node.
Variables are substituted in command.
<grep regexp="regexp" group="0" />
This node must come after the previously described ones. It is used to further filter the output. The previous output is matched against the regular expression regexp and the parenthesis group specified by group is returned. By default, group is 0, which indicates the whole output of the command.
For instance, extracting the version number from gcc
can be done
with:
<version> <external>gcc -v</external> <grep regexp="^gcc version (\S+)" group="1" /> </version>
<directory group="0">regexp</directory>
If the contents of the node is a <directory
> child, this
indicates that GPRconfig should find all the files matching the
regular expression. Regexp is a path relative to the directory that contains
the <executable>
file, and should use unix directory separators
(ie ’/’), since the actual directory will be converted into this format
before the match, for system independence of the knowledge base.
The group attribute indicates which parenthesis group should be returned. It defaults to 0 which indicates the whole matched path. If this attribute is a string rather than an integer, then it is the value returned.
regexp can be any valid regular expression. This will only match a directory or file name, not a subdirectory. Remember to quote special characters, including “.”, if you do not mean to use a regexp.
For instance, finding the list of supported runtimes for the GNAT compiler is done with:
<runtimes> <directory group="1"> \.\./lib/gcc/${TARGET}/.*/rts-(.*)/adainclude </directory> <directory group="default"> \.\./lib/gcc/${TARGET}/.*/adainclude </directory> </runtimes>
Note the second node, which matches the default run-time, and displays it as such.
<filter>value1,value2,...</filter>
This node must come after one the previously described ones. It is used to further filter the output. The previous output is split into words (it is considered as a comma-separated or space-separated list of words), and only those words in ‘value1’, ‘value2’,… are kept.
For instance, the gcc
compiler will return a variety of supported
languages, including “ada”. If we do not want to use it as an Ada
compiler we can specify:
<languages> <external regexp="languages=(\S+)" group="1">gcc -v</external> <filter>c,c++,fortran</filter> </languages>
<must_match>regexp</must_match>
If this node is present, then the filtered output is compared with the specified regular expression. If no match is found, then the executable is not stored in the list of known compilers.
For instance, if you want to have a <compiler_description>
tag
specific to an older version of GCC, you could write:
<version> <external regexp="gcc version (\S+)" group="1">gcc -v </external> <must_match>2.8.1</must_match> </version>
Other versions of gcc will not match this <compiler_description>
node.