Skip to content

Commit

Permalink
WIP (#192): Migrate to scons build tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
I-mikan-I committed Mar 5, 2024
1 parent 8bec9db commit e623a06
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Sconstruct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from pathlib import Path
import os

def find_benchmarks(bd):
dir_iter = Path('src').iterdir()
return [bench for bench in dir_iter if bench.is_dir()]

def parse_options():
AddOption('--build-dir', nargs=1, type='string', default='bd')
AddOption('--config-dir', nargs=1, type='string', default='config2')
config_dir = Path(GetOption('config_dir'))

vars = Variables(config_dir / 'config.py', ARGUMENTS)
vars.Add('cc', default=env['CC'])
vars.Add('cflags', default=env['CCFLAGS'])
vars.Add('ld', default=env['LINK'])
vars.Add('ldflags', default=env['LINKFLAGS'])
vars.Add('user_libs', default=[])
vars.Add('warmup_heat', default=1)
vars.Add('cpu_mhz', default=1)
return vars

def setup_directories(bd, config_dir):
VariantDir(bd / "src", "src")
VariantDir(bd / "support", "support")
VariantDir(bd / "config", config_dir)
SConsignFile(bd / ".sconsign.dblite")

def populate_build_env(env, vars):
vars.Update(env)
env.Append(CPPDEFINES={ 'WARMUP_HEAT' : '${warmup_heat}',
'CPU_MHZ' : '${cpu_mhz}'})
env.Append(CPPPATH=['support', config_dir])
env.Replace(CCFLAGS = "${cflags}")
env.Replace(LINKFLAGS = "${ldflags}")
env.Replace(CC = "${cc}")
env.Replace(LINK = "${ld}")
env.Prepend(LIBS = "${user_libs}")

def build_support_objects(env):
support_objects = []
support_objects += env.Object(str(bd / 'support/main.c'))
support_objects += env.Object(str(bd / 'support/beebsc.c'))
support_objects += env.Object(str(bd / 'config/boardsupport.c'))
env.Default(support_objects)
return support_objects


# MAIN BUILD SCRIPT
env = DefaultEnvironment()
vars = parse_options()

bd = Path(GetOption('build_dir'))
config_dir = Path(GetOption('config_dir'))

setup_directories(bd, config_dir)
populate_build_env(env, vars)

# Setup Help Text
env.Help("\nCustomizable Variables:", append=True)
env.Help(vars.GenerateHelpText(env), append=True)

support_objects = build_support_objects(env)
benchmark_paths = find_benchmarks(bd)

benchmark_objects = {
(bd / bench / bench.name): env.Object(Glob(str(bd / bench / "*.c")))

for bench in benchmark_paths
}
env.Default(benchmark_objects.values())

for benchname, objects in benchmark_objects.items():
bench_exe = env.Program(str(benchname), objects + support_objects)
env.Default(bench_exe)

# call user script
SConscript(config_dir / "SConscript.py", exports='env')
3 changes: 3 additions & 0 deletions config2/SConscript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Import('env')

#print([str(s) for s in BUILD_TARGETS])
24 changes: 24 additions & 0 deletions config2/boardsupport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (C) 2019 Clemson University
Contributor Ola Jeppsson <[email protected]>
This file is part of Embench.
SPDX-License-Identifier: GPL-3.0-or-later */

#include <support.h>

void
initialise_board ()
{
}

void __attribute__ ((noinline)) __attribute__ ((externally_visible))
start_trigger ()
{
}

void __attribute__ ((noinline)) __attribute__ ((externally_visible))
stop_trigger ()
{
}
9 changes: 9 additions & 0 deletions config2/boardsupport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Copyright (C) 2019 Clemson University
Contributor Ola Jeppsson <[email protected]>
This file is part of Embench.
SPDX-License-Identifier: GPL-3.0-or-later */

#define CPU_MHZ 1
68 changes: 68 additions & 0 deletions config2/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Chip configuration for Baseline RISC-V Configuration
#
# Copyright (C) 2019 Embecosm Limited and the University of Bristol
#
# Contributor Graham Markall <[email protected]>
# Contributor Jeremy Bennett <[email protected]>
# Contributor Ola Jeppsson <[email protected]>
#
# This file is part of Embench.
#
# SPDX-License-Identifier: GPL-3.0-or-later

# This is a python setting of parameters for the chip. The following
# parameters may be set (other keys are silently ignored). Defaults are shown
# in brackets
# - cc ('cc')
# - ld (same value as for cc)
# - cflags ([])
# - ldflags ([])
# - cc_define_pattern ('-D{0}')
# - cc_incdir_pattern ('-I{0}')
# - cc_input_pattern ('{0}')
# - cc_output_pattern ('-o {0}')
# - ld_input_pattern ('{0}')
# - ld_output_pattern ('-o {0}')
# - user_libs ([])
# - dummy_libs ([])
# - cpu_mhz (1)
# - warmup_heat (1)

# The "flags" and "libs" parameters (cflags, ldflags, user_libs, dummy_libs)
# should be lists of arguments to be passed to the compile or link line as
# appropriate. Patterns are Python format patterns used to create arguments.
# Thus for GCC or Clang/LLVM defined constants can be passed using the prefix
# '-D', and the pattern '-D{0}' would be appropriate (which happens to be the
# default).

# "user_libs" may be absolute file names or arguments to the linker. In the
# latter case corresponding arguments in ldflags may be needed. For example
# with GCC or Clang/LLVM is "-l" flags are used in "user_libs", the "-L" flags
# may be needed in "ldflags".

# Dummy libs have their source in the "support" subdirectory. Thus if 'crt0'
# is specified, there should be a source file 'dummy-crt0.c' in the support
# directory.

# There is no need to set an unused parameter, and this file may be empty to
# set no flags.

# Parameter values which are duplicated in architecture, board, chip or
# command line are used in the following order of priority
# - default value
# - architecture specific value
# - chip specific value
# - board specific value
# - command line value

# For flags, this priority is applied to individual flags, not the complete
# list of flags.

cflags = [
'-c', '-O2', '-fdata-sections', '-ffunction-sections'
]
ldflags = [
'-O2', '-Wl,-gc-sections'
]
user_libs = ['m']
dummy_benchmark = 'dummy-benchmark'

0 comments on commit e623a06

Please sign in to comment.