BSD 4_4_Lite2 development
[unix-history] / usr / src / contrib / gcc-2.3.3 / populate
CommitLineData
132aa614
C
1#!/bin/sh
2#
3# NAME
4# populate
5#
6# SYNOPSIS
7# populate target-dir [ source-dir ... ]
8#
9# DESCRIPTION
10# Adjunct script for GNU C++ to populate a directory with C++
11# compatible header files.
12#
13# For each header file (whose name ends in .h) which resides in one
14# of the indicated source-dirs, create a corresponding file in the
15# target-dir (with the same name) which looks like:
16#
17# #ifndef __IN_C_REGION__
18# #define __IN_C_REGION__
19# extern "C" {
20# #include_next <header.h>
21# }
22# #undef __IN_C_REGION__
23# #else
24# #include_next <header.h>
25# #endif
26#
27# Where "header.h" is the name of the original header file in the
28# source-dir.
29#
30# If a file with the appropriate name already exists in the target
31# directory, it will not be overwritten.
32#
33# NOTES
34# This script assumes that your native header files are already
35# at least compliant with ANSI C, and that all functions declared
36# therein are properly prototyped (as they must be for C++).
37#
38# Currently, this condition is not fully satisfied by many (if any)
39# systems. On System V Release 4, most of the system header files
40# do seem to be properly prototyped though, and OSF/1 also has
41# prototyped header files, but some of the argument type specifica-
42# tions for some function prototypes in some OSF/1 header files may
43# lack `const' qualifiers in certain places where they ought to appear.
44# (This is due to the fact that OSF/1 conformat to POSIX-1988 rather
45# than to the newer POSIX-1990 standard.)
46#
47# If your system's native include files are not properly prototyped,
48# that's OK. This script will still do it's normal job (in the normal
49# way) but the resulting (indirect) header files will not be very useful
50# for g++ programming unless (and until) somebody puts in all of the
51# prototypes for all of the functions which are declared in these files.
52#
53# Note that in some cases, a header file with a given name may exist
54# in two or more of the given source directories. That's perfectly
55# alright. Only one (corresponding) header file will be placed into
56# the target directory for each such group of kindred source files.
57#
58# This script should probably be invoked from the GCC Makefile, via:
59#
60# populate $(libdir)/g++-include $(libsubdir)/include /usr/include
61#
62# That would insure the creation of a C++ compatible set of headers
63# (in the sepcial g++-include directory) corresponding to all of the
64# normal GCC header files and all of the native system's header files.
65#
66# AUTHOR
67# Ron Guilmette (rfg@ncd.com)
68#
69# COPYRIGHT
70# This file is part of GNU CC.
71#
72# GNU CC is free software; you can redistribute it and/or modify
73# it under the terms of the GNU General Public License as published by
74# the Free Software Foundation; either version 2, or (at your option)
75# any later version.
76#
77# GNU CC is distributed in the hope that it will be useful,
78# but WITHOUT ANY WARRANTY; without even the implied warranty of
79# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80# GNU General Public License for more details.
81#
82# You should have received a copy of the GNU General Public License
83# along with GNU CC; see the file COPYING. If not, write to
84# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
85
86progname=$0
87progname=`basename $progname`
88original_dir=`pwd`
89if [ `echo $1 | wc -w` = 0 ] ; then
90 echo $progname\: usage\: $progname target-dir \[ source-dir \.\.\. \]
91 exit 1
92fi
93rel_target_dir=$1
94shift
95
96if [ `expr $rel_target_dir : '\(.\)'` != '/' ] ; then
97 abs_target_dir=$original_dir/$rel_target_dir
98else
99 abs_target_dir=$rel_target_dir
100fi
101
102if [ \! -d $abs_target_dir ] ; then
103 echo $progname\: creating directory $rel_target_dir
104 mkdir $abs_target_dir
105fi
106
107echo $progname\: populating \`$rel_target_dir\'
108
109if [ `echo $* | wc -w` != 0 ] ; then
110 for rel_source_dir in $*; do
111 if [ `expr $rel_source_dir : '\(.\)'` != '/' ] ; then
112 abs_source_dir=$original_dir/$rel_source_dir
113 else
114 abs_source_dir=$rel_source_dir
115 fi
116 echo $progname\: input dir\: \`$rel_source_dir\'
117 done
118fi
119
120tmp_file=/tmp/$progname.$$
121rm -f $tmp_file
122echo '#ifndef __IN_C_REGION__' > $tmp_file
123echo '#define __IN_C_REGION__' >> $tmp_file
124echo 'extern "C" {' >> $tmp_file
125echo '#include_next <=>' >> $tmp_file
126echo '}' >> $tmp_file
127echo '#undef __IN_C_REGION__' >> $tmp_file
128echo '#else' >> $tmp_file
129echo '#include_next <=>' >> $tmp_file
130echo '#endif' >> $tmp_file
131
132if [ `echo $* | wc -w` != 0 ] ; then
133 for rel_source_dir in $*; do
134 if [ `expr $rel_source_dir : '\(.\)'` != '/' ] ; then
135 abs_source_dir=$original_dir/$rel_source_dir
136 else
137 abs_source_dir=$rel_source_dir
138 fi
139 if [ \! -d $abs_source_dir ] ; then
140 echo $progname\: warning\: no such directory\: \`$rel_source_dir\'
141 continue
142 fi
143 cd $abs_source_dir
144 rel_source_subdirs=`find . -type d -print | sed 's%^\./%%' | sed 's/\.//'`
145 if [ `echo $rel_source_subdirs | wc -w` != 0 ] ; then
146 for rel_source_subdir in $rel_source_subdirs; do
147 abs_target_subdir=$abs_target_dir/$rel_source_subdir
148 if [ \! -d $abs_target_subdir ] ; then
149 mkdir $abs_target_subdir
150 fi
151 done
152 fi
153 rel_source_files=`find . -type f -name \*.h -print | sed 's%^\./%%'`
154 if [ `echo $rel_source_files | wc -w` != 0 ] ; then
155 for rel_source_file in $rel_source_files; do
156 abs_source_file=$abs_source_dir/$rel_source_file
157 abs_target_file=$abs_target_dir/$rel_source_file
158 if [ \! -f $abs_target_file ] ; then
159 sed 's%=%'"$rel_source_file"'%' $tmp_file > $abs_target_file
160 fi
161 done
162 fi
163 done
164fi
165rm -f $tmp_file
166exit 0