diff options
author | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-05-12 00:04:00 +0200 |
---|---|---|
committer | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-05-12 00:04:00 +0200 |
commit | bb2ff0bf94695962a7973282698097066c4e1068 (patch) | |
tree | 608dd281ab7d700e2b80fe6069d57f1f05ec26ad | |
parent | 2ffb713f84dbd740e213b156eb9a513a7ea8f05b (diff) |
No path problem now?
-rwxr-xr-x | tool/Toolchain/GNU.py | 31 | ||||
-rwxr-xr-x | tool/Toolchain/Hitachi.py | 31 | ||||
-rwxr-xr-x | tool/Toolchain/__init__.py | 17 | ||||
-rwxr-xr-x | tool/Toolchain/base.py | 27 | ||||
-rwxr-xr-x | tool/__main__.py | 19 |
5 files changed, 94 insertions, 31 deletions
diff --git a/tool/Toolchain/GNU.py b/tool/Toolchain/GNU.py index 530aaa5..25c5d3a 100755 --- a/tool/Toolchain/GNU.py +++ b/tool/Toolchain/GNU.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 ''' The GNU toolchain. ''' -import os, platform +import os from subprocess import call from .base import Toolchain @@ -12,6 +12,7 @@ class GNUToolchain(Toolchain): cxx_standards = ['c++98', 'c++11', 'c++14'] # Supported extensions + lib_ext = 'a' lang = { 'cc': ['c', 'C'], 'cxx': ['cpp', 'CPP', 'cc', 'CC', 'cp', 'CP', 'cxx', \ @@ -38,14 +39,20 @@ class GNUToolchain(Toolchain): # C/C++ warning flags self.__cwarn = ['-Wall', '-Wextra', '-Wno-attributes', '-pedantic'] + # Check if the binaries exist + self.getutil({ + 'gcc': ['sh3eb-elf-gcc'], + 'as': ['sh3eb-elf-as'], + 'ar': ['sh3eb-elf-ar']}) + def direct__cc(self, obj, src, incdirs, std): - commandline = ['sh3eb-elf-gcc', '-x', 'c', '-std=' + std] + commandline = [self.util['gcc']] + commandline += ['-x', 'c', '-std=' + std] commandline += ['-c', '-o', obj, src] commandline += ['-O2', '-ffreestanding'] commandline += self.__cwarn + self.__ccpu - if platform.system() == 'Windows': incpath = ';'.join(incdirs) - else: incpath = ':'.join(incdirs) + incpath = os.pathsep.join(incdirs) env = os.environ.copy() env['CPATH'] = incpath env['C_INCLUDE_PATH'] = incpath @@ -54,13 +61,13 @@ class GNUToolchain(Toolchain): return call(commandline, env=env) def direct__cxx(self, obj, src, incdirs, std): - commandline = ['sh3eb-elf-gcc', '-x', 'c++', '-std=' + std] + commandline = [self.util['gcc']] + commandline += ['-x', 'c++', '-std=' + std] commandline += ['-c', '-o', obj, src] commandline += ['-O2', '-ffreestanding'] commandline += self.__cwarn + self.__ccpu - if platform.system() == 'Windows': incpath = ';'.join(incdirs) - else: incpath = ':'.join(incdirs) + incpath = os.pathsep.join(incdirs) env = os.environ.copy() env['CPATH'] = incpath env['C_INCLUDE_PATH'] = incpath @@ -69,12 +76,12 @@ class GNUToolchain(Toolchain): return call(commandline, env=env) def direct__asmc(self, obj, src, incdirs): - commandline = ['sh3eb-elf-gcc', '-x', 'assembler-with-cpp'] + commandline = [self.util['gcc']] + commandline += ['-x', 'assembler-with-cpp'] commandline += ['-c', '-o', obj, src] commandline += self.__ccpu - if platform.system() == 'Windows': incpath = ';'.join(incdirs) - else: incpath = ':'.join(incdirs) + incpath = os.pathsep.join(incdirs) env = os.environ.copy() env['CPATH'] = incpath env['C_INCLUDE_PATH'] = incpath @@ -83,14 +90,14 @@ class GNUToolchain(Toolchain): return call(commandline, env=env) def direct__asm(self, obj, src): - commandline = ['sh3eb-elf-as'] + commandline = [self.util['as']] commandline += ['-c', '-o', obj, src] commandline += self.__acpu return call(commandline) def direct__pack(self, lib, objs): - commandline = ['sh3eb-elf-ar'] + commandline = [self.util['ar']] commandline += ['rcs', lib, *objs] return call(commandline) diff --git a/tool/Toolchain/Hitachi.py b/tool/Toolchain/Hitachi.py index dcc83e5..649cada 100755 --- a/tool/Toolchain/Hitachi.py +++ b/tool/Toolchain/Hitachi.py @@ -13,6 +13,7 @@ class HitachiToolchain(): cxx_standards = ['c++98'] # Supported extensions + lib_ext = 'lib' lang = { 'cc': ['c', 'C'], 'cxx': ['cpp', 'CPP', 'cc', 'CC', 'cp', 'CP', 'cxx', 'CXX', 'c++'], @@ -31,7 +32,11 @@ class HitachiToolchain(): if arch[-3:] == 'dsp': self.__cpu.append('-dspc') - # TODO: check if the binaries exist + # Check if the binaries exist + self.getutil({ + 'shc': ['shc.exe'], + 'asmsh': ['asmsh.exe'], + 'lnk': ['LnkSpawn.exe']}) def direct__cc(self, obj, src, incdirs=[]): # Make the temporary thing with all of the subcommands. @@ -44,8 +49,12 @@ class HitachiToolchain(): '-nologo', '-debug', sep='\n', file=tmp) tmp.close() + # Make the command line. + commandline = [self.util['shc']] + commandline += ['-subcommand=' + tmpinfo[1]] + # Open the subprocess - ret = call(['shc.exe', '-subcommand='+tmpinfo[1]]) + ret = call(commandline) os.remove(tmpinfo[1]) return ret @@ -60,8 +69,12 @@ class HitachiToolchain(): '-nologo', '-debug', sep='\n', file=tmp) tmp.close() + # Make the command line. + commandline = [self.util['shc']] + commandline += ['-subcommand=' + tmpinfo[1]] + # Open the subprocess - ret = call(['shc.exe', '-subcommand='+tmpinfo[1]]) + ret = call(commandline) os.remove(tmpinfo[1]) return ret @@ -75,8 +88,12 @@ class HitachiToolchain(): '-nologo', '-chgincpath', '-errorpath', sep='\n', file=tmp) tmp.close() + # Make the command line. + commandline = [self.util['asmsh']] + commandline += ['-subcommand=' + tmpinfo[1]] + # Open the subprocess - ret = call(['asmsh.exe', '-subcommand='+tmpinfo[1]]) + ret = call(commandline) os.remove(tmpinfo[1]) return ret @@ -89,7 +106,11 @@ class HitachiToolchain(): '-exit', sep='\n', file=tmp) tmp.close() + # Make the command line. + commandline = [self.util['lnk']] + commandline += ['-subcommand=' + tmpinfo[1]] + # Open the subprocess - ret = call(['asmsh.exe', '-subcommand='+tmpinfo[1]]) + ret = call(commandline) os.remove(tmpinfo[1]) return ret diff --git a/tool/Toolchain/__init__.py b/tool/Toolchain/__init__.py index 808cdc7..e5ef515 100755 --- a/tool/Toolchain/__init__.py +++ b/tool/Toolchain/__init__.py @@ -1,10 +1,13 @@ #!/usr/bin/env python3 -#from .Hitachi import HitachiToolchain +from .Hitachi import HitachiToolchain from .GNU import GNUToolchain -def get_toolchain(name, arch): - if name.lower() in ["hitachi", "renesas"]: - return HitachiToolchain(arch) - if name.lower() in ["gnu", "gcc"]: - return GNUToolchain(arch) - return None +def get_toolchain(name, arch, tooldir): + args = [arch] + if tooldir: args += [tooldir] + + if name.lower() in ["hitachi", "renesas"]: + return HitachiToolchain(*args) + if name.lower() in ["gnu", "gcc"]: + return GNUToolchain(*args) + print("Toolchain '%s' did not exist."%name) diff --git a/tool/Toolchain/base.py b/tool/Toolchain/base.py index b47f945..27b11aa 100755 --- a/tool/Toolchain/base.py +++ b/tool/Toolchain/base.py @@ -1,19 +1,44 @@ #!/usr/bin/env python3 ''' Toolchain base class. ''' +import os + class Toolchain(): arches = [] c_standards = [] cxx_standards = [] lang = {} - def __init__(self, arch = 'sh3'): + def __init__(self, arch = 'sh3', tooldir = ''): ''' Initialize the class. ''' if not arch in self.arches: raise Exception("This arch is not supported by the toolchain.") + self.__tooldir = tooldir self.arch = arch + def getutil(self, utilities): + if self.__tooldir: udirs = [self.__tooldir] + elif 'PATH' in os.environ: udirs = os.environ['PATH'].split(os.pathsep) + else: udirs = [] + + self.util = {} + for name, utils in utilities.items(): + found = False + for util in utils: + for path in udirs: + binpath = os.path.join(path, util) + if os.path.isfile(os.path.join(path, util)): + self.util[name] = os.path.join(path, util) + found = True + break + if found: + break + if not name in self.util: + print(("%s not found, please add the utility directory " + + "in your path,\nor use the `--tooldir` option.") % name) + exit(1) + def cc(self, obj, src, incdirs=[], std='c89'): if not std in self.c_standards: return 1 diff --git a/tool/__main__.py b/tool/__main__.py index 24dcf7c..027ac82 100755 --- a/tool/__main__.py +++ b/tool/__main__.py @@ -20,6 +20,10 @@ if __name__ == '__main__': help='The platform (OS) for which to build.') argparser.add_argument('--modules', dest='modules', default=[], help='The modules to compile.') + argparser.add_argument('--tools', dest='toolchain', default='gnu', + help='The toolchain to use.') + argparser.add_argument('--tooldir', dest='tooldir', default=None, + help='The directory with the toolchain in it.') argparser.add_argument('command', nargs='?', default='build', help='The command to execute.') args = argparser.parse_args() @@ -40,10 +44,10 @@ if __name__ == '__main__': # Clean! if args.command == 'clean': modules = list_modules(mroot, None, '*', globalconfig['default'], []) - try: rmtree('libcarrot.a') - except: True + try: os.remove('libcarrot.a') + except FileNotFoundError: True try: rmtree('include') - except: True + except FileNotFoundError: True for name, module in modules.items(): print("Cleaning '%s'."%(name)) try: rmtree(module.getpath('obj')) @@ -51,7 +55,7 @@ if __name__ == '__main__': exit(0) # Make the commands. - toolchain = get_toolchain('gnu', args.arch) + toolchain = get_toolchain('gnu', args.arch, args.tooldir) ext = { 'cc': toolchain.lang['cc'] if 'cc' in toolchain.lang else [], 'cxx': toolchain.lang['cxx'] if 'cxx' in toolchain.lang else [], @@ -173,11 +177,14 @@ if __name__ == '__main__': ext['cc'] + ext['cxx'] + ext['asmc'] + ext['asm']))] # Make the library. - print('AR %s'%'libcarrot.a') - if toolchain.pack('libcarrot.a', objs): + print('AR %s'%'libcarrot.' + toolchain.lib_ext) + if toolchain.pack('libcarrot.' + toolchain.lib_ext, objs): exit(1) # Install the headers. + print('Making the common include folder.') + try: rmtree('include') + except FileNotFoundError: True for name, module in modules.items(): for inc in module.getfiles('include', ['h', 'hpp', None]): try: os.makedirs(os.path.join('include', os.path.dirname(inc))) |