#!/bin/sh
#
# Copyright (C) 2002 Khalid Aziz <khalid_aziz at hp.com>
# Copyright (C) 2002 Randy Dunlap <rddunlap at osdl.org>
# Copyright (C) 2002 Al Stone <ahs3 at fc.hp.com>
# Copyright (C) 2002 Hewlett-Packard Company
#
# SPDX-License-Identifier:     GPL-2.0-or-later
#
#   Busybox version by Matteo Croce <3297627799 at wind.it>
#
#   This script is taken from busybox projects - only file names
#   were changed.
#
# Rules to generate swupdateopts.h from .config:
#      - Retain lines that begin with "CONFIG_"
#      - Retain lines that begin with "# CONFIG_"
#      - lines that use double-quotes must \\-escape-quote them

config=.config

{
echo "\
#ifndef _SWCONFIGOPTS_H
#define _SWCONFIGOPTS_H
/*
 * swupdate configuration settings.
 *
 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
 *
 * This file is generated automatically by scripts/mkconfigs.
 * Do not edit.
 */
static const char swupdateconfig_config[] ALIGN1 ="

grep -e '^# CONFIG_' -e '^CONFIG_' "$config" \
| sed -e 's/\"/\\\"/g' -e 's/^/"/' -e 's/$/\\n"/'

echo ";"
echo "#endif"
} >"$1"

{
echo "\
#ifndef _SWCONFIGOPTS_BZ2_H
#define _SWCONFIGOPTS_BZ2_H
/*
 * swupdate configuration settings.
 *
 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
 *
 * This file is generated automatically by scripts/mkconfigs.
 * Do not edit.
 */
static const char swconfig_config_bz2[] ALIGN1 = {"

grep -e '^# CONFIG_' -e '^CONFIG_' "$config" \
| bzip2 -1 | dd bs=2 skip=1 2>/dev/null \
| od -v -t x1 \
| sed -e 's/^[^ ]*//' \
        -e 's/ //g' \
        -e '/^$/d' \
        -e 's/\(..\)/0x\1,/g'

echo "};"
echo "#endif"
} >"$2"
