def _SendToJob(self, type): self.job.AddCommandGroup(self.sourceFiles, False) if type == 'shared': binaryName = self.binary + osutil.SharedLibSuffix() elif type == 'executable': binaryName = self.binary + osutil.ExecutableSuffix() elif type == 'static': binaryName = osutil.StaticLibPrefix( ) + self.binary + osutil.StaticLibSuffix() binaryPath = os.path.join(self.runner.outputFolder, self.job.workFolder, binaryName) if len(self.sourceFiles) > 0: self.alwaysRelink = True if type == 'static': if osutil.IsUnixy(): args = ['ar'] args.append('rcs') args.append(binaryName) args.extend([i for i in self.objFiles]) self.job.AddCommand(LinkCommand(args, self, binaryPath)) return else: args = ['lib.exe'] args.append('/OUT:' + binaryName) args.extend([i for i in self.objFiles]) self.job.AddCommand(LinkCommand(args, self, binaryPath)) return if self.hadCxxFiles: cc = self.compiler.cxx else: cc = self.compiler.cc args = cc.command.split(' ') args.extend([i for i in self.objFiles]) if isinstance(cc, MSVC): args.append('/link') args.extend(self.compiler['POSTLINKFLAGS']) args.extend(self.env['POSTLINKFLAGS']) if isinstance(cc, CompatGCC): if type == 'shared': if self.runner.target['platform'] == 'darwin': args.append('-dynamiclib') else: args.append('-shared') args.extend(['-o', binaryName]) elif isinstance(cc, MSVC): args.append('/OUT:' + binaryName) if type == 'shared': args.append('/DLL') args.append('/PDB:"' + self.binary + '.pdb' + '"') self.job.AddCommand(LinkCommand(args, self, binaryPath))
def __init__(self, binary, runner, job, compiler): BinaryBuilder.__init__(self, binary, runner, job, compiler) self.binaryFile = binary + osutil.ExecutableSuffix()
def VerifyCompiler(self, name, mode, vendor): args = name.split(' ') if 'CPPFLAGS' in self.env: args.extend(self.env['CPPFLAGS']) if 'CFLAGS' in self.env: args.extend(self.env['CFLAGS']) if mode == 'cxx' and 'CXXFLAGS' in self.env: args.extend(self.env['CXXFLAGS']) filename = 'test.{0}'.format(mode) file = open(filename, 'w') file.write(""" #include <stdio.h> #include <stdlib.h> int main() { #if defined __ICC printf("icc %d\\n", __ICC); #elif defined __clang__ # if defined(__clang_major__) && defined(__clang_minor__) printf("clang %d.%d\\n", __clang_major__, __clang_minor__); # else printf("clang 1.%d\\n", __GNUC_MINOR__); # endif #elif defined __GNUC__ printf("gcc %d.%d\\n", __GNUC__, __GNUC_MINOR__); #elif defined _MSC_VER printf("msvc %d\\n", _MSC_VER); #elif defined __TenDRA__ printf("tendra 0\\n"); #else #error "Unrecognized compiler!" #endif #if defined __cplusplus printf("cxx\\n"); #else printf("c\\n"); #endif exit(0); } """) file.close() if mode == 'c': executable = 'test' + osutil.ExecutableSuffix() elif mode == 'cxx': executable = 'testp' + osutil.ExecutableSuffix() try: os.unlink(executable) except: pass if vendor == 'gcc' and mode == 'cxx': args.extend(['-fno-exceptions', '-fno-rtti']) args.extend([filename, '-o', executable]) print('Checking {0} compiler (vendor test {1})... '.format(mode, vendor), end = '') print(args) p = osutil.CreateProcess(args) if p == None: print('not found') return False if osutil.WaitForProcess(p) != 0: print('failed with return code {0}'.format(p.returncode)) return False exe = osutil.MakePath('.', executable) p = osutil.CreateProcess([executable], executable = exe) if p == None: print('failed to create executable') return False if osutil.WaitForProcess(p) != 0: print('executable failed with return code {0}'.format(p.returncode)) return False lines = p.stdoutText.splitlines() if len(lines) != 2: print('invalid executable output') return False if lines[1] != mode: print('requested {0} compiler, found {1}'.format(mode, lines[1])) vendor, version = lines[0].split(' ') if vendor == 'gcc': v = GCC(name, version) elif vendor == 'clang': v = Clang(name, version) elif vendor == 'msvc': v = MSVC(name, version) else: print('Unknown vendor {0}'.format(vendor)) return False if mode == 'c': self.cc = v elif mode == 'cxx': self.cxx = v print('found {0} version {1}'.format(vendor, version)) return True