2016-11-05 22:00:23 +01:00
|
|
|
#! /bin/bash
|
|
|
|
|
2017-02-25 19:02:07 +01:00
|
|
|
#
|
|
|
|
# Basic configuration
|
|
|
|
#
|
|
|
|
|
2016-11-05 22:00:23 +01:00
|
|
|
declare -A conf
|
2017-02-25 19:02:07 +01:00
|
|
|
|
|
|
|
# Behavior
|
|
|
|
conf[GINT_DIAGNOSTICS]=
|
|
|
|
conf[GINT_NO_SYSCALLS]=
|
|
|
|
conf[GINT_EXTENDED_LIBC]=
|
|
|
|
|
|
|
|
# Size limits
|
2016-11-05 22:00:23 +01:00
|
|
|
conf[ATEXIT_MAX]=16
|
|
|
|
conf[RTC_CB_ARRAY_SIZE]=5
|
|
|
|
conf[EVENTS_QUEUE_SIZE]=64
|
2017-02-25 19:02:07 +01:00
|
|
|
|
|
|
|
# Output files
|
2017-01-22 18:35:02 +01:00
|
|
|
output_gcc="gcc.cfg"
|
|
|
|
output_make="Makefile.cfg"
|
|
|
|
|
2017-02-25 19:02:07 +01:00
|
|
|
#
|
|
|
|
# Help screen and output util
|
|
|
|
#
|
|
|
|
|
2017-01-22 18:35:02 +01:00
|
|
|
error="\e[31;1merror:\e[0m"
|
2017-02-25 19:02:07 +01:00
|
|
|
Cg="$(tput setaf 8)$(tput bold)"
|
2017-01-22 18:35:02 +01:00
|
|
|
Cr="$(tput setaf 1)$(tput bold)"
|
2017-02-25 19:02:07 +01:00
|
|
|
Cy="$(tput setaf 2)$(tput bold)"
|
2017-01-22 18:35:02 +01:00
|
|
|
Cp="$(tput setaf 5)$(tput setaf 62)$(tput bold)"
|
|
|
|
C0="$(tput setaf 0)$(tput sgr 0)"
|
2016-11-05 22:00:23 +01:00
|
|
|
|
|
|
|
help()
|
|
|
|
{
|
|
|
|
cat << EOF
|
|
|
|
Configuration script for the gint library.
|
|
|
|
|
|
|
|
Options that affect the behavior of the library:
|
2017-02-25 19:02:07 +01:00
|
|
|
$Cr--diagnostics $Cg[default:$Cp false$Cg]$C0
|
|
|
|
Use gint in debug mode, where the library outputs some diagnostics in
|
|
|
|
memory or briefly on screen to diagnose incompatibilites or crashes.
|
|
|
|
$Cr--no-syscalls $Cg[default:$Cp false$Cg]$C0
|
|
|
|
Never use syscalls. Expect some trouble with the malloc() function... do
|
|
|
|
not trigger this switch unless you know what you are doing.
|
|
|
|
$Cr--extended-libc $Cg[default:$Cp false$Cg]$C0
|
|
|
|
Enable specific C99 headers/features that are normally not required by
|
|
|
|
calculator programs. This may allow porting programs from other platforms.
|
2016-11-05 22:00:23 +01:00
|
|
|
|
|
|
|
Options that customize size limits:
|
2017-02-25 19:02:07 +01:00
|
|
|
$Cr--atexit-max$C0=$Cy<integer>$Cg [default:$Cp 16$Cg]$C0
|
|
|
|
Number of exit handlers that can be registered by atexit().
|
|
|
|
$Cr--rtc-callbacks$C0=$Cy<integer>$Cg [default:$Cp 5$Cg]$C0
|
|
|
|
Number of RTC callbacks that can be registered.
|
|
|
|
$Cr--events-queue-size$C0=$Cy<integer>$Cg [default:$Cp 64$Cg]$C0
|
|
|
|
Number of events simultaneously stored in the event queue.
|
2016-11-05 22:00:23 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2017-02-25 19:02:07 +01:00
|
|
|
#
|
|
|
|
# Parsing arguments
|
|
|
|
#
|
|
|
|
|
|
|
|
fail=false
|
2016-11-05 22:00:23 +01:00
|
|
|
for arg; do case "$arg" in
|
|
|
|
-h | --help) help;;
|
2017-02-25 19:02:07 +01:00
|
|
|
--diagnostics) conf[GINT_DIAGNOSTICS]=true;;
|
|
|
|
--no-syscalls) conf[GINT_NO_SYSCALLS]=true;;
|
2017-01-22 18:35:02 +01:00
|
|
|
--extended-libc) conf[GINT_EXTENDED_LIBC]=true;;
|
2016-11-05 22:00:23 +01:00
|
|
|
|
|
|
|
--atexit-max=*)
|
|
|
|
size=${arg#*=}
|
|
|
|
if [[ $size == +([0-9]) ]]; then
|
|
|
|
conf[ATEXIT_MAX]=$size
|
2017-01-22 18:35:02 +01:00
|
|
|
else echo -e "$error --atexit-max expects an integer value"
|
2016-11-05 22:00:23 +01:00
|
|
|
fail=true; fi;;
|
|
|
|
--rtc-callbacks=*)
|
|
|
|
size=${arg#*=}
|
|
|
|
if [[ $size == +([0-9]) ]]; then
|
|
|
|
conf[RTC_CB_ARRAY_SIZE]=$size
|
2017-01-22 18:35:02 +01:00
|
|
|
else echo -e "$error --rtc-callbacks expects an integer value"
|
2016-11-05 22:00:23 +01:00
|
|
|
fail=true; fi;;
|
|
|
|
--events-queue-size=*)
|
|
|
|
size=${arg#*=}
|
|
|
|
if [[ $size == +([0-9]) ]]; then
|
|
|
|
conf[EVENTS_QUEUE_SIZE]=$size
|
2017-01-22 18:35:02 +01:00
|
|
|
else echo -e "$error --events-queue-size expects an integer"\
|
|
|
|
"value"
|
2016-11-05 22:00:23 +01:00
|
|
|
fail=true; fi;;
|
|
|
|
|
|
|
|
--atexit-max | --rtc-callbacks | --events-queue-size)
|
2017-01-22 18:35:02 +01:00
|
|
|
echo -e "$error syntax for $arg is $arg=<integer-value>";;
|
2016-11-05 22:00:23 +01:00
|
|
|
|
|
|
|
*)
|
2017-01-22 18:35:02 +01:00
|
|
|
echo -e "$error unrecognized argument '$arg'"; fail=true;;
|
2016-11-05 22:00:23 +01:00
|
|
|
esac; done
|
|
|
|
|
2017-02-25 19:02:07 +01:00
|
|
|
#
|
|
|
|
# Output config routines
|
|
|
|
#
|
|
|
|
|
2017-01-22 18:35:02 +01:00
|
|
|
output_config_gcc()
|
2016-11-05 22:00:23 +01:00
|
|
|
{
|
2017-02-25 19:02:07 +01:00
|
|
|
[ "${conf[GINT_DIAGNOSTICS]}" != "" ] && echo "-D GINT_DIAGNOSTICS"
|
|
|
|
[ "${conf[GINT_NO_SYSCALLS]}" != "" ] && echo "-D GINT_NO_SYSCALLS"
|
|
|
|
[ "${conf[GINT_EXTENDED_LIBC]}" != "" ] && echo "-D GINT_EXTENDED_LIBC"
|
|
|
|
|
2016-11-05 22:00:23 +01:00
|
|
|
echo "-D ATEXIT_MAX=${conf[ATEXIT_MAX]}"
|
|
|
|
echo "-D RTC_CB_ARRAY_SIZE=${conf[RTC_CB_ARRAY_SIZE]}"
|
|
|
|
echo "-D EVENTS_QUEUE_SIZE=${conf[EVENTS_QUEUE_SIZE]}"
|
2017-01-22 18:35:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
output_config_make()
|
|
|
|
{
|
|
|
|
[ "${conf[GINT_EXTENDED_LIBC]}" != "" ] && echo "config_ext=true"
|
2016-11-05 22:00:23 +01:00
|
|
|
}
|
|
|
|
|
2017-02-25 19:02:07 +01:00
|
|
|
#
|
|
|
|
# Output config
|
|
|
|
#
|
|
|
|
|
2016-11-05 22:00:23 +01:00
|
|
|
if $fail; then
|
|
|
|
echo "Configuration has not been modified."
|
|
|
|
else
|
2017-01-22 18:35:02 +01:00
|
|
|
output_config_gcc > $output_gcc
|
|
|
|
output_config_make > $output_make
|
|
|
|
echo "Configuration saved in $output_gcc and $output_make."
|
2016-11-05 22:00:23 +01:00
|
|
|
fi
|