# --- T2-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# T2 SDE: package/.../musl/parse-config
# Copyright (C) 2004 - 2019 The T2 SDE 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.
# --- T2-COPYRIGHT-NOTE-END ---

if [ "$SDECFG_LIBC" == "musl" ]; then
	[ "$pkg" != "musl" ] && var_append flist''del '|' "usr/lib[^/]*/charset.alias"

        # the most typical fix is to config.sub
        #
        musl_fix_configsub() {
        local x; for x; do
                echo "musl_fix_configsub: adding musl_arch_target support to $x"
                cp -f $x $x.orig
                sed -e 's,\([-]\?linux\)-gnu\*,\1-gnu\* | \1-musl\*,g' $x.orig > $x
                diff -u $x.orig $x || true
        done
        }
        musl_auto_fix_configsub() {
		local f
		grep /config.sub $builddir/untar.txt | cut -d / -f 2- |
		while read f; do
			if ! grep -q '\-musl' $f; then
				musl_fix_configsub $f
			fi
		done
        }
	hook_add postpatch 5 'musl_auto_fix_configsub'

	case "$pkg" in
	coreutils)	var_append extraconfopt ' ' '--with-included-regex' ;;
	gcc)	var_append extraconfopt ' ' '--disable-multilib' ;;
	esac

	# patching
	if [ "`echo $confdir/*.patch.musl`" != "$confdir/*.patch.musl" ]; then
		echo_status "musl: appending patches..."
		var_append patchfiles ' ' "`echo $confdir/*.patch.musl`"
	fi
fi
