# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../busybox/busybox.conf
# Copyright (C) 2006 - 2008 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# 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 ---

for x in $( match_source_file -p patch ); do
	var_append patchfiles ' ' $x
done

. $base/package/*/uclibc/conffiles-functions.in

runconf=0
var_append conffiles ' ' "$builddir/.config"

hook_add premake 1 'busybox_config'
busybox_config() {
	local BB_arch=$( echo $arch | arch2uname )

	# generate default config rules
	default_config > $builddir/.config

	if [ "$SDECFG_PKG_BUSYBOX_DEFCONFIG" == 0 ]; then
		eval $MAKE allnoconfig ARCH=$BB_arch
	else
		eval $MAKE defconfig ARCH=$BB_arch
	fi
	conffiles_loop 2 ARCH=$BB_arch
}

default_config() {
	echo "O CONFIG_MAKEDEVS"

	if [ "$SDECFG_STATIC" == 1 ]; then
		echo "X CONFIG_STATIC"
	else
		echo "O CONFIG_STATIC"
		echo "X CONFIG_BUILD_LIBBUSYBOX"
	fi

	if [ "$SDECFG_PKG_BUSYBOX_ET" = 1 ] ; then
		echo "X CONFIG_PREFIX \"$root${SDECFG_PKG_BUSYBOX_ET_DIR#/}\""
	elif [ "$SDECFG_PKG_BUSYBOX_SYMLINKS" = 0 ] ; then
		echo "X CONFIG_INSTALL_APPLET_DONT"
		echo "O CONFIG_INSTALL_APPLET_SYMLINKS"
		echo "X CONFIG_PREFIX \"${root:-/}\""
	else
		echo "X CONFIG_PREFIX \"${root:-/}\""
	fi

	if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
		echo "O CONFIG_LOCALE_SUPPORT"
	fi

	if [ "$SDECFG_DEBUG" = 0 ]; then
		echo "O CONFIG_DEBUG"
	else
		echo "X CONFIG_DEBUG"
	fi

	if [ "$SDECFG_PKG_BUSYBOX_SUSv2" != 1 ]; then
		echo "O CONFIG_INCLUDE_SUSv2"
	else
		echo "X CONFIG_INCLUDE_SUSv2"
	fi
}

# add custom/target configuration from $targetdir
if [ -e $targetdir/busybox.config ] ; then
	var_append conffiles ' ' $targetdir/busybox.config
fi

if [ "$SDECFG_PKG_BUSYBOX_ET" = 1 ] ; then
	prefix="${SDECFG_PKG_BUSYBOX_ET_DIR#/}"
	set_confopt

	var_append flistroot ' ' "${prefix%%/*}"
	var_append conffiles ' ' "$confdir/emergency.config"
fi

var_append conffiles ' ' $confdir/broken.config

# when SDECFG_DEBUG is enabled, we don't get busybox, just busybox_unstripped
# but `make install` still expects busybox to be there
#
[ "$SDECFG_DEBUG" != 1 ] || hook_add inmake 5 'cp -v busybox_unstripped busybox'

# save .config file for the future
hook_add postdoc 9 'cp -v .config busybox.links $root/$docdir'