xref: /netbsd-src/external/gpl2/dtc/dtc2netbsd (revision c9b5b227bd56360e2fe5ed2e43da7c91985bd8ef)
1#! /bin/sh
2#
3#	$NetBSD: dtc2netbsd,v 1.2 2017/06/16 22:47:22 jmcneill Exp $
4#
5#
6# Copyright (c) 2017 The NetBSD Foundation, Inc.
7# All rights reserved.
8#
9# This code is derived from software contributed to The NetBSD Foundation
10# by Nick Hudson
11#
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions
14# are met:
15# 1. Redistributions of source code must retain the above copyright
16#    notice, this list of conditions and the following disclaimer.
17# 2. Redistributions in binary form must reproduce the above copyright
18#    notice, this list of conditions and the following disclaimer in the
19#    documentation and/or other materials provided with the distribution.
20#
21# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32#
33# dtc2netbsd:  convert a dtc source tree into netbsd dtc/libfdt source trees
34#
35# Rough instructions for importing new dtc release:
36#
37#	$ cd /some/where/temporary
38#	$ tar xpfz /dtc/release/tar/file
39#	$ DTCSRCS=$(pwd)
40#	$ WRKDIR=/an/other/temporary
41#	$ sh /usr/src/external/gpl2/dtc/dtc2netbsd $DTCSRCS $WRKDIR
42#
43# Import libfdt using
44#	$ cd $WRKDIR/libfdt
45#	$ cvs import -m "Import libfdt <version>" src/sys/external/bsd/libfdt/dist DTC dtc-<version>
46#
47# merge libfdt sources using, e.g.
48#	$ cvs -d cvs.netbsd.org:/cvsroot checkout -jdtc-1-4-1 -jdtc-1-4-4 src/sys/external/bsd/libfdt/dist
49#
50# Import dtc using
51#	$ cd $WRKDIR/dtc
52#	$ cvs import -m "Import dtc YYYY-MM-DD" src/external/gpl2/dtc/dist DTC dtc-<version>
53# merge dtc sources using, e.g.
54# 	$ cvs -d cvs.netbsd.org:/cvsroot checkout -jdtc-1-4-1 -jdtc-1-4-4 src/external/gpl2/dtc/dist
55#
56# Update the version string in the version_gen.h header to match the imported version:
57#	$ echo '#define DTC_VERSION "DTC 1.4.4"' > src/external/gpl2/dtc/usr.bin/dtc/version_gen.h
58
59if [ $# -ne 2 ]; then echo "dtc2netbsd dtcsrc tmpdir"; exit 1; fi
60
61r=$1
62d=$2
63
64case "$d" in
65	/*)
66		;;
67	*)
68		d=`/bin/pwd`/$d
69		;;
70esac
71
72case "$r" in
73	/*)
74		;;
75	*)
76		r=`/bin/pwd`/$r
77		;;
78esac
79
80echo preparing directory $d
81rm -rf $d
82mkdir -p $d/dtc
83
84### Copy the files and directories
85echo copying $r to $d
86cd $r
87pax -rw * $d/dtc
88mv $d/dtc/libfdt $d/libfdt
89
90# cd to import directory
91cd $d
92
93#
94
95### Remove the $'s around RCS tags
96cleantags $d
97
98### Add our NetBSD RCS Id
99find $d -type f -name '*.[chly]' -print | while read c; do
100	sed 1q < $c | grep -q '\$NetBSD' || (
101echo "/*	\$NetBSD\$	*/" >/tmp/dtc$$
102echo "" >>/tmp/dtc$$
103cat $c  >> /tmp/dtc$$
104mv /tmp/dtc$$ $c && echo added NetBSD RCS tag to $c
105	)
106done
107
108echo done
109
110### Clean up any CVS directories that might be around.
111echo "cleaning up CVS residue."
112(
113	cd $d
114	find . -type d -name "CVS" -print | xargs rm -r
115)
116echo done
117
118### Fixing file and directory permissions.
119echo "Fixing file/directory permissions."
120(
121	cd $d
122	find . -type f -print | xargs chmod u+rw,go+r
123	find . -type d -print | xargs chmod u+rwx,go+rx
124)
125echo done
126
127exit 0
128