简体   繁体   English

Python scons构建

[英]Python scons building

Now I am studying an open source fluid simulation called pabalos. 现在,我正在研究一种名为pabalos的开源流体模拟。 I have some problems building my own program that links against the library. 我在构建自己的与图书馆链接的程序时遇到了一些问题。

The library is built from source using scons. 该库是使用scons从源代码构建的。

The directory of the project is : 该项目的目录是:

[fred@suck palabos-v1.1r0]$ls
codeblocks/  examples/           jlabos/  pythonic/  SConstruct  utility/
COPYING      externalLibraries/  lib/     scons/     src/

I will refer to this as the project root directory! 我将其称为项目根目录!

The project's official building documentation says: 该项目的官方建筑文件说:

The library Palabos makes use of an on-demand compilation process. Palabos库利用按需编译过程。 The code is compiled the first time it is used by an end-user application, and then automatically re-used in future, until a new compilation is needed due to a modification of the code or compilation options. 该代码在最终用户应用程序首次使用时进行编译,然后在将来自动重用,直到由于修改了代码或编译选项而需要进行新的编译为止。

In the examples directory, there are some example code directories, such as : 在示例目录中,有一些示例代码目录,例如:

[fred@suck palabos-v1.1r0]$ls examples/showCases/rectangularChannel3d/*
examples/showCases/rectangularChannel3d/Makefile
examples/showCases/rectangularChannel3d/rectangularChannel3D.cpp

The Makefile of the example is: 该示例的Makefile是:

[fred@suck rectangularChannel3d]$cat Makefile 
##########################################################################
## Makefile for the Palabos example program rectangularChannel3D.
##
## The present Makefile is a pure configuration file, in which
## you can select compilation options. Compilation dependencies
## are managed automatically through the Python library SConstruct.
##
## If you don't have Python, or if compilation doesn't work for other
## reasons, consult the Palabos user's guide for instructions on manual
## compilation.
##########################################################################

# USE: multiple arguments are separated by spaces.
#   For example: projectFiles = file1.cpp file2.cpp
#                optimFlags   = -O -finline-functions

# Leading directory of the Palabos source code
palabosRoot   = ../../..
# Name of source files in current directory to compile and link with Palabos
projectFiles = rectangularChannel3D.cpp

# Set optimization flags on/off
optimize     = true
# Set debug mode and debug flags on/off
debug        = false
# Set profiling flags on/off
profile      = false
# Set MPI-parallel mode on/off (parallelism in cluster-like environment)
MPIparallel  = true
# Set SMP-parallel mode on/off (shared-memory parallelism)
SMPparallel  = false
# Decide whether to include calls to the POSIX API. On non-POSIX systems,
#   including Windows, this flag must be false, unless a POSIX environment is
#   emulated (such as with Cygwin).
usePOSIX     = true

# Path to external libraries (other than Palabos)
libraryPaths =
# Path to inlude directories (other than Palabos)
includePaths =  
# Dynamic and static libraries (other than Palabos)
libraries    = 

# Compiler to use without MPI parallelism
serialCXX    = g++
# Compiler to use with MPI parallelism
parallelCXX  = mpicxx
# General compiler flags (e.g. -Wall to turn on all warnings on g++)
compileFlags = -Wall -Wnon-virtual-dtor
# General linker flags (don't put library includes into this flag)
linkFlags    =
# Compiler flags to use when optimization mode is on
optimFlags   = -O3
# Compiler flags to use when debug mode is on
debugFlags   = -g
# Compiler flags to use when profile mode is on
profileFlags = -pg


##########################################################################
# All code below this line is just about forwarding the options
# to SConstruct. It is recommended not to modify anything there.
##########################################################################

SCons     = $(palabosRoot)/scons/scons.py -j 2 -f $(palabosRoot)/SConstruct

SConsArgs = palabosRoot=$(palabosRoot) \
            projectFiles="$(projectFiles)" \
            optimize=$(optimize) \
            debug=$(debug) \
            profile=$(profile) \
            MPIparallel=$(MPIparallel) \
            SMPparallel=$(SMPparallel) \
            usePOSIX=$(usePOSIX) \
            serialCXX=$(serialCXX) \
            parallelCXX=$(parallelCXX) \
            compileFlags="$(compileFlags)" \
            linkFlags="$(linkFlags)" \
            optimFlags="$(optimFlags)" \
            debugFlags="$(debugFlags)" \
        profileFlags="$(profileFlags)" \
        libraryPaths="$(libraryPaths)" \
        includePaths="$(includePaths)" \
        libraries="$(libraries)"

compile:
    python $(SCons) $(SConsArgs)

clean:
    python $(SCons) -c $(SConsArgs)
    /bin/rm -vf `find $(palabosRoot) -name '*~'`

I know this makefile will call scons, and SConstruct file is in the project root dir as I have shown. 我知道这个makefile将调用scons,并且SConstruct文件在项目根目录中,如我所显示的。

The SContstruct file is : SContstruct文件是:

[fred@suck palabos-v1.1r0]$cat SConstruct 
###########################################################
# Configuration file for the compilation of Palabos code,
# using the SConstruct library.
# IT IS NOT RECOMMENDED TO MODIFY THIS FILE.
# Compilation should be personalized by adjusting the 
# Makefile in the directory of the main source files.
# See Palabos examples for sample Makefiles.
###########################################################

import os
import sys
import glob

argdict = dict(ARGLIST)

# Read input parameters
palabosRoot   = argdict['palabosRoot']
projectFiles  = Split(argdict['projectFiles'])
optimize      = argdict['optimize'].lower() == 'true'
debug         = argdict['debug'].lower() == 'true'
profile       = argdict['profile'].lower() == 'true'
MPIparallel   = argdict['MPIparallel'].lower() == 'true'
SMPparallel   = argdict['SMPparallel'].lower() == 'true'
usePOSIX      = argdict['usePOSIX'].lower() == 'true'
serialCXX     = argdict['serialCXX']
parallelCXX   = argdict['parallelCXX']
compileFlags  = Split(argdict['compileFlags'])
linkFlags     = Split(argdict['linkFlags'])
optimFlags    = Split(argdict['optimFlags'])
debugFlags    = Split(argdict['debugFlags'])
profileFlags  = Split(argdict['profileFlags'])
libraryPaths  = Split(argdict['libraryPaths'])
includePaths  = Split(argdict['includePaths'])
libraries     = Split(argdict['libraries'])

# Read the optional input parameters
try:
    dynamicLibrary = argdict['dynamicLibrary'].lower() == 'true'
except:
    dynamicLibrary = False

try:
    srcPaths = Split(argdict['srcPaths'])
except:
    srcPaths = []

flags = compileFlags
allPaths = [palabosRoot+'/src'] + [palabosRoot+'/externalLibraries'] + includePaths

if optimize:
    flags.append(optimFlags)

if debug:
    flags.append(debugFlags)
    flags.append('-DPLB_DEBUG')

if profile:
    flags.append(profileFlags)
    linkFlags.append(profileFlags)

if MPIparallel:
    compiler = parallelCXX
    flags.append('-DPLB_MPI_PARALLEL')
else:
    compiler = serialCXX

if SMPparallel:
    flags.append('-DPLB_SMP_PARALLEL')

if usePOSIX:
    flags.append('-DPLB_USE_POSIX')

env = Environment ( ENV       = os.environ,
                    CXX       = compiler,
                    CXXFLAGS  = flags,
                    LINKFLAGS = linkFlags,
                    CPPPATH   = allPaths
                  )

if dynamicLibrary:
    LibraryGen = env.SharedLibrary
else:
    LibraryGen = env.Library


sourceFiles = []
for srcDir in glob.glob(palabosRoot+'/src/*'):
    sourceFiles.extend(glob.glob(srcDir+'/*.cpp'))

for srcDir in srcPaths:
    sourceFiles.extend(glob.glob(srcDir+'/*.cpp'))

sourceFiles.extend(glob.glob(palabosRoot+'/externalLibraries/tinyxml/*.cpp'));

if MPIparallel:
    palabos_library = LibraryGen( target  = palabosRoot+'/lib/plb_mpi',
                                  source  = sourceFiles )
else:
    palabos_library = LibraryGen( target  = palabosRoot+'/lib/plb',
                                  source  = sourceFiles )

local_objects = env.Object(source = projectFiles)

all_objects = local_objects + palabos_library

env.Program(all_objects, LIBS=libraries, LIBPATH=libraryPaths)

My problem is: 我的问题是:

When I changed the source file rectangularChannel3D.cpp in the example dir, and run make, the palabos library should not be rebuilt since I didn't change the library project's source file (in the 'src' dir of the root dir) at all. 当我在示例目录中更改源文件rectangleChannel3D.cpp并运行make时,不应重建palabos库,因为我根本没有更改库项目的源文件(在根目录的“ src”目录中) 。 But actually the lib file "libplb.a" had been rebuilt!! 但是实际上lib文件“ libplb.a” 已经被重建了!! So why? 所以为什么?

I agree with Brady. 我同意布雷迪。 Try contacting the project you're trying to build. 尝试联系您要构建的项目。

Alternatively, if you get no help from them, and/or really want to fix this yourself, SCons has a flag --debug=explain which will tell you why any object is being build/rebuilt. 另外,如果您没有得到他们的帮助,并且/或者真的想自己修复此问题,SCons会带有--debug=explain标志,它会告诉您为什么要构建/重建任何对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM