#!/bin/sh CPROTO=cproto CPROTO_FLAGS="-I. -I./include -I./include/zori -I./include/tr -D CPROTO" c_files=$(find src -iname "*.c" | tr "\n" ' ') for each in $c_files do dir=$(dirname "$each") cfile=$(basename "$each") hdir=include${dir#src} bfile="${cfile%.c}" haid="${bfile}_proto.h" guard="${bfile}_proto_included" hfile="$hdir/$haid" # printf "%s: %s->%s\n" "$each" "$dir" "$hfile $guard" if grep -q '@generate_cproto@' $each then mkdir -p "$hdir" temp=$(mktemp) if [ -e "$hfile" ] then if [ "$each" -ot "$hfile" ] then printf "Skipping file: $hfile: up to date.\n" continue fi else # create file if it doesn't exist to avoid chicken and egg problems. touch "$hfile" fi printf "Generating $hfile from $each. ${CPROTO_PATH} \n" printf "/* This file was generated by runcprotoall */\n" > "$temp" printf "\n#ifndef CPROTO /* Needed to protect cproto from itself. */\n#ifndef ${guard}\n" >> "$temp" if cproto $CPROTO_FLAGS -I"$hdir" "$each" >> "$temp" then printf "\n#endif /* ${guard} */ \n#endif /* CPROTO */" >> "$temp" mv -f "$temp" "$hfile" git add "$hfile" else printf "cproto failed\n" exit 1 fi fi done