1import args
2import config.compile.processor
3import config.compile.C
4import config.framework
5import config.libraries
6import os
7import sys
8
9import config.setsOrdered as sets
10
11class Preprocessor(config.compile.processor.Processor):
12  '''The CUDA preprocessor'''
13  def __init__(self, argDB):
14    config.compile.processor.Processor.__init__(self, argDB, 'CUDAPP', 'CUDAPPFLAGS', '.cpp', '.c')
15    self.language        = 'CUDA'
16    self.includeDirectories = sets.Set()
17    return
18
19class Compiler(config.compile.processor.Processor):
20  '''The CUDA compiler'''
21  def __init__(self, argDB, usePreprocessorFlags = True):
22    config.compile.processor.Processor.__init__(self, argDB, 'CUDAC', 'CUDAFLAGS', '.cu', '.o')
23    self.language        = 'CUDA'
24    self.requiredFlags[-1]  = '-c'
25    self.outputFlag         = '-o'
26    self.includeDirectories = sets.Set()
27    if usePreprocessorFlags:
28      self.flagsName.extend(Preprocessor(argDB).flagsName)
29    return
30
31  def getTarget(self, source):
32    '''Return None for header files'''
33    import os
34
35    base, ext = os.path.splitext(source)
36    if ext == '.h':
37      return None
38    return base+'.o'
39
40  def getCommand(self, sourceFiles, outputFile = None):
41    '''If no outputFile is given, do not execute anything'''
42    if outputFile is None:
43      return 'true'
44    return config.compile.processor.Processor.getCommand(self, sourceFiles, outputFile)
45
46class Linker(config.compile.C.Linker):
47  '''The CUDA linker'''
48  def __init__(self, argDB):
49    self.compiler        = Compiler(argDB, usePreprocessorFlags = False)
50    self.configLibraries = config.libraries.Configure(config.framework.Framework(clArgs = '', argDB = argDB, tmpDir = os.getcwd()))
51    config.compile.processor.Processor.__init__(self, argDB, [self.compiler.name], ['CUDAC_LINKER_FLAGS'], '.o', '.a')
52    self.language   = 'CUDA'
53    self.outputFlag = '-o'
54    self.libraries  = sets.Set()
55    return
56
57  def getExtraArguments(self):
58    if not hasattr(self, '_extraArguments'):
59      return ''
60    return self._extraArguments
61  extraArguments = property(getExtraArguments, config.compile.processor.Processor.setExtraArguments, doc = 'Optional arguments for the end of the command')
62
63class SharedLinker(config.compile.C.SharedLinker):
64  '''The CUDA shared linker: Just use regular linker for now'''
65  def __init__(self, argDB):
66    config.compile.C.SharedLinker.__init__(self, argDB)
67    self.language = 'CUDA'
68    return
69
70class StaticLinker(config.compile.C.StaticLinker):
71  '''The CUDA static linker, just use C for now'''
72  def __init__(self, argDB):
73    config.compile.C.StaticLinker.__init__(self, argDB)
74    self.language = 'CUDA'
75    return
76
77class DynamicLinker(config.compile.C.DynamicLinker):
78  '''The CUDA dynamic linker, just use C for now'''
79  def __init__(self, argDB):
80    config.compile.C.DynamicLinker.__init__(self, argDB)
81    self.language = 'CUDA'
82    return
83