mkdep.awk 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # +----------------------------------------------------------------------+
  2. # | PHP Version 5 |
  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. # $Id$
  18. #
  19. # Usage:
  20. #
  21. # echo top_srcdir top_builddir srcdir CPP [CPP-ARGS] filenames | \
  22. # awk -f mkdep.awk > dependencies
  23. {
  24. top_srcdir=$1
  25. top_builddir=$2
  26. srcdir=$3
  27. cmd=$4
  28. for (i = 5; i <= NF; i++) {
  29. if (match($i, "^-[A-Z]") == 0)
  30. break;
  31. cmd=cmd " " $i
  32. }
  33. dif=i-1
  34. for (; i <= NF; i++)
  35. filenames[i-dif]=$i
  36. no_files=NF-dif
  37. for(i = 1; i <= no_files; i++) {
  38. if (system("test -r " filenames[i]) != 0)
  39. continue
  40. target=filenames[i]
  41. sub(srcdir "/", "", target)
  42. target2=target
  43. sub("\.(c|cpp)$", ".lo", target);
  44. sub("\.(c|cpp)$", ".slo", target2);
  45. for (e in used)
  46. delete used[e]
  47. cmdx=cmd " " filenames[i]
  48. done=0
  49. while ((cmdx | getline) > 0) {
  50. if (match($0, "^# [0-9]* \".*\.h\"") != 0) {
  51. if (sub(top_srcdir, "$(top_srcdir)", $3) == 0)
  52. sub(top_builddir, "$(top_builddir)", $3)
  53. if (substr($3,2,1) != "/" && used[$3] != 1) {
  54. if (done == 0)
  55. printf(target " " target2 ":")
  56. done=1
  57. printf(" \\\n\t" substr($3,2,length($3)-2))
  58. used[$3] = 1;
  59. }
  60. }
  61. }
  62. if (done == 1)
  63. print "\n"
  64. }
  65. }