2012-10-17 5 views
2

원본 파일 이름을 유지하면서 작성한 공유 라이브러리의 모든 디버그 기호를 제거하려고한다고 가정 해 봅시다. SCONS : 대상에서 작업을 수행하는 방법

나는 방법에 명령을 추가하려고 : 두 가지 방법이 동일한 대상, 나는이 개 목표는 ENV에 의해 반환하기 때문에 것 같아요 주어졌다 :

def mySharedLibrary(self, *args, **kwargs): 
    # do some common work for every shared library like add a soname or append some lib files to LIBS  parameter 
    target = SharedLibary(*args, **kwargs) 
    target = env.Command(target,target, "objcopy --strip-debug ${SOURCE}") 
    return target 

나는이 오류가 발생합니다. Command와 SharedLibrary는 정확히 같은 이름입니다.

아이디어가 있으십니까?

미리 감사드립니다.

+0

(계산 의존성 문제가 도착을). 어쨌든 당신은 박탈 된 표적에 대해 다른 이름을 사용해야합니다. – Torsten

답변

1

나는 동일한 문제가 있었고 동일한 오류가 발생했습니다. 내가해야 할 일은 중간 타겟/라이브러리를 만드는 것이 었습니다. 중간 목표와 최종 목표에는 각각 자체 라이브러리 이름이 있으므로 SCons는 혼동하지 않습니다.

당신은 아마 다음과 같이 뭔가를 할 수 :

env.SharedLibrary(target = 'namePreStrip', source = 'yourSource') 
env.Command(target = 'name', source = 'namePreStrip', 'objcopy...') 

나는 몇 가지 라이브러리에서 라이브러리를 구축하는 objcopy의 사용. 저는 여기에 구현 된 실제 소스 코드입니다 :

# 
# Build an object file out of several other source files, objects, and libraries 
# Optionally execute objcopy on the resulting library, depending if objcopyFlags 
# has been populated 
# 
# env - SCons Environment used to build, Mandatory arg 
# target - resulting library name, without LIBPREFIX and LIBSUFFIX, ej 'nsp2p', 
#   Mandatory arg 
# sourceFiles - list of '.cc' files that will be compiled and included in the 
#    resulting lib, Optional arg 
# objects - list of already compiled object files to be included in resulting lib, 
#   Optional arg 
# libraries - list of libraries to be included in resulting lib, Optional arg 
# objcopyFlags - list of flags to pass to objcopy command. objcopy will only 
#    be executed if this list is populated, Optional arg 
# 
# One of [sourceFiles, objects, or libraries] must be specified, else nothing 
# will be performed 
# 
# Not using a custom builder because I dont like the way SCons prints the 
# entire command each time its called, even if its not going to actually 
# build anything AND I need more method args than provided by custom builders 
# 
def buildWholeArchive(self, env, target, sourceFiles, objects, libraries, objcopyFlags): 
    if len(sourceFiles) == 0 and len(objects) == 0 and len(libraries) == 0: 
     print "Incorrect use of buildWholeArchive, at least one of [sourceFiles | objects | librarires] must be specified, no build action will be performed" 
     return None 

    # Compile each source file 
    objNodes = [] 
    if len(sourceFiles) > 0: 
     objNodes = env.Object(source = sourceFiles) 

    cmdList = [] 
    cmdList.append(env['CXX']) 
    cmdList.append('-nostdlib -r -o $TARGET -Wl,--whole-archive') 
    for obj in objNodes: 
     cmdList.append(env.File(obj).abspath) 
    for obj in objects: 
     cmdList.append(env.File(obj).abspath) 
    for lib in libraries: 
     cmdList.append(lib) 
    cmdList.append('-Wl,--no-whole-archive') 
    cmd = ' '.join(cmdList) 

    libTarget = '%s%s%s' % (env['LIBPREFIX'], target, env['LIBSUFFIX']) 

    if len(objcopyFlags) > 0: 
     # First create the library, then run objcopy on it 
     objTarget = '%s%s_preObjcopy%s' % (env['LIBPREFIX'], target, env['LIBSUFFIX']) 
     preObjcopyTarget = env.Command(target = objTarget, source = [], action = cmd) 
     env.Depends(preObjcopyTarget, [objNodes, sourceFiles, objects, libraries]) 

     objCmdList = [env['OBJCOPY']] 
     objCmdList.extend(objcopyFlags) 
     objCmdList.append('$SOURCE $TARGET') 
     objcopyCmd = ' '.join(objCmdList) 
     archiveTarget = env.Command(target = libTarget, source = preObjcopyTarget, action = objcopyCmd) 
    else: 
     # Just create the library 
     archiveTarget = env.Command(target = libTarget, source = [], action = cmd) 
     env.Depends(archiveTarget, [objNodes, sourceFiles, objects, libraries]) 

    return archiveTarget 

는 그리고 여기 내가 전화하는 방법입니다

이 가
sourceFiles = ['file1.cc', 'file2.cc'] 
libSource = [] 
if 'OcteonArchitecture' in env: 
    libSource.append(lib1) 
    libSource.append(lib2) 
libSource.append(lib3) 

objcopy = [] 
if 'OcteonArchitecture' in env: 
    objcopy.extend([ 
     '--redefine-sym calloc=ns_calloc', 
     '--redefine-sym free=ns_free', 
     '--redefine-sym malloc=ns_malloc', 
     '--redefine-sym realloc=ns_realloc']) 

archiveTarget = clonedEnv.buildWholeArchive(target = libName, 
              sourceFiles = sourceFiles, 
              objects = [], 
              libraries = libSource, 
              objcopyFlags = objcopy) 
env.Alias('libMyLib', archiveTarget) 
당신이 대상을 덮어 쓸 수 없기 때문에 그것은 SCons는 아키텍처 인해 할 수없는
관련 문제