#!/bin/bash
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: lib/sde-config/pkgseldir_compile.sh
|
|
# Copyright (C) 2008 - 2010 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
PKGSEL_LIST_VAR="$1"
|
|
VAR_PREFIX="$2"
|
|
OUT_PREFIX="$3"
|
|
|
|
shift 3
|
|
|
|
OUT_CONFIG="${OUT_PREFIX}config.in"
|
|
OUT_PKGSEL="${OUT_PREFIX}pkgsel.in"
|
|
OUT_PKGSELAWK="${OUT_PREFIX}pkgsel.awk"
|
|
|
|
trap ' ' INT
|
|
|
|
module_get_var()
|
|
{
|
|
echo "${VAR_PREFIX}${1}" | tr ' a-z-' '_A-Z_'
|
|
}
|
|
|
|
module_get_description()
|
|
{
|
|
sed -n -e 's/^#[ \t]*Description:[ \t]*\(.*\)/\1/p' "$1"
|
|
}
|
|
|
|
module_get_default()
|
|
{
|
|
sed -n -e 's/^# Default: \(.*\)/\1/p' "$1"
|
|
}
|
|
|
|
module_render()
|
|
{
|
|
local pkgseldir="$1" module_dir="$2" module_filename="$3" module_name="$4" module_type="$5"
|
|
local file= var= desc= default=
|
|
|
|
# recompose the full path to the module file
|
|
file="$pkgseldir${module_dir:+/$module_dir}/$module_filename"
|
|
var="$( module_get_var "$module_name" )"
|
|
|
|
# print headers
|
|
cat <<-EOT | tee -a "$OUT_CONFIG.$$" >> "$OUT_PKGSEL.$$"
|
|
# BEGIN:$var ($module_filename)
|
|
#
|
|
EOT
|
|
|
|
case "$module_type" in
|
|
auto)
|
|
cat <<-EOT >> "$OUT_PKGSEL.$$"
|
|
$PKGSEL_LIST_VAR="\$$PKGSEL_LIST_VAR $file"
|
|
EOT
|
|
;;
|
|
boolean)
|
|
desc="$( module_get_description "$file" )"
|
|
default="$( module_get_default "$file" )"
|
|
|
|
cat <<-EOT >> "$OUT_CONFIG.$$"
|
|
bool '${desc:-${module_name//_/ }}' $var ${default:-0}
|
|
EOT
|
|
|
|
cat <<-EOT >> "$OUT_PKGSEL.$$"
|
|
if [ "\$$var" = 1 ]; then
|
|
$PKGSEL_LIST_VAR="\$$PKGSEL_LIST_VAR $file"
|
|
fi
|
|
EOT
|
|
;;
|
|
esac
|
|
|
|
# print footers
|
|
cat <<-EOT | tee -a "$OUT_CONFIG.$$" >> "$OUT_PKGSEL.$$"
|
|
# END:$var
|
|
|
|
EOT
|
|
}
|
|
|
|
cat <<-EOT | tee "$OUT_CONFIG.$$" > "$OUT_PKGSEL.$$"
|
|
# Generated by $0
|
|
# ($( date ))
|
|
# using: $@
|
|
|
|
EOT
|
|
|
|
for pkgseldir; do
|
|
if [ ! -d "$pkgseldir" ]; then
|
|
echo "$pkgseldir: Invalid pkgseldir." >&2
|
|
continue
|
|
else
|
|
pkgseldir=$( cd "$pkgseldir"; pwd -P )
|
|
fi
|
|
|
|
bin/find "$pkgseldir" -name '*.all' -o -name '*.ask' | sort | while read module; do
|
|
# simple parsing
|
|
#
|
|
module_dir="${module%/*}"
|
|
module_filename="${module##*/}"
|
|
module_file_ext="${module##*.}"
|
|
|
|
case "$module_file_ext" in
|
|
all) module_type=auto
|
|
;;
|
|
ask) module_type=boolean
|
|
;;
|
|
*) # not a module
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
# make $module_dir $pkgseldir relative
|
|
if [ "$module_dir" = "$pkgseldir" ]; then
|
|
module_dir=
|
|
else
|
|
module_dir="${module_dir#$pkgseldir/}"
|
|
fi
|
|
|
|
module_name="$( echo "${module_filename%.*}" | sed -e 's/^[0-9][0-9]-//' )"
|
|
|
|
module_render "$pkgseldir" "$module_dir" "$module_filename" "$module_name" "$module_type"
|
|
done
|
|
done
|
|
|
|
cat <<EOT >> "$OUT_PKGSEL.$$"
|
|
|
|
# Update .awk file only if needed
|
|
#
|
|
if [ ! -s "$OUT_PKGSELAWK" -o "\$( cat "$OUT_PKGSELAWK.cache" 2> /dev/null)" != "\$$PKGSEL_LIST_VAR" ]; then
|
|
echo "\$$PKGSEL_LIST_VAR" > $OUT_PKGSELAWK.cache
|
|
|
|
cat <<-EOF > "$OUT_PKGSELAWK.\$\$"
|
|
# Generated by \$0
|
|
# \$( date )
|
|
# using: \$$PKGSEL_LIST_VAR
|
|
|
|
EOF
|
|
|
|
lib/sde-config/pkgsel2awk.sh \$$PKGSEL_LIST_VAR >> "$OUT_PKGSELAWK.\$\$"
|
|
mv "$OUT_PKGSELAWK.\$\$" "$OUT_PKGSELAWK"
|
|
fi
|
|
EOT
|
|
|
|
for x in $OUT_CONFIG $OUT_PKGSEL; do
|
|
mv "$x.$$" "$x"
|
|
done
|