Skip to content

Commit

Permalink
Merge pull request #928 from kernelkit/update-generate-defconfig
Browse files Browse the repository at this point in the history
generate-defconfig.sh: Allow to have multiple change configurations
  • Loading branch information
wkz authored Feb 4, 2025
2 parents 84521ea + 4ba43e2 commit a608c4a
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions utils/generate-defconfig.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#!/bin/sh
# Create new defconfigs by only applying the changes from a standard defconfig

set -e

SCRIPT_DIR="$(readlink -f $(dirname -- "$0"))"
MERGE_CONFIG="${SCRIPT_DIR}/../buildroot/support/kconfig/merge_config.sh"

usage() {
cat <<EOF
Usage: $(basename "$0") -b BASE_CONFIG -c CHANGES -o OUTPUT_FILE
Usage: $(basename "$0") -b BASE_CONFIG -c CHANGES... -o OUTPUT_FILE
Create a new defconfig by applying changes to a base configuration.
Required Options:
-b, --base BASE Path to base defconfig file
-c, --changes CHANGES Path to config changes to apply
-c, --changes CHANGES Path to config changes to apply (can be specified multiple times)
-o, --output OUTPUT Path to output defconfig file
Example:
$(basename "$0") \\
-b configs/aarch64_defconfig \\
-c changes/no-containers.conf \\
-o configs/aarch64_wo_containers_defconfig
-c changes/extra-features.conf \\
-o configs/aarch64_custom_defconfig
EOF
exit 1
}

check_file() {
file="$1"
type="$2"

if [ ! -f "$file" ]; then
echo "Error: $type file does not exist: $file" >&2
exit 1
Expand All @@ -38,31 +38,34 @@ check_file() {
fi
}

base=""
output=""
changes=""

while [ $# -gt 0 ]; do
case $1 in
-b|--base)
base="$2"
shift 2
;;
-c|--changes)
changes="$2"
shift 2
;;
-o|--output)
output="$2"
shift 2
;;
*)
usage
exit 1
;;
-b|--base)
base="$2"
shift 2
;;
-c|--changes)
changes="$changes $2"
shift 2
;;
-o|--output)
output="$2"
shift 2
;;
*)
usage
exit 1
;;
esac
done

if [ -z $output ] || [ -z $changes ] || [ -z $output ]; then
usage
exit 1
if [ -z "$base" ] || [ -z "$changes" ] || [ -z "$output" ]; then
usage
exit 1
fi

if [ ! -x "$MERGE_CONFIG" ]; then
Expand All @@ -71,10 +74,13 @@ if [ ! -x "$MERGE_CONFIG" ]; then
fi

check_file "$base" "Base config"
check_file "$changes" "Changes config"
for change in $changes; do
check_file "$change" "Changes config"
done

TMPDIR=`mktemp -d`
$MERGE_CONFIG -O "$TMPDIR" "$base" "$changes"

O="$TMPDIR" make savedefconfig
mv "$TMPDIR"/defconfig "$output"
rm -r "$TMPDIR"

0 comments on commit a608c4a

Please sign in to comment.