gen_asm_deps.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. ##
  3. ## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  4. ##
  5. ## Use of this source code is governed by a BSD-style license
  6. ## that can be found in the LICENSE file in the root of the source
  7. ## tree. An additional intellectual property rights grant can be found
  8. ## in the file PATENTS. All contributing project authors may
  9. ## be found in the AUTHORS file in the root of the source tree.
  10. ##
  11. self=$0
  12. show_help() {
  13. echo "usage: $self [options] <srcfile>"
  14. echo
  15. echo "Generate Makefile dependency information from assembly code source"
  16. echo
  17. exit 1
  18. }
  19. die_unknown(){
  20. echo "Unknown option \"$1\"."
  21. echo "See $0 --help for available options."
  22. exit 1
  23. }
  24. for opt do
  25. optval="${opt#*=}"
  26. case "$opt" in
  27. --build-pfx=*) pfx="${optval}"
  28. ;;
  29. --depfile=*) out="${optval}"
  30. ;;
  31. -I*) raw_inc_paths="${raw_inc_paths} ${opt}"
  32. inc_path="${inc_path} ${opt#-I}"
  33. ;;
  34. -h|--help) show_help
  35. ;;
  36. *) [ -f "$opt" ] && srcfile="$opt"
  37. ;;
  38. esac
  39. done
  40. [ -n "$srcfile" ] || show_help
  41. sfx=${sfx:-asm}
  42. includes=$(LC_ALL=C egrep -i "include +\"?[a-z0-9_/]+\.${sfx}" $srcfile |
  43. perl -p -e "s;.*?([a-z0-9_/]+.${sfx}).*;\1;")
  44. #" restore editor state
  45. for inc in ${includes}; do
  46. found_inc_path=
  47. for idir in ${inc_path}; do
  48. [ -f "${idir}/${inc}" ] && found_inc_path="${idir}" && break
  49. done
  50. if [ -f `dirname $srcfile`/$inc ]; then
  51. # Handle include files in the same directory as the source
  52. $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} `dirname $srcfile`/$inc
  53. elif [ -n "${found_inc_path}" ]; then
  54. # Handle include files on the include path
  55. $self --build-pfx=$pfx --depfile=$out ${raw_inc_paths} "${found_inc_path}/$inc"
  56. else
  57. # Handle generated includes in the build root (which may not exist yet)
  58. echo ${out} ${out%d}o: "${pfx}${inc}"
  59. fi
  60. done
  61. echo ${out} ${out%d}o: $srcfile