1
0
This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
ZyXEL_VMG8623-T50B/vmg8623_t50b_default_release/scripts_qca/extractVendorSDKCfg.sh

100 lines
2.9 KiB
Bash
Executable File

#!/bin/sh
if [ $# -lt 3 ]; then
echo "Usage: extractVendorSDKCfg.sh <cfg prefix> <input file> <output file> [C header file]"
echo -e "\tThis script will extract configs from <input file>"
echo -e "\tOutput file is used to store extracted configs"
echo -e "\t<cfg prefix> "
exit -1
fi
OPENWRT_CFG_FILE=$2
if [ ! -e $OPENWRT_CFG_FILE ]; then
echo "File '$OPENWRT_CFG_FILE' not found!"
exit -2
fi
if [ -z "$1" ]; then
echo "Prefix can't be empty!"
exit -3
fi
if [ ! -z `echo $1 | grep CONFIG_` ]; then
REMOVE_PREFIX_CONFIG=y
CFG_PREFIX=`echo $1 | sed "s/CONFIG_//"`
# echo;echo "!!!! CFG_PREFIX=$CFG_PREFIX !!!!";echo
else
CFG_PREFIX=$1
fi
if [ -n "$3" ]; then
VENDOR_CFG_FILE=$3
else
echo "Not specify the output file name"
exit -4
fi
echo -e "#\n# Automatically generated by make menuconfig + extractVendorSDKCfg.sh : don't edit" > $VENDOR_CFG_FILE
echo -e "# `date`\n#\n" >> $VENDOR_CFG_FILE
# 1. using 'grep' to filter the vendor configurations which prefix is "CONFIG_${CFG_PREFIX}_"
if [ "$REMOVE_PREFIX_CONFIG" = "y" ]; then
# 2. using 'sed' to remove prefix 'CONFIG_${CFG_PREFIX}_
cat $OPENWRT_CFG_FILE | grep "CONFIG_${CFG_PREFIX}_" | grep -v "CONFIG_${CFG_PREFIX}_RM_QUOTES_" | sed "s/CONFIG_${CFG_PREFIX}_//" >> $VENDOR_CFG_FILE
else
# 2. using 'sed' to remove prefix '${CFG_PREFIX}_
cat $OPENWRT_CFG_FILE | grep "CONFIG_${CFG_PREFIX}_" | grep -v "CONFIG_${CFG_PREFIX}_RM_QUOTES_" | sed "s/${CFG_PREFIX}_//" >> $VENDOR_CFG_FILE
fi
# To collect options which need to remove quotes
OPT_RM_QUOTES=`cat $OPENWRT_CFG_FILE | grep "^CONFIG_${CFG_PREFIX}_RM_QUOTES_" | sed "s/${CFG_PREFIX}_RM_QUOTES_//" | sed "s/=y//"`
# remove quotes
for i in $OPT_RM_QUOTES; do
#echo "search '$i'"; sed -n "/\b$i\b/p" $2
old=`sed -n "/\b$i\b/p" $VENDOR_CFG_FILE`
new=`echo $old | sed "s/\"//g"`
#echo "old=$old";echo "new=$new";echo
sed -i "s/$old/$new/g" $VENDOR_CFG_FILE
done
# create C style header file
if [ -n "$4" ]; then
mkdir -p $(dirname $4)
echo -e "/*\n * Automatically generated by make menuconfig + extractVendorSDKCfg.sh : don't edit\n */\n" > $4
if [ -n "$5" ]; then
HEADER_FILE_FLAG=$5
else
HEADER_FILE_FLAG=_$(echo $(basename $4) | tr '[:lower:]' '[:upper:]' | sed "s/\./_/")_
fi
echo -e "#ifndef $HEADER_FILE_FLAG" >> $4
echo -e "#define $HEADER_FILE_FLAG\n" >> $4
while read cfg; do
if [ -z "$cfg" ]; then
continue
fi
# unset configuration
if [ "`echo $cfg | cut -c 1`" = "#" ]; then
if [ -n "`echo $cfg | grep 'CONFIG_'`" ]; then
cfg_name=`echo $cfg | cut -d' ' -f2`
echo "#undef $cfg_name" >> $4
fi
continue
fi
cfg_name=`echo $cfg | cut -d'=' -f1`
cfg_val=`echo $cfg | cut -d'=' -f2`
if [ "$cfg_val" = "m" ]; then
echo "#undef $cfg_name" >> $4
echo "#define ${cfg_name}_MODULE 1" >> $4
continue
fi
if [ "$cfg_val" = "y" ]; then
echo "#define $cfg_name 1" >> $4
else
echo "#define $cfg_name $cfg_val" >> $4
fi
done < $VENDOR_CFG_FILE
echo -e "\n#endif" >> $4
fi