1#! /bin/sh 2# $Id: headers-sh.in,v 1.11 2011/10/18 23:49:13 tom Exp $ 3############################################################################## 4# Copyright (c) 2004-2007,2011 Thomas E. Dickey # 5# # 6# Permission is hereby granted, free of charge, to any person obtaining a # 7# copy of this software and associated documentation files (the "Software"), # 8# to deal in the Software without restriction, including without limitation # 9# the rights to use, copy, modify, merge, publish, distribute, distribute # 10# with modifications, sublicense, and/or sell copies of the Software, and to # 11# permit persons to whom the Software is furnished to do so, subject to the # 12# following conditions: # 13# # 14# The above copyright notice and this permission notice shall be included in # 15# all copies or substantial portions of the Software. # 16# # 17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # 18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # 20# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # 21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # 23# DEALINGS IN THE SOFTWARE. # 24# # 25# Except as contained in this notice, the name(s) of the above copyright # 26# holders shall not be used in advertising or otherwise to promote the sale, # 27# use or other dealings in this Software without prior written # 28# authorization. # 29############################################################################## 30# 31# Adjust includes for header files that reside in a subdirectory of 32# /usr/include, etc. 33# 34# Parameters (the first case creates the sed script): 35# $1 is the target directory 36# $2 is the source directory 37# or (the second case does the install, using the sed script): 38# $1 is the script to use for installing 39# $2 is the target directory 40# $3 is the source directory 41# $4 is the file to install, editing source/target/etc. 42 43PACKAGE=@PACKAGE@ 44PKGNAME=@PACKAGE_PREFIX@ 45CONFIGH=@PACKAGE_CONFIG@ 46SUB_INC=@SUB_INC@ 47 48: ${TMPDIR:=/tmp} 49 50TMPSED=headers.sed 51 52DIGIT=0123456789 53alpha=abcdefghijklmnopqrstuvwxyz 54ALPHA=ABCDEFGHIJKLMNOPQRSTUVWXYZ 55 56alnum=_${DIGIT}${alpha} 57ALNUM=_${DIGIT}${ALPHA} 58MIXED=_${DIGIT}${ALPHA}${alpha} 59 60pkgname=`echo "$PKGNAME" | tr "$ALPHA" "$alpha"` 61 62if test $# = 2 ; then 63 rm -f $TMPSED 64 DST=$1 65 REF=$2 66 LEAF=`basename $DST` 67 68 # map the include-directory, if needed, to the subdirectory 69 case $DST in 70 /*/include/$LEAF) 71 END=`basename $DST` 72 for i in $REF/*.h 73 do 74 NAME=`basename $i` 75 echo "s/<$NAME>/<$END\/$NAME>/g" >> $TMPSED 76 done 77 ;; 78 *) 79 touch $TMPSED 80 ;; 81 esac 82 83 # cannot do _this_ in -e options: 84 cat >headers.tmp <<EOF 85s/^#[^ ][^ ]*// 86s/[^'$MIXED']/ /g 87s/[ ][ ]*/ /g 88s/^ // 89s/ $// 90:split 91 h 92 s/ .*// 93 p 94 t next 95 b done 96:next 97 x 98 s/^[^ ][^ ]* // 99 t split 100:done 101EOF 102 # pick up autoconf-style symbols used in the application's headers 103 for name in $REF/*.h 104 do 105 sed -e 's/^[ ][ ]*#[ ][ ]*/#/' $name \ 106 | egrep '^#(if|ifdef|ifndef|elif)' \ 107 | sed -f headers.tmp \ 108 | sort -u \ 109 | egrep '^(HAVE_|NEED_|NO_|ENABLE_|DISABLE_)' \ 110 | sed -e 's%^\(.*\)%s/\\<\1\\>/'${PKGNAME}'_\1/g%' >>$TMPSED 111 done 112 rm -f headers.tmp 113 114 # pick up autoconf-defined symbols in the config.h file 115 for name in ` 116 egrep '^#define[ ][ ]*['$ALNUM']' $REF/$CONFIGH \ 117 | sed \ 118 -e 's/^#define[ ][ ]*//' \ 119 -e 's/[ ].*//' \ 120 | egrep -v "^${PACKAGE}_" \ 121 | sort -u` 122 do 123 echo "s/\\<$name\\>/${PKGNAME}_$name/g" >>$TMPSED 124 done 125 126 if test "$SUB_INC" = yes 127 then 128 echo "s,#include <${pkgname}_,#include <${PACKAGE}/${pkgname}_," >>$TMPSED 129 fi 130 131 echo '/_FILE_OFFSET_BITS/d' >>$TMPSED 132 133 # reduce the count if possible, since some old sed's limit is 100 lines 134 sort -u $TMPSED >headers.tmp 135 mv headers.tmp $TMPSED 136else 137 PRG="" 138 while test $# != 3 139 do 140 PRG="$PRG $1"; shift 141 done 142 143 DST=$1 144 REF=$2 145 SRC=$3 146 147 SHOW=`basename $SRC` 148 TMPSRC=$TMPDIR/${SHOW}-text$$ 149 TMPEDT=$TMPDIR/${SHOW}-edit$$ 150 TMPTMP=$TMPDIR/${SHOW}-temp$$ 151 152 echo " ... $SHOW" 153 test -f $REF/$SRC && SRC="$REF/$SRC" 154 155 rm -f $TMPSRC 156 cat $SRC >$TMPSRC 157 158 tmp1=1 159 while true 160 do 161 tmp2=`expr $tmp1 + 49` 162 if test $tmp1 = 1 163 then 164 sed "${tmp2}q" $TMPSED >$TMPEDT 165 else 166 sed "1,${tmp1}d; ${tmp2}q" $TMPSED >$TMPEDT 167 fi 168 test -s $TMPEDT || break 169 sed -f $TMPEDT $TMPSRC > $TMPTMP 170 mv $TMPTMP $TMPSRC 171 tmp1=$tmp2 172 done 173 174 NAME=`basename $SRC` 175 176 # Just in case someone gzip'd manpages, remove the conflicting copy. 177 test -f $DST/$NAME.gz && rm -f $DST/$NAME.gz 178 179 if test "$SUB_INC" = yes 180 then 181 case $NAME in #(vi 182 ${pkgname}_*) #(vi 183 case "$PRG" in #(vi 184 *install*) 185 test -d $DST/$PACKAGE || mkdir -p $DST/$PACKAGE 186 ;; 187 esac 188 NAME=$PACKAGE/$NAME 189 ;; 190 *) 191 NAME=$PACKAGE.h 192 ;; 193 esac 194 fi 195 196 eval $PRG $TMPSRC $DST/$NAME 197 rm -f $TMPEDT $TMPTMP $TMPSRC 198fi 199# vile:ts=4 sw=4 200