diff options
Diffstat (limited to 'bootstrap')
-rwxr-xr-x | bootstrap | 118 |
1 files changed, 86 insertions, 32 deletions
@@ -1,5 +1,11 @@ #!/bin/bash +if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then + echo "Your BASH shell version (${BASH_VERSION}) is too old." >&2 + echo "Run bootstrap on a machine with BASH 4.x" >&2 + exit 1 +fi + ######################################## # Common meta-language implementation. Syntax: # @@ -71,18 +77,21 @@ find_end() set_iter() { local name="${1}" + local -a temp if [ "${info[iter_${name}]+set}" = "set" ]; then error "Iterator over '${name}' is already set up" fi shift debug "Setting iterator over '${name}' to '$*'" + temp=("$@") info[iter_${name}]="$*" + info[#${name}]=${#temp[@]} } run_if() { - local cond="${1}" + local cond="$*" local endline find_end "if" @@ -116,8 +125,9 @@ do_foreach() for k in "${!info[@]}"; do saveinfo["${k}"]=${info["${k}"]} done - eval "enter_${var} ${v}" - eval "$@" + if eval "enter_${var} ${v}"; then + eval "$@" + fi info=() for k in "${!saveinfo[@]}"; do info["${k}"]=${saveinfo["${k}"]} @@ -127,24 +137,53 @@ do_foreach() run_foreach() { - local var="${1}" local endline + local var="${1}" + shift if [ "${info[iter_${var}]+set}" != "set" ]; then error "line ${l}: iterator over '${var}' is not defined" fi find_end "foreach" debug "Loop over '${var}', lines ${l}..${endline}" - do_foreach ${var} run_lines $[l + 1] $[endline - 1] + do_foreach ${var} run_lines_if $[l + 1] $[endline - 1] "$*" lnext=$[endline + 1] debug "Continue at line ${lnext}" } +run_lines_if() +{ + local start="${1}" + local end="${2}" + shift 2 + local cond="$*" + local a prev + + for a in ${cond}; do + if [ -n "${prev}" ]; then + case "${prev}" in + if-differs) + if [ "${info[${a}]}" = "${saveinfo[${a}]}" ]; then + return + fi + ;; + *) + error "line ${l}: unknown condition '${prev}' for loop" + ;; + esac + prev= + else + prev=${a} + fi + done + run_lines "${start}" "${end}" +} + run_lines() { local start="${1}" local end="${2}" - local l lnext s s1 v + local l lnext s s1 v vp pp p val debug "Running lines ${start}..${end}" l=${start} @@ -160,8 +199,34 @@ run_lines() *@@*@@*) v="${s#*@@}" v="${v%%@@*}" + # $v now includes variable name + any postprocessing + vp="${v%%[|?]*}" + pp="${v#${vp}}" + # $vp is name of the variable proper, $pp is any postprocessing + if [ "${info[${vp}]+set}" != "set" ]; then + error "line ${l}: reference to undefined variable '${vp}'" + fi if [ "${info[${v}]+set}" != "set" ]; then - error "line ${l}: reference to undefined variable '${v}'" + # We know the base variable, need to cache postprocessed value + val="${info[${vp}]}" + # Apply postprocessing(s) + while [ -n "${pp}" ]; do + case "${pp}" in + "|"*) + # Kconfigize + pp="${pp#|}" + val=${val//[^0-9A-Za-z_]/_} + val=${val^^} + ;; + "?"*) + pp="${pp#?}" + p="${pp%%[|?]*}" + pp="${pp#${p}}" + val="${val:+${p}}" + ;; + esac + done + info[${v}]="${val}" fi s1="${s1}${s%%@@*}\${info[${v}]}" s="${s#*@@*@@}" @@ -180,10 +245,10 @@ run_lines() debug "Evaluate: ${s}" case "${s}" in "#!if "*) - run_if "${s#* }" + run_if ${s#* } ;; "#!foreach "*) - run_foreach "${s#* }" + run_foreach ${s#* } ;; "#!//"*) # Comment, do nothing @@ -215,15 +280,14 @@ run_template() ######################################## -# Convert the argument to a Kconfig-style macro -kconfigize() +# Leave only relevant portion of the string +relevantize() { - local v="${1}" local p pb pa vx + local v="${1}" shift - # If optional patterns are provided, find the first match - # and contract to the matching portion. + # Find the first match and contract to the matching portion. for p in "$@"; do pb=${p%|*} pa=${p#*|} @@ -233,9 +297,7 @@ kconfigize() break fi done - - v=${v//[^0-9A-Za-z_]/_} - echo "${v^^}" + echo "${v}" } # Helper for cmp_versions: compare an upstream/debian portion of @@ -478,11 +540,11 @@ enter_fork() info[mirrors]= info[archive_filename]='@{pkg_name}-@{version}' info[archive_dirname]='@{pkg_name}-@{version}' + info[versionlocked]= + info[origin]= eval `read_package_desc ${fork}` - info[pfx]=`kconfigize ${fork}` - info[originpfx]=`kconfigize ${info[origin]}` if [ -r "packages/${info[origin]}.help" ]; then info[originhelp]=`sed 's/^/ /' "packages/${info[origin]}.help"` else @@ -493,7 +555,6 @@ enter_fork() info[vcs]=${info[repository]%% *} info[repository_url]=${info[repository]#* } fi - info[versionlocked]=`kconfigize "${info[versionlocked]}"` versions=`cd packages/${fork} && \ for f in */version.desc; do [ -r "${f}" ] && echo "${f%/version.desc}"; done` @@ -519,16 +580,11 @@ enter_fork() enter_version() { - local -A ver_postfix=( \ - [,yes,,]=" (OBSOLETE)" \ - [,,yes,]=" (EXPERIMENTAL)" \ - [,yes,yes,]=" (OBSOLETE,EXPERIMENTAL)" ) local version="${1}" eval `read_version_desc ${info[fork]} ${version}` info[ver]=${version} - info[kcfg]=`kconfigize ${version} ${info[relevantpattern]}` - info[ver_postfix]=${ver_postfix[,${info[obsolete]},${info[experimental]},]} + info[ver_sel]=`relevantize ${version} ${info[relevantpattern]}` } enter_milestone() @@ -537,7 +593,6 @@ enter_milestone() local cmp info[ms]=${ms} - info[ms_kcfg]=`kconfigize ${ms}` if [ -n "${info[ver]}" ]; then info[version_cmp_milestone]=`cmp_versions ${info[ver]} ${info[ms]}` fi @@ -564,22 +619,23 @@ gen_packages() msg "Master packages: ${pkg_masters[@]}" # Now for each master, create its kconfig file with version - # definitions. + # definitions. As a byproduct, generate a list of all package + # versions for maintenance purposes. + exec 3>"maintainer/package-versions" for p in "${pkg_masters[@]}"; do msg "Generating '${config_versions_dir}/${p}.in'" exec >"${config_versions_dir}/${p}.in" # Base definitions for the whole config file info=( \ [master]=${p} \ - [masterpfx]=`kconfigize ${p}` \ [nforks]=${pkg_nforks[${p}]} \ - [all_milestones]=${pkg_milestones[${p}]} \ [relevantpattern]=${pkg_relevantpattern[${p}]} \ ) set_iter fork ${pkg_forks[${p}]} set_iter milestone ${pkg_milestones[${p}]} run_template "maintainer/kconfig-versions.template" + run_template "maintainer/package-versions.template" >&3 done } @@ -606,7 +662,6 @@ enter_choice() local l info[choice]="${choice}" - info[kcfg_choice]=`kconfigize "${choice}"` # Not local, we need these arrays be set in enter_dependency/enter_help deplines=( ) @@ -644,7 +699,6 @@ gen_selection() msg "Generating ${dir}.in" exec >"${config_gen_dir}/${dir}.in" info=( \ - [prefix]=`kconfigize ${dir}` \ [dir]=${dir} \ [label]="${label}" \ ) |