#! /bin/sh
#
# $NetBSD: dwctwo2netbsd,v 1.4 2015/08/30 13:03:00 skrll Exp $
#
# Copyright (c) 2013 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# dwctwo2netbsd: prepare the synopsys driver sources for import into the
# netbsd dwc2 source tree, under src/sys/external/bsd/dwc2/dist,
# based on the other *2netbsd scripts in the NetBSD source tree
#
# Instructions for importing new dwc2 release:
#
# $ DATE=$(date +%F)
# $ cd /some/where/temporary
# $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
# $ DWC2SRCS=$(pwd)/drivers/usb/dwc2
# $ WRKDIR=/an/other/temporary
# $ sh /usr/src/sys/external/bsd/dwc2/dwctwo2netbsd $DWC2SRCS $WRKDIR
# $ cd $WRKDIR
# $ cvs -d cvs.netbsd.org:/cvsroot import -m "Import dwc2 $DATE" src/sys/external/bsd/dwc2/dist SYNOPSYS dwc2-$DATE
#
if [ $# -ne 2 ]; then echo "dwctwo2netbsd src dest"; exit 1; fi
r=$1
d=$2
case "$d" in
/*)
;;
*)
d=`/bin/pwd`/$d
;;
esac
case "$r" in
/*)
;;
*)
r=`/bin/pwd`/$r
;;
esac
echo preparing directory $d
rm -rf $d
mkdir -p $d
### Copy the files and directories
echo copying $r to $d
cd $r
# Not copied
# pci.c platform.c
#
for f in \
core.c core.h core_intr.c hcd.c hcd.h hcd_ddma.c hcd_intr.c hcd_queue.c \
hw.h
do
n=$(echo $f | sed -e 's:_::')
cp $r/$f $d/dwc2_$n
done
# cd to import directory
cd $d
### dwc2 distribution doesn't have RCS/CVS tags, so add them.
### Add our NetBSD RCS Id
find $d -type f -name '*.[ch]' -print | while read c; do
sed 1q < $c | grep -q '\$NetBSD' || (
echo "/* \$NetBSD\$ */" >/tmp/dwc2n$$
echo "" >>/tmp/dwc2n$$
cat $c >> /tmp/dwc2n$$
mv /tmp/dwc2n$$ $c && echo added NetBSD RCS tag to $c
)
done
echo done
### Clean up any CVS directories that might be around.
echo "cleaning up CVS residue."
(
cd $d
find . -type d -name "CVS" -print | xargs rm -r
)
echo done
### Fixing file and directory permissions.
echo "Fixing file/directory permissions."
(
cd $d
find . -type f -print | xargs chmod u+rw,go+r
find . -type d -print | xargs chmod u+rwx,go+rx
)
echo done
exit 0