1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
|
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN">
<book id="BuildSystemManual" lang="en">
<bookinfo>
<title>ASE BuildSystem Manual</title>
<authorgroup>
<author>
<firstname>Matthew</firstname>
<othername>G.</othername>
<surname>Knepley</surname>
</author>
</authorgroup>
<date>July, 2005</date>
<releaseinfo>Release tag ???</releaseinfo>
</bookinfo>
<chapter id="Introduction">
<title>Introduction</title>
<para>The BuildSystem from ASE is intended to be a Python replacement for the GNU autotools. It actually encompasses
somewhat more, as it supports integrated version control and automatic code generation. However, the most useful
comparisons will come from <command>autoconf</command>, <command>make</command>, and <command>libtool</command>. The
system is not designed to be monolithic. Thus each component may be used independently, meaning logging, configuration,
and build are all separate modules which do not require each other. This allows a user to incremenetally adopt the most
useful portions of the package.</para>
</chapter>
<chapter id="Configure">
<title>Configure</title>
<sect1 id="Configure-Design-Sketch">
<title>Configure Design Sketch</title>
<para>The system is based upon an autonomous unit, objects of class <classname>config.base.Configure</classname>, which
are responsible for discovering configuration information for a particular package or purpose. The only interface which
must be supported is the <methodname>configure</methodname> method, as shown below. Support for lower-level operations
such as compiling and linking will be discussed in section ???.</para>
<classsynopsis language="python">
<ooclass>
<classname>Configure</classname>
</ooclass>
<methodsynopsis>
<void/><methodname>configure</methodname><methodparam><parameter>self</parameter></methodparam>
</methodsynopsis>
</classsynopsis>
<para>This collection of configure objects is managed by a <classname>config.base.Framework</classname> object. As we
will see in section ???, the framework manages all dependecies between modules and output of configure information. The
framework is itself a subclass of <classname>config.base.Configure</classname> for which the
<methodname>configure</methodname> method manages the entire configuration process. In order to associate a module with
the given framework, it also provides the <methodname>require</methodname> method, discussed in section ???. Thus, the
minimal framework interface is given by:</para>
<classsynopsis language="python">
<ooclass>
<classname>Framework</classname>
</ooclass>
<ooclass>
<classname>config.base.Configure</classname>
</ooclass>
<methodsynopsis>
<void/><methodname>require</methodname>
<methodparam><parameter>self</parameter></methodparam>
<methodparam><parameter>moduleName</parameter></methodparam>
<methodparam><parameter>depChild</parameter></methodparam>
<methodparam><parameter>keywordArgs</parameter><initializer>{}</initializer></methodparam>
</methodsynopsis>
<methodsynopsis>
<void/><methodname>configure</methodname><methodparam><parameter>self</parameter></methodparam>
</methodsynopsis>
</classsynopsis>
<para>This design allows user modules to be seamlessly integrated into the framework without changing the paradigm, or
even any of the original code. Modules can be specified on the command line, or left in special directories. Although it
is common to derive from <classname>config.base.Configure</classname>, the only necessity is that the user provide a
<methodname>configure</methodname> method for the framework to execute.</para>
<para>The framework does provide the traditional output mechanisms from <command>autoconf</command>, namely
<methodname>#define</methodname> statements and file substitutions, to which we add make variables and
rules. However, the preferred interaction mechanism is to use member variables directly from the configure objects. This
is illustrated in section ???</para>
</sect1>
<sect1 id="Running-configure">
<title>Running configure</title>
<para>The first step in running configure is to show the help:
<screen>
<prompt>bash$</prompt> <command>framework.py -help</command>
<computeroutput>
Python Configure Help
Comma separated lists should be given between [] (use \[ \] in tcsh/csh)
For example: --with-mpi-lib=\[/usr/local/lib/libmpich.a,/usr/local/lib/libpmpich.a\]
----------------------------------------------------------------------------------------
Script:
--help : Print this help message current: 1
--h : Print this help message current: 0
Framework:
--configModules : A list of Python modules with a Configure class current: []
--ignoreCompileOutput : Ignore compiler output current: 1
--ignoreLinkOutput : Ignore linker output current: 1
--ignoreWarnings : Ignore compiler and linker warnings current: 0
--doCleanup : Delete any configure generated files (turn off for debugging) current: 1
--with-alternatives : Provide a choice among alternative package installations current: 0
--with-executables-search-path : A list of directories used to search for executables current: []
--with-packages-search-path : A list of directories used to search for packages current: []
--with-batch : Machine uses a batch system to submit jobs current: 0
</computeroutput>
</screen>
The options shown will depend upon the modules loaded with <option>-configModules</option>. For instance, we will
normally load the compiler module, which reveals the host of optios controlling preprocessors, compilers, and linkers.
<screen>
<prompt>bash$</prompt> <command>framework.py -configModules=[config.compilers] -help</command>
<computeroutput>
Python Configure Help
Comma separated lists should be given between [] (use \[ \] in tcsh/csh)
For example: --with-mpi-lib=\[/usr/local/lib/libmpich.a,/usr/local/lib/libpmpich.a\]
----------------------------------------------------------------------------------------
Script:
--help : Print this help message current: 1
--h : Print this help message current: 0
Framework:
--configModules : A list of Python modules with a Configure class current: []
--ignoreCompileOutput : Ignore compiler output current: 1
--ignoreLinkOutput : Ignore linker output current: 1
--ignoreWarnings : Ignore compiler and linker warnings current: 0
--doCleanup : Delete any configure generated files (turn off for debugging) current: 1
--with-alternatives : Provide a choice among alternative package installations current: 0
--with-executables-search-path : A list of directories used to search for executables current: []
--with-packages-search-path : A list of directories used to search for packages current: []
--with-batch : Machine uses a batch system to submit jobs current: 0
Compilers:
--with-cpp=<prog> : Specify the C preprocessor
--with-cc=<prog> : Specify the C compiler
--with-cxx=<prog> : Specify the C++ compiler
--with-fc=<prog> : Specify the Fortran compiler
--with-64-bit-pointers=<bool> : Use 64 bit compilers and libraries current: 0
--CPP=<prog> : Specify the C preprocessor
--CPPFLAGS=<string> : Specify the C preprocessor options current:
--CXXPP=<prog> : Specify the C++ preprocessor
--CC=<prog> : Specify the C compiler
--CFLAGS=<string> : Specify the C compiler options current:
--CXX=<prog> : Specify the C++ compiler
--CXXFLAGS=<string> : Specify the C++ compiler options current:
--CXX_CXXFLAGS=<string> : Specify the C++ compiler-only options current:
--FC=<prog> : Specify the Fortran compiler
--FFLAGS=<string> : Specify the Fortran compiler options current:
--LD=<prog> : Specify the default linker
--CC_LD=<prog> : Specify the linker for C only
--CXX_LD=<prog> : Specify the linker for C++ only
--FC_LD=<prog> : Specify the linker for Fortran only
--LDFLAGS=<string> : Specify the linker options current:
--with-ar : Specify the archiver
-AR : Specify the archiver flags
-AR_FLAGS : Specify the archiver flags
--with-ranlib : Specify ranlib
--with-shared-libraries : Enable shared libraries current: 1
--with-shared-ld=<prog> : Specify the shared linker
--with-f90-header=<file> : Specify the C header for the F90 interface, e.g. f90_intel.h
--with-f90-source=<file> : Specify the C source for the F90 interface, e.g. f90_intel.c
</computeroutput>
</screen>
The syntax for list and dictionary option values is identical to Python syntax. However, in some shells (like
<command>csh</command>), brackets must be escaped, and braces will usually have to be enclosed in quotes.</para>
<para>The modules indicated with <option>-configModules</option> are located using <envar>PYTHONPATH</envar>. Since
specifying environment variables can be inconvenient and error prone, it is common to provide a driver which alters
<varname>sys.path</varname>, as is done for PETSc. In fact, the PETSc driver
<itemizedlist>
<listitem><para>Verifies <envar>PETSC_ARCH</envar></para></listitem>
<listitem><para>Checks for invalid Cygwin versions</para></listitem>
<listitem><para>Checks for RedHat 9, which has a threads bug</para></listitem>
<listitem><para>Augments <envar>PYTHONPATH</envar></para></listitem>
<listitem><para>Adds the default PETSc configure module</para></listitem>
<listitem><para>Persists the configuration in <filename>RDict.db</filename></para></listitem>
<listitem><para>Handles exceptions</para></listitem>
</itemizedlist>
</para>
</sect1>
<sect1 id="Adding-a-module">
<title>Adding a module</title>
<para>As we discussed in the introduction, all that is strictly necessary for a configure module, is to provide a class
named <classname>Configure</classname> with a method <methodname>configure</methodname> taking no arguments. However,
there are a variety of common operations, which will be illustrated in the sections below.</para>
<sect2 id="Using-other-modules">
<title>Using other modules</title>
<para>We will often want to use the methods or results of other configure modules in order to perform checks in our
own. The framework provides a mechanism for retrieving the object for any given configure module. As an example,
consider checking for the <methodname>ddot</methodname> function in the BLAS library. The relevant Python code would
be
<programlisting>
import config.base
class Configure(config.base.Configure):
def __init__(self, framework):
config.base.Configure.__init__(self, framework)
self.compilers = self.framework.require('config.compilers', self)
self.libraries = self.framework.require('config.libraries', self)
return
def configure(self):
return self.libraries.check('libblas.a', 'ddot', otherLibs = self.compilers.flibs,
fortranMangle = 1)
</programlisting>
The <methodname>require</methodname> call will return the configure object from the given module, creating it if
necessary. If the second argument is given, the framework will ensure that the returned configure object runs
<emphasis>before</emphasis> the passed configure object. Notice that we can use the returned object either to call
methods, like <methodname>check</methodname> from <classname>config.libraries</classname>, or use member variables, such
as the list of Fortran compatibility libraries <methodname>flibs</methodname> from
<classname>config.compilers</classname>.
</para>
<para>The underlying implementation in the framework uses a directed acyclic graph to indicate dependencies among
modules. The vertices of this graph, configure objects, are topologically sorted and then executed. Moreover, child
objects can be added to the framework without respecting the dependency structure, but this is discouraged.</para>
</sect2>
<sect2 id="Adding-a-test">
<title>Adding a test</title>
<para>A user could of course perform all tests in the object's <methodname>configure</methodname> method, but the base
class provides useful logging support for this purpose. Consider again the BLAS example, which will now become,
<programlisting>
def checkDot(self):
'''Verify that the ddot() function is contained in the BLAS library'''
return self.libraries.check('libblas.a', 'ddot', otherLibs = self.compilers.flibs,
fortranMangle = 1)
def configure(self):
self.executeTest(self.checkDot)
return
</programlisting>
Passing our test module to the framework,
<screen>
<prompt>docs$</prompt> <command>PYTHONPATH=`pwd` ../config/framework.py --configModules=[examples.blasTest]</command>
</screen>
we produce the following log output in <filename>configure.log</filename>. Notice that it not only records the method and module, but the method doc string,
all shell calls, and any output actions as well.</para>
<screen>
<computeroutput>
================================================================================
TEST checkDot from examples.blasTest(/PETSc3/sidl/BuildSystem/docs/examples/blasTest.py:10)
TESTING: checkDot from examples.blasTest(/PETSc3/sidl/BuildSystem/docs/examples/blasTest.py:10)
Verify that the ddot() function is contained in the BLAS library
Checking for functions ['ddot'] in library ['libblas.a'] ['-lfrtbegin', '-lg2c', '-lm',
'-L/usr/lib/gcc-lib/i486-linux/3.3.5', '-L/usr/lib/gcc-lib/i486-linux/3.3.5/../../..',
'-lm', '-lgcc_s']
sh: gcc -c -o conftest.o -fPIC conftest.c
Executing: gcc -c -o conftest.o -fPIC conftest.c
sh:
sh: gcc -o conftest -fPIC conftest.o -lblas -lfrtbegin -lg2c -lm
-L/usr/lib/gcc-lib/i486-linux/3.3.5 -L/usr/lib/gcc-lib/i486-linux/3.3.5/../../.. -lm -lgcc_s
Executing: gcc -o conftest -fPIC conftest.o -lblas -lfrtbegin -lg2c -lm
-L/usr/lib/gcc-lib/i486-linux/3.3.5 -L/usr/lib/gcc-lib/i486-linux/3.3.5/../../.. -lm -lgcc_s
sh:
Defined HAVE_LIBBLAS to 1 in config.libraries
</computeroutput>
</screen>
</sect2>
<sect2 id="Checking-for-headers">
<title>Checking for headers</title>
<para>Often, we would like to test for the presence of certain headers. This is done is a completely analogous way to
the library case, using instead the <classname>config.headers</classname> module. Below, we test for the presence of the
<command>curses</command> header.
<programlisting>
import config.base
class Configure(config.base.Configure):
def __init__(self, framework):
config.base.Configure.__init__(self, framework)
self.headers = self.framework.require('config.headers, self)
return
def checkCurses(self):
'Verify that we have the curses header'
return self.headers.check('curses.h')
def configure(self):
self.executeTest(self.checkCurses)
return
</programlisting>
Running this test
<screen>
<prompt>docs$</prompt> <command>PYTHONPATH=`pwd` ../config/framework.py --configModules=[examples.cursesTest]</command>
</screen>
produces the following log output.</para>
<screen>
<computeroutput>
================================================================================
TEST checkCurses from examples.cursesTest(/PETSc3/sidl/BuildSystem/docs/examples/cursesTest.py:9)
TESTING: checkCurses from examples.cursesTest(/PETSc3/sidl/BuildSystem/docs/examples/cursesTest.py:9)
Verify that we have the curses header
Checking for header: curses.h
sh: gcc -E conftest.c
Executing: gcc -E conftest.c
sh: # 1 "conftest.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "conftest.c"
# 1 "confdefs.h" 1
# 2 "conftest.c" 2
# 1 "conffix.h" 1
# 3 "conftest.c" 2
# 1 "/usr/include/curses.h" 1 3 4
# 58 "/usr/include/curses.h" 3 4
# 1 "/usr/include/ncurses_dll.h" 1 3 4
# 59 "/usr/include/curses.h" 2 3 4
# 99 "/usr/include/curses.h" 3 4
typedef unsigned long chtype;
# 1 "/usr/include/stdio.h" 1 3 4
# 28 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 295 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 296 "/usr/include/features.h" 2 3 4
# 318 "/usr/include/features.h" 3 4
#...
... W* win,int* y, int* x, _Bool to_screen);
extern _Bool mouse_trafo (int*, int*, _Bool);
extern int mcprint (char *, int);
extern int has_key (int);
extern void _tracef (const char *, ...) ;
extern void _tracedump (const char *, WINDOW *);
extern char * _traceattr (attr_t);
extern char * _traceattr2 (int, chtype);
extern char * _nc_tracebits (void);
extern char * _tracechar (int);
extern char * _tracechtype (chtype);
extern char * _tracechtype2 (int, chtype);
# 1203 "/usr/include/curses.h" 3 4
extern char * _tracemouse (const MEVENT *);
extern void trace (const unsigned int);
# 4 "conftest.c" 2
Defined HAVE_CURSES_H to 1 in config.headers
</computeroutput>
</screen>
<para>Alternatively, we could have specified that this header be included in the list of header files checked by default.</para>
<programlisting>
import config.base
class Configure(config.base.Configure):
def __init__(self, framework):
config.base.Configure.__init__(self, framework)
self.headers = self.framework.require('config.headers, self)
self.headers.headers.append('curses.h')
return
def checkCurses(self):
'Verify that we have the curses header'
return self.headers.haveHeader('curses.h')
def configure(self):
self.executeTest(self.checkCurses)
return
</programlisting>
<para>In addition, the base class does include lower level support for preprocessing files. The
<methodname>preprocess</methodname> method takes a code string as input and return a tuple of the
<command>(stdout,stderr,error code)</command> for the run. The <methodname>outputPreprocess</methodname> method returns
only the standard output, and <methodname>checkPreprocess</methodname> returns true if no error occurs.</para>
</sect2>
<sect2 id="Checking-for-libraries">
<title>Checking for libraries</title>
<para>We have already demonstrated a test for the existence of a function in a library. However the
<methodname>check</methodname> method is much more general. It allows the specification of multiple libraries and
multiple functions, as well as auxiliary libraries. For instance, to check for the <methodname>MPI_Init</methodname> and
<methodname>MPI_Comm_create</methodname> functions in MPICH when the Fortran bindings are active, we would use:
<programlisting>
self.libraries.check(['libmpich.so', 'libpmpich.so'], ['MPI_Init', 'MPI_Comm_create'],
otherLibs = self.compilers.flibs)
</programlisting>
As in the BLAS example, we can also turn on Fortran name mangling. The caller may also supply a function prototype and
calling sequence, which are necessary if the current language is C++.
</para>
<para>It is also necessary at some times to determine whether a given library is a shared object. This can be
accomplished using the <methodname>checkShared</methodname> method, as we demonstrate with the MPICH library in a call
taken from the MPI configure module in PETSc.
<programlisting>
self.libraries.checkShared('#include <mpi.h>\n', 'MPI_Init', 'MPI_Initialized',
'MPI_Finalize', checkLink = self.checkMPILink,
libraries = self.lib)
</programlisting>
The theory for the check is that a shared object will have only one copy of any global variable. Thus functions such as
<methodname>MPI_Initialized</methodname> will render consistent results across other libraries. The test begins by
creating two dynamic libraries, both of which link the given library. Then an executable is constructed which loads the
libraries in turn. The first library calls the initizlization functions, here <methodname>MPI_Init</methodname>, and the
second library calls the initialization check function, here <methodname>MPI_Initialized</methodname>. The check
function will return true if the given library is a shared object. This organization is shown in figure ???</para>
<para>
<inlinemediaobject>
<imageobject><imagedata fileref="sharedLibraryCheck" format="EPS"/></imageobject>
<imageobject><imagedata fileref="sharedLibraryCheck" format="JPG"/></imageobject>
<!-- <textobject><phrase>A diagram of the link structure for the shared library test</phrase></textobject> -->
</inlinemediaobject>
</para>
<para>The lower level interface to compiling and linking in the base class mirrors that for preprocessing. The
<methodname>outputCompile</methodname> and <methodname>checkCompile</methodname> methods function in the same way. The
code is now broken up into four distinct sections. There are includes, the body of <methodname>main</methodname>, and a
possible replacement for the beginning and end of the <methodname>main</methodname> declaration. The linking methods,
<methodname>outputLink</methodname> and <methodname>checkLink</methodname>, are exactly analogous.</para>
<para>There are also some convenience methods provided to handle compiler and linker flags. The
<methodname>checkCompilerFlag</methodname> and <methodname>checkLinkerFlag</methodname> try to determine whether a given
flag is accepted by the processor, while <methodname>addCompilerFlag</methodname> and
<methodname>addLinkerFlag</methodname> will do that check and add any valid flag to the list of default flags.</para>
</sect2>
<sect2 id="Checking-for-executables">
<title>Checking for executables</title>
<para>The <methodname>getExecutable</methodname> method is used to locate executable files. For instance, this code
would allow us to locate the <command>valgrind</command> binary.
<programlisting>
self.getExecutable('valgrind')
</programlisting>
If the program is found, a member variable of the same name will be set in the object to the program name, and a make
macro defined to it as well. We can opt for these to contain the full path by using the <option>getFullPath</option>
argument. In addition, we can change the name of the member variable and macro using the <option>resultName</option>
argument.
</para>
<para>We also have control over the search path used. If we give no arguments, the default path from the environment is
used. This can be overridden with a new path using the <option>path</option> argument, either as a Python list or a
colon separated string. Furthermore, the default path can be added to this custom path using the
<option>useDefaultPath</option> argument. For instance, this call
<programlisting>
self.getExecutable('valgrind', path=['/opt/valgrind-1.0'], getFullPath=1,
useDefaultPath=1, resultName='grinder')
</programlisting>
will check for <command>valgrind</command> first in <filename>/opt/valgrind-1.0</filename> and then along the default
path. If found in the first location, it will set <varname>self.grinder</varname> to
<filename>/opt/valgrind-1.0/valgrind</filename> as well as define <envar>GRINDER</envar> to the same value in makefiles.
</para>
<para>As in the cases of preprocessing, compiling, and linking, the lower level operations are also exposed. The
<methodname>checkRun</methodname> method takes in a code string and returns true if the executable runs without
error. The <methodname>outputRun</methodname> method returns the output and status code. Both methods us the safe
execution routine <methodname>config.base.Configure.executeShellCommand</methodname> which accepts a timeout. Moreover,
there commands can run in the special batch mode described in section ???.</para>
</sect2>
<sect2 id="Output-results">
<title>Output results</title>
<para>The BuildSystem configure includes the traditional output methods employed by <command>autoconf</command> to
enable communication with <command>make</command>. Individual configure modules use the
<methodname>addDefine</methodname> method to add C <methodname>#define</methodname> statements to a configuration header
and the <methodname>addSubstitution</methodname> to setup substitution rules for specified files. For instance, to
activate the parmetis package, we might provide
<programlisting>
self.addDefine('HAVE_PARMETIS', 1)
</programlisting>
and then for the make process
<programlisting>
self.addSubstitution('PARMETIS_INCLUDE', ' '.join([self.libraries.getIncludeArgument(i)
for i in self.include]))
self.addSubstitution('PARMETIS_LIB, ' '.join([self.libraries.getLibArgument(l)
for l in self.lib]))
</programlisting>
</para>
<para>The actual output of this data is controlled by the framework. The user specifies the header file using the
<varname>header</varname> field of the framework, and then the file is created automatically during the configure
process, but can be output at any time using the <methodname>outputHeader</methodname> method. Furthermore, the
<methodname>addSubstitutionFile</methodname> method can be used to tag a file for substitution, and also specify a
different file for the result of the substitution.</para>
<para>In the <command>autoconf</command> approach, separating the defines and substitutions for different packages
becomes troublesome, and in some cases impossible to maintain. To help with this, we have introduced
<emphasis>prefixes</emphasis> for the defines and substitutions. The are strings, unique to each module, which are
prepended with an underscore to each identifier defined or substituted. These are set on a per object basis using the
<varname>headerPrefix</varname> and <varname>substPrefix</varname> members. For instance, in our
parmetis example, if we instead used the code
<programlisting>
self.headerPrefix = 'MATT'
self.addDefine('HAVE_PARMETIS', 1)
</programlisting>
in our configuration header we would see
<programlisting>
#ifndef MATT_HAVE_PARMETIS
#define MATT_HAVE_PARMETIS 1
#endif
</programlisting>
Note that the value of the prefix is used at output time, not at the time that the define or substitution is set.
</para>
<para>Another extension of the old-style output mechanisms adds more C structure to the interface. The
<methodname>addTypedef</methodname> method allows a typedef from one typename to another, which in
<command>autoconf</command> is handled by a define. Likewise <methodname>addPrototype</methodname> can add a missing
function prototype to a header. Since these are C specific structures, they are output into a separate configuration
header file, which is controlled by the <varname>cHeader</varname> member variable.</para>
<para>Extending in a different direction, we allow makefile structures to be specified directly rather than through
substitutions. Using <methodname>addMakeMacro</methodname>, we can add variable definitions to the configuration
makefile, whereas <methodname>addMakeRule</methodname> allows the user to specify a make target, complete with
dependencies and action. As an example, we will replace our parmetis example from above with the following code
<programlisting>
self.addMakeMacro('PARMETIS_INCLUDE', ' '.join([self.libraries.getIncludeArgument(i)
for i in self.include]))
self.addMakeMacro('PARMETIS_LIB, ' '.join([self.libraries.getLibArgument(l)
for l in self.lib]))
self.addMakeRule('.c.o', '', ['${CC} -c -o $@ -I${PARMETIS_INCLUDE} $<'])
self.addMakeRule('myApp', '${.c=.o:SOURCE}', ['${CC} -o $@ $< ${PARMETIS_LIB}'])
</programlisting>
which will produce
<programlisting>
PARMETIS_INCLUDE = -I/home/knepley/petsc-dev/externalpackages/parmetis/build/Darwin-x86_64/include
PARMETIS_LIB = -L/home/knepley/petsc-dev/externalpackages/parmetis/build/Darwin-x86_64/lib -lparmetis -lmetis
</programlisting>
in the file specified by the <varname>makeMacroHeader</varname> member variable, and
<programlisting>
myApp: ${.c=.o:SOURCE}
${CC} -i $@ $< ${PARMETIS_LIB}
</programlisting>
in the file specified by the <varname>makeRuleHeader</varname> member variable.</para>
<para>The above output methods are all specified on a per configure object basis, however this may become confusing in a
large project. All the prefixes and output filenames would have to be coordinated. A common strategy is to use the
framework for coordination, putting all the output into the framework object itself. For instance, we might have
<programlisting>
self.framework.addDefine('HAVE_PARMETIS', 1)
</programlisting>
which would allow the define to appear in the headre specified by the framework with the framework prefix.
</para>
</sect2>
</sect1>
<sect1 id="Configuring-batch-systems">
<title>Configuring batch systems</title>
<para>It is not uncommon for large clusters or supercomputing centers to have a batch execution policy, making it
difficult for configure to execute the few tests that depend on executing code, rather than compiling and linking it. To
handle this case, we provide the <option>--with-batch</option> argument. The code to be run is collected in a single
executable which the user must submit to the system. This executable produces a <emphasis>reconfigure</emphasis> script
which may then be run to fully configure the system.</para>
<para>When configure is run with the <option>--with-batch</option> option, the following message will appear.
<screen>
<prompt>petsc-dev$</prompt> <command>./config/configure.py --with-batch</command>
</screen>
produces the following log output.
<screen>
<computeroutput>
=================================================================================
Since your compute nodes require use of a batch system or mpirun you must:
1) Submit ./conftest to your batch system (this will generate the file reconfigure)
2) Run "python reconfigure" (to complete the configure process).
=================================================================================
</computeroutput>
</screen>
The user must then execute the <filename>conftest</filename> binary, and then run the <command>python
reconfigure</command> command.
</para>
<para>If a user defined test relies upon running code, he may make it suitable for a batch system. The
<methodname>checkRun</methodname> method takes the <option>defaultArg</option> argument which names a configure option
whose value may substitute for the outcome of the test, allowing a user to preempt the run. For instance, the
<methodname>config.types.checkEndian</methodname> method contains the code
<programlisting>
if self.checkRun('', body, defaultArg = 'isLittleEndian'):
</programlisting>
which means the <option>isLittleEndian</option> option can be given to replace the output of the run. However, this does
the require the user to supply the missing option.</para>
<para>To automate this process, the test should first check for batch mode. Using the
<methodname>addBatchInclude</methodname> and <methodname>addBatchBody</methodname> methods, code can be included in the
batch executable. We return to the endian test to illustrate this usage.
<programlisting>
if not self.framework.argDB['with-batch']:
body = '''
/* Are we little or big endian? From Harbison & Steele. */
union
{
long l;
char c[sizeof(long)];
} u;
u.l = 1;
exit(u.c[sizeof(long) - 1] == 1);
'''
if self.checkRun('', body, defaultArg = 'isLittleEndian'):
endian = 'little'
else:
endian = 'big'
else:
self.framework.addBatchBody(
['{',
' union {long l; char c[sizeof(long)];} u;',
' u.l = 1;',
' fprintf(output, " \'--with-endian=%s\',\\n",\
(u.c[sizeof(long) - 1] == 1) ? "little" : "big");',
'}'])
# Dummy value
endian = 'little'
</programlisting>
The batch body code should output configure options to the <varname>output</varname> file descriptor. These are
collected for the new configure run in the <filename>reconfigure</filename> script.
</para>
</sect1>
</chapter>
<chapter id="Build">
<title>Build</title>
<para>The build operation now encompasses the configure, compile, link, install, and update operations.</para>
<sect1 id="Running-make">
<title>Running make</title>
<para>All options for both configuration and build are given to <filename>make.py</filename>. Thus, the simplest build
is merely
<screen>
<prompt>petsc-dev$</prompt> <command>./make.py</command>
</screen>
The help is also given by <option>-help</option>, but this time it will also include build switches.
<screen>
<prompt>petsc-dev$</prompt> <command>./make.py -help</command>
<computeroutput>
Script Help
-----------
Script:
--help : Print this help message current: 1
--h : Print this help message current: 0
Make:
-forceConfigure : Force a reconfiguration current: 0
-ignoreCompileOutput : Ignore compiler output current: 1
-defaultRoot : Directory root for all packages current: ../..
-prefix : Root for installation of libraries and binaries
SIDLMake:
-bootstrap : Generate the bootstrap client current: 0
-outputSIDLFiles : Write generated files to disk current: 1
-excludeLanguages=<languages> : Do not load configurations from RDict for the given languages current: []
-excludeBasenames=<names> : Do not load configurations from RDict for these SIDL base names current: []
</computeroutput>
</screen>
</para>
</sect1>
<sect1 id="Makers">
<title>Makers</title>
<para>The build operation now encompasses configure, compile, and link operations, which are coordinated by objects of
class <classname>maker.Maker</classname>. This object manages:
<itemizedlist>
<listitem><para>configuration,</para></listitem>
<listitem><para>build,</para></listitem>
<listitem><para>install, and</para></listitem>
<listitem><para>project dependencies</para></listitem>
</itemizedlist>
All options, no matter which component they are intended for, are given uniformly to <filename>make.py</filename>.
</para>
<sect2 id="SIDLMaker">
<title>SIDLMaker</title>
<para>This is a subclass which handles source generation from SIDL.</para>
</sect2>
</sect1>
<sect1 id="Builders">
<title>Builders</title>
<para>The build operation now encompasses the configure, compile, and link operations.</para>
</sect1>
<sect1 id="LanguageProcessors">
<title>LanguageProcessors</title>
<para>The build operation now encompasses the configure, compile, and link operations.</para>
</sect1>
<sect1 id="Interaction-with-Configure">
<title>Interaction with Configure</title>
<para>The pickled configure is loaded by Maker, and then the config.compile objects are jacked into the Builder.</para>
</sect1>
</chapter>
</book>
|