xref: /netbsd-src/external/bsd/pcc/prepare-import.sh (revision 70f7362772ba52b749c976fb5e86e39a8b2c9afc)
1#!/bin/sh -x
2#
3#	prepare pcc distribution for import
4#
5# pcc can be built as part of the toolchain by setting
6#
7#	HAVE_PCC=yes
8#
9# and as a native binary for a release build by setting
10#
11#	MKPCC=yes
12#
13
14#
15# TODO
16# - some files only have NetBSD tags to start with, they end up with none
17
18set -e
19
20if [ ! -d work -o ! -d work/pcc ]; then
21	echo "checkout or unpack pcc to work/ first, eg"
22	echo ""
23	echo "    cvs -d :pserver:anonymous@pcc.ludd.ltu.se:/cvsroot -f checkout -P -d work -N pcc"
24	echo ""
25	exit 1
26fi
27
28echo "====> Removing pcc CVS directories..."
29find work -type d -name CVS | xargs rm -Rf
30
31echo "====> Fixing file and directory permissions..."
32find work -type d -exec chmod u=rwx,go=rx {} \;
33find work -type f -exec chmod u=rw,go=r {} \;
34
35echo "====> Fixing RCS tags..."
36# fix existing RCS tags, and insert blank NetBSD tags
37for f in $(grep -RL '\$(NetBSD|Id).*\$' work); do
38    sed -e '/\$NetBSD\$/d'				\
39	-e 's,\$\(NetBSD[[:>:]].*\)\$,\1,'		\
40	-e 's,\(.*\)\$\(Id[[:>:]].*\)\$\(.*\),\1\2\3	\
41\1\$NetBSD\$\3,'					\
42	< ${f} > ${f}_tmp
43    mv ${f}_tmp ${f}
44done
45
46echo "====> Creating pcc \"config.h\" file..."
47mkdir work/tmp
48cd work/tmp
49env -i PATH=/bin:/usr/bin /bin/sh ../pcc/configure --enable-tls
50cd ../..
51#
52# comment out items we provide at build time from Makefile.inc
53# define PREPROCESSOR as pcpp to avoid conflicts with GCC
54#
55sed -e "s,^\(#define[[:space:]]*VERSSTR[[:>:]].*\)\$,/* \1 */,"					\
56    -e "s,^\(#define[[:space:]]*HOST_BIG_ENDIAN[[:>:]].*\)\$,/* \1 */,"				\
57    -e "s,^\(#define[[:space:]]*HOST_LITTLE_ENDIAN[[:>:]].*\)\$,/* \1 */,"			\
58    -e "s,^\(#define[[:space:]]*TARGET_BIG_ENDIAN[[:>:]].*\)\$,/* \1 */,"			\
59    -e "s,^\(#define[[:space:]]*TARGET_LITTLE_ENDIAN[[:>:]].*\)\$,/* \1 */,"			\
60    -e "s,^\(.*[[:<:]]PREPROCESSOR[[:>:]].*\)\$,#define PREPROCESSOR \"pcpp\","			\
61    < work/tmp/config.h > work/config.h
62
63#
64# update Makefile.inc to create version string at build time
65#
66datestamp=$(cat work/pcc/DATESTAMP)
67version=$(sed -n -e "/PACKAGE_VERSION/s/.*\"\(.*\)\"/\1/p" < work/config.h)
68sed -e "/^PCC_DATESTAMP=/s/=.*$/=${datestamp}/"	\
69    -e "/^PCC_VERSION=/s/=.*$/=${version}/"	\
70	< Makefile.inc > work/Makefile.inc
71
72echo "====> Replacing pcc sources..."
73rm -Rf dist/pcc dist/pcc-libs
74mv work/pcc dist
75if cmp -s work/config.h include/config.h; then :; else
76    echo "====> Updating include/config.h..."
77    mv work/config.h include/config.h
78fi
79if cmp -s work/Makefile.inc Makefile.inc; then :; else
80    echo "====> Updating Makefile.inc..."
81    mv work/Makefile.inc Makefile.inc
82fi
83
84echo "====> Done."
85rm -Rf work
86
87echo ""
88echo "after testing, use the following command to import from the dist directory,"
89echo ""
90echo "    cvs import src/external/bsd/pcc/dist ragge pcc-${datestamp}"
91echo ""
92echo "providing a ChangeLog in the commit message."
93