| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
|
| 4 |
BASHVER=$(expr ${BASH_VERSINFO[0]} \* 1000 + ${BASH_VERSINFO[1]}) |
| 5 |
|
| 6 |
if [ "$BASHVER" -lt 3002 ]; then |
| 7 |
echo "ERROR: mklove requires bash version 3.2 or later but you are using $BASH_VERSION ($BASHVER)" |
| 8 |
echo " See https://github.com/edenhill/mklove/issues/15" |
| 9 |
exit 1 |
| 10 |
fi |
| 11 |
|
| 12 |
MKL_CONFIGURE_ARGS="$0 $*" |
| 13 |
|
| 14 |
# Load base module |
| 15 |
source mklove/modules/configure.base |
| 16 |
|
| 17 |
# Read some special command line options right away that must be known prior to |
| 18 |
# sourcing modules. |
| 19 |
mkl_in_list "$*" "--no-download" && MKL_NO_DOWNLOAD=1 |
| 20 |
# Disable downloads when --help is used to avoid blocking calls. |
| 21 |
mkl_in_list "$*" "--help" && MKL_NO_DOWNLOAD=1 |
| 22 |
mkl_in_list "$*" "--debug" && MKL_DEBUG=1 |
| 23 |
|
| 24 |
# This is the earliest possible time to check for color support in |
| 25 |
# terminal because mkl_check_terminal_color_support uses mkl_dbg which |
| 26 |
# needs to know if MKL_DEBUG is set |
| 27 |
mkl_check_terminal_color_support |
| 28 |
|
| 29 |
# Delete temporary Makefile and header files on exit. |
| 30 |
trap "{ rm -f $MKL_OUTMK $MKL_OUTH; }" EXIT |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
## |
| 35 |
## Load builtin modules |
| 36 |
## |
| 37 |
|
| 38 |
# Builtin options, etc. |
| 39 |
mkl_require builtin |
| 40 |
|
| 41 |
# Host/target support |
| 42 |
mkl_require host |
| 43 |
|
| 44 |
# Compiler detection |
| 45 |
mkl_require cc |
| 46 |
|
| 47 |
|
| 48 |
# Load application provided modules (in current directory), if any. |
| 49 |
for fname in configure.* ; do |
| 50 |
if [[ $fname = 'configure.*' ]]; then |
| 51 |
continue |
| 52 |
fi |
| 53 |
|
| 54 |
# Skip temporary files |
| 55 |
if [[ $fname = *~ ]]; then |
| 56 |
continue |
| 57 |
fi |
| 58 |
|
| 59 |
mkl_require $fname |
| 60 |
done |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
## |
| 66 |
## Argument parsing (options) |
| 67 |
## |
| 68 |
## |
| 69 |
|
| 70 |
_SAVE_ARGS="$*" |
| 71 |
|
| 72 |
# Parse arguments |
| 73 |
while [[ ! -z $@ ]]; do |
| 74 |
if [[ $1 != --* ]]; then |
| 75 |
mkl_err "Unknown non-option argument: $1" |
| 76 |
mkl_usage |
| 77 |
exit 1 |
| 78 |
fi |
| 79 |
|
| 80 |
opt=${1#--} |
| 81 |
shift |
| 82 |
|
| 83 |
if [[ $opt = *=* ]]; then |
| 84 |
name="${opt%%=*}" |
| 85 |
arg="${opt#*=}" |
| 86 |
eqarg=1 |
| 87 |
else |
| 88 |
name="$opt" |
| 89 |
arg="" |
| 90 |
eqarg=0 |
| 91 |
fi |
| 92 |
|
| 93 |
safeopt="$(mkl_env_esc $name)" |
| 94 |
|
| 95 |
if ! mkl_func_exists opt_$safeopt ; then |
| 96 |
mkl_err "Unknown option $opt" |
| 97 |
mkl_usage |
| 98 |
exit 1 |
| 99 |
fi |
| 100 |
|
| 101 |
# Check if this option needs an argument. |
| 102 |
reqarg=$(mkl_meta_get "MKL_OPT_ARGS" "$(mkl_env_esc $name)") |
| 103 |
if [[ ! -z $reqarg ]]; then |
| 104 |
if [[ $eqarg == 0 && -z $arg ]]; then |
| 105 |
arg="$1" |
| 106 |
shift |
| 107 |
|
| 108 |
if [[ -z $arg && $reqarg != '\*' ]]; then |
| 109 |
mkl_err "Missing argument to option --$name $reqarg" |
| 110 |
exit 1 |
| 111 |
fi |
| 112 |
fi |
| 113 |
else |
| 114 |
if [[ ! -z $arg ]]; then |
| 115 |
mkl_err "Option --$name expects no argument" |
| 116 |
exit 1 |
| 117 |
fi |
| 118 |
arg=y |
| 119 |
fi |
| 120 |
|
| 121 |
case $name in |
| 122 |
re|reconfigure) |
| 123 |
oldcmd=$(head -1 config.log | grep '^# configure exec: ' | \ |
| 124 |
sed -e 's/^\# configure exec: [^ ]*configure//') |
| 125 |
echo "Reconfiguring: $0 $oldcmd" |
| 126 |
exec $0 $oldcmd |
| 127 |
;; |
| 128 |
|
| 129 |
list-modules) |
| 130 |
echo "Modules loaded:" |
| 131 |
for mod in $MKL_MODULES ; do |
| 132 |
echo " $mod" |
| 133 |
done |
| 134 |
exit 0 |
| 135 |
;; |
| 136 |
|
| 137 |
list-checks) |
| 138 |
echo "Check functions in calling order:" |
| 139 |
for mf in $MKL_CHECKS ; do |
| 140 |
mod=${mf%:*} |
| 141 |
func=${mf#*:} |
| 142 |
echo -e "${MKL_GREEN}From module $mod:$MKL_CLR_RESET" |
| 143 |
declare -f $func |
| 144 |
echo "" |
| 145 |
done |
| 146 |
exit 0 |
| 147 |
;; |
| 148 |
|
| 149 |
update-modules) |
| 150 |
fails=0 |
| 151 |
echo "Updating modules" |
| 152 |
for mod in $MKL_MODULES ; do |
| 153 |
echo -n "Updating $mod..." |
| 154 |
if mkl_module_download "$mod" > /dev/null ; then |
| 155 |
echo -e "${MKL_GREEN}ok${MKL_CLR_RESET}" |
| 156 |
else |
| 157 |
echo -e "${MKL_RED}failed${MKL_CLR_RESET}" |
| 158 |
fails=$(expr $fails + 1) |
| 159 |
fi |
| 160 |
done |
| 161 |
exit $fails |
| 162 |
;; |
| 163 |
|
| 164 |
help) |
| 165 |
mkl_usage |
| 166 |
exit 0 |
| 167 |
;; |
| 168 |
|
| 169 |
*) |
| 170 |
opt_$safeopt "$arg" || exit 1 |
| 171 |
mkl_var_append MKL_OPTS_SET "$safeopt" |
| 172 |
;; |
| 173 |
esac |
| 174 |
done |
| 175 |
|
| 176 |
if [[ ! -z $MKL_CLEAN ]]; then |
| 177 |
mkl_clean |
| 178 |
exit 0 |
| 179 |
fi |
| 180 |
|
| 181 |
# Move away previous log file |
| 182 |
[[ -f $MKL_OUTDBG ]] && mv $MKL_OUTDBG ${MKL_OUTDBG}.old |
| 183 |
|
| 184 |
|
| 185 |
# Create output files |
| 186 |
echo "# configure exec: $0 $_SAVE_ARGS" >> $MKL_OUTDBG |
| 187 |
echo "# On $(date)" >> $MKL_OUTDBG |
| 188 |
|
| 189 |
rm -f $MKL_OUTMK $MKL_OUTH |
| 190 |
|
| 191 |
|
| 192 |
# Load cache file |
| 193 |
mkl_cache_read |
| 194 |
|
| 195 |
# Run checks |
| 196 |
mkl_checks_run |
| 197 |
|
| 198 |
# Check accumulated failures, will not return on failure. |
| 199 |
mkl_check_fails |
| 200 |
|
| 201 |
# Generate outputs |
| 202 |
mkl_generate |
| 203 |
|
| 204 |
# Summarize what happened |
| 205 |
mkl_summary |
| 206 |
|
| 207 |
# Write cache file |
| 208 |
mkl_cache_write |
| 209 |
|
| 210 |
|
| 211 |
echo "" |
| 212 |
echo "Now type 'make' to build" |
| 213 |
trap - EXIT |
| 214 |
exit 0 |