diff options
author | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-05-11 23:11:19 +0200 |
---|---|---|
committer | Thomas "Cakeisalie5" Touhey <thomas@touhey.fr> | 2017-05-11 23:11:19 +0200 |
commit | 2ffb713f84dbd740e213b156eb9a513a7ea8f05b (patch) | |
tree | 47e9443820b90f01c26a7a6f448e45c2dab1e296 | |
parent | c931c4c650cce03209b16bf8c128a549aff8295c (diff) |
Library is generated!
-rw-r--r-- | .editorconfig | 19 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | arch/casiowin/config.yml | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | tool/Module.py | 16 | ||||
-rwxr-xr-x[-rw-r--r--] | tool/Toolchain/GNU.py | 9 | ||||
-rwxr-xr-x[-rw-r--r--] | tool/Toolchain/Hitachi.py | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | tool/Toolchain/__init__.py | 14 | ||||
-rwxr-xr-x[-rw-r--r--] | tool/Toolchain/base.py | 4 | ||||
-rwxr-xr-x | tool/__main__.py | 287 |
9 files changed, 215 insertions, 140 deletions
diff --git a/.editorconfig b/.editorconfig index 36b1d27..d1b1264 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,20 +2,15 @@ root = true # Unix-style newlines with a newline ending every file. +# Also, tabulations for all source files. [*] +charset = utf-8 end_of_line = lf insert_final_newline = true - -# Okay, not for Makefiles, because of Hmake. -[Makefile*] -end_of_line = crlf -[build/*] -end_of_line = crlf - -# TABULATIONS. -# Sorry to all the people who like spaces, but here, we use tabulations. -# But yeah, this is inspired from my (Cakeisalie5) coding style, and -# I use tabulations for reasons. Please don't hate me for this. -[*] indent_style = tab indent_size = 4 + +# Actually, not for Python files. +[*.py] +indent_style = space +indent_size = 4 @@ -1,4 +1,5 @@ /Makefile.cfg +/include /lib*.a # that's for modules diff --git a/arch/casiowin/config.yml b/arch/casiowin/config.yml index 78093e9..4cb37c8 100644 --- a/arch/casiowin/config.yml +++ b/arch/casiowin/config.yml @@ -1,2 +1,3 @@ version: potatosdk-1.0 arch: ['sh3', 'sh4a'] +main: ['casiowin/fxlib-libc'] diff --git a/tool/Module.py b/tool/Module.py index c0764e7..c731477 100644..100755 --- a/tool/Module.py +++ b/tool/Module.py @@ -78,10 +78,14 @@ def list_modules(root, arch, platform = None, default={}, module_names=[]): # List the main directories if not module_names or type(module_names) != list: # Get subdirectories to discover. - subdirs = ['all'] - if platform and platform != 'all' \ - and os.path.isdir(os.path.join(root, platform)): - subdirs += [platform] + if platform == '*': + subdirs = [i for i in os.listdir(root) \ + if os.path.isdir(os.path.join(root, i))] + else: + subdirs = ['all'] + if platform and platform != 'all' \ + and os.path.isdir(os.path.join(root, platform)): + subdirs += [platform] # Find the main modules module_names = [] @@ -94,14 +98,14 @@ def list_modules(root, arch, platform = None, default={}, module_names=[]): # Remove things with unsupported architecture for name in module_names: module = SourceModule(root, name) - if module.arch and not arch in module.arch: + if arch and module.arch and not arch in module.arch: module_names.remove(name) # Gather the modules. modules = {} for name in module_names: module = SourceModule(root, name, default) - if module.arch and not arch in module.arch: + if arch and module.arch and not arch in module.arch: continue for dep in module.deps: if not dep in module_names: diff --git a/tool/Toolchain/GNU.py b/tool/Toolchain/GNU.py index 6425ef3..530aaa5 100644..100755 --- a/tool/Toolchain/GNU.py +++ b/tool/Toolchain/GNU.py @@ -3,7 +3,7 @@ import os, platform from subprocess import call -from Toolchain.base import Toolchain +from .base import Toolchain class GNUToolchain(Toolchain): # Supported arches and standards @@ -89,5 +89,8 @@ class GNUToolchain(Toolchain): return call(commandline) - def direct__ar(self, lib, objs): - call(['ar', 'rcs', lib, *objs]) + def direct__pack(self, lib, objs): + commandline = ['sh3eb-elf-ar'] + commandline += ['rcs', lib, *objs] + + return call(commandline) diff --git a/tool/Toolchain/Hitachi.py b/tool/Toolchain/Hitachi.py index f34790c..dcc83e5 100644..100755 --- a/tool/Toolchain/Hitachi.py +++ b/tool/Toolchain/Hitachi.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 ''' Renesas/Hitachi toolchain. ''' -from Toolchain.base import Toolchain import os from subprocess import call from tempfile import mkstemp +from .base import Toolchain class HitachiToolchain(): arches = ['sh1', 'sh2', 'sh2e', 'sh2a', 'sh2afpu', 'sh2dsp', 'sh3', @@ -80,7 +80,7 @@ class HitachiToolchain(): os.remove(tmpinfo[1]) return ret - def direct__ar(self, lib, objs): + def direct__pack(self, lib, objs): # Make the temporary thing with all of the subcommands. tmpinfo = mkstemp() tmp = os.fdopen(tmpinfo[1]) diff --git a/tool/Toolchain/__init__.py b/tool/Toolchain/__init__.py index 0cb03ce..808cdc7 100644..100755 --- a/tool/Toolchain/__init__.py +++ b/tool/Toolchain/__init__.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 -#from Toolchain.Hitachi import HitachiToolchain -from Toolchain.GNU import GNUToolchain +#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 + if name.lower() in ["hitachi", "renesas"]: + return HitachiToolchain(arch) + if name.lower() in ["gnu", "gcc"]: + return GNUToolchain(arch) + return None diff --git a/tool/Toolchain/base.py b/tool/Toolchain/base.py index b5adac7..b47f945 100644..100755 --- a/tool/Toolchain/base.py +++ b/tool/Toolchain/base.py @@ -33,3 +33,7 @@ class Toolchain(): def asm(self, obj, src): try: self.direct__asmc(obj, src) except: return 1 + + def pack(self, lib, objs): + try: self.direct__pack(lib, objs) + except: return 1 diff --git a/tool/__main__.py b/tool/__main__.py index 4b68b64..24dcf7c 100755 --- a/tool/__main__.py +++ b/tool/__main__.py @@ -3,121 +3,188 @@ import os import yaml +from argparse import ArgumentParser +from shutil import rmtree, copyfile from Module import list_modules from Toolchain import get_toolchain -# User interface. -arch = 'sh4a' -module_names = ['all/sh-intrinsic'] - -# Open the main configuration -root = os.path.join(os.path.dirname(__file__), '..') -globalconfig = yaml.load(open(os.path.join(root, "config.yml")).read()) -if 'arch' in globalconfig and not arch in globalconfig['arch']: - print("Unsupported arch for libcarrot") - exit(0) - -# Make the commands. -toolchain = get_toolchain('gnu', arch) - -# List the modules -mroot = os.path.normpath(os.path.join(root, globalconfig['modules'])) -modules = list_modules(mroot, arch, - default=globalconfig['default'], platform='casiowin') -if not modules: - print('No modules, check that your config is correct.') - exit(1) - -for name, module in modules.items(): - # C files - for source in module.getfiles('src', toolchain.lang['cc']): - objpath = module.getpath('obj', source + '.o') - - incdirs = [] - objmtime = os.path.getmtime(objpath) if os.path.exists(objpath) else -1 - depmtime = os.path.getmtime(module.getpath('src', source)) - for nam, md in [(name, module)]+[(i, modules[i]) for i in module.deps]: - files = [md.getpath('include', i) \ - for i in md.getfiles('include', ['h'])] - if files: - incdirs.append(md.getpath('include')) - maxmtimes = [os.path.getmtime(f) for f in files] - depmtime = max(depmtime, *maxmtimes) - - if objmtime < depmtime: - # Make the object directory. - try: os.makedirs(os.path.dirname(objpath)) +if __name__ == '__main__': + # User interface. + __prog_description__ = \ + 'Specify the libcarrot modules to build, and build them.' + + argparser = ArgumentParser(prog='tool', description=__prog_description__) + argparser.add_argument('--arch', dest='arch', default='sh4a', + help='The architecture for which to build.') + argparser.add_argument('--platform', dest='platform', default='casiowin', + help='The platform (OS) for which to build.') + argparser.add_argument('--modules', dest='modules', default=[], + help='The modules to compile.') + argparser.add_argument('command', nargs='?', default='build', + help='The command to execute.') + args = argparser.parse_args() + + # Check for unknown command. + if not args.command in ['build', 'clean']: + print("Unknown command '%s'."%(args.command)) + exit(1) + + # Open the main configuration + root = os.path.join(os.path.dirname(__file__), '..') + globalconfig = yaml.load(open(os.path.join(root, "config.yml")).read()) + if 'arch' in globalconfig and not args.arch in globalconfig['arch']: + print("Unsupported arch for libcarrot") + exit(0) + mroot = os.path.normpath(os.path.join(root, globalconfig['modules'])) + + # Clean! + if args.command == 'clean': + modules = list_modules(mroot, None, '*', globalconfig['default'], []) + try: rmtree('libcarrot.a') + except: True + try: rmtree('include') + except: True + for name, module in modules.items(): + print("Cleaning '%s'."%(name)) + try: rmtree(module.getpath('obj')) + except FileNotFoundError: True + exit(0) + + # Make the commands. + toolchain = get_toolchain('gnu', args.arch) + ext = { + 'cc': toolchain.lang['cc'] if 'cc' in toolchain.lang else [], + 'cxx': toolchain.lang['cxx'] if 'cxx' in toolchain.lang else [], + 'asmc': toolchain.lang['asmc'] if 'asmc' in toolchain.lang else [], + 'asm': toolchain.lang['asm'] if 'asm' in toolchain.lang else []} + + # List the modules + modules = list_modules(mroot, args.arch, args.platform, + default=globalconfig['default'], module_names=args.modules) + if not modules: + print('No modules, check that your config is correct.') + exit(1) + + for name, module in modules.items(): + # C files + for source in module.getfiles('src', ext['cc']): + objpath = module.getpath('obj', source + '.o') + + incdirs = [] + if not os.path.exists(objpath): objmtime = -1 + else: objmtime = os.path.getmtime(objpath) + depmtime = os.path.getmtime(module.getpath('src', source)) + mods = [(name, module)] + [(i, modules[i]) for i in module.deps] + for nam, md in mods: + files = [md.getpath('include', i) \ + for i in md.getfiles('include', ['h'])] + if files: + incdirs.append(md.getpath('include')) + maxmtimes = [os.path.getmtime(f) for f in files] + depmtime = max(depmtime, *maxmtimes) + + if objmtime < depmtime: + # Make the object directory. + try: os.makedirs(os.path.dirname(objpath)) + except FileExistsError: True + + # Do the command. + print('[%s] CC %s'%(name, source)) + srcfile = module.getpath('src', source) + if toolchain.cc(objpath, srcfile, incdirs): + exit(1) + + # C++ files + for source in module.getfiles('src', ext['cxx']): + objpath = module.getpath('obj', source + '.o') + + incdirs = [] + if not os.path.exists(objpath): objmtime = -1 + else: objmtime = os.path.getmtime(objpath) + depmtime = os.path.getmtime(module.getpath('src', source)) + mods = [(name, module)] + [(i, modules[i]) for i in module.deps] + for nam, md in mods: + files = [md.getpath('include', i) \ + for i in md.getfiles('include', ['h', 'hpp', None])] + if files: + incdirs.append(md.getpath('include')) + maxmtimes = [os.path.getmtime(f) for f in files] + depmtime = max(depmtime, *maxmtimes) + + if objmtime < depmtime: + # Make the object directory. + try: os.makedirs(os.path.dirname(objpath)) + except FileExistsError: True + + # Do the command. + print('[%s] CXX %s'%(name, source)) + srcfile = module.getpath('src', source) + if toolchain.cxx(objpath, srcfile, incdirs): + exit(1) + + # Assembly with C preprocessor + for source in module.getfiles('src', ext['asmc']): + objpath = module.getpath('obj', source + '.o') + + incdirs = [] + if not os.path.exists(objpath): objmtime = -1 + else: objmtime = os.path.getmtime(objpath) + depmtime = os.path.getmtime(module.getpath('src', source)) + mods = [(name, module)] + [(i, modules[i]) for i in module.deps] + for nam, md in mods: + files = [md.getpath('include', i) \ + for i in md.getfiles('include', ['h'])] + if files: + incdirs.append(md.getpath('include')) + maxmtimes = [os.path.getmtime(f) for f in files] + depmtime = max(depmtime, *maxmtimes) + + if objmtime < depmtime: + # Make the object directory. + try: os.makedirs(os.path.dirname(objpath)) + except FileExistsError: True + + # Do the command. + print('[%s] ASMC %s'%(name, source)) + srcfile = module.getpath('src', source) + if toolchain.asmc(objpath, srcfile, incdirs): + exit(1) + + # Assembly + for source in module.getfiles('src', ext['asm']): + objpath = module.getpath('obj', source + '.o') + if not os.path.exists(objpath): objmtime = -1 + else: objmtime = os.path.getmtime(objpath) + if objmtime < os.path.getmtime(module.getpath('src', source)): + # Make the object directory. + try: os.makedirs(os.path.dirname(objpath)) + except FileExistsError: True + + # Do the command. + print('[%s] ASM %s'%(name, source)) + if toolchain.asm(objpath, module.getpath('src', source)): + exit(1) + + # Get the objects. + objs = [] + for name, module in modules.items(): + objs += [*map(lambda x:module.getpath('obj', x + '.o'), + module.getfiles('src', + ext['cc'] + ext['cxx'] + ext['asmc'] + ext['asm']))] + + # Make the library. + print('AR %s'%'libcarrot.a') + if toolchain.pack('libcarrot.a', objs): + exit(1) + + # Install the headers. + 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))) except FileExistsError: True - # Do the command. - print('[%s] CC %s'%(name, source)) - if toolchain.cc(objpath, module.getpath('src', source), incdirs): - exit(1) - - # C++ files - for source in module.getfiles('src', toolchain.lang['cxx']): - objpath = module.getpath('obj', source + '.o') - - incdirs = [] - objmtime = os.path.getmtime(objpath) if os.path.exists(objpath) else -1 - depmtime = os.path.getmtime(module.getpath('src', source)) - for nam, md in [(name, module)]+[(i, modules[i]) for i in module.deps]: - files = [md.getpath('include', i) \ - for i in md.getfiles('include', ['h', 'hpp', None])] - if files: - incdirs.append(md.getpath('include')) - maxmtimes = [os.path.getmtime(f) for f in files] - depmtime = max(depmtime, *maxmtimes) - - if objmtime < depmtime: - # Make the object directory. - try: os.makedirs(os.path.dirname(objpath)) + try: copyfile(module.getpath('include', inc), \ + os.path.join('include', inc)) except FileExistsError: True - # Do the command. - print('[%s] CXX %s'%(name, source)) - if toolchain.cxx(objpath, module.getpath('src', source), incdirs): - exit(1) - - # Assembly with C preprocessor - for source in module.getfiles('src', toolchain.lang['asmc']): - objpath = module.getpath('obj', source + '.o') - - incdirs = [] - objmtime = os.path.getmtime(objpath) if os.path.exists(objpath) else -1 - depmtime = os.path.getmtime(module.getpath('src', source)) - for nam, md in [(name, module)]+[(i, modules[i]) for i in module.deps]: - files = [md.getpath('include', i) \ - for i in md.getfiles('include', ['h'])] - if files: - incdirs.append(md.getpath('include')) - maxmtimes = [os.path.getmtime(f) for f in files] - depmtime = max(depmtime, *maxmtimes) - - if objmtime < depmtime: - # Make the object directory. - try: os.makedirs(os.path.dirname(objpath)) - except FileExistsError: True - - # Do the command. - print('[%s] ASMC %s'%(name, source)) - if toolchain.asmc(objpath, module.getpath('src', source), incdirs): - exit(1) - - # Assembly - for source in module.getfiles('asm', toolchain.lang['asm']): - objpath = module.getpath('obj', source + '.o') - objmtime = os.path.getmtime(objpath) if os.path.exists(objpath) else -1 - if objmtime < os.path.getmtime(module.getpath('src', source)): - # Make the object directory. - try: os.makedirs(os.path.dirname(objpath)) - except: FileExistsError: True - - # Do the command. - print('[%s] ASM %s'%(name, source)) - if toolchain.asm(objpath, module.getpath('src', source)): - exit(1) - -exit(0) - # End of file. |