gint/configure

130 lines
3.3 KiB
Bash
Executable file

#! /bin/bash
#
# Basic configuration
#
declare -A conf
# Behavior
conf[GINT_DIAGNOSTICS]=
conf[GINT_NO_SYSCALLS]=
conf[GINT_EXTENDED_LIBC]=
# Size limits
conf[ATEXIT_MAX]=16
conf[TIMER_SLOTS]=16
conf[EVENTS_QUEUE_SIZE]=64
# Output files
output_gcc="gcc.cfg"
output_make="Makefile.cfg"
#
# Help screen and output util
#
error="\e[31;1merror:\e[0m"
Cg="$(tput setaf 8)$(tput bold)"
Cr="$(tput setaf 1)$(tput bold)"
Cy="$(tput setaf 2)$(tput bold)"
Cp="$(tput setaf 5)$(tput setaf 62)$(tput bold)"
C0="$(tput setaf 0)$(tput sgr 0)"
help()
{
cat << EOF
Configuration script for the gint library.
Options that affect the behavior of the library:
$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.
Options that customize size limits:
$Cr--atexit-max$C0=$Cy<integer>$Cg [default:$Cp 16$Cg]$C0
Number of exit handlers that can be registered by atexit().
$Cr--timer-slots$C0=$Cy<integer>$Cg [default:$Cp 16$Cg]$C0
Number of virtual timers that may be registered at the same time.
$Cr--events-queue-size$C0=$Cy<integer>$Cg [default:$Cp 64$Cg]$C0
Number of events simultaneously stored in the event queue.
EOF
exit 0
}
#
# Parsing arguments
#
fail=false
for arg; do case "$arg" in
-h | --help) help;;
--diagnostics) conf[GINT_DIAGNOSTICS]=true;;
--no-syscalls) conf[GINT_NO_SYSCALLS]=true;;
--extended-libc) conf[GINT_EXTENDED_LIBC]=true;;
--atexit-max=*)
size=${arg#*=}
if [[ $size == +([0-9]) ]]; then
conf[ATEXIT_MAX]=$size
else echo -e "$error --atexit-max expects an integer value"
fail=true; fi;;
--timer-slots=*)
size=${arg#*=}
if [[ $size == +([0-9]) ]]; then
conf[TIMER_SLOTS]=$size
else echo -e "$error --timer-slots expects an integer value"
fail=true; fi;;
--events-queue-size=*)
size=${arg#*=}
if [[ $size == +([0-9]) ]]; then
conf[EVENTS_QUEUE_SIZE]=$size
else echo -e "$error --events-queue-size expects an integer"\
"value"
fail=true; fi;;
--atexit-max | --timer-slots | --events-queue-size)
echo -e "$error syntax for $arg is $arg=<integer-value>";;
*)
echo -e "$error unrecognized argument '$arg'"; fail=true;;
esac; done
#
# Output config routines
#
output_config_gcc()
{
[ "${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"
echo "-D ATEXIT_MAX=${conf[ATEXIT_MAX]}"
echo "-D TIMER_SLOTS=${conf[TIMER_SLOTS]}"
echo "-D EVENTS_QUEUE_SIZE=${conf[EVENTS_QUEUE_SIZE]}"
}
output_config_make()
{
[ "${conf[GINT_EXTENDED_LIBC]}" != "" ] && echo "config_ext=true"
}
#
# Output config
#
if $fail; then
echo "Configuration has not been modified."
else
output_config_gcc > $output_gcc
output_config_make > $output_make
echo "Configuration saved in $output_gcc and $output_make."
fi