xref: /openbmc/u-boot/scripts/build-whitelist.sh (revision 1a88a04e)
1#!/bin/sh
2# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5
6# This script creates the configuration whitelist file. This file contains
7# all the config options which are allowed to be used outside Kconfig.
8# Please do not add things to the whitelist. Instead, add your new option
9# to Kconfig.
10#
11export LC_ALL=C LC_COLLATE=C
12
13# There are two independent greps. The first pulls out the component parts
14# of CONFIG_SYS_EXTRA_OPTIONS. An example is:
15#
16#	SUN7I_GMAC,AHCI,SATAPWR=SUNXI_GPB(8)
17#
18# We want this to produce:
19#	CONFIG_SUN7I_GMAC
20#	CONFIG_AHCI
21#	CONFIG_SATAPWR
22#
23# The second looks for the rest of the CONFIG options, but excludes those in
24# Kconfig and defconfig files.
25#
26(
27git grep CONFIG_SYS_EXTRA_OPTIONS |sed -n \
28	's/.*CONFIG_SYS_EXTRA_OPTIONS="\(.*\)"/\1/ p' \
29	| tr , '\n' \
30	| sed 's/ *\([A-Za-z0-9_]*\).*/CONFIG_\1/'
31
32git grep CONFIG_ | \
33	egrep -vi "(Kconfig:|defconfig:|README|\.py|\.pl:)" \
34	| tr ' \t' '\n\n' \
35	| sed -n 's/^\(CONFIG_[A-Za-z0-9_]*\).*/\1/p'
36) \
37	|sort |uniq >scripts/config_whitelist.txt.tmp1;
38
39# Finally, we need a list of the valid Kconfig options to exclude these from
40# the whitelist.
41cat `find . -name "Kconfig*"` |sed -n \
42	-e 's/^\s*config *\([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
43	-e 's/^\s*menuconfig *\([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
44	|sort |uniq >scripts/config_whitelist.txt.tmp2
45
46# Use only the options that are present in the first file but not the second.
47comm -23 scripts/config_whitelist.txt.tmp1 scripts/config_whitelist.txt.tmp2 \
48	|sort |uniq >scripts/config_whitelist.txt.tmp3
49
50# If scripts/config_whitelist.txt already exists, take the intersection of the
51# current list and the new one.  We do not want to increase whitelist options.
52if [ -r scripts/config_whitelist.txt ]; then
53	comm -12 scripts/config_whitelist.txt.tmp3 scripts/config_whitelist.txt \
54		> scripts/config_whitelist.txt.tmp4
55	mv scripts/config_whitelist.txt.tmp4 scripts/config_whitelist.txt
56else
57	mv scripts/config_whitelist.txt.tmp3 scripts/config_whitelist.txt
58fi
59
60rm scripts/config_whitelist.txt.tmp*
61
62unset LC_ALL LC_COLLATE
63