recipe.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "mk.h"
  2. int
  3. dorecipe(Node *node)
  4. {
  5. int did = 0;
  6. char buf[BIGBLOCK], cwd[256];
  7. Arc *a, *aa;
  8. Node *n;
  9. Rule *r = 0;
  10. Symtab *s;
  11. Word head, ahead, lp, ln, *w, *ww, *aw;
  12. aa = 0;
  13. /*
  14. pick up the rule
  15. */
  16. for(a = node->prereqs; a; a = a->next)
  17. if(*a->r->recipe)
  18. r = (aa = a)->r;
  19. /*
  20. no recipe? go to buggery!
  21. */
  22. if(r == 0){
  23. if(!(node->flags&VIRTUAL) && !(node->flags&NORECIPE)){
  24. if(getwd(cwd, sizeof cwd))
  25. fprint(2, "mk: no recipe to make '%s' in directory %s\n", node->name, cwd);
  26. else
  27. fprint(2, "mk: no recipe to make '%s'\n", node->name);
  28. Exit();
  29. }
  30. if(strchr(node->name, '(') && node->time == 0)
  31. MADESET(node, MADE);
  32. else
  33. update(0, node);
  34. if(tflag){
  35. if(!(node->flags&VIRTUAL))
  36. touch(node->name);
  37. else if(explain)
  38. Bprint(&bout, "no touch of virtual '%s'\n", node->name);
  39. }
  40. return(did);
  41. }
  42. /*
  43. build the node list
  44. */
  45. node->next = 0;
  46. head.next = 0;
  47. ww = &head;
  48. ahead.next = 0;
  49. aw = &ahead;
  50. if(r->attr&REGEXP){
  51. ww->next = newword(node->name);
  52. aw->next = newword(node->name);
  53. } else {
  54. for(w = r->alltargets; w; w = w->next){
  55. if(r->attr&META)
  56. subst(aa->stem, w->s, buf, sizeof(buf));
  57. else
  58. strecpy(buf, buf + sizeof buf - 1, w->s);
  59. aw->next = newword(buf);
  60. aw = aw->next;
  61. if((s = symlook(buf, S_NODE, 0)) == 0)
  62. continue; /* not a node we are interested in */
  63. n = s->u.ptr;
  64. if(aflag == 0 && n->time) {
  65. for(a = n->prereqs; a; a = a->next)
  66. if(a->n && outofdate(n, a, 0))
  67. break;
  68. if(a == 0)
  69. continue;
  70. }
  71. ww->next = newword(buf);
  72. ww = ww->next;
  73. if(n == node) continue;
  74. n->next = node->next;
  75. node->next = n;
  76. }
  77. }
  78. for(n = node; n; n = n->next)
  79. if((n->flags&READY) == 0)
  80. return(did);
  81. /*
  82. gather the params for the job
  83. */
  84. lp.next = ln.next = 0;
  85. for(n = node; n; n = n->next){
  86. for(a = n->prereqs; a; a = a->next){
  87. if(a->n){
  88. addw(&lp, a->n->name);
  89. if(outofdate(n, a, 0)){
  90. addw(&ln, a->n->name);
  91. if(explain)
  92. fprint(1, "%s(%ld) < %s(%ld)\n",
  93. n->name, n->time, a->n->name, a->n->time);
  94. }
  95. } else {
  96. if(explain)
  97. fprint(1, "%s has no prerequisites\n",
  98. n->name);
  99. }
  100. }
  101. MADESET(n, BEINGMADE);
  102. }
  103. /* print("lt=%s ln=%s lp=%s\n",wtos(head.next, ' '),wtos(ln.next, ' '),wtos(lp.next, ' '));/**/
  104. run(newjob(r, node, aa->stem, aa->match, lp.next, ln.next, head.next, ahead.next));
  105. return(1);
  106. }
  107. void
  108. addw(Word *w, char *s)
  109. {
  110. Word *lw;
  111. for(lw = w; w = w->next; lw = w){
  112. if(strcmp(s, w->s) == 0)
  113. return;
  114. }
  115. lw->next = newword(s);
  116. }