1#! /bin/sh
2#
3#	$NetBSD: groff2netbsd,v 1.3 2004/07/30 15:29:45 wiz Exp $
4#
5# Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28#
29# groff2netbsd:  convert an groff source tree into a
30# netbsd groff source tree, under basesrc/dist,
31# based on bind2netbsd by Bernd Ernesti and changes by Simon Burge
32#
33# Rough instructions for importing new groff release:
34#
35#	$ cd /some/where/temporary
36#	$ tar xpfz /new/groff/release/tar/file
37#	$ sh /usr/src/gnu/dist/groff/groff2netbsd groff-1.x.y `pwd`
38#	$ cd src/gnu/dist/groff
39#	$ cvs import -m "Import groff 1.x.y" src/gnu/dist/groff FSF groff-1-x-y
40# merge sources according to instructions given
41# e.g. cvs -d cvs.netbsd.org:/cvsroot checkout -jgroff-1-19 -jgroff-1-19-1 src/gnu/dist/groff
42#	$ cd ../../../groff-1.x.y
43#	$ run ./configure
44# merge newly generated src/include/config.h with 
45# /usr/src/gnu/usr.bin/groff/include/config.h; compare VARIABLES in Makefile
46# with those in /usr/src/gnu/usr.bin/groff/Makefile.inc
47#	$ cd ..
48#	$ rm -r gnusrc groff-1.x.y
49#	$ cd /usr/src/gnu/usr.bin/groff
50#	$ cvs commit -m "Updated autoconf generated files for groff 1.x.y."
51#
52#	- check makefiles to see if any extra sources have been added.
53#	- update distrib/sets if necessary.
54
55if [ $# -ne 2 ]; then echo "groff2netbsd src dest"; exit 1; fi
56
57r=$1
58d=$2/src/gnu/dist/groff
59
60case "$d" in
61	/*)
62		;;
63	*)
64		d=`/bin/pwd`/$d
65		;;
66esac
67
68case "$r" in
69	/*)
70		;;
71	*)
72		r=`/bin/pwd`/$r
73		;;
74esac
75
76echo preparing directory $d
77rm -rf $d
78mkdir -p $d
79
80### Copy the files and directories
81echo copying $r to $d
82cd $r
83pax -rw * $d
84
85# cd to import directory
86cd $d
87
88### Remove the $'s around RCS tags
89find $d -type f -print | xargs egrep -l '\$(Id|Created|Header|NetBSD|Revision)' | while read f; do
90	sed -e 's/\$\(Id.*\) \$/\1/' \
91	    -e 's/\$\(Created.*\) \$/\1/' \
92	    -e 's/\$\(Header.*\) \$/\1/' \
93	    -e 's/\$\(NetBSD.*\) \$/\1/' \
94	    -e 's/\$\(Revision.*\) \$/\1/' \
95	    $f > /tmp/groff1f$$ && mv /tmp/groff1f$$ $f && \
96	echo removed RCS tag from $f
97done
98
99### Add our NetBSD RCS Id
100find $d -type f -name '*.[chly]' -print | while read c; do
101	sed 1q < $c | grep -q '\$NetBSD' || (
102echo "/*	\$NetBSD\$	*/" >/tmp/groff3n$$
103echo "" >>/tmp/groff3n$$
104cat $c  >> /tmp/groff3n$$
105mv /tmp/groff3n$$ $c && echo added NetBSD RCS tag to $c
106	)
107done
108
109find $d -type f -name '*.cpp' -print | while read c; do
110	sed 1q < $c | grep -q '\$NetBSD' || (
111echo "/*	\$NetBSD\$	*/" >/tmp/groff3n$$
112echo "" >>/tmp/groff3n$$
113cat $c  >> /tmp/groff3n$$
114mv /tmp/groff3n$$ $c && echo added NetBSD RCS tag to $c
115	)
116done
117
118find $d -type f -name '*.[0-9]' -print | while read m; do
119	sed 1q < $m | grep -q '\$NetBSD' || (
120echo ".\\\"	\$NetBSD\$" >/tmp/groff2m$$
121echo ".\\\"" >>/tmp/groff2m$$
122cat $m >> /tmp/groff2m$$
123mv /tmp/groff2m$$ $m && echo added NetBSD RCS tag to $m
124	)
125done
126
127find $d -type f -name '*.texi' -print | while read t; do
128        sed "2 s/^/@c \$NetBSD\$\\
129/" < $t > /tmp/groff4t$$
130	mv /tmp/groff4t$$ $t && echo added NetBSD RCS tag to $t
131done
132
133echo done
134
135### Clean up any CVS directories that might be around.
136echo "cleaning up CVS residue."
137(
138	cd $d
139	find . -type d -name "CVS" -print | xargs rm -r
140)
141echo done
142
143### Fixing file and directory permissions.
144echo "Fixing file/directory permissions."
145(
146	cd $d
147	find . -type f -print | xargs chmod u+rw,go+r
148	find . -type d -print | xargs chmod u+rwx,go+rx
149)
150echo done
151
152exit 0
153