Differences

This shows you the differences between two versions of the page.

sep:software:sepscons [2009/02/12 11:05]
sjoerd
sep:software:sepscons [2015/05/27 02:06] (current)
Line 12: Line 12:
It is already said that there are many ways to get to the same result in SCons. The examples on this page are often straight forward and offer for much flexibility. It is already said that there are many ways to get to the same result in SCons. The examples on this page are often straight forward and offer for much flexibility.
-===== Features =====+The main feature of SEPSCons is an Environment initiation function wrapped around the SCons ''Environment'' function. This function configures a SCons construction environment for our SEP computing environment. After initiating a SEPSCons construction environment one can still change construction keys using the SCons functions ''env.Replace()'', ''env.Append()'' or ''env.Prepend()''.
-The main feature of SEPSCons is a initiation function, that configures a SCons construction environment for our SEP computing environment. After initiating a SEPSCons construction environment one can still change construction keys using the SCons functions ''env.Replace()'', ''env.Append()'' or ''env.Prepend()''. +Very important for your research is the proper implementation of a directory tree to carefully organize the project. SEPSCons handles these with with a class ''Folders''. This class is regularly used by other SEPSCons functions to evaluate where to build from and where to build to.
- +
-Very important for your research is the proper implementation of a directory tree to carefully organize the project. A common organization scheme would include a source folder (''/src''), a binary folder (''/bin'') and a result folder (''/fig''). These folders are implementing using SCons functionality. In addition to above three directories, separate module (''/mod'') and object (''/obj'') folders can avoid cluttering of intermediate files into the binary folder. To that objective SEPSCons initiated environments have a ''MODDIR''-key and the ''OBJDIR''-key. The module files are automatically placed in the module folder by the (fortran) compiler. Object files are placed in the object folder, when the alternative SEPSCons builder commands ''env.OProgram'' and ''env.OLibrary()'' are used (see below). These recursively declare Object build entries and than a Program respectively Library build entry.+
====== How to use SCons and SEPSCons ====== ====== How to use SCons and SEPSCons ======
Line 37: Line 35:
</code> </code>
In your SConstruct and SConscript files, you can make the functions and variables of SEPSCons available to SCons by using the python ''import'' command. In your SConstruct and SConscript files, you can make the functions and variables of SEPSCons available to SCons by using the python ''import'' command.
-<code python> 
-import SEPSCons 
-</code> 
- 
- 
- 
- 
- 
-====== SCons files of a typical SEPSCons project ====== 
-SCons is used by a SConstruct file. To run this SConstruct file, this file is best placed in your ''/localdir/''. This SConstruct-file, is the equivalent of a Makefile, all commands you whish to make available for your project can be written in this ''SConstruct''-file. Presently, we only aim to construct executables, so at this stage the contents of ''SConstruct'' are best be kept minimal. We only whish to specify a ''/localdir/src/'' folder and a ''localdir/bin/'' folder.  
- 
-''/localdir/SConstruct'' 
-<code python> 
-import SEPSCons 
-SConscript( ['src/SConscript'], variant_dir = 'bin', duplicate = 0 ) 
-</code> 
- 
-Strictly speaking, the ''import SDRSCons'' command is redundant here, because we do not use any the functionalities or variables made available in SEPSCons. ''SConscript()'' is a SCons function that makes all SCons commands inside the specified SConscript file available to SCons. The ''variant_dir'' variable that is passed on to this SConscript file is the folder that is used as the target folder for the builds specified in the included SConscript file. the ''duplicate'' variable is set to be ''0'' to avoid the default but unnecessary copying of source files from the ''/localdir/src/'' folder to the ''/localdir/bin'' folder prior to the compiler execution inside the ''/localdir/bin'' folder. Instead, SCons now issues a compiler execution command that specifies the source and binary folders. 
- 
-The SConscript file contains SCons ''Program()'' and (optional) ''Object()'' functions that are necessary to construct a executable from it's source file(s). We start by importing the SEPSCons module and initializing a SCons default construction environment in this example named ''env''. We than continue to initialize this ''env'' SConstruction environment as a SEPSCons environment by calling the SEPSCons function ''init( )''. This associates a SEPlib version to this SConstruction environment and configured the Fortran and C compiler Flags of SCons for our computing environment. We also enabled a set of variables and functions to this environment that will come in useful working with the SEP computing environment. 
- 
-Initialize an environment with the ifort compiler\\ \\ 
-''/localdir/SConstruct'' 
<code python> <code python>
from SEPSCons import * from SEPSCons import *
-fld = Folders( B='#bin', S='#src', M='#mod' ) 
-env = SEnvironment( tools=['ifort'], folders=fld ) 
</code> </code>
- 
- 
- 
-Notice how we supply the optional argument ''LIBS='$SEPLIBF90'''. ''SEPLIBF90'' is a pre-defined set of libraries for Fortran that make the most basic SEPlib libraries available. It's c counterpart is named ''$SEPLIBC''. For many c programs, the Fortran library set would work as well. 
Congratulation's, you are now ready to issue SCons and SEPSCons commands to foster research that can benefit the greater good of humankind. Congratulation's, you are now ready to issue SCons and SEPSCons commands to foster research that can benefit the greater good of humankind.
 +
