1'''! Python scripts used by the PSCF makefile build system. '''
33 base = os.path.basename(cfile)
34 groups = base.split(
'.')
38 abspath = os.path.abspath(cfile)
39 relpath = os.path.relpath(abspath, srcdir)
40 reldir = os.path.dirname(relpath)
43 if (reldir !=
'.' and reldir !=
''):
44 blddir = os.path.normpath(os.path.join(blddir, reldir))
45 srcdir = os.path.normpath(os.path.join(srcdir, reldir))
50 pfile = os.path.normpath(os.path.join(srcdir, base)) +
'.p'
51 dfile = os.path.normpath(os.path.join(blddir, base)) +
'.d'
54 command = processor +
' '
55 command += pfile +
' '
56 command += options +
' '
61 editDepend(pfile, dfile, blddir, extraDependencies)
90 base = os.path.basename(cfile)
91 groups = base.split(
'.')
95 abspath = os.path.abspath(cfile)
96 relpath = os.path.relpath(abspath, srcdir)
97 reldir = os.path.dirname(relpath)
100 if (reldir !=
'.' and reldir !=
''):
101 blddir = os.path.normpath(os.path.join(blddir, reldir))
102 srcdir = os.path.normpath(os.path.join(srcdir, reldir))
107 pfile = os.path.normpath(os.path.join(srcdir, base)) +
'.p'
108 dfile = os.path.normpath(os.path.join(blddir, base)) +
'.d'
111 command = processor +
' '
112 command += options +
' '
114 command +=
' > ' + pfile
135 file = open(pfile,
'r')
136 lines = file.readlines()
140 groups = lines[0].split(
":")
145 base = os.path.basename(target)
146 target = os.path.normpath(os.path.join(blddir, base))
150 for i
in range(len(lines)):
158 text.append(target +
': ')
161 path = os.path.abspath(dep)
165 if extraDependencies:
166 deps = extraDependencies.split()
168 path = os.path.abspath(dep)
171 file = open(dfile,
'w')
172 file.write(str(text))
189 file = open(pfile,
'r')
190 lines = file.readlines()
194 groups = lines[0].split(
":")
199 base = os.path.basename(target)
200 target = os.path.normpath(os.path.join(blddir, base))
204 for i
in range(len(lines)):
212 text.append(target +
': ')
215 pair = [srcroot, dep]
216 if (os.path.commonprefix(pair) == srcroot):
217 path = os.path.abspath(dep)
221 if extraDependencies:
222 deps = extraDependencies.split()
224 path = os.path.abspath(dep)
227 file = open(dfile,
'w')
228 file.write(str(text))
246 def __init__(self, path = '.', pathFromSrc = '.', pathToSrc ='.', parent = None, isTest=False):
258 self.
root = parent.root
273 dirFilePath = self.
makePath(
'dir.txt')
274 if os.path.exists(dirFilePath):
275 file = open(dirFilePath,
'r')
285 if os.path.isdir(path):
291 pathToSrc =
'..' + os.sep + self.
pathToSrc
293 maker =
MakeMaker(path, pathFromSrc, pathToSrc, self,
True)
296 self.
dirs.append(maker)
298 def setGlobalInclude(self, text):
300 for dir
in self.
dirs:
301 dir.setGlobalInclude(text)
303 def setDefines(self, text):
305 for dir
in self.
dirs:
308 def addLibrary(self, libName, libObjs):
313 def setLinkObjs(self, text):
315 for dir
in self.
dirs:
316 dir.setLinkObjs(text)
319 ''' Make include line suitable for a makefile'''
321 return 'include $(SRC_DIR)' + os.sep + base +
'\n'
323 return 'include $(SRC_DIR)' + os.sep + self.
pathFromSrc + os.sep + base +
'\n'
326 ''' Return suffix for source files: cpp or cc '''
334 Find all header and source files
in this directory.
335 Note: Does
not recursively descend into subdirectories
340 for name
in os.listdir(self.
path):
343 if os.path.isfile(path):
344 base = os.path.basename(path)
345 groups = base.split(
'.')
351 self.
srcs.append(base)
357 for name
in os.listdir(self.
path):
360 if os.path.isfile(path):
361 base = os.path.basename(path)
362 groups = base.split(
'.')
367 if base
not in self.
srcs:
368 self.
hdrs.append(base)
377 for dir
in self.
dirs:
385 if len(self.
dirs) > 0:
386 for dir
in self.
dirs:
387 basename = os.path.basename(dir.path)
388 if basename !=
'tests':
389 varpath = basename + os.sep +
'sources.mk'
403 wrapper.append(prefix +
'SRCS=')
404 for dir
in self.
dirs:
405 basename = os.path.basename(dir.path)
406 if basename !=
'tests':
407 wrapper.append(
'$(' + dir.dirname +
'_SRCS) ')
408 for base
in self.
srcs:
412 file.write(str(wrapper))
416 file.write(prefix +
'OBJS=$(')
417 file.write(prefix +
'SRCS:.' + self.
srcSuffix() +
'=.o)')
426 file.write(
'\t$(AR) rcs ' + self.
libName +
' ' + self.
libObjs +
'\n')
434 file = open(self.
makePath(
'makefile'),
'w')
435 file.write(
'SRC_DIR_REL =' + self.
pathToSrc +
'\n\n')
438 file.write(
'include $(SRC_DIR_REL)/test/sources.mk\n')
439 file.write(
'include sources.mk\n')
445 targets =
'$(' + objs +
')'
446 deps =
'$(' + objs +
':.o=.d)'
448 for base
in self.
srcs:
449 targets +=
' ' + base
450 file.write(
'all: ' + targets)
454 file.write(
'clean:\n\trm -f ' + targets +
' ' + deps)
458 file.write(
'clean-deps:\n\trm -f ' + deps)
461 for base
in self.
srcs:
462 file.write(base +
': ' + base +
'.o ' + self.
linkObjs +
'\n')
463 file.write(
'\t$(CXX) $(LDFLAGS) $(INCLUDES) $(DEFINES)')
464 file.write(
' -o ' + base +
' ' + base +
'.o \\\n')
465 file.write(
'\t ' + self.
linkObjs +
'\n\n')
467 file.write(
'-include ' + deps +
'\n\n')
470 def makePath(self, string):
472 return self.
path + os.sep + string
476 def makePathFromSrc(self, string):
482 def srcDirPath(self):
489 return os.sep.join(shifts)
496 def filenames(self, pattern = '*', recursive = 1):
497 r = glob.glob( self.
path +
'/' + pattern)
499 for dir
in self.
dirs:
500 r.extend(dir.filenames(pattern))
505 r.append( self.
path +
'\n' )
507 r.append( str(x) +
'\n' )
508 for x
in self.
srcs.keys() :
509 r.append( str(x) +
'\n' )
Class to construct makefile system for a set of source files.
def srcSuffix(self)
Return suffix for source files: cpp or cc.
def makeInclude(self, base)
Make include line suitable for a makefile.
def makePathFromSrc(self, string)
def makePath(self, string)
def __init__(self, path='.', pathFromSrc='.', pathToSrc='.', parent=None, isTest=False)
Constructor.
def find(self)
Find all header and source files in this directory.
Class to wrap line breaks.
Utilities for manipulating files and paths.
def open_w(path)
Open file with specified path for writing, return file object.
def editDepend(pfile, dfile, blddir, extraDependencies)
Edit the dependency file created for a C/C++ file by the compiler.
def createDependencyFileCpp(processor, options, cfile, srcdir, blddir, extraDependencies='')
Create a *.d dependency file for a C/C++ source file.
def createDependencyFileCuda(processor, options, cfile, srcdir, blddir, extraDependencies='')
Create a *.d dependency file for a CUDA source file.
def editDependLocal(pfile, dfile, blddir, srcroot, extraDependencies)
Edit the dependency file created for a CUDA file by the compiler.
Utilities for manipulating and searching text strings.
def readLabelledList(file, label)
Read line of form "label = string", in which string may contains spaces.