1#!/bin/sh 2# 3# modified for dgux by hassey@dg-rtp.dg.com based on 4# 5# fixinc.svr4 written by Ron Guilmette (rfg@ncd.com). 6# 7# This file is part of GNU CC. 8# 9# GNU CC is free software; you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation; either version 2, or (at your option) 12# any later version. 13# 14# GNU CC is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with GNU CC; see the file COPYING. If not, write to 21# the Free Software Foundation, 59 Temple Place - Suite 330, 22# Boston, MA 02111-1307, USA. 23# 24# 25# See README-fixinc for more information. 26 27# Fail if no arg to specify a directory for the output. 28if [ x$1 = x ] 29then echo fixincludes: no output directory specified 30exit 1 31fi 32 33# Directory in which to store the results. 34LIB=${1?"fixincludes: output directory not specified"} 35 36# Make sure it exists. 37if [ ! -d $LIB ]; then 38 mkdir $LIB || exit 1 39fi 40 41ORIG_DIR=`${PWDCMD-pwd}` 42 43# Make LIB absolute if it is relative. 44# Don't do this if not necessary, since may screw up automounters. 45case $LIB in 46/*) 47 ;; 48*) 49 cd $LIB; LIB=`${PWDCMD-pwd}` 50 ;; 51esac 52 53echo 'Building fixincludes in ' ${LIB} 54 55# Determine whether this filesystem has symbolic links. 56if ln -s X $LIB/ShouldNotExist 2>/dev/null; then 57 rm -f $LIB/ShouldNotExist 58 LINKS=true 59else 60 LINKS=false 61fi 62 63echo 'Making directories:' 64# Directory containing the original header files. 65shift 66if [ $# -eq 0 ] ; then 67 set /usr/include 68fi 69 70INLIST="$@" 71 72for INPUT in ${INLIST} ; do 73cd ${ORIG_DIR} 74cd ${INPUT} 75 76if $LINKS; then 77 files=`ls -LR | sed -n s/:$//p` 78else 79 files=`find . -type d -print | sed '/^.$/d'` 80fi 81for file in $files; do 82 rm -rf $LIB/$file 83 if [ ! -d $LIB/$file ] 84 then mkdir $LIB/$file 85 fi 86done 87 88# treetops gets an alternating list 89# of old directories to copy 90# and the new directories to copy to. 91treetops="${INPUT} ${LIB}" 92 93if $LINKS; then 94 echo 'Making internal symbolic directory links' 95 for file in $files; do 96 dest=`ls -ld $file | sed -n 's/.*-> //p'` 97 if [ "$dest" ]; then 98 cwd=`pwd` 99 # In case $dest is relative, get to $file's dir first. 100 cd ${INPUT} 101 cd `echo ./$file | sed -n 's&[^/]*$&&p'` 102 # Check that the target directory exists. 103 # Redirections changed to avoid bug in sh on Ultrix. 104 (cd $dest) > /dev/null 2>&1 105 if [ $? = 0 ]; then 106 cd $dest 107 # X gets the dir that the link actually leads to. 108 x=`pwd` 109 # If link leads back into ${INPUT}, 110 # make a similar link here. 111 if expr $x : "${INPUT}/.*" > /dev/null; then 112 # Y gets the actual target dir name, relative to ${INPUT}. 113 y=`echo $x | sed -n "s&${INPUT}/&&p"` 114 # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}. 115 dots=`echo "$file" | 116 sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'` 117 echo $file '->' $dots$y ': Making link' 118 rm -fr ${LIB}/$file > /dev/null 2>&1 119 ln -s $dots$y ${LIB}/$file > /dev/null 2>&1 120 else 121 # If the link is to outside ${INPUT}, 122 # treat this directory as if it actually contained the files. 123# This line used to have $dest instead of $x. 124# $dest seemed to be wrong for links found in subdirectories 125# of ${INPUT}. Does this change break anything? 126 treetops="$treetops $x ${LIB}/$file" 127 fi 128 fi 129 cd $cwd 130 fi 131 done 132fi 133 134# Completely replace <_int_varargs.h> with a file that defines 135# va_list and gnuc_va_list 136 137file=_int_varargs.h 138if [ -r ${INPUT}/$file ]; then 139 echo Replacing $file 140 cat > ${LIB}/$file << EOF 141/* This file was generated by fixinc.dgux. */ 142#ifndef __INT_VARARGS_H 143#define __INT_VARARGS_H 144 145#if defined(__m88k__) && defined (__DGUX__) 146#ifndef __GNUC_VA_LIST 147#define __GNUC_VA_LIST 148typedef struct 149{ 150 int __va_arg; /* argument number */ 151 int *__va_stk; /* start of args passed on stack */ 152 int *__va_reg; /* start of args passed in regs */ 153} __gnuc_va_list; 154#endif /* not __GNUC_VA_LIST */ 155#endif /* 88k && dgux */ 156 157#ifndef _VA_LIST_ 158#define _VA_LIST_ 159typedef __gnuc_va_list va_list; 160#endif /* _VA_LIST_ */ 161 162#endif /* __INT_VARARGS_H */ 163 164EOF 165 chmod a+r ${LIB}/$file 166fi 167 168echo 'Removing unneeded directories:' 169cd $LIB 170files=`find . -type d -print | sort -r` 171for file in $files; do 172 rmdir $LIB/$file > /dev/null 2>&1 173done 174 175if $LINKS; then 176 echo 'Making internal symbolic non-directory links' 177 cd ${INPUT} 178 files=`find . -type l -print` 179 for file in $files; do 180 dest=`ls -ld $file | sed -n 's/.*-> //p'` 181 if expr "$dest" : '[^/].*' > /dev/null; then 182 target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"` 183 if [ -f $target ]; then 184 ln -s $dest ${LIB}/$file >/dev/null 2>&1 185 fi 186 fi 187 done 188fi 189 190done 191 192if [ x${INSTALL_ASSERT_H} != x ] 193then 194 cd ${ORIG_DIR} 195 rm -f include/assert.h 196 cp ${srcdir}/assert.h include/assert.h || exit 1 197 chmod a+r include/assert.h 198fi 199 200exit 0 201