2020-09-17 19:27:01 +02:00
|
|
|
#! /bin/bash
|
2020-10-24 21:48:45 +02:00
|
|
|
# Fx C standard library configuration script
|
2020-09-17 19:27:01 +02:00
|
|
|
|
|
|
|
# output file
|
|
|
|
confile='fxlibc.cfg'
|
|
|
|
|
|
|
|
# Build options
|
|
|
|
toolchain=sh-elf
|
|
|
|
prefix=
|
|
|
|
cflags=
|
|
|
|
|
|
|
|
# wanted Makefile
|
|
|
|
makefile='Makefile.default'
|
|
|
|
|
|
|
|
# configuration
|
2020-10-11 10:15:34 +02:00
|
|
|
debug=false
|
|
|
|
|
|
|
|
# ABI support
|
|
|
|
support_vhex_kernel=false
|
|
|
|
support_casio_abi_fx9860=false
|
|
|
|
support_casio_abi_fxcg50=false
|
|
|
|
|
|
|
|
# format
|
|
|
|
format_static=false
|
|
|
|
format_dynamic=false
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
# Help screen
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
help()
|
|
|
|
{
|
|
|
|
cat << EOF
|
2020-10-07 11:37:54 +02:00
|
|
|
Configuration script for the fx calculator standard C library.
|
2020-09-17 19:27:01 +02:00
|
|
|
Usage: $0 [OPTION]...
|
|
|
|
|
|
|
|
You should build out-of-tree by creating a build directory and configuring from
|
|
|
|
there.
|
|
|
|
|
|
|
|
Debug the fxlibc
|
2020-10-07 11:37:54 +02:00
|
|
|
--debug Enable valgrind flags (-g3)
|
|
|
|
--unit-test Check C-functoon validity with Criterion
|
2020-09-17 19:27:01 +02:00
|
|
|
|
|
|
|
Build options:
|
2020-10-07 11:37:54 +02:00
|
|
|
--toolchain=TRIPLET Build with a different toolchain
|
|
|
|
[sh-elf-gcc] (or [gcc] when the '--unit_test' flag is set)
|
|
|
|
--cflags=FLAGS Additional compiler flags at end of command
|
|
|
|
--prefix=PREFIX Install prefix (PREFIX/lib and PREFIX/include are used)
|
2020-09-17 19:27:01 +02:00
|
|
|
|
|
|
|
ABI support:
|
2020-10-24 21:48:45 +02:00
|
|
|
--support=<target>,<target>, ...
|
|
|
|
Support all <target> ABI if supported by the library.
|
2020-10-07 11:37:54 +02:00
|
|
|
|
2020-10-24 21:48:45 +02:00
|
|
|
target-list:
|
|
|
|
* vhex
|
|
|
|
Enable the Vhex kernel support
|
|
|
|
* fx9860g, fxcg50
|
|
|
|
Enable the support of the Casio' ABI
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2020-10-24 21:48:45 +02:00
|
|
|
fx9860 covers all fx-9860G II-like monochromes models that support
|
|
|
|
addins or can be flashed with an OS that does. This includes SH3 and
|
|
|
|
SH4 machines.
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2020-10-24 21:48:45 +02:00
|
|
|
fxcg50 covers just the fx-CG 50; there is some unofficial compatibility
|
|
|
|
with fx-CG 10/20. All of these are SH4-only.
|
|
|
|
|
|
|
|
The 'ABI support' is used to allow some part of the code, in particular the
|
|
|
|
'unistd' part, I/O management and additionals feature. (like process, fs, ...).
|
2020-09-17 19:27:01 +02:00
|
|
|
|
|
|
|
Format:
|
2020-10-11 10:15:34 +02:00
|
|
|
--static Generate static libraries (default)
|
|
|
|
--dynamic Generate dynamic libraries (Vhex kernel dependant)
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
Little note for the generation of dynamic libraries. The superH toolchain currently
|
|
|
|
used (GCC) does not support the '--shared' flags when the archive is build. So we
|
|
|
|
need to create manually an archive that can be used like a shared library.
|
2020-09-17 19:27:01 +02:00
|
|
|
|
|
|
|
To do this we need to do several steps:
|
|
|
|
1) build the sources with the PIE mode as if it were a executable without entry point.
|
|
|
|
2) manually extract symbols defined as 'global' from the generated ELF.
|
2020-10-07 11:37:54 +02:00
|
|
|
3) we create "stubs": functions that will have the same name than the wanted shared
|
|
|
|
libraries and will call internal VHEX loader primitives with the libraries
|
|
|
|
name, function address and size, etc....Then the loader will load the shared
|
|
|
|
function and override the "user function (stub)" to force it to jump into
|
|
|
|
the "real" function (trampoline).
|
|
|
|
4) all generated stubs will be compiled and linked through a static lib that SHOULD
|
|
|
|
be used in the user program which uses the "dynamic library"
|
2020-09-17 19:27:01 +02:00
|
|
|
EOF
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2020-10-24 21:48:45 +02:00
|
|
|
#---
|
|
|
|
# Check early help options
|
|
|
|
#---
|
2020-10-27 12:03:10 +01:00
|
|
|
if [[ $# -eq 1 ]] && [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then
|
2020-10-26 19:01:16 +01:00
|
|
|
help
|
2020-10-24 21:48:45 +02:00
|
|
|
fi
|
|
|
|
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2020-10-11 10:15:34 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
# Check mandatory build location
|
|
|
|
# @note:
|
|
|
|
# * You should build out-of-tree by creating a build directory and configuring
|
|
|
|
# from there.
|
2020-10-11 10:15:34 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
if [ -f 'make/Makefile.default' ]; then
|
2020-10-07 11:37:54 +02:00
|
|
|
echo 'error: you should configure from a build directory, like this:' >&2
|
|
|
|
echo ' mkdir build && cd build && ../configure [options..]' >&2
|
2020-09-17 19:27:01 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-10-11 10:15:34 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
# Parsing arguments
|
2020-10-11 10:15:34 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
for arg; do case "$arg" in
|
2020-10-26 19:01:16 +01:00
|
|
|
# Help options
|
2020-10-07 11:37:54 +02:00
|
|
|
--help | -h)
|
2020-09-17 19:27:01 +02:00
|
|
|
help;;
|
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
# debug options
|
2020-09-17 19:27:01 +02:00
|
|
|
--debug)
|
2020-10-11 10:15:34 +02:00
|
|
|
debug=true;;
|
2020-09-17 19:27:01 +02:00
|
|
|
--unit-test)
|
|
|
|
makefile='Malefile.unitest';;
|
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
# build options
|
2020-09-17 19:27:01 +02:00
|
|
|
--toolchain=*)
|
|
|
|
toolchain=${arg#*=};;
|
|
|
|
--prefix=*)
|
|
|
|
prefix=${arg#*=};;
|
|
|
|
--cflags=*)
|
|
|
|
cflags=${arg#*=};;
|
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
# ABI support
|
2020-10-24 21:48:45 +02:00
|
|
|
--support=*)
|
|
|
|
IFS=',' read -ra target_abi <<< "${arg#*=}"
|
|
|
|
for abi in "${target_abi[@]}"; do case "$abi" in
|
|
|
|
all)
|
|
|
|
support_vhex_kernel=true
|
|
|
|
support_casio_abi_fx9860=true
|
|
|
|
support_casio_abi_fxcg50=true;;
|
|
|
|
vhex)
|
|
|
|
support_vhex_kernel=true;;
|
|
|
|
fx9860g)
|
|
|
|
support_casio_abi_fx9860=true;;
|
|
|
|
fxcg50)
|
|
|
|
support_casio_abi_fxcg50=true;;
|
|
|
|
*)
|
|
|
|
echo "error: unreconized target '$abi', giving up." >&2
|
|
|
|
exit 1
|
|
|
|
esac; done;;
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
# format options
|
2020-10-11 10:15:34 +02:00
|
|
|
--static)
|
|
|
|
format_static=true;;
|
|
|
|
--dynamic)
|
|
|
|
format_dynamic=true;;
|
2020-10-07 11:37:54 +02:00
|
|
|
|
|
|
|
# error part
|
2020-09-17 19:27:01 +02:00
|
|
|
*)
|
2020-10-07 11:37:54 +02:00
|
|
|
echo "error: unreconized argument '$arg', giving up." >&2
|
2020-09-17 19:27:01 +02:00
|
|
|
exit 1
|
|
|
|
esac; done
|
|
|
|
|
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
# Check error
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
|
|
|
# If no prefix is specified, install to the GCC's build folder
|
|
|
|
if [[ -z "$prefix" ]]
|
|
|
|
then
|
|
|
|
# ask the toolchain where is his installation path
|
|
|
|
echo "No prefix specified, let's ask the compiler:"
|
|
|
|
echo " Call: \"$toolchain-gcc --print-search-dirs | grep install | sed 's/install: //'\""
|
|
|
|
if ! inst=$("$toolchain"-gcc --print-search-dirs | grep install | sed 's/install: //'); then
|
|
|
|
echo " Call: returned $?, giving up." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo " Got '$inst'".
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
# check if the directory exist
|
|
|
|
if [[ ! -d $inst ]]; then
|
|
|
|
echo "Directory does not exist (or is not a directory), giving up." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
prefix=$inst
|
|
|
|
fi
|
|
|
|
|
2020-10-11 10:15:34 +02:00
|
|
|
# TODO
|
2020-10-07 11:37:54 +02:00
|
|
|
# TODO: check if the wanted lib exist (check lib verion too)!
|
2020-10-11 10:15:34 +02:00
|
|
|
# TODO
|
2020-10-07 11:37:54 +02:00
|
|
|
|
2020-10-24 21:48:45 +02:00
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
# Dump appropriate Makefile
|
|
|
|
# @note:
|
|
|
|
# * We have 3 makefile: normal, dynlib, unit_test
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
dst='Makefile'
|
|
|
|
src="../make/$makefile"
|
2020-10-26 19:01:16 +01:00
|
|
|
if ! [ -e $src ] ; then
|
2020-10-07 11:37:54 +02:00
|
|
|
echo "error: target makefile ($src) does not exist !" >&2
|
2020-09-17 19:27:01 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-26 18:01:04 +01:00
|
|
|
[ -e "$dst" ] && [ "$(readlink $dst)" = "$src" ] && rm $dst
|
2020-09-17 19:27:01 +02:00
|
|
|
ln -s $src $dst
|
|
|
|
|
|
|
|
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
2020-09-17 19:27:01 +02:00
|
|
|
# Generate the configuration file
|
2020-10-07 11:37:54 +02:00
|
|
|
#---
|
|
|
|
generate_config()
|
2020-09-17 19:27:01 +02:00
|
|
|
{
|
2020-10-11 10:15:34 +02:00
|
|
|
echo 'CONFIG.CFLAGS := '
|
|
|
|
echo 'CONFIG.TARGET := '
|
|
|
|
echo 'CONFIG.FORMAT := '
|
2020-10-07 11:37:54 +02:00
|
|
|
echo "CONFIG.TOOLCHAIN := $toolchain"
|
|
|
|
[ "$prefix" ] && echo "CONFIG.PREFIX := $prefix"
|
|
|
|
[ "$cflags" ] && echo "CONFIG.CFLAGS += $cflags"
|
|
|
|
|
2020-10-11 10:15:34 +02:00
|
|
|
# debug / unit tests
|
|
|
|
[ $debug = true ] && echo 'CONFIG.CFLAGS += -g3'
|
|
|
|
|
|
|
|
# ABI support
|
|
|
|
[ $support_vhex_kernel = true ] && echo 'CONFIG.TARGET += fxlibc-vhex'
|
2020-10-14 12:24:57 +02:00
|
|
|
[ $support_casio_abi_fx9860 = true ] && echo 'CONFIG.TARGET += fxlibc-fx9860g'
|
2020-10-11 10:15:34 +02:00
|
|
|
[ $support_casio_abi_fxcg50 = true ] && echo 'CONFIG.TARGET += fxlibc-fxcg50'
|
|
|
|
|
|
|
|
# formats
|
|
|
|
[ $format_static = true ] && echo 'CONFIG.FORMAT += static'
|
|
|
|
[ $format_dynamic = true ] && echo 'CONFIG.FORMAT += dynamic'
|
2020-09-17 19:27:01 +02:00
|
|
|
}
|
|
|
|
generate_config > $confile
|
|
|
|
|
|
|
|
echo "Configuration saved in $confile, ready to make!"
|
|
|
|
exit 0
|