runcprotoall 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. if [ -e "$hfile" ]
  20. then
  21. if [ "$each" -ot "$hfile" ]
  22. then
  23. printf "Skipping file: $hfile: up to date.\n"
  24. continue
  25. fi
  26. else
  27. # create file if it doesn't exist to avoid chicken and egg problems.
  28. touch "$hfile"
  29. fi
  30. printf "Generating $hfile from $each. ${CPROTO_PATH} \n"
  31. printf "/* This file was generated by runcprotoall */\n" > "$temp"
  32. printf "\n#ifndef CPROTO /* Needed to protect cproto from itself. */\n#ifndef ${guard}\n" >> "$temp"
  33. if cproto $CPROTO_FLAGS -I"$hdir" "$each" >> "$temp"
  34. then
  35. printf "\n#endif /* ${guard} */ \n#endif /* CPROTO */" >> "$temp"
  36. mv -f "$temp" "$hfile"
  37. git add "$hfile"
  38. else
  39. printf "cproto failed\n"
  40. exit 1
  41. fi
  42. fi
  43. done