Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Oct 2002 17:52:38 +1300
From:      Andrew Turner <zombie@i4free.co.nz>
To:        current@freebsd.org
Subject:   Kernel option dependency finding
Message-ID:  <3DAE4216.40706@i4free.co.nz>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Hello,

Find attached a script I have started writing to find option dependency 
from the NOTES files.

Would other developers please test this script and submit suggestions 
back to me (on or off the list).

Andrew Turner

[-- Attachment #2 --]
#!/bin/sh

#Default options
LINTCONF=LINT.CONF
LINTCONF1=LINT.CONF1
ARCH=`uname -m`
ARCH1=$ARCH
SRCDIR=/sys
START=0
END=0
NOCLEAN=0
TMPDIR=/tmp/makedepend
WD=`pwd`

#Read the command line
while [ $# -ne 0 ]
do
	case "$1" in
		--src-dir)
			shift
			SRCDIR=$1
			shift
			;;
		--conf-dir)
			shift
			CNFDIR=$1
			shift
			;;
		--compile-dir)
			shift
			CMPDIR=$1
			shift
			;;
		--arch)
			shift
			ARCH=$1
			shift
			;;
		--no-copy)
			NOCOPY="YES"
			shift
			;;
		--no-clean)
			shift
			NOCLEAN=1
			;;
		--start)
			shift
			START=$1
			shift
			;;
		--end)
			shift
			END=$1
			shift
			;;
		--clean)
			rm -f ${LINTCONF} ${LINTCONF1} bad_list LINT tmp
			exit 0
			;;
		*)
			CMD=`basename $0`
			echo "USAGE: $CMD [option]"
			echo
			echo "Where option is any of:"
			echo
			echo "--help"
			echo "  This help"
			echo "--clean"
			echo "   Clean the work directory"
			echo "--no-clean"
			echo "   Don't clean up"
			echo "--src-dir <Kernel Source Directory>:"
			echo "   The top of the kernel source default: /sys"
			echo "--conf-dir <Kernel Conf Directory>:"
			echo "   The conf files dir default: <src-dir>/<arch>/conf"
			echo "--compile-dir <Kernel Compile Dir>:"
			echo "   The dir the kernel to run make [depend] in default: <src-dir>/compile"
			echo "--arch <Build Arch>:"
			echo "   The Arch to build for default: $ARCH1"
			echo "--start <start>"
			echo "--end <end>"
			echo "   Only build kernels numbered between <start> and <end>"
			exit 1
			;;
	esac
done

# Move the options in the order we wan't them
# This script builds in a decending order so $START is always larger then $END
if [ $START -lt $END ]
then
	STARTTMP=$START
	START=$END
	END=$STARTTMP
fi

# If we change end then finish on the one we said to
if [ $END -ne 0 ]
then
	END=`expr $END - 1`
fi

# Set the default dir for running make
COMPDIR=$SRCDIR/$ARCH/compile

# If is set as an option change it
if [ $CMPDIR ]
then
	COMPDIR=$CMPDIR
fi

# Set the default dir for the config files
CONFDIR=$SRCDIR/$ARCH/conf

# If is set as an option change it
if [ $CNFDIR ]
then
	CONFDIR=$CNFDIR
fi

# Clean the build directories
if [ $NOCLEAN -eq 0 ]
then
	rm -f ${LINTCONF} ${LINTCONF1} bad_list LINT tmp
	rm -f ${CONFDIR}/DEPEND.*
	rm -fr ${TMPDIR}
	mkdir -p ${TMPDIR}
	touch ${TMPDIR}/pass
	touch ${TMPDIR}/fail.config
	touch ${TMPDIR}/fail.depend
	touch ${TMPDIR}/fail.make
fi

# Do the copying on LINT/NOTES
if [ $NOCOPY ]
then
	:
else
	cd ${CONFDIR}
	make LINT
	cd $WD
	cp ${CONFDIR}/LINT ./
fi

if [ -f LINT ]
then
	:
else
	echo "Error: No LINT/NOTES File"
	exit 1
fi

if [ -f depend ]
then
	:
else
	touch depend
fi

# The changeable Config Options from LINT/NOTES
cat LINT | grep "^options" > ${LINTCONF}
cat LINT | grep "^device" >> ${LINTCONF}
cat LINT | grep "^pseudo-device" >> ${LINTCONF}

# Make a list of unwanted options
# The first character is always a !
awk '{ if ($1 =="!") print $2 " " $3 }' < depend > bad_list

# Remove the unwanted options
BADLINES=`awk '{ nlines++ } END { if ( nlines ) { print nlines } else { print "0" } }' < bad_list`
while [ ${BADLINES} -ne 0 ]
do
	LINE=`cat bad_list | head -n ${BADLINES} | tail -n 1`
	BADTYPE=`echo ${LINE} | awk '{print $1}'`
	BADDEV=`echo ${LINE} | awk '{print $2}'`

	cat ${LINTCONF} | awk "{ if ((\$1 == \"$BADTYPE\") && (\$2 ~ \"$BADDEV\")) { } else { print \$0 } }" > ${LINTCONF}2

	mv ${LINTCONF}2 ${LINTCONF}
	BADLINES=`expr $BADLINES - 1`
done

rm -f bad_list

# Unchangable Config Options from LINT/NOTES
cat LINT | grep "^ident" > ${LINTCONF1}
cat LINT | grep "^machine" >> ${LINTCONF1}
cat LINT | grep "^maxusers" >> ${LINTCONF1}
cat LINT | grep "^makeoptions" >> ${LINTCONF1}
cat LINT | grep "^cpu" >> ${LINTCONF1}

# If start is set use it as the first config
if [ $START -eq 0 ]
then
	START=`awk '{ nlines++ } END { print nlines }' < ${LINTCONF}`
fi

LINE=$START

#echo $LINE > no_lines

# Build the config files for LINT/NOTES in $CONFDIR
# The file is always called DEPEND.${LINE}
while [ ${LINE} -ne $END ]
do
	cat ${LINTCONF1} > ${CONFDIR}/DEPEND.${LINE}
	awk "{ line++; if ( line == $LINE ) printf \"#\"; print \$0}" < ${LINTCONF} >> ${CONFDIR}/DEPEND.${LINE}
	LINE=`expr $LINE - 1`
done


# Do the builds
LINE=$START
while [ $LINE -ne $END ]
do
	cd ${CONFDIR}
	config DEPEND.${LINE} > ${TMPDIR}/${LINE}.config
	if [ $? -eq 0 ]
	then
		cd ${COMPDIR}/DEPEND.${LINE}
		make clean > /dev/null 2>&1
		make depend > ${TMPDIR}/${LINE}.depend 2>&1
		if [ $? -eq 0 ]
		then
			make > ${TMPDIR}/${LINE}.make 2>&1
			if [ $? -eq 0 ]
			then
				echo $LINE >> ${TMPDIR}/pass
			else
				echo $LINE >> ${TMPDIR}/fail.make
			fi
		else
			echo $LINE >> ${TMPDIR}/fail.depend
		fi
	else
		echo $LINE >> ${TMPDIR}/fail.config
	fi
	make clean > /dev/null 2>&1
	LINE=`expr $LINE - 1`
done
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3DAE4216.40706>