recipe.c 2.5 KB

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