diff --git a/iop/scripts/genconfig.sh b/iop/scripts/genconfig.sh index 5df1f9580..6d21bb468 100755 --- a/iop/scripts/genconfig.sh +++ b/iop/scripts/genconfig.sh @@ -298,6 +298,24 @@ function genconfig { fi } + get_subtarget_for_device() { + readonly target="$1" + readonly device="$2" + readonly targetinfo_file="tmp/info/.targetinfo-feeds_$target" + readonly target_profile_line="Target-Profile: DEVICE_$device" + # We want to know after which Target: $target/$subtarget line + # our $target_profile_line appears + # This is a crude way to "parse" the file using shell 🤯 + # 1. grep for both lines with line number output + # 2. grep again to determine the device profile line that we looked for + # but output one context line before as well to determine corresponding subtarget line + # 4. Use head and sed to extract the subtarget + grep "^Target: $target/\|^$target_profile_line" "$targetinfo_file" \ + | grep -E -B1 "^$target_profile_line" \ + | head -n1 \ + | sed -E "s|^Target: $target/||" + } + create_and_copy_files() { local BOARDTYPE=$1 @@ -345,12 +363,11 @@ function genconfig { airoha | iopsys_mediatek | brcmbca | ipq95xx) # This assumes the device name to be unique within one target, # which is a fair assumption to make. - local mk_file="$(grep -Fx --files-with-matches "define Device/${BOARDTYPE}" "$target_config_path/../image/"*.mk)" - if [ -z "$mk_file" ]; then + local subtarget="$(get_subtarget_for_device "$target" "$BOARDTYPE")" + if [ -z "$subtarget" ]; then echo "Error determining subtarget for $target / ${BOARDTYPE}" return 1 fi - local subtarget="$(basename "${mk_file%.mk}")" echo "CONFIG_TARGET_${target}=y" >> .config echo "CONFIG_TARGET_${target}_${subtarget}=y" >> .config echo "CONFIG_TARGET_DEVICE_${target}_${subtarget}_DEVICE_${BOARDTYPE}=y" >> .config diff --git a/iop/scripts/genconfig_min.sh b/iop/scripts/genconfig_min.sh index d46219603..ffc3ab6ba 100644 --- a/iop/scripts/genconfig_min.sh +++ b/iop/scripts/genconfig_min.sh @@ -272,6 +272,24 @@ function genconfig_min { fi } + get_subtarget_for_device() { + readonly target="$1" + readonly device="$2" + readonly targetinfo_file="tmp/info/.targetinfo-feeds_$target" + readonly target_profile_line="Target-Profile: DEVICE_$device" + # We want to know after which Target: $target/$subtarget line + # our $target_profile_line appears + # This is a crude way to "parse" the file using shell 🤯 + # 1. grep for both lines with line number output + # 2. grep again to determine the device profile line that we looked for + # but output one context line before as well to determine corresponding subtarget line + # 4. Use head and sed to extract the subtarget + grep "^Target: $target/\|^$target_profile_line" "$targetinfo_file" \ + | grep -E -B1 "^$target_profile_line" \ + | head -n1 \ + | sed -E "s|^Target: $target/||" + } + create_and_copy_files() { local BOARDTYPE=$1 @@ -316,15 +334,14 @@ function genconfig_min { # Special handling for targets which use TARGET_DEVICES case "$target" in - airoha | iopsys_mediatek | brcmbca | ipq95xx) + airoha | iopsys_mediatek | brcmbca | ipq95xx) # This assumes the device name to be unique within one target, # which is a fair assumption to make. - local mk_file="$(grep -Fx --files-with-matches "define Device/${BOARDTYPE}" "$target_config_path/../image/"*.mk)" - if [ -z "$mk_file" ]; then + local subtarget="$(get_subtarget_for_device "$target" "$BOARDTYPE")" + if [ -z "$subtarget" ]; then echo "Error determining subtarget for $target / ${BOARDTYPE}" return 1 fi - local subtarget="$(basename "${mk_file%.mk}")" echo "CONFIG_TARGET_${target}=y" >> .config echo "CONFIG_TARGET_${target}_${subtarget}=y" >> .config echo "CONFIG_TARGET_DEVICE_${target}_${subtarget}_DEVICE_${BOARDTYPE}=y" >> .config