summaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/files/merge_config.sh
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/linux/files/merge_config.sh')
-rwxr-xr-xrecipes-kernel/linux/files/merge_config.sh142
1 files changed, 142 insertions, 0 deletions
diff --git a/recipes-kernel/linux/files/merge_config.sh b/recipes-kernel/linux/files/merge_config.sh
new file mode 100755
index 0000000..33f18d4
--- /dev/null
+++ b/recipes-kernel/linux/files/merge_config.sh
@@ -0,0 +1,142 @@
1#!/bin/sh
2# merge_config.sh - Takes a list of config fragment values, and merges
3# them one by one. Provides warnings on overridden values, and specified
4# values that did not make it to the resulting .config file (due to missed
5# dependencies or config symbol removal).
6#
7# Portions reused from kconf_check and generate_cfg:
8# http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check
9# http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg
10#
11# Copyright (c) 2009-2010 Wind River Systems, Inc.
12# Copyright 2011 Linaro
13#
14# This program is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License version 2 as
16# published by the Free Software Foundation.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21# See the GNU General Public License for more details.
22
23
24usage() {
25 echo "Usage: $0 [OPTIONS] [CONFIG [...]]"
26echo " -h display this help text"
27echo " -m only merge the fragments, do not execute the make command"
28echo " -n use allnoconfig instead of alldefconfig"
29echo " -x use allmodconfig instead of alldefconfig"
30echo " -d debug. Don't cleanup temporary files"
31}
32
33MAKE_FLAG=true
34ALLTARGET=alldefconfig
35
36# There are two variables that impact where the .config will be dropped,
37# O= and KBUILD_OUTPUT=. So we'll respect those variables and use them as
38# an output directory as well. These two variables are not propagating
39# automatically to the kernel build, so always explicitly setting O=
40# and passing it to the kernel build ensures that it is respected.
41if [ -n "$KBUILD_OUTPUT" ]; then
42 O=$KBUILD_OUTPUT
43fi
44if [ -z "$O" ]; then
45 O=.
46fi
47
48while true; do
49 case $1 in
50 "-n")
51 ALLTARGET=allnoconfig
52 shift
53 continue
54 ;;
55 "-m")
56 MAKE_FLAG=false
57 shift
58 continue
59 ;;
60 "-d")
61 DEBUG=true
62 shift
63 continue
64 ;;
65 "-h")
66 usage
67 exit
68 ;;
69 *)
70 break
71 ;;
72 esac
73done
74
75clean_up() {
76 rm -f $TMP_FILE
77 exit
78}
79if [ -z "$DEBUG" ]; then
80 trap clean_up SIGHUP SIGINT SIGTERM
81fi
82
83
84MERGE_LIST=$*
85SED_CONFIG_EXP="s/^\(# \)\{0,1\}\(CONFIG_[a-zA-Z0-9_]*\)[= ].*/\2/p"
86TMP_FILE=$(mktemp $O/.tmp.config.XXXXXXXXXX)
87
88# Merge files, printing warnings on overrided values
89for MERGE_FILE in $MERGE_LIST ; do
90 echo "Merging $MERGE_FILE"
91 CFG_LIST=$(sed -n "$SED_CONFIG_EXP" $MERGE_FILE)
92
93 for CFG in $CFG_LIST ; do
94 grep -q -w $CFG $TMP_FILE
95 if [ $? -eq 0 ] ; then
96 PREV_VAL=$(grep -w $CFG $TMP_FILE)
97 NEW_VAL=$(grep -w $CFG $MERGE_FILE)
98 if [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then
99 echo Value of $CFG is redefined by fragment $MERGE_FILE:
100 echo Previous value: $PREV_VAL
101 echo New value: $NEW_VAL
102 echo
103 fi
104 sed -i "/$CFG[ =]/d" $TMP_FILE
105 fi
106 done
107 cat $MERGE_FILE >> $TMP_FILE
108done
109
110if [ "$MAKE_FLAG" = "false" ]; then
111 cp $TMP_FILE $O/.config
112 echo "#"
113 echo "# merged configuration written to $O/.config (needs make)"
114 echo "#"
115 if [ -z "$DEBUG" ]; then
116 clean_up
117 fi
118 exit
119fi
120
121# Use the merged file as the starting point for:
122# alldefconfig: Fills in any missing symbols with Kconfig default
123# allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
124make KCONFIG_ALLCONFIG=$TMP_FILE O=$O $ALLTARGET
125
126
127# Check all specified config values took (might have missed-dependency issues)
128for CFG in $(sed -n "$SED_CONFIG_EXP" $TMP_FILE); do
129
130 REQUESTED_VAL=$(sed -n "$SED_CONFIG_EXP" $TMP_FILE | grep -w -e "$CFG")
131 ACTUAL_VAL=$(sed -n "$SED_CONFIG_EXP" $O/.config | grep -w -e "$CFG")
132 if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
133 echo "Value requested for $CFG not in final .config"
134 echo "Requested value: $REQUESTED_VAL"
135 echo "Actual value: $ACTUAL_VAL"
136 echo ""
137 fi
138done
139
140if [ -z "$DEBUG" ]; then
141 clean_up
142fi