xref: /netbsd-src/crypto/external/bsd/heimdal/heimdal2netbsd (revision b8d761750af89f7f654594559a66a17564f2339e)
1#! /bin/sh
2#
3#	$NetBSD: heimdal2netbsd,v 1.1 2011/04/13 19:04:40 elric Exp $
4#
5# Copyright (c) 2011 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# heimdal2netbsd:  convert a heimdal source tree into a
30# netbsd amd source tree, under src/crypto/external/bsd/heimdal/dist
31# based on bind2netbsd by Bernd Ernesti and changes by Simon Burge
32#
33# Rough instructions for importing new heimdal release from their git
34# repository:
35#
36#	$ export SRCDIR=/usr/src
37#	$ export HEIMDAL_SRCDIR=src/crypto/external/bsd/heimdal
38#	$ cd /some/where/temporary
39#	$ git clone git://svn.h5l.org/heimdal.git
40#	$ sh $SRCDIR/$HEIMDAL_SRCDIR/heimdal2netbsd heimdal `pwd`
41#	$ cd $HEIMDAL_SRCDIR/dist
42#       $ cvs -d ... import $HEIMDAL_SRCDIR/dist HEIMDAL head-20110317
43#	$ cd /some/where/temporary/heimdal
44#	$ autoreconf -f -i
45#	$ ./configure
46#	$ make
47#	>>> merge newly generated config.h
48#	>>> with $HEIMDAL_SRCDIR/include/config.h
49#	>>> and check out diffs in generated headers
50#	>>> and C files.
51#	$ cd ..
52#	$ rm -r src heimdal
53#	$ cd $SRCDIR/$HEIMDAL_SRCDIR
54#	$ cvs commit -m "Updated generated files for Heimdal head-20110317"
55#
56#	- check makefiles to see if any extra sources have been added.
57#	- update distrib/sets if necessary.
58
59if [ $# -ne 2 ]; then echo "heimdal2netbsd src dest"; exit 1; fi
60
61r=$1
62d=$2/src/crypto/external/bsd/heimdal/dist
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
83
84### Copy the files and directories
85echo copying $r to $d
86cd $r
87pax -rw * $d
88
89### Remove unneeded files
90#echo removing unneeded directories and files
91#find $d/po -name '*[0-9] XXX:
92find $d -name '*.cat[0-9]' | xargs rm -f && echo removed catman pages
93find $d -name '*.info' | xargs rm -f	 && echo removed info pages
94rm -rf $d/appl				 && echo removed appl
95rm -rf $d/lib/libedit			 && echo removed lib/libedit
96rm -rf $d/lib/sqlite			 && echo removed lib/sqlite
97rm -rf $d/doc/standardisation		 && echo removed doc/standardisation
98
99# Fix man pages
100find $d -type f -name '*.[1358]' -print | while read f; do
101	sed \
102	    -e 's,\.Os HEIMDAL,.Os,' \
103	    -e 's,\.Pa krb5.h,.Pa krb5/krb5.h,' \
104	    -e 's,\.In krb5.h,.In krb5/krb5.h,' \
105	    -e 's,\.Pa gssapi.h,.Pa gssapi/gssapi.h,' \
106	    -e 's,\.In gssapi.h,.In gssapi/gssapi.h,' \
107	    -e 's,#include <krb5.h>,#include <krb5/krb5.h>,' \
108	    < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
109	echo fixing man page $f
110done
111
112# Fix include usage
113
114KRB5_INCRE="asn1-common|asn1_err"
115KRB5_INCRE="$KRB5_INCRE|base64"
116KRB5_INCRE="$KRB5_INCRE|cms_asn1"
117KRB5_INCRE="$KRB5_INCRE|com_err"
118KRB5_INCRE="$KRB5_INCRE|com_right"
119KRB5_INCRE="$KRB5_INCRE|crmf_asn1"
120KRB5_INCRE="$KRB5_INCRE|der|der-protos"
121KRB5_INCRE="$KRB5_INCRE|digest_asn1"
122KRB5_INCRE="$KRB5_INCRE|getarg"
123KRB5_INCRE="$KRB5_INCRE|hdb|hdb_err|hdb-protos|hdb_asn1"
124KRB5_INCRE="$KRB5_INCRE|heim_asn1|heim_err"
125KRB5_INCRE="$KRB5_INCRE|heimbase"
126KRB5_INCRE="$KRB5_INCRE|heimntlm|heimntlm-protos"
127KRB5_INCRE="$KRB5_INCRE|hex"
128KRB5_INCRE="$KRB5_INCRE|hx509|hx509-protos|hx509_err"
129KRB5_INCRE="$KRB5_INCRE|k524_err"
130KRB5_INCRE="$KRB5_INCRE|kafs"
131KRB5_INCRE="$KRB5_INCRE|kcm|kcm-protos"
132KRB5_INCRE="$KRB5_INCRE|kdc|kdc-protos"
133KRB5_INCRE="$KRB5_INCRE|krb5|krb5-private|krb5-protos|krb5-types"
134KRB5_INCRE="$KRB5_INCRE|krb5_asn1|krb5_err|krb5_ccapi"
135KRB5_INCRE="$KRB5_INCRE|krb5-v4compat"
136KRB5_INCRE="$KRB5_INCRE|krb_err"
137KRB5_INCRE="$KRB5_INCRE|kx509_asn1"
138KRB5_INCRE="$KRB5_INCRE|ntlm_err"
139KRB5_INCRE="$KRB5_INCRE|ocsp_asn1"
140KRB5_INCRE="$KRB5_INCRE|parse_bytes|parse_time|parse_units"
141KRB5_INCRE="$KRB5_INCRE|pkcs8_asn1|pkcs9_asn1|pkcs10_asn1|pkcs12_asn1"
142KRB5_INCRE="$KRB5_INCRE|pkinit_asn1"
143KRB5_INCRE="$KRB5_INCRE|resolve"
144KRB5_INCRE="$KRB5_INCRE|rfc2459_asn1"
145KRB5_INCRE="$KRB5_INCRE|roken|roken-common"
146KRB5_INCRE="$KRB5_INCRE|rtbl"
147KRB5_INCRE="$KRB5_INCRE|sl|ss"
148KRB5_INCRE="$KRB5_INCRE|wind|wind_err"
149KRB5_INCRE="$KRB5_INCRE|xdbm"
150
151GSS_INCRE="gssapi|gssapi_krb5|gssapi_spnego|gssapi_ntlm|gssapi_oid"
152
153KADM5_INCRE="admin|kadm5-protos|kadm5-pwcheck|kadm5_err"
154
155find $d -type f -name '*.[ch]' -a ! -name compile_et.? -print | while read f; do
156	sed -E \
157	    -e "s,#include <($GSS_INCRE)\\.h>,#include <gssapi/\\1.h>,"	   \
158	    -e "s,#include \"($KRB5_INCRE)\\.h\",#include <krb5/\\1.h>,"   \
159	    -e "s,#include <($KRB5_INCRE)\\.h>,#include <krb5/\\1.h>,"	   \
160	    -e "s,#include <($KADM5_INCRE)\\.h>,#include <kadm5/\\1.h>,"   \
161	    < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
162	echo fixing include paths in $f
163done
164
165#
166# In these files, we want only to fix the paths in the generated files, not
167# in the file itself.  To do this, we search for "#include meaning that
168# it can't be on the left column.
169
170for f in $d/lib/sl/slc-gram.y $d/lib/com_err/compile_et.c; do
171	sed -E -e "s,(.#include <)($KRB5_INCRE)\\.h>,\\1krb5/\\2.h>," \
172	    < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
173	echo fixing include paths in $f
174done
175
176# Freeze imported NetBSD RCSID's.
177find $d -type f -print | xargs egrep -l '\$NetBSD:' | while read f; do
178	sed \
179	    -e 's/\$\(NetBSD.*\) \$/\1/' \
180	    < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
181	echo froze NetBSD RCSID for $f
182done
183
184# Convert unexpanded RCSID's to the NetBSD way.
185find $d -type f -print | xargs egrep -l 'RCSID\("\$Id\$"\)' | while read f; do
186	sed -e 's/RCSID("\$\Id\$")/__RCSID("\$NetBSD\$")/' \
187	    < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
188	echo converted RCSID to NetBSD for $f
189done
190
191### Remove the $'s around RCS tags
192find $d -type f -print | xargs egrep -l \
193    '\$(Author|Date|Header|Id|Locker|Log|Name|RCSfile|Revision|Source|State)' |
194    while read f; do
195	sed \
196	    -e 's/\$\(Author.*\) \$/\1/' \
197	    -e 's/\$\(Date.*\) \$/\1/' \
198	    -e 's/\$\(Header.*\) \$/\1/' \
199	    -e 's/\$\(Id.*\) \$/\1/' \
200	    -e 's/\$\(Locker.*\) \$/\1/' \
201	    -e 's/\$\(Log.*\) \$/\1/' \
202	    -e 's/\$\(Name.*\) \$/\1/' \
203	    -e 's/\$\(RCSfile.*\) \$/\1/' \
204	    -e 's/\$\(Revision.*\) \$/\1/' \
205	    -e 's/\$\(Source.*\) \$/\1/' \
206	    -e 's/\$\(State.*\) \$/\1/' \
207	    < $f > /tmp/heimdal1f$$ && mv /tmp/heimdal1f$$ $f && \
208	echo removed \$RCS tag from $f
209done
210
211### Add our NetBSD RCS Id
212find $d -type f -name '*.[chly]' -print | while read c; do
213	sed 1q < $c | grep -q '\$NetBSD' || (
214echo "/*	\$NetBSD\$	*/" >/tmp/amd3n$$
215echo "" >>/tmp/amd3n$$
216cat $c  >> /tmp/amd3n$$
217mv /tmp/amd3n$$ $c && echo added NetBSD RCS tag to $c
218	)
219done
220
221find $d -type f -name '*.[0-9]' -print | while read m; do
222	sed 1q < $m | grep -q '\$NetBSD' || (
223echo ".\\\"	\$NetBSD\$" >/tmp/amd2m$$
224echo ".\\\"" >>/tmp/amd2m$$
225cat $m >> /tmp/amd2m$$
226mv /tmp/amd2m$$ $m && echo added NetBSD RCS tag to $m
227	)
228done
229
230find $d -type f -name '*.texi' -print | while read t; do
231        sed "2 s/^/@c \$NetBSD\$\\
232/" < $t > /tmp/amd4t$$
233	mv /tmp/amd4t$$ $t && echo added NetBSD RCS tag to $t
234done
235
236echo done
237
238### Clean up any CVS directories that might be around.
239echo "cleaning up CVS residue."
240(
241	cd $d
242	find . -type d -name "CVS" -print | xargs rm -r
243)
244echo done
245
246echo "cleaning up git residue."
247rm -rf $d/.git
248
249### Fixing file and directory permissions.
250echo "Fixing file/directory permissions."
251(
252	cd $d
253	find . -type f -print | xargs chmod u+rw,go+r
254	find . -type d -print | xargs chmod u+rwx,go+rx
255)
256echo done
257
258exit 0
259