mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Refactor the build to try and get as much material as possible out of SConstruct.
This commit is contained in:
72
SConstruct
72
SConstruct
@@ -24,8 +24,9 @@ from __future__ import with_statement
|
||||
|
||||
import os
|
||||
|
||||
posixServicesDirectory = "containers/posix/"
|
||||
includeDirectory = 'include'
|
||||
containersDirectory = 'containers'
|
||||
posixServicesDirectory = containersDirectory + '/posix'
|
||||
toolsDirectory = 'tools'
|
||||
cml2ToolsDirectory = toolsDirectory + '/cml2-tools'
|
||||
buildDirectory = 'build'
|
||||
@@ -92,6 +93,12 @@ else :
|
||||
'kernelCompiler': 'arm-none-eabi-gcc',
|
||||
'cpuOption': 'arm926ej-s'}
|
||||
},
|
||||
includeDirectory = includeDirectory,
|
||||
containersDirectory = containersDirectory,
|
||||
posixServicesDirectory = posixServicesDirectory,
|
||||
toolsDirectory = toolsDirectory,
|
||||
cml2ToolsDirectory = cml2ToolsDirectory,
|
||||
buildDirectory = buildDirectory,
|
||||
)
|
||||
|
||||
# It is assumed that the C code is assuming that the configuration file will be found at l4/config.h so create it there.
|
||||
@@ -127,53 +134,43 @@ else :
|
||||
baseEnvironment = configuration.Finish()
|
||||
baseEnvironment.Append(configFiles = ('#' + configHPath,))
|
||||
baseEnvironment['CC'] = baseEnvironment['toolChains'][configuration.env['CPU']]['mainCompiler']
|
||||
##
|
||||
## Using the cpu option changes the behaviour of the test execution, it generates an illegal instruction exception :-(
|
||||
##
|
||||
#baseEnvironment.Append(CCFLAGS = ['-mcpu=' + baseEnvironment['toolChains'][baseEnvironment['CPU']]['cpuOption']])
|
||||
|
||||
########## Build the libraries ########################
|
||||
|
||||
libraryEnvironment = baseEnvironment.Clone()
|
||||
libraryEnvironment.Append(CCFLAGS = '-nostdinc')
|
||||
libraryEnvironment.Append(LIBS = ['gcc'])
|
||||
|
||||
libs = {}
|
||||
crts = {}
|
||||
for variant in ['baremetal']:
|
||||
(libs[variant], crts[variant]) = SConscript('libs/c/SConscript', variant_dir = buildDirectory + '/lib/c/' + variant, duplicate = 0, exports = {'environment': libraryEnvironment, 'variant': variant})
|
||||
(libs[variant], crts[variant]) = SConscript('libs/c/SConscript', variant_dir = buildDirectory + '/lib/c/' + variant, duplicate = 0,
|
||||
exports = {'environment': baseEnvironment, 'variant': variant})
|
||||
|
||||
baseEnvironment['baremetal_libc'] = libs['baremetal']
|
||||
baseEnvironment['baremetal_crt0'] = crts['baremetal']
|
||||
|
||||
libelf = SConscript('libs/elf/SConscript', variant_dir = buildDirectory + '/lib/elf', duplicate = 0, exports = {'environment': libraryEnvironment})
|
||||
libelf = SConscript('libs/elf/SConscript', variant_dir = buildDirectory + '/lib/elf', duplicate = 0, exports = {'environment': baseEnvironment})
|
||||
|
||||
Alias('libs', crts.values() + libs.values() + [libelf])
|
||||
|
||||
########## Build the kernel ########################
|
||||
|
||||
kernelEnvironment = baseEnvironment.Clone()
|
||||
kernelEnvironment['CC'] = baseEnvironment['toolChains'][baseEnvironment['CPU']]['kernelCompiler']
|
||||
kernelEnvironment.Append(LINKFLAGS = ['-T' + includeDirectory + '/l4/arch/' + baseEnvironment['ARCH'] + '/linker.lds'])
|
||||
kernelEnvironment.Append(LIBS = ['gcc'])
|
||||
kernelEnvironment.Append(CPPPATH = ['#' + buildDirectory, '#' + buildDirectory + '/l4', '#' + includeDirectory, '#' + includeDirectory + '/l4'])
|
||||
####
|
||||
#### TODO: Why are these files forcibly included, why not just leave it up to the C code to include things?
|
||||
####
|
||||
kernelEnvironment.Append(CPPFLAGS = ['-include', 'config.h', '-include', 'cml2Config.h', '-include', 'macros.h', '-include', 'types.h', '-D__KERNEL__'])
|
||||
|
||||
startAxf = SConscript('src/SConscript' , variant_dir = buildDirectory + '/kernel' , duplicate = 0, exports = {'environment': kernelEnvironment})
|
||||
startAxf = SConscript('src/SConscript' , variant_dir = buildDirectory + '/kernel' , duplicate = 0, exports = {'environment': baseEnvironment})
|
||||
|
||||
Alias('kernel', startAxf)
|
||||
|
||||
########## Build the task libraries ########################
|
||||
|
||||
taskSupportLibraryEnvironment = baseEnvironment.Clone()
|
||||
taskSupportLibraryEnvironment.Append(LIBS = ['gcc'])
|
||||
taskSupportLibraryEnvironment.Append(CPPPATH = ['#' + buildDirectory, '#' + buildDirectory + '/l4', '#' + includeDirectory])
|
||||
|
||||
taskLibraryNames = [f.name for f in Glob(posixServicesDirectory + 'lib*')]
|
||||
taskLibraryNames = [f.name for f in Glob(posixServicesDirectory + '/lib*')]
|
||||
|
||||
taskLibraries = []
|
||||
for library in taskLibraryNames:
|
||||
taskLibraries.append(SConscript(posixServicesDirectory + library + '/SConscript', variant_dir = buildDirectory + '/' + posixServicesDirectory + library, duplicate = 0, exports = {'environment': taskSupportLibraryEnvironment, 'posixServicesDirectory': posixServicesDirectory}))
|
||||
taskLibraries.append(SConscript(posixServicesDirectory + '/' + library + '/SConscript', variant_dir = buildDirectory + '/' + posixServicesDirectory + '/' + library,
|
||||
duplicate = 0, exports = {'environment': taskSupportLibraryEnvironment}))
|
||||
|
||||
Alias ('tasklibs', taskLibraries)
|
||||
|
||||
@@ -181,8 +178,8 @@ else :
|
||||
|
||||
def buildTask(programName, sources, environment, previousImage, extraCppPath=None):
|
||||
e = environment.Clone()
|
||||
e.Append(LINKFLAGS=['-T' + posixServicesDirectory + programName + '/include/linker.lds'])
|
||||
e.Append(LIBPATH=['#build/' + posixServicesDirectory + programName])
|
||||
e.Append(LINKFLAGS=['-T' + e['posixServicesDirectory'] + '/' + programName + '/include/linker.lds'])
|
||||
e.Append(LIBPATH=['#build/' + e['posixServicesDirectory'] + '/' + programName])
|
||||
if extraCppPath: e.Append(CPPPATH=extraCppPath)
|
||||
objects = e.StaticObject(sources)
|
||||
Depends(objects, e['configFiles'])
|
||||
@@ -195,8 +192,8 @@ else :
|
||||
tasksEnvironment.Append(LIBS = taskLibraries + ['gcc'] + taskLibraries)
|
||||
tasksEnvironment.Append(CPPDEFINES = ['__USERSPACE__'])
|
||||
tasksEnvironment.Append(CPPPATH = ['#' + buildDirectory, '#' + buildDirectory + '/l4', '#' + includeDirectory, 'include', \
|
||||
'#' + posixServicesDirectory + 'libl4/include', '#' + posixServicesDirectory + 'libc/include', \
|
||||
'#' + posixServicesDirectory + 'libmem', '#' + posixServicesDirectory + 'libposix/include'])
|
||||
'#' + posixServicesDirectory + '/libl4/include', '#' + posixServicesDirectory + '/libc/include', \
|
||||
'#' + posixServicesDirectory + '/libmem', '#' + posixServicesDirectory + '/libposix/include'])
|
||||
tasksEnvironment.Append(buildTask = buildTask)
|
||||
|
||||
####
|
||||
@@ -206,14 +203,15 @@ else :
|
||||
|
||||
#### taskNameList = [ f.name for f in Glob(posixServicesDirectory + '*') if f.name not in taskLibraryNames + ['bootdesc'] ]
|
||||
#### imageOrderData = [(taskName, []) for taskName in taskNameList]
|
||||
execfile(posixServicesDirectory + 'taskOrder.py')
|
||||
execfile(posixServicesDirectory + '/taskOrder.py')
|
||||
imageOrderData = [(taskName, []) for taskName in taskOrder]
|
||||
imageOrderData[0][1].append(startAxf)
|
||||
tasks = []
|
||||
for i in range(len(imageOrderData)):
|
||||
taskName = imageOrderData[i][0]
|
||||
dependency = imageOrderData[i][1]
|
||||
program = SConscript(posixServicesDirectory + taskName + '/SConscript', variant_dir = buildDirectory + '/' + posixServicesDirectory + taskName, duplicate = 0, exports = {'environment': tasksEnvironment, 'previousImage': dependency[0], 'posixServicesDirectory':posixServicesDirectory})
|
||||
program = SConscript(posixServicesDirectory + '/' + taskName + '/SConscript', variant_dir = buildDirectory + '/' + posixServicesDirectory + '/' + taskName,
|
||||
duplicate = 0, exports = {'environment': tasksEnvironment, 'previousImage': dependency[0]})
|
||||
tasks.append(program)
|
||||
if i < len(imageOrderData) - 1:
|
||||
imageOrderData[i+1][1].append(program)
|
||||
@@ -222,27 +220,15 @@ else :
|
||||
|
||||
########## Create the boot description ########################
|
||||
|
||||
taskName = 'bootdesc'
|
||||
|
||||
bootdescEnvironment = baseEnvironment.Clone()
|
||||
bootdescEnvironment.Append(LINKFLAGS = ['-T' + posixServicesDirectory + taskName + '/linker.lds'])
|
||||
bootdescEnvironment.Append(LIBS = ['gcc'])
|
||||
bootdescEnvironment.Append(CPPPATH = ['#' + includeDirectory])
|
||||
|
||||
bootdesc = SConscript(posixServicesDirectory + taskName + '/SConscript', variant_dir = buildDirectory + '/' + posixServicesDirectory + taskName, duplicate = 0, exports = {'environment': bootdescEnvironment, 'images': [startAxf] + tasks})
|
||||
bootdesc = SConscript(posixServicesDirectory + '/bootdesc/SConscript', variant_dir = buildDirectory + '/' + posixServicesDirectory + '/bootdesc',
|
||||
duplicate = 0, exports = {'environment': baseEnvironment, 'images': [startAxf] + tasks})
|
||||
|
||||
Alias('bootdesc', bootdesc)
|
||||
|
||||
########## Do the packing / create loadable ########################
|
||||
|
||||
loaderEnvironment = baseEnvironment.Clone()
|
||||
loaderEnvironment.Append(LINKFLAGS = ['-T' + buildDirectory + '/loader/linker.lds'])
|
||||
loaderEnvironment.Append(LIBS = [libelf, libs['baremetal'], 'gcc', libs['baremetal']])
|
||||
loaderEnvironment.Append(CPPPATH = ['#libs/elf/include', '#' + buildDirectory + '/loader'])
|
||||
|
||||
#### TODO: Fix the tasks data structure so as to avoid all the assumptions.
|
||||
|
||||
loader = SConscript('loader/SConscript', variant_dir = buildDirectory + '/loader', duplicate = 0, exports = {'environment': loaderEnvironment, 'images':[startAxf, bootdesc] + tasks, 'posixServicesDirectory': posixServicesDirectory})
|
||||
loader = SConscript('loader/SConscript', variant_dir = buildDirectory + '/loader', duplicate = 0,
|
||||
exports = {'environment': baseEnvironment, 'images': [startAxf, bootdesc] + tasks, 'libsInOrder': [libelf, libs['baremetal'], 'gcc', libs['baremetal']]})
|
||||
|
||||
Alias('final', loader)
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ import shutil
|
||||
|
||||
Import('environment', 'images')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(LINKFLAGS = ['-T' + e['posixServicesDirectory'] + '/bootdesc/linker.lds'])
|
||||
e.Append(CPPPATH = ['#' + e['includeDirectory']])
|
||||
|
||||
bootdescTemplate = \
|
||||
'''
|
||||
/* This file is autogenerated, do not edit by hand. */
|
||||
@@ -85,10 +89,9 @@ def relocateBootdesc(target, source, env):
|
||||
os.system("arm-none-linux-gnueabi-objcopy --adjust-section-vma .data=" + end + " " + source[0].path)
|
||||
shutil.copyfile(source[0].path, target[0].path)
|
||||
|
||||
bootdescSource = environment.Command('bootdesc.c', images, generateBootdesc)
|
||||
objects = environment.Object(bootdescSource)
|
||||
Depends(objects, environment['configFiles'])
|
||||
bootdesc = environment.Command('bootdesc.axf', environment.Program('bootdesc_intermediate', objects) + [images[1]] , relocateBootdesc)
|
||||
Depends(bootdesc, environment['configFiles'])
|
||||
objects = e.Object(e.Command('bootdesc.c', images, generateBootdesc))
|
||||
Depends(objects, e['configFiles'])
|
||||
bootdesc = e.Command('bootdesc.axf', e.Program('bootdesc_intermediate', objects) + [images[1]] , relocateBootdesc)
|
||||
Depends(bootdesc, e['configFiles'])
|
||||
|
||||
Return('bootdesc')
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#
|
||||
# Author: Russel Winder
|
||||
|
||||
Import('environment', 'posixServicesDirectory')
|
||||
Import('environment')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(CPPPATH = ['include', 'include/arch'])
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#
|
||||
# Author: Russel Winder
|
||||
|
||||
Import('environment', 'posixServicesDirectory')
|
||||
Import('environment')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(CPPPATH = ['#' + posixServicesDirectory + 'libl4/include' , '.' ])
|
||||
e.Append(CPPPATH = ['#' + environment['posixServicesDirectory'] + '/libl4/include' , '.' ])
|
||||
|
||||
mmObjects = e.StaticObject(Glob('mm/*.c'))
|
||||
Depends(mmObjects, e['configFiles'])
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#
|
||||
# Author: Russel Winder
|
||||
|
||||
Import('environment', 'posixServicesDirectory')
|
||||
Import('environment')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(CPPPATH = ['include', 'include/posix', '#' + posixServicesDirectory + 'libl4/include'])
|
||||
e.Append(CPPPATH = ['include', 'include/posix', '#' + environment['posixServicesDirectory'] + '/libl4/include'])
|
||||
|
||||
# TODO: There are errors in this code that -Werror gives problems with.
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
#
|
||||
# Author: Russel Winder
|
||||
|
||||
Import('environment', 'previousImage', 'posixServicesDirectory')
|
||||
Import('environment', 'previousImage')
|
||||
|
||||
taskName = 'test0'
|
||||
|
||||
def createTestExecLinkerScript(target, source, env):
|
||||
with open(target[0].path, 'w') as outFile:
|
||||
outFile.write('''
|
||||
outFile.write("""
|
||||
/*
|
||||
* Simple linker script for userspace or svc tasks.
|
||||
*
|
||||
@@ -61,7 +61,7 @@ SECTIONS
|
||||
.bss : AT (ADDR(.bss) - offset) { *(.bss) }
|
||||
_end = .;
|
||||
}
|
||||
''' % ( source[0].path ))
|
||||
""" % ( source[0].path ))
|
||||
|
||||
def createTestExecS(target, source, env):
|
||||
with open(target[0].path, 'w') as outFile:
|
||||
@@ -74,13 +74,13 @@ def createTestExecS(target, source, env):
|
||||
''' % ( source[0].path ))
|
||||
|
||||
testTaskEnvironment = environment.Clone()
|
||||
testTaskEnvironment.Append(CPPPATH=['#' + posixServicesDirectory +'libposix/include/posix'])
|
||||
testExecLinkerScript = Command('#build/' + posixServicesDirectory + taskName + '/include/test_exec_linker.lds', testTaskEnvironment['physicalBaseLinkerScript'], createTestExecLinkerScript)
|
||||
testTaskEnvironment.Append(CPPPATH=['#' + testTaskEnvironment['posixServicesDirectory'] +'/libposix/include/posix'])
|
||||
testExecLinkerScript = Command('#build/' + testTaskEnvironment['posixServicesDirectory'] +'/' + taskName + '/include/test_exec_linker.lds', testTaskEnvironment['physicalBaseLinkerScript'], createTestExecLinkerScript)
|
||||
testExecEnvironment = testTaskEnvironment.Clone()
|
||||
testExecEnvironment.Append(LINKFLAGS=['-T' + testExecLinkerScript[0].path])
|
||||
testExec = testExecEnvironment.Program('test_exec', Glob('src/test_exec/*.[cS]'))
|
||||
Depends(testExec, testExecLinkerScript)
|
||||
testExecS = Command('#build/' + posixServicesDirectory + taskName + '/test_exec.S', testExec, createTestExecS)
|
||||
testExecS = Command('#build/' + testTaskEnvironment['posixServicesDirectory'] + '/' + taskName + '/test_exec.S', testExec, createTestExecS)
|
||||
program = testTaskEnvironment['buildTask'](taskName, Glob('*.c') + Glob('src/*.[cS]') + testExecS, testTaskEnvironment, previousImage)
|
||||
Depends(program, testExec)
|
||||
|
||||
|
||||
@@ -19,16 +19,17 @@
|
||||
|
||||
Import('environment', 'variant')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(CPPPATH = ['include', 'include/sys-' + variant + '/arch-' + environment['ARCH']])
|
||||
e.Append(CCFLAGS = '-nostdinc')
|
||||
|
||||
source = \
|
||||
Glob('src/*.c') + \
|
||||
Glob('src/sys-' + variant + '/*.c') + \
|
||||
Glob('src/sys-' + variant + '/arch-' + environment['ARCH'] + '/*.c') + \
|
||||
Glob('src/sys-' + variant + '/arch-' + environment['ARCH'] + '/plat-' + environment['PLATFORM'] + '/*.c') + \
|
||||
Glob('src/arch-' + environment['ARCH'] + '/*.c') + \
|
||||
Glob('src/arch-' + environment['ARCH'] + '/*.S')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(CPPPATH = ['include', 'include/sys-' + variant + '/arch-' + environment['ARCH']])
|
||||
Glob('src/sys-' + variant + '/arch-' + e['ARCH'] + '/*.c') + \
|
||||
Glob('src/sys-' + variant + '/arch-' + e['ARCH'] + '/plat-' + e['PLATFORM'] + '/*.c') + \
|
||||
Glob('src/arch-' + e['ARCH'] + '/*.c') + \
|
||||
Glob('src/arch-' + e['ARCH'] + '/*.S')
|
||||
|
||||
objects = e.StaticObject(source)
|
||||
Depends (objects, e['configFiles'])
|
||||
|
||||
@@ -21,6 +21,7 @@ Import('environment')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(CPPPATH = ['include', '#libs/c/include', '#libs/c/include/arch/' + e['ARCH']])
|
||||
e.Append(CCFLAGS = '-nostdinc')
|
||||
|
||||
objects = e.StaticObject(Glob('src/*.c'))
|
||||
Depends(objects, e['configFiles'])
|
||||
|
||||
@@ -20,7 +20,12 @@
|
||||
import os.path
|
||||
import subprocess
|
||||
|
||||
Import('environment', 'images', 'posixServicesDirectory')
|
||||
Import('environment', 'images', 'libsInOrder')
|
||||
|
||||
e = environment.Clone()
|
||||
e.Append(LINKFLAGS = ['-T' + e['buildDirectory'] + '/loader/linker.lds'])
|
||||
e.Append(LIBS = libsInOrder)
|
||||
e.Append(CPPPATH = ['#libs/elf/include', '#' + e['buildDirectory'] + '/loader'])
|
||||
|
||||
def convertAddress(address):
|
||||
'''Convert the string representation of the address given as parameter to a string representation of the
|
||||
@@ -129,10 +134,10 @@ linkerScript = Command('linker.lds', ['linker.lds.in'] + images, createLinkerScr
|
||||
|
||||
## TODO: deal with the situation where there are other .c and .S files in the directory.
|
||||
|
||||
objects = environment.Object(['arch.c' , kernelS, startAxfS, mainC])
|
||||
Depends(objects, environment['configFiles'])
|
||||
objects = e.Object(['arch.c' , kernelS, startAxfS, mainC])
|
||||
Depends(objects, e['configFiles'])
|
||||
Depends(objects, images)
|
||||
program = environment.Program('final', objects + [environment['baremetal_crt0']])
|
||||
program = e.Program('final', objects + [e['baremetal_crt0']])
|
||||
Depends(program, linkerScript)
|
||||
|
||||
Return('program')
|
||||
|
||||
@@ -21,26 +21,36 @@ import os.path
|
||||
|
||||
Import('environment')
|
||||
|
||||
e = environment.Clone()
|
||||
e['CC'] = e['toolChains'][e['CPU']]['kernelCompiler']
|
||||
e.Append(CPPPATH = ['#' + e['buildDirectory'], '#' + e['buildDirectory'] + '/l4', '#' + e['includeDirectory'], '#' + e['includeDirectory'] + '/l4'])
|
||||
e.Append(LINKFLAGS = ['-T' + e['includeDirectory'] + '/l4/arch/' + e['ARCH'] + '/linker.lds'])
|
||||
####
|
||||
#### TODO: Why are these files forcibly included, why not just leave it up to the C code to include things?
|
||||
####
|
||||
e.Append(CPPFLAGS = ['-include', 'config.h', '-include', 'cml2Config.h', '-include', 'macros.h', '-include', 'types.h', '-D__KERNEL__'])
|
||||
e.Append(LIBS = ['gcc'])
|
||||
|
||||
sources = \
|
||||
Glob('api/*.[cS]') + \
|
||||
Glob('generic/*.[cS]') + \
|
||||
Glob('lib/*.[cS]') + \
|
||||
Glob('arch/' + environment['ARCH'] + '/*.[cS]') + \
|
||||
Glob('arch/' + environment['ARCH'] + '/' + environment['SUBARCH'] +'/*.[cS]') + \
|
||||
Glob('glue/' + environment['ARCH'] + '/*.[cS]') + \
|
||||
Glob('platform/' + environment['PLATFORM'] + '/*.[cS]')
|
||||
Glob('arch/' + e['ARCH'] + '/*.[cS]') + \
|
||||
Glob('arch/' + e['ARCH'] + '/' + e['SUBARCH'] +'/*.[cS]') + \
|
||||
Glob('glue/' + e['ARCH'] + '/*.[cS]') + \
|
||||
Glob('platform/' + e['PLATFORM'] + '/*.[cS]')
|
||||
|
||||
for item in environment['DRIVER'] :
|
||||
for item in e['DRIVER'] :
|
||||
path = 'drivers/' + item
|
||||
if not os.path.isdir(path):
|
||||
feature , device = item.split ( '/' )
|
||||
raise ValueError, 'Driver ' + device + ' for ' + feature + ' not available.'
|
||||
sources += Glob(path + '/*.[cS]')
|
||||
|
||||
objects = environment.Object(sources)
|
||||
Depends(objects, environment['configFiles'])
|
||||
objects = e.Object(sources)
|
||||
Depends(objects, e['configFiles'])
|
||||
|
||||
startAxf = environment.Program('start.axf', objects)
|
||||
Depends(startAxf, environment['configFiles'])
|
||||
startAxf = e.Program('start.axf', objects)
|
||||
Depends(startAxf, e['configFiles'])
|
||||
|
||||
Return('startAxf')
|
||||
|
||||
Reference in New Issue
Block a user