mkdep.awk 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # +----------------------------------------------------------------------+
  2. # | PHP Version 7 |
  3. # +----------------------------------------------------------------------+
  4. # | Copyright (c) 2000-2006 The PHP Group |
  5. # +----------------------------------------------------------------------+
  6. # | This source file is subject to version 3.01 of the PHP license, |
  7. # | that is bundled with this package in the file LICENSE, and is |
  8. # | available through the world-wide-web at the following url: |
  9. # | http://www.php.net/license/3_01.txt |
  10. # | If you did not receive a copy of the PHP license and are unable to |
  11. # | obtain it through the world-wide-web, please send a note to |
  12. # | license@php.net so we can mail you a copy immediately. |
  13. # +----------------------------------------------------------------------+
  14. # | Author: Sascha Schumann <sascha@schumann.cx> |
  15. # +----------------------------------------------------------------------+
  16. #
  17. # Usage:
  18. #
  19. # echo top_srcdir top_builddir srcdir CPP [CPP-ARGS] filenames | \
  20. # awk -f mkdep.awk > dependencies
  21. {
  22. top_srcdir=$1
  23. top_builddir=$2
  24. srcdir=$3
  25. cmd=$4
  26. for (i = 5; i <= NF; i++) {
  27. if (match($i, "^-[A-Z]") == 0)
  28. break;
  29. cmd=cmd " " $i
  30. }
  31. dif=i-1
  32. for (; i <= NF; i++)
  33. filenames[i-dif]=$i
  34. no_files=NF-dif
  35. for(i = 1; i <= no_files; i++) {
  36. if (system("test -r " filenames[i]) != 0)
  37. continue
  38. target=filenames[i]
  39. sub(srcdir "/", "", target)
  40. target2=target
  41. sub("\.(c|cpp)$", ".lo", target);
  42. sub("\.(c|cpp)$", ".slo", target2);
  43. for (e in used)
  44. delete used[e]
  45. cmdx=cmd " " filenames[i]
  46. done=0
  47. while ((cmdx | getline) > 0) {
  48. if (match($0, "^# [0-9]* \".*\.h\"") != 0) {
  49. if (sub(top_srcdir, "$(top_srcdir)", $3) == 0)
  50. sub(top_builddir, "$(top_builddir)", $3)
  51. if (substr($3,2,1) != "/" && used[$3] != 1) {
  52. if (done == 0)
  53. printf(target " " target2 ":")
  54. done=1
  55. printf(" \\\n\t" substr($3,2,length($3)-2))
  56. used[$3] = 1;
  57. }
  58. }
  59. }
  60. if (done == 1)
  61. print "\n"
  62. }
  63. }