fxlibc/configure

211 lines
5.9 KiB
Text
Raw Normal View History

2020-09-17 19:27:01 +02:00
#! /bin/bash
2020-10-07 11:37:54 +02:00
#
# -= TODO =-
# * check if the wanted lib exist (check lib verion too)!
# * option to list all installed libraries with their versions
# * each ABI options define one specific libs (fxlibc-common, fxlibc-vhex, fxlibc-fx9860g, fxlibc-fxcg50)
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
declare -A config
config[__DEBUG]=false
config[__ENABLE_VALGRIND]=false
2020-10-07 11:37:54 +02:00
config[__SUPPORT_VHEX_KERNEL]=false
config[__SUPPORT_CASIO_FX9860]=false
config[__SUPPORT_CASIO_FXCG50]=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-07 11:37:54 +02:00
--support-vhex
Enable the Vhex kernel support
--support-casio-fx9860,
--support-casio-fxcg50
Enable the support of the Casio' ABI (used by malloc, free, ...)
2020-09-17 19:27:01 +02:00
fx9860 covers all fx-9860G II-like monochromes models that support add-ins
or can be flashed with an OS that does. This includes SH3 and SH4 machines.
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'
2020-10-07 11:37:54 +02:00
part, I/O management and additionals feature. (like process, fs, ...).
2020-09-17 19:27:01 +02:00
Format:
2020-10-07 11:37:54 +02:00
--dyn-lib Generate dynamic librairies (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
}
#
# Check mandatory build location
# @note:
# * You should build out-of-tree by creating a build directory and configuring
# from there.
#
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
#
# Parsing arguments
#
for arg; do case "$arg" in
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)
config[__DEBUG]=true;;
--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
--support-vhex)
2020-09-17 19:27:01 +02:00
config[__SUPPORT_VHEX_KERNEL]=true;;
2020-10-07 11:37:54 +02:00
--support-casio-abi-fx9860)
config[__SUPPORT_CASIO_ABI_FX9860]=true;;
--support-casio-abi-fxcg50)
config[__SUPPORT_CASIO_ABI_FXCG50]=true;;
2020-09-17 19:27:01 +02:00
2020-10-07 11:37:54 +02:00
# format options
2020-09-17 19:27:01 +02:00
--dyn-lib)
makefile='Makefile.dynlib';;
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
#---
# Check ABI support error
if [ ${config[__SUPPORT_CASIO_ABI_FX9860]} = true ] && [ ${config[__SUPPORT_CASIO_ABI_FXCG50]} = true ] ||
[ ${config[__SUPPORT_VHEX_KERNEL]} = true ] && [ ${config[__SUPPORT_CASIO_ABI_FXCG50]} = true ] ||
[ ${config[__SUPPORT_VHEX_KERNEL]} = true ] && [ ${config[__SUPPORT_CASIO_ABI_FX9860]} = true ]; then
echo "error: too many ABI target" >&2
2020-09-17 19:27:01 +02:00
exit 1
fi
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
#
# TODO: check if the wanted lib exist (check lib verion too)!
2020-09-17 19:27:01 +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"
if ! test $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-07 11:37:54 +02:00
[ $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-07 11:37:54 +02:00
echo "CONFIG.CFLAGS := "
echo "CONFIG.TARGET := "
echo "CONFIG.TOOLCHAIN := $toolchain"
[ "$prefix" ] && echo "CONFIG.PREFIX := $prefix"
[ "$cflags" ] && echo "CONFIG.CFLAGS += $cflags"
#[ ${config[__DEBUG]} = true ] && echo "CONFIG.CFLAGS += -g3"
[ ${config[__SUPPORT_VHEX_KERNEL]} = true ] && echo "CONFIG.TARGET += fxlibc-vhex"
[ ${config[__SUPPORT_CASIO_ABI_FX9860]} = true ] && echo "CONFIG.TARGET += fxlibc-fx9860"
[ ${config[__SUPPORT_CASIO_ABI_FXCG50]} = true ] && echo "CONFIG.TARGET += fxlibc-fxcg50"
2020-09-17 19:27:01 +02:00
}
generate_config > $confile
echo "Configuration saved in $confile, ready to make!"
exit 0