1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Usage: configcheck.sh .config .config-template
5#
6# Copyright (C) IBM Corporation, 2011
7#
8# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
9
10T=${TMPDIR-/tmp}/abat-chk-config.sh.$$
11trap 'rm -rf $T' 0
12mkdir $T
13
14cat $1 > $T/.config
15
16cat $2 | sed -e 's/\(.*\)=n/# \1 is not set/' -e 's/^#CHECK#//' |
17grep -v '^CONFIG_INITRAMFS_SOURCE' |
18awk	'
19{
20		print "if grep -q \"" $0 "\" < '"$T/.config"'";
21		print "then";
22		print "\t:";
23		print "else";
24		if ($1 == "#") {
25			print "\tif grep -q \"" $2 "\" < '"$T/.config"'";
26			print "\tthen";
27			print "\t\tif test \"$firsttime\" = \"\""
28			print "\t\tthen"
29			print "\t\t\tfirsttime=1"
30			print "\t\tfi"
31			print "\t\techo \":" $2 ": improperly set\"";
32			print "\telse";
33			print "\t\t:";
34			print "\tfi";
35		} else {
36			print "\tif test \"$firsttime\" = \"\""
37			print "\tthen"
38			print "\t\tfirsttime=1"
39			print "\tfi"
40			print "\techo \":" $0 ": improperly set\"";
41		}
42		print "fi";
43	}' | sh
44