]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - scripts/config
kconfig: Print errors to stderr in the Makefile
[mirror_ubuntu-bionic-kernel.git] / scripts / config
CommitLineData
8e54701e
AK
1#!/bin/bash
2# Manipulate options in a .config file from the command line
3
4usage() {
5 cat >&2 <<EOL
6Manipulate options in a .config file from the command line.
7Usage:
8config options command ...
9commands:
10 --enable|-e option Enable option
11 --disable|-d option Disable option
1f990cf9 12 --module|-m option Turn option into a module
f0a6332c
JA
13 --set-str option string
14 Set option to "string"
15 --set-val option value
16 Set option to value
1f990cf9 17 --state|-s option Print state of option (n,y,m,undef)
8e54701e
AK
18
19 --enable-after|-E beforeopt option
20 Enable option directly after other option
21 --disable-after|-D beforeopt option
22 Disable option directly after other option
23 --module-after|-M beforeopt option
24 Turn option into module directly after other option
25
26 commands can be repeated multiple times
27
28options:
29 --file .config file to change (default .config)
30
31config doesn't check the validity of the .config file. This is done at next
32 make time.
8e54701e
AK
33EOL
34 exit 1
35}
36
37checkarg() {
38 ARG="$1"
39 if [ "$ARG" = "" ] ; then
40 usage
41 fi
42 case "$ARG" in
43 CONFIG_*)
44 ARG="${ARG/CONFIG_/}"
45 ;;
46 esac
47 ARG="`echo $ARG | tr a-z A-Z`"
48}
49
56643222
MM
50set_var() {
51 local name=$1 new=$2 before=$3
52
53 name_re="^($name=|# $name is not set)"
54 before_re="^($before=|# $before is not set)"
55 if test -n "$before" && grep -Eq "$before_re" "$FN"; then
56 sed -ri "/$before_re/a $new" "$FN"
57 elif grep -Eq "$name_re" "$FN"; then
58 sed -ri "s:$name_re.*:$new:" "$FN"
59 else
60 echo "$new" >>"$FN"
61 fi
8e54701e
AK
62}
63
64if [ "$1" = "--file" ]; then
65 FN="$2"
66 if [ "$FN" = "" ] ; then
67 usage
68 fi
47312d2c 69 shift 2
8e54701e
AK
70else
71 FN=.config
72fi
73
2302e873
AK
74if [ "$1" = "" ] ; then
75 usage
76fi
77
8e54701e
AK
78while [ "$1" != "" ] ; do
79 CMD="$1"
80 shift
81 case "$CMD" in
47312d2c
MM
82 --refresh)
83 ;;
84 --*-after)
85 checkarg "$1"
86 A=$ARG
87 checkarg "$2"
88 B=$ARG
89 shift 2
90 ;;
45f53cc9 91 -*)
8e54701e 92 checkarg "$1"
8e54701e
AK
93 shift
94 ;;
47312d2c
MM
95 esac
96 case "$CMD" in
97 --enable|-e)
98 set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
99 ;;
8e54701e
AK
100
101 --disable|-d)
56643222 102 set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
8e54701e
AK
103 ;;
104
105 --module|-m)
56643222 106 set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
8e54701e
AK
107 ;;
108
1f990cf9 109 --set-str)
d6686da8
YM
110 # sed swallows one level of escaping, so we need double-escaping
111 set_var "CONFIG_$ARG" "CONFIG_$ARG=\"${1//\"/\\\\\"}\""
1f990cf9
MM
112 shift
113 ;;
114
f0a6332c
JA
115 --set-val)
116 set_var "CONFIG_$ARG" "CONFIG_$ARG=$1"
117 shift
118 ;;
119
8e54701e 120 --state|-s)
8e54701e
AK
121 if grep -q "# CONFIG_$ARG is not set" $FN ; then
122 echo n
123 else
124 V="$(grep "^CONFIG_$ARG=" $FN)"
125 if [ $? != 0 ] ; then
126 echo undef
127 else
d6686da8
YM
128 V="${V/#CONFIG_$ARG=/}"
129 V="${V/#\"/}"
130 V="${V/%\"/}"
131 V="${V/\\\"/\"}"
132 echo "${V}"
8e54701e
AK
133 fi
134 fi
8e54701e
AK
135 ;;
136
137 --enable-after|-E)
56643222 138 set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
8e54701e
AK
139 ;;
140
141 --disable-after|-D)
56643222 142 set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
8e54701e
AK
143 ;;
144
145 --module-after|-M)
56643222 146 set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
8e54701e
AK
147 ;;
148
149 # undocumented because it ignores --file (fixme)
150 --refresh)
151 yes "" | make oldconfig
152 ;;
153
154 *)
155 usage
156 ;;
157 esac
158done
159