Line 87: Line 57:
SLibrary SLibrary
 +
 +====== Elementary SEPSCons ======
 +This section goes step by step through an elementary SEPSCons example. Though more complicated builds are not much more involved. In the project folder, you open a file ''SConstruct'' where as a first step you import SEPSCons:
 +<code python>
 +from SEPSCons import *
 +</code>
 +The second step is to define the folder structure of your project. You will typically want to define a source folder SRC and a build folder BLD. Use the SEPSCons folder function like this:
 +<code python>
 +fld = Folders( BLD='#bin', SRC='#src' )
 +</code>
 +Secondly, we will need to initilize a scons environment with for example the tool '''ifort''' that operates with the specified folder structure ''fld'' using the SEnvironment function.
 +<code python>
 +env = SEnvironment( tools=['ifort'], folders=fld )
 +</code>
 +We are now ready to define a program from a source code. Just supply the main f90 file to the SProgram function.
 +<code python>
 +env.SProgram('driver.f90')
 +</code>
 +Running this scons file would create the program ''driver.x'' in the ''~/bin'' folder. The whole SConstruct file looks like:\\
 +''~/SConstruct''
 +<code python>
 +from SEPSCons import *
 +fld = Folders( BLD='#bin', SRC='#src')
 +env = SEnvironment( tools=['ifort'], folders=fld )
 +env.SProgram('driver.f90')
 +</code>
 +==== Build, Clean and Burn ====
 +Although the target of the above ''SConstruct'' file is ''~/bin/driver.x'', it is aliased under ''driver.x''. Thus running
 +<code>
 +>> scons driver.x
 +</code>
 +Would build the specific target. All intermediate files can be cleaned running scons with the clean flag:
 +<code>
 +>> scons -c driver.x
 +</code>
 +or
 +<code>
 +>> scons --clean driver.x
 +</code>
 +The final target file ''~/bin/driver.x'' was kept save from the clean because SProgram protected it with the SCons ''Noclean'' function. When the target needs to be burned, just run SCons with the burn flag:
 +<code>
 +>> scons --burn driver.x
 +</code>
 +This will enable clean mode and while the target is not protected by ''Noclean''. Effectively removing all the files created by the initial build.
====== FFTW and OPENMP ====== ====== FFTW and OPENMP ======
Line 104: Line 118:
====== Old Make Library sets ====== ====== Old Make Library sets ======
 +When you start to build executables with SCons, you might want to know these old Make file library sets. It will help you figure out which libraries you need to add to the Build Environments to get your programs to compile.\\ \\
SEPLIBC   = ['sep']\\ SEPLIBC   = ['sep']\\
SEPLIBF90 = ['sepf90','sep'] + env['F90LIBS']\\ SEPLIBF90 = ['sepf90','sep'] + env['F90LIBS']\\
/web/html/data/attic/sep/software/sepscons.1234436736.txt.gz · Last modified: 2015/05/26 22:41 (external edit)
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0