#!/bin/sh -euf PROG="${0##*/}" usage() { [ "$1" = 0 ] || exec >&2 cat < include_dir - system includes location project_include_dir - project includes prefix - ?? Examle: $PROG '/usr/include' '/usr/src/RPM/BUILD/firefox-1.5/dist/include' 'firefox' EOF [ -n "$1" ] && exit "$1" || exit } msg() { printf %s\\n "$@" } find_header() { local path="$1" && shift local fn="$1" && shift while [ -n "$path" ]; do [ -f "$path/$fn" ] && break path="${path%/*}" done [ -f "$path/$fn" ] && msg "$path/$fn" || return 1 } [ "$#" -eq 3 ] || usage 1 include_dir="$1" && shift indir="$1" && shift my_place="$1" && shift find "$indir/" -name '*.h' | while read h; do sed -ne 's|^[[:space:]]*#[[:space:]]*include[[:space:]]\+"\([^"]\+\)".*$|\1|p' -- "$h" | sort -u | while read ih; do ih_name="${ih##*/}" eh="$(find "$include_dir" -name "$ih_name")" || msg "Error: $h: '$ih'" if [ -z "$eh" ]; then if ! eh="$(find_header "${h%/*}" "$ih")"; then eh="$(find "$indir/" -name "$ih_name")" || msg "Error: $h: '$ih'" [ "$(printf %s\\n "$eh" |wc -l)" = "1" ] || { msg "Error: $h: '$(msg "$eh" |tr \\n \ )'"; continue; } fi [ -n "$eh" ] || { echo "Error: not found: $h: '$ih'"; continue; } subst "s%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$my_place/${eh#$indir/}>%" -- "$h" || msg "Error: $h" continue fi nh="${eh#$include_dir/}" # check nss/nspr nh="${nh#*nspr/}" nh="${nh#*nss/}" subst "s%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$nh>%" -- "$h" || echo "Error: $h: 's%^\([[:space:]]*#[[:space:]]*include\)[[:space:]]\+\"$ih\"%\1 <$nh>%'" done done