2014-04-24 132 views
0

由於我是Scons的新手,我發現很難將現有的Makefile遷移到Scons。排除Scons中Build的某些文件

背景: 我有一個directory.I 50個文件要只* .CXX擴展名來過濾文件,太沒有文件名字符串「的win32」。

有人可以推算,這個邏輯的實現在使用SCons:

Makefile文件執行:

WIN32FILTER = $(wildcard *win32*) 
CXXOBJS = $(patsubst %.cxx,%.o,$(filter-out $(WIN32FILTER),$(wildcard *.cxx))) 

在使用SCons,我想是這樣的:

moduleSources = '' 
for root, dirs, files in os.walk('./'): 
    for filename in fnmatch.filter(files, '*.cxx'): 
     if "win32" not in filename: 
      moduleSources += ' ' + filename 

env.StaticLibrary("support_host", moduleSources) 

moduleSources這裏應包含所有* .cxx文件的列表(不包括win32字符串)將被用來製作靜態庫。

任何幫助表示讚賞。

+0

完全不熟悉Scons自己,但它看起來像'Glob'函數可能是你想要的。如果Glob支持減法,可能類似於Glob('*。cxx') - Glob('* win32 *')'。如果沒有,那麼對第一個「Glob」結果的過濾或理解應該做你想做的事情(還有其他關於這樣做的答案)。 –

+0

etan - 您應該將其作爲答案發布。這比使用os.walk更好。 – bdbaddog

回答

0

您創建一個包含空格的字符串來描述源代碼文件集。這不符合你的希望。

而是創建一個文件名列表。以下SConstruct做你想要的:

import os 
import fnmatch 

env = Environment() 

moduleSources = [] 
for root, dirs, files in os.walk('./'): 
    for filename in fnmatch.filter(files, '*.cxx'): 
     if "win32" not in filename: 
      moduleSources.append(os.path.join(root, filename)) 

env.StaticLibrary("support_host", moduleSources)