#! /bin/sh
#
# Network UPS Tools: drivers/gendb
#
# This is a hack to create a bunch of identical rules for building
# the drivers without relying on either the % patterns of GNU Make or the
# for...endfor of BSD Make.  They're both neat, but they're also not
# portable.  Ugh.
#

MFDB=Makefile.drvbuild

rm -f $MFDB

cat > $MFDB << EOF
# Network UPS Tools: drivers/$MFDB
#
# WARNING: This file is generated by the gendb script.  Any changes
#          to this file will be erased the next time it runs!
#
EOF

for i in $*
do

	# tack on any per-driver portability extras
	case $i in
		isbmex)
			EXTRA="-lm"
			;;
		tripplite)
			EXTRA="-lm"
			;;
		upscode2)
			EXTRA="-lm"
			;;
		*)
			EXTRA=""
	esac	

	echo "$i: $i.o main.o serial.o dstate.o ../common/state.o ../common/upsconf.o ../common/parseconf.o \$(LIBDEP)" >> $MFDB
	echo "	\$(CC) \$(CFLAGS) -o $i $i.o main.o serial.o dstate.o ../common/state.o ../common/upsconf.o ../common/parseconf.o \$(LIBOBJ) $EXTRA" >> $MFDB
done
