xref: /netbsd-src/external/bsd/less/less2netbsd (revision 9f87808a517727341ac3af65736cd6b578980fba)
1#!/bin/sh
2#
3#	$NetBSD: less2netbsd,v 1.7 2023/10/06 06:05:07 simonb Exp $
4#
5# Copyright (c) 2011 The NetBSD Foundation, Inc.
6# All rights reserved.
7#
8# This code is derived from software contributed to The NetBSD Foundation
9# by Matthias Scheler.
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions
13# are met:
14# 1. Redistributions of source code must retain the above copyright
15#    notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright
17#    notice, this list of conditions and the following disclaimer in the
18#    documentation and/or other materials provided with the distribution.
19#
20# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31#
32
33# less2netbsd: Prepare a less source tree for import into the NetBSD
34# source repository, under src/external .
35# based on many other *2netbsd scripts
36#
37# Rough instructions for importing new less release:
38#
39#	$ cd /some/where/temporary
40#	$ tar xpfz /new/less/release/tar/file
41#	$ sh /usr/src/external/bsd/less/less2netbsd less-xyz `pwd`
42#	$ cd src/external/bsd/less/dist
43#	$ cvs -d cvs.netbsd.org:/cvsroot import src/external/bsd/less/dist \
44#		GREENWOODSOFTWARE LESS-xyz
45#	   Enter the new NEWS portion as your commit message
46#	   Check for any conflicts, merge, fix and commit them
47#	$ cd ../../../../../less-xyz
48#	$ ./configure
49#	   Add "/*	$NetBSD: less2netbsd,v 1.7 2023/10/06 06:05:07 simonb Exp $	*/" to new defines.h
50#	$ cp defines.h /usr/src/external/bsd/less/include
51#	$ cd /usr/src/external/bsd/less
52#	$ cvs update
53#	$ cvs commit -m "Updated autoconf generated files for less xyz."
54#	$ cd /some/where/temporary
55#	   ... and clean up the leftovers
56
57PROGNAME=$(basename "$0")
58if [ $# -ne 2 ]; then
59	echo "Usage: $PROGNAME src dest" >&2
60	exit 1
61fi
62
63r=$1
64d=$2/src/external/bsd/less/dist
65
66case "$d" in
67	/*)
68		;;
69	*)
70		d=`/bin/pwd`/$d
71		;;
72esac
73
74case "$r" in
75	/*)
76		;;
77	*)
78		r=`/bin/pwd`/$r
79		;;
80esac
81
82# Start with clean target directory
83echo preparing directory $d
84rm -rf $d
85mkdir -p $d
86
87# Change to the source directory.
88if [ -d $r ] && cd $r; then
89	:
90else
91	echo "${PROGNAME}: cannot access directory \"$r\"." >&2
92	exit 1
93fi
94
95# Copy the files and directories
96echo copying $r to $d
97cd $r
98pax -rwpp * $d
99
100# Check whether the source directory looks sane.
101CHECK_FILES="LICENSE configure less.h version.c"
102for FILENAME in $CHECK_FILES; do
103	if [ ! -f "$FILENAME" ]; then
104		echo "${PROGNAME}: less distribution incomplete." >&2
105		exit
106	fi
107done
108
109# Check whether the "configure" was run.
110REQUIRED_HEADERS=defines.h
111for FILENAME in $REQUIRED_HEADERS
112do
113	if [ -f "$FILENAME" ]; then
114		echo "${PROGNAME}: \"./configure\" run too early, start again." >&2
115		exit 1
116	fi
117done
118
119# Fix the permissions.
120find . -type d -printx | xargs chmod 755
121find . -type f -printx | xargs chmod 644
122chmod 755 configure
123
124# Remove files generated by "configure".
125REMOVE_FILES="Makefile config.log config.status"
126rm -f $REMOVE_FILES
127
128# Remove extra files/dirs that we don't want to import
129rm -rf lesstest
130
131# Add NetBSD RCS Ids.
132find . -type f -name "*.[ch]" -print |
133while read FILENAME
134do
135	if ! grep -q '\$NetBSD' "$FILENAME"; then
136		NEW_FILENAME="${FILENAME}.new"
137		rm -f "${NEW_FILENAME}"
138		(echo "/*	\$NetBSD\$	*/"
139		 echo ""
140		 cat "$FILENAME") >"${NEW_FILENAME}"
141		mv -f "${NEW_FILENAME}" "$FILENAME"
142	fi
143done
144
145# Remove formatted manual pages.
146find . -type f -name "*.man" -delete
147
148# Rename unformatted manual pages.
149find . -type f -name "*.nro" -print |
150while read FILENAME
151do
152	mv "$FILENAME" "${FILENAME%.nro}.1"
153done
154
155# Determine the version number.
156VERSION=$(sed -n -e 's#char version\[\] = "\(.*\)";#\1#p' version.c)
157
158# Print out information for the import.
159cat <<EOF
160You can import now.
161
162Path:		src/external/bsd/less/dist
163Vendortag:	GREENWOODSOFTWARE
164Releasetag:	LESS-$VERSION
165EOF
166
167exit 0
168