runcprotoall 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. CPROTO=cproto
  3. CPROTO_FLAGS="-I. -I./include -I./include/zori -I./include/tr -D CPROTO"
  4. c_files=$(find src -iname "*.c" | tr "\n" ' ')
  5. for each in $c_files
  6. do
  7. dir=$(dirname "$each")
  8. cfile=$(basename "$each")
  9. hdir=include${dir#src}
  10. bfile="${cfile%.c}"
  11. haid="${bfile}_proto.h"
  12. guard="${bfile}_proto_included"
  13. hfile="$hdir/$haid"
  14. # printf "%s: %s->%s\n" "$each" "$dir" "$hfile $guard"
  15. if grep -q '@generate_cproto@' $each
  16. then
  17. mkdir -p "$hdir"
  18. temp=$(mktemp)
  19. printf "Generating $hfile from $each. ${CPROTO_PATH} \n"
  20. # create file if it doesn't exist to avoid chicken and egg problems.
  21. touch "$hfile"
  22. printf "/* This file was generated by runcprotoall */\n" > "$temp"
  23. printf "\n#ifndef CPROTO /* Needed to protect cproto from itself. */\n#ifndef ${guard}\n" >> "$temp"
  24. if cproto $CPROTO_FLAGS -I"$hdir" "$each" >> "$temp"
  25. then
  26. printf "\n#endif /* ${guard} */ \n#endif /* CPROTO */" >> "$temp"
  27. mv -f "$temp" "$hfile"
  28. else
  29. printf "cproto failed\n"
  30. exit 1
  31. fi
  32. fi
  33. done