18c2ecf20Sopenharmony_ci#!/bin/bash
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Usage: configinit.sh config-spec-file results-dir
58c2ecf20Sopenharmony_ci#
68c2ecf20Sopenharmony_ci# Create a .config file from the spec file.  Run from the kernel source tree.
78c2ecf20Sopenharmony_ci# Exits with 0 if all went well, with 1 if all went well but the config
88c2ecf20Sopenharmony_ci# did not match, and some other number for other failures.
98c2ecf20Sopenharmony_ci#
108c2ecf20Sopenharmony_ci# The first argument is the .config specification file, which contains
118c2ecf20Sopenharmony_ci# desired settings, for example, "CONFIG_NO_HZ=y".  For best results,
128c2ecf20Sopenharmony_ci# this should be a full pathname.
138c2ecf20Sopenharmony_ci#
148c2ecf20Sopenharmony_ci# Copyright (C) IBM Corporation, 2013
158c2ecf20Sopenharmony_ci#
168c2ecf20Sopenharmony_ci# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciT=${TMPDIR-/tmp}/configinit.sh.$$
198c2ecf20Sopenharmony_citrap 'rm -rf $T' 0
208c2ecf20Sopenharmony_cimkdir $T
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci# Capture config spec file.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cic=$1
258c2ecf20Sopenharmony_ciresdir=$2
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cised -e 's/^\(CONFIG[0-9A-Z_]*\)=.*$/grep -v "^# \1" |/' < $c > $T/u.sh
288c2ecf20Sopenharmony_cised -e 's/^\(CONFIG[0-9A-Z_]*=\).*$/grep -v \1 |/' < $c >> $T/u.sh
298c2ecf20Sopenharmony_cigrep '^grep' < $T/u.sh > $T/upd.sh
308c2ecf20Sopenharmony_ciecho "cat - $c" >> $T/upd.sh
318c2ecf20Sopenharmony_ciif test -z "$TORTURE_TRUST_MAKE"
328c2ecf20Sopenharmony_cithen
338c2ecf20Sopenharmony_ci	make clean > $resdir/Make.clean 2>&1
348c2ecf20Sopenharmony_cifi
358c2ecf20Sopenharmony_cimake $TORTURE_KMAKE_ARG $TORTURE_DEFCONFIG > $resdir/Make.defconfig.out 2>&1
368c2ecf20Sopenharmony_cimv .config .config.sav
378c2ecf20Sopenharmony_cish $T/upd.sh < .config.sav > .config
388c2ecf20Sopenharmony_cicp .config .config.new
398c2ecf20Sopenharmony_ciyes '' | make $TORTURE_KMAKE_ARG oldconfig > $resdir/Make.oldconfig.out 2> $resdir/Make.oldconfig.err
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci# verify new config matches specification.
428c2ecf20Sopenharmony_ciconfigcheck.sh .config $c
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciexit 0
45