2017-10-22 00:33:27 -07:00
|
|
|
die() # $1 = exit code, use : to not exit when printing warnings $@ = exit or warning messages
|
|
|
|
{
|
|
|
|
ret="$1"
|
|
|
|
shift 1
|
|
|
|
printf %s\\n "$@" >&2
|
|
|
|
case "$ret" in
|
|
|
|
: ) return 0 ;;
|
|
|
|
* ) exit "$ret" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2015-06-17 13:05:26 -03:00
|
|
|
print_help_option() # $1 = option $@ = description
|
|
|
|
{
|
|
|
|
_opt="$1"
|
|
|
|
shift 1
|
2017-10-23 23:41:52 -07:00
|
|
|
printf ' %-26s %s\n' "$_opt" "$@"
|
2015-06-17 13:05:26 -03:00
|
|
|
}
|
|
|
|
|
2010-12-30 02:52:02 +01:00
|
|
|
print_help()
|
2012-06-02 22:05:14 +02:00
|
|
|
{ cat << EOF
|
|
|
|
====================
|
|
|
|
Quickbuild script
|
|
|
|
====================
|
|
|
|
Package: $PACKAGE_NAME
|
|
|
|
|
|
|
|
General environment variables:
|
2015-06-17 13:05:26 -03:00
|
|
|
CC: C compiler
|
|
|
|
CFLAGS: C compiler flags
|
|
|
|
CXX: C++ compiler
|
|
|
|
CXXFLAGS: C++ compiler flags
|
|
|
|
LDFLAGS: Linker flags
|
2012-06-02 22:05:14 +02:00
|
|
|
|
|
|
|
General options:
|
|
|
|
EOF
|
2015-06-17 13:05:26 -03:00
|
|
|
print_help_option "--prefix=PATH" "Install path prefix"
|
|
|
|
print_help_option "--global-config-dir=PATH" "System wide config file prefix"
|
2017-11-22 15:21:12 -08:00
|
|
|
print_help_option "--build=BUILD" "The build system (no-op)"
|
2017-11-22 15:33:35 -08:00
|
|
|
print_help_option "--host=HOST" "Cross-compile with HOST-gcc instead of gcc"
|
2015-06-17 13:05:26 -03:00
|
|
|
print_help_option "--help" "Show this help"
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Custom options:"
|
|
|
|
|
2017-11-17 19:08:36 -08:00
|
|
|
while read -r VAR COMMENT; do
|
|
|
|
TMPVAR="${VAR%=*}"
|
|
|
|
COMMENT="${COMMENT#*#}"
|
|
|
|
VAL="${VAR#*=}"
|
|
|
|
VAR="$(echo "${TMPVAR#HAVE_}" | tr '[:upper:]' '[:lower:]')"
|
2016-01-29 18:57:21 +01:00
|
|
|
case "$VAR" in
|
2017-10-24 00:18:23 -07:00
|
|
|
'c89_'*) continue;;
|
2012-06-12 22:16:16 +02:00
|
|
|
*)
|
2016-01-29 18:57:21 +01:00
|
|
|
case "$VAL" in
|
|
|
|
'yes'*)
|
2016-03-21 00:12:56 +01:00
|
|
|
print_help_option "--disable-$VAR" "Disable $COMMENT";;
|
2016-01-29 18:57:21 +01:00
|
|
|
'no'*)
|
2017-10-23 23:41:52 -07:00
|
|
|
print_help_option "--enable-$VAR" "Enable $COMMENT";;
|
2016-01-29 18:57:21 +01:00
|
|
|
'auto'*)
|
2017-10-23 23:41:52 -07:00
|
|
|
print_help_option "--enable-$VAR" "Enable $COMMENT"
|
2016-03-21 00:12:56 +01:00
|
|
|
print_help_option "--disable-$VAR" "Disable $COMMENT";;
|
2016-01-29 18:57:21 +01:00
|
|
|
*)
|
2017-10-23 23:41:52 -07:00
|
|
|
print_help_option "--with-$VAR" "Config $COMMENT";;
|
2016-01-29 18:57:21 +01:00
|
|
|
esac
|
2012-06-02 22:05:14 +02:00
|
|
|
esac
|
|
|
|
done < 'qb/config.params.sh'
|
2010-12-30 02:52:02 +01:00
|
|
|
}
|
|
|
|
|
2012-06-02 22:05:14 +02:00
|
|
|
opt_exists() # $opt is returned if exists in OPTS
|
2017-11-18 01:17:00 -08:00
|
|
|
{ opt="$(echo "$1" | tr '[:lower:]' '[:upper:]')"
|
|
|
|
err="$2"
|
|
|
|
eval "set -- $OPTS"
|
|
|
|
for OPT do [ "$opt" = "$OPT" ] && return; done
|
2017-10-22 00:33:27 -07:00
|
|
|
die 1 "Unknown option $err"
|
2010-12-30 02:52:02 +01:00
|
|
|
}
|
|
|
|
|
2012-06-02 22:05:14 +02:00
|
|
|
parse_input() # Parse stuff :V
|
2017-11-17 19:08:36 -08:00
|
|
|
{ OPTS=; while read -r VAR _; do
|
|
|
|
TMPVAR="${VAR%=*}"
|
|
|
|
OPTS="$OPTS ${TMPVAR##HAVE_}"
|
|
|
|
done < 'qb/config.params.sh'
|
|
|
|
#OPTS contains all available options in config.params.sh - used to speedup
|
|
|
|
#things in opt_exists()
|
2012-06-02 22:05:14 +02:00
|
|
|
|
|
|
|
while [ "$1" ]; do
|
|
|
|
case "$1" in
|
|
|
|
--prefix=*) PREFIX=${1##--prefix=};;
|
2013-05-28 01:59:06 +02:00
|
|
|
--global-config-dir=*) GLOBAL_CONFIG_DIR=${1##--global-config-dir=};;
|
2017-11-22 15:21:12 -08:00
|
|
|
--build=*) BUILD="${1#*=}";;
|
2012-12-09 01:20:55 +02:00
|
|
|
--host=*) CROSS_COMPILE=${1##--host=}-;;
|
2012-06-02 22:05:14 +02:00
|
|
|
--enable-*)
|
2016-01-29 00:48:11 +01:00
|
|
|
opt_exists "${1##--enable-}" "$1"
|
2012-06-02 22:05:14 +02:00
|
|
|
eval "HAVE_$opt=yes"
|
|
|
|
;;
|
|
|
|
--disable-*)
|
2016-01-29 00:48:11 +01:00
|
|
|
opt_exists "${1##--disable-}" "$1"
|
2012-06-02 22:05:14 +02:00
|
|
|
eval "HAVE_$opt=no"
|
2017-01-16 15:06:46 -05:00
|
|
|
eval "HAVE_NO_$opt=yes"
|
2012-06-02 22:05:14 +02:00
|
|
|
;;
|
|
|
|
--with-*)
|
2014-06-05 11:45:44 +02:00
|
|
|
arg="${1##--with-}"
|
|
|
|
val="${arg##*=}"
|
2016-01-29 00:48:11 +01:00
|
|
|
opt_exists "${arg%%=*}" "$1"
|
2014-06-05 11:45:44 +02:00
|
|
|
eval "$opt=\"$val\""
|
2012-06-02 22:05:14 +02:00
|
|
|
;;
|
|
|
|
-h|--help) print_help; exit 0;;
|
2017-10-22 00:33:27 -07:00
|
|
|
*) die 1 "Unknown option $1";;
|
2012-06-02 22:05:14 +02:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2010-12-30 02:52:02 +01:00
|
|
|
}
|
|
|
|
|
2012-06-02 22:05:14 +02:00
|
|
|
. qb/config.params.sh
|
2010-12-30 02:52:02 +01:00
|
|
|
|
2017-10-22 00:33:27 -07:00
|
|
|
parse_input "$@"
|