#!/bin/sh
|
#!/bin/bash
|
# Makefile.config -- script for automatic configuration of Makefile variables
|
# Makefile.config -- script for automatic configuration of Makefile variables
|
# Copyright (C) 2002-2003 Stefan Ziegenbalg
|
# Copyright (C) 2002-2003 Stefan Ziegenbalg
|
|
|
configfile=Makefile.conf
|
configfile=Makefile.conf
|
|
|
# nice output routines
|
# nice output routines
|
# \033 is just ascii ESC
|
# \033 is just ascii ESC
|
# \033[G move to column
|
# \033[G move to column
|
# \033[1m switch bold on
|
# \033[1m switch bold on
|
# \033[31m switch red on
|
# \033[31m switch red on
|
# \033[32m switch green on
|
# \033[32m switch green on
|
# \033[33m switch yellow on
|
# \033[33m switch yellow on
|
# \033[m switch color/bold off
|
# \033[m switch color/bold off
|
echo_red () {
|
echo_red () {
|
echo -e "\033[31m\033[1m$1\033[m" >&2
|
echo -e "\033[31m\033[1m$1\033[m" >&2
|
}
|
}
|
|
|
echo_green () {
|
echo_green () {
|
echo -e "\033[32m$1\033[m" >&2
|
echo -e "\033[32m$1\033[m" >&2
|
}
|
}
|
|
|
echo_yellow () {
|
echo_yellow () {
|
echo -e "\033[33m\033[1m$1\033[m" >&2
|
echo -e "\033[33m\033[1m$1\033[m" >&2
|
}
|
}
|
|
|
# read config file
|
# read config file
|
readconfig () {
|
readconfig () {
|
result="-"
|
result="-"
|
read var par
|
read var par
|
while [ "$result" = "-" -a "$var" != "" ]; do
|
while [ "$result" = "-" -a "$var" != "" ]; do
|
[ "$var" = "$1" ] && result=$par
|
[ "$var" = "$1" ] && result=$par
|
read var par
|
read var par
|
done
|
done
|
echo $result
|
echo $result
|
}
|
}
|
|
|
# remove temporay files
|
# remove temporay files
|
rmtmp () {
|
rmtmp () {
|
rm -f $tmpfile $tmpfile.*
|
rm -f $tmpfile $tmpfile.*
|
}
|
}
|
|
|
# checks coompilinmg + running
|
# checks coompilinmg + running
|
# $1 compiler command + flags
|
# $1 compiler command + flags
|
# $2 test file (without .pas)
|
# $2 test file (without .pas)
|
checkcr () {
|
checkcr () {
|
echo "$1 $2" >> $tmpfile.log
|
echo "$1 $2" >> $tmpfile.log
|
$1 $2 >> $tmpfile.log 2>> $tmpfile.log
|
$1 $2 >> $tmpfile.log 2>> $tmpfile.log
|
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
echo "./$2" >> $tmpfile.log
|
echo "./$2" >> $tmpfile.log
|
./$2
|
./$2
|
else
|
else
|
return 1
|
return 1
|
fi
|
fi
|
}
|
}
|
|
|
# checks command
|
# checks command
|
findexec () {
|
findexec () {
|
result=""
|
result=""
|
for i; do
|
for i; do
|
if [ "$result" = "" ]; then
|
if [ "$result" = "" ]; then
|
if [ "${i#*/}" = "$i" ]; then
|
if [ "${i#*/}" = "$i" ]; then
|
which $i >> $tmpfile.log 2>> $tmpfile.log
|
which $i >> $tmpfile.log 2>> $tmpfile.log
|
[ "$?" = "0" ] && result=$i
|
[ "$?" = "0" ] && result=$i
|
else
|
else
|
[ -x $i -a ! -d $i ] && result=$i
|
[ -x $i -a ! -d $i ] && result=$i
|
fi
|
fi
|
fi
|
fi
|
done
|
done
|
echo $result
|
echo $result
|
}
|
}
|
|
|
|
|
failure () {
|
failure () {
|
echo -n $failreturn
|
echo -n $failreturn
|
exit 1
|
exit 1
|
}
|
}
|
|
|
#####################
|
#####################
|
##### main part #####
|
##### main part #####
|
#####################
|
#####################
|
failreturn=""
|
failreturn=""
|
case "$1" in
|
case "$1" in
|
"pc2") cmd=pc; failreturn="ppc386" ;;
|
"pc2") cmd=pc; failreturn="ppc386" ;;
|
"install2") cmd=install; failreturn="install" ;;
|
"install2") cmd=install; failreturn="install" ;;
|
"findexec2") cmd=findexec; failreturn=${2%% *} ;;
|
"findexec2") cmd=findexec; failreturn=${2%% *} ;;
|
*) cmd=$1 ;;
|
*) cmd=$1 ;;
|
esac
|
esac
|
|
|
case "$cmd" in
|
case "$cmd" in
|
"findexec") varname=$cmd_$2 ;;
|
"findexec") varname=$cmd_$2 ;;
|
"have_unit") varname=have_$3 ;;
|
"have_unit") varname=have_$3 ;;
|
"unit_flags") varname=$3"_flags" ;;
|
"unit_flags") varname=$3"_flags" ;;
|
*) varname=$cmd ;;
|
*) varname=$cmd ;;
|
esac
|
esac
|
tmpfile="conf_$varname"
|
tmpfile="conf_$varname"
|
|
|
result="-"
|
result="-"
|
[ -f $configfile -a "$varname" != "" ] && result=`readconfig $varname < $configfile`
|
[ -f $configfile -a "$varname" != "" ] && result=`readconfig $varname < $configfile`
|
|
|
if [ "$result" != "-" ]; then
|
if [ "$result" != "-" ]; then
|
echo $result
|
echo $result
|
exit 0
|
exit 0
|
fi
|
fi
|
|
|
result=""
|
result=""
|
rm -f $tmpfile.log
|
rm -f $tmpfile.log
|
case "$cmd" in
|
case "$cmd" in
|
"pc")
|
"pc")
|
echo -n "Checking for freepascal compiler (FLAGS=\"$2\"): " >&2
|
echo -n "Checking for freepascal compiler (FLAGS=\"$2\"): " >&2
|
echo -e "begin\nend." > $tmpfile.pas
|
echo -e "begin\nend." > $tmpfile.pas
|
for i in ppc386 fpc pc $3; do
|
for i in ppc386 fpc pc $3; do
|
if [ "$result" = "" ]; then
|
if [ "$result" = "" ]; then
|
if [ "${i#*/}" = "$i" ]; then
|
if [ "${i#*/}" = "$i" ]; then
|
which $i >> $tmpfile.log 2>> $tmpfile.log
|
which $i >> $tmpfile.log 2>> $tmpfile.log
|
[ "$?" = "0" ] && checkcr "$i $2" $tmpfile && result=$i
|
[ "$?" = "0" ] && checkcr "$i $2" $tmpfile && result=$i
|
else
|
else
|
[ -x $i -a ! -d $i ] && checkcr "$i $2" $tmpfile && result=$i
|
[ -x $i -a ! -d $i ] && checkcr "$i $2" $tmpfile && result=$i
|
fi
|
fi
|
fi
|
fi
|
done
|
done
|
if [ "$result" != "" ]; then
|
if [ "$result" != "" ]; then
|
echo_green "$result"
|
echo_green "$result"
|
rmtmp
|
rmtmp
|
else
|
else
|
echo_red "not found"
|
echo_red "not found"
|
failure
|
failure
|
fi
|
fi
|
;;
|
;;
|
"install")
|
"install")
|
echo -n "Checking for install command: " >&2
|
echo -n "Checking for install command: " >&2
|
result=`findexec install ginstall $2`
|
result=`findexec install ginstall $2`
|
if [ "$result" != "" ]; then
|
if [ "$result" != "" ]; then
|
echo_green "$result"
|
echo_green "$result"
|
rmtmp
|
rmtmp
|
else
|
else
|
echo_red "not found"
|
echo_red "not found"
|
failure
|
failure
|
fi
|
fi
|
;;
|
;;
|
"have_unit" | "unit_flags" )
|
"have_unit" | "unit_flags" )
|
echo -n "Checking for $3 unit: " >&2
|
echo -n "Checking for $3 unit: " >&2
|
echo -e "uses $3;\nbegin\nend." > $tmpfile.pas
|
echo -e "uses $3;\nbegin\nend." > $tmpfile.pas
|
for i in $4 " "; do
|
for i in $4 " "; do
|
if [ "$result" = "" ]; then
|
if [ "$result" = "" ]; then
|
if [ "$i" = " " ]; then
|
if [ "$i" = " " ]; then
|
checkcr "$2" $tmpfile && result=$i
|
checkcr "$2" $tmpfile && result=$i
|
else
|
else
|
[ -f $i/$3.ppu ] && checkcr "$2 -Fu$i" $tmpfile && result=$i
|
[ -f $i/$3.ppu ] && checkcr "$2 -Fu$i" $tmpfile && result=$i
|
fi
|
fi
|
fi
|
fi
|
done
|
done
|
if [ "$result" != "" ]; then
|
if [ "$result" != "" ]; then
|
if [ "$result" = " " ]; then
|
if [ "$result" = " " ]; then
|
echo_green "available"
|
echo_green "available"
|
else
|
else
|
echo_green "$result"
|
echo_green "$result"
|
result="-Fu$result"
|
result="-Fu$result"
|
fi
|
fi
|
if [ "$1" = "have_unit" ]; then
|
if [ "$1" = "have_unit" ]; then
|
echo "$3""_flags $result" >> $configfile
|
echo "$3""_flags $result" >> $configfile
|
result=1
|
result=1
|
else
|
else
|
echo "have_$3 1" >> $configfile
|
echo "have_$3 1" >> $configfile
|
fi
|
fi
|
rmtmp
|
rmtmp
|
else
|
else
|
echo_yellow "not available"
|
echo_yellow "not available"
|
echo "$3""_flags " >> $configfile
|
echo "$3""_flags " >> $configfile
|
if [ "$1" = "have_unit" ]; then
|
if [ "$1" = "have_unit" ]; then
|
result=0
|
result=0
|
else
|
else
|
echo "have_$3 0" >> $configfile
|
echo "have_$3 0" >> $configfile
|
failure
|
failure
|
fi
|
fi
|
fi
|
fi
|
;;
|
;;
|
"optalign")
|
"optalign")
|
echo -n "Checking for -Oa flag: " >&2
|
echo -n "Checking for -Oa flag: " >&2
|
echo -e "begin\nend." > $tmpfile.pas
|
echo -e "begin\nend." > $tmpfile.pas
|
checkcr "$2 -Oa" $tmpfile
|
checkcr "$2 -Oa" $tmpfile
|
if [ "$?" = "0" ]; then
|
if [ "$?" = "0" ]; then
|
echo_green "works"
|
echo_green "works"
|
result=1
|
result=1
|
rmtmp
|
rmtmp
|
else
|
else
|
echo_yellow "failed"
|
echo_yellow "failed"
|
result=0
|
result=0
|
fi
|
fi
|
;;
|
;;
|
"findexec")
|
"findexec")
|
echo -n "Checking for $2: " >&2
|
echo -n "Checking for $2: " >&2
|
result=`findexec $3`
|
result=`findexec $3`
|
if [ "$result" != "" ]; then
|
if [ "$result" != "" ]; then
|
echo_green "$result"
|
echo_green "$result"
|
rmtmp
|
rmtmp
|
else
|
else
|
echo_red "not found"
|
echo_red "not found"
|
failure
|
failure
|
fi
|
fi
|
;;
|
;;
|
*)
|
*)
|
echo "$0 -- script for automatic configuration of Makefile variables"
|
echo "$0 -- script for automatic configuration of Makefile variables"
|
echo
|
echo
|
echo
|
echo
|
echo " !! Run make to build the project or run ./update to update the Makefile (e.g. after changing sources)!!"
|
echo " !! Run make to build the project or run ./update to update the Makefile (e.g. after changing sources)!!"
|
echo
|
echo
|
echo
|
echo
|
echo "Usage: $0 [options]"
|
echo "Usage: $0 [options]"
|
echo ""
|
echo ""
|
echo "variables:"
|
echo "variables:"
|
echo " pc [compiler flags [additional compilers]]"
|
echo " pc [compiler flags [additional compilers]]"
|
echo " checks for freepascal compiler, returns \"\" on failure"
|
echo " checks for freepascal compiler, returns \"\" on failure"
|
echo ""
|
echo ""
|
echo " pc2 [compiler flags [additional compilers]]"
|
echo " pc2 [compiler flags [additional compilers]]"
|
echo " as above, but ppc386 is returned on failure"
|
echo " as above, but ppc386 is returned on failure"
|
echo ""
|
echo ""
|
echo " install [additonal commands]"
|
echo " install [additonal commands]"
|
echo " checks for install command, returns \"\" on failure"
|
echo " checks for install command, returns \"\" on failure"
|
echo ""
|
echo ""
|
echo " install2 [additonal commands]"
|
echo " install2 [additonal commands]"
|
echo " as above, but install is returned on failure"
|
echo " as above, but install is returned on failure"
|
echo ""
|
echo ""
|
echo " have_unit []"
|
echo " have_unit []"
|
echo " checks whether is available; returns 0 on failure, 1 on success; unit list must be coma separated"
|
echo " checks whether is available; returns 0 on failure, 1 on success; unit list must be coma separated"
|
echo ""
|
echo ""
|
echo " unit_flags []"
|
echo " unit_flags []"
|
echo " as above, but returns \"-ul\" if unit found in []"
|
echo " as above, but returns \"-ul\" if unit found in []"
|
echo ""
|
echo ""
|
echo " optalign "
|
echo " optalign "
|
echo " checks whether -Oa flag works"
|
echo " checks whether -Oa flag works"
|
echo ""
|
echo ""
|
echo " findexec "
|
echo " findexec "
|
echo " checks for existing executable in "
|
echo " checks for existing executable in "
|
echo ""
|
echo ""
|
echo " findexec2 "
|
echo " findexec2 "
|
echo " as above, but first variant is returned on failure"
|
echo " as above, but first variant is returned on failure"
|
echo ""
|
echo ""
|
exit 1
|
exit 1
|
;;
|
;;
|
esac
|
esac
|
|
|
[ "$result" != "" -a "$varname" != "" ] && echo "$varname $result" >> $configfile
|
[ "$result" != "" -a "$varname" != "" ] && echo "$varname $result" >> $configfile
|
echo $result
|
echo $result
|
|
|
|
|