tsort_init_ops.sh 923 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # This script is meant to be run by the build system.
  3. set -e
  4. compile="$1"
  5. output_file="$2"
  6. shift 2
  7. tmpfile1=$(mktemp)
  8. tmpfile2=$(mktemp)
  9. cleanup()
  10. {
  11. rm -f $tmpfile1 $tmpfile2
  12. }
  13. trap cleanup EXIT
  14. process()
  15. {
  16. target=$1
  17. shift
  18. for dep in $@; do
  19. echo $target $dep
  20. done
  21. }
  22. # Define KERN_INIT_H so that the INIT_XXX macros aren't expanded.
  23. $compile -E -DKERN_INIT_H "$@" \
  24. | sed -e 's/#.*$//' \
  25. | tr '\n' ' ' \
  26. | tr -s ' ' \
  27. | sed -E -e 's/INIT_OP_DEP\(([a-zA-Z0-9_]*), 1 \)/\1/g' \
  28. | grep -P -o 'INIT_OP_DEFINE\(.*?\)' \
  29. | sed -e 's/^INIT_OP_DEFINE(//' \
  30. | sed -e 's/).*$//' \
  31. | tr -d , \
  32. | while read line; do
  33. process $line
  34. done > $tmpfile1
  35. if [ -z "$(cat $tmpfile1)" ]; then
  36. return 1
  37. fi
  38. # XXX Avoid using pipes because of the lack of a standard -o pipefail variant.
  39. tsort < $tmpfile1 > $tmpfile2
  40. tac < $tmpfile2 > "$output_file"