mk.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <regexp.h>
  5. extern Biobuf bout;
  6. typedef struct Bufblock
  7. {
  8. struct Bufblock *next;
  9. char *start;
  10. char *end;
  11. char *current;
  12. } Bufblock;
  13. typedef struct Word
  14. {
  15. char *s;
  16. struct Word *next;
  17. } Word;
  18. typedef struct Envy
  19. {
  20. char *name;
  21. Word *values;
  22. } Envy;
  23. extern Envy *envy;
  24. typedef struct Rule
  25. {
  26. char *target; /* one target */
  27. Word *tail; /* constituents of targets */
  28. char *recipe; /* do it ! */
  29. short attr; /* attributes */
  30. short line; /* source line */
  31. char *file; /* source file */
  32. Word *alltargets; /* all the targets */
  33. int rule; /* rule number */
  34. Reprog *pat; /* reg exp goo */
  35. char *prog; /* to use in out of date */
  36. struct Rule *chain; /* hashed per target */
  37. struct Rule *next;
  38. } Rule;
  39. extern Rule *rules, *metarules, *patrule;
  40. /* Rule.attr */
  41. #define META 0x0001
  42. #define UNUSED 0x0002
  43. #define UPD 0x0004
  44. #define QUIET 0x0008
  45. #define VIR 0x0010
  46. #define REGEXP 0x0020
  47. #define NOREC 0x0040
  48. #define DEL 0x0080
  49. #define NOVIRT 0x0100
  50. #define NREGEXP 10
  51. typedef struct Arc
  52. {
  53. short flag;
  54. struct Node *n;
  55. Rule *r;
  56. char *stem;
  57. char *prog;
  58. char *match[NREGEXP];
  59. struct Arc *next;
  60. } Arc;
  61. /* Arc.flag */
  62. #define TOGO 1
  63. typedef struct Node
  64. {
  65. char *name;
  66. long time;
  67. unsigned short flags;
  68. Arc *prereqs;
  69. struct Node *next; /* list for a rule */
  70. } Node;
  71. /* Node.flags */
  72. #define VIRTUAL 0x0001
  73. #define CYCLE 0x0002
  74. #define READY 0x0004
  75. #define CANPRETEND 0x0008
  76. #define PRETENDING 0x0010
  77. #define NOTMADE 0x0020
  78. #define BEINGMADE 0x0040
  79. #define MADE 0x0080
  80. #define MADESET(n,m) n->flags = (n->flags&~(NOTMADE|BEINGMADE|MADE))|(m)
  81. #define PROBABLE 0x0100
  82. #define VACUOUS 0x0200
  83. #define NORECIPE 0x0400
  84. #define DELETE 0x0800
  85. #define NOMINUSE 0x1000
  86. typedef struct Job
  87. {
  88. Rule *r; /* master rule for job */
  89. Node *n; /* list of node targets */
  90. char *stem;
  91. char **match;
  92. Word *p; /* prerequistes */
  93. Word *np; /* new prerequistes */
  94. Word *t; /* targets */
  95. Word *at; /* all targets */
  96. int nproc; /* slot number */
  97. struct Job *next;
  98. } Job;
  99. extern Job *jobs;
  100. typedef struct Symtab
  101. {
  102. short space;
  103. char *name;
  104. union{
  105. void *ptr;
  106. uintptr value;
  107. } u;
  108. struct Symtab *next;
  109. } Symtab;
  110. enum {
  111. S_VAR, /* variable -> value */
  112. S_TARGET, /* target -> rule */
  113. S_TIME, /* file -> time */
  114. S_PID, /* pid -> products */
  115. S_NODE, /* target name -> node */
  116. S_AGG, /* aggregate -> time */
  117. S_BITCH, /* bitched about aggregate not there */
  118. S_NOEXPORT, /* var -> noexport */
  119. S_OVERRIDE, /* can't override */
  120. S_OUTOFDATE, /* n1\377n2 -> 2(outofdate) or 1(not outofdate) */
  121. S_MAKEFILE, /* target -> node */
  122. S_MAKEVAR, /* dumpable mk variable */
  123. S_EXPORTED, /* var -> current exported value */
  124. S_BULKED, /* we have bulked this dir */
  125. S_WESET, /* variable; we set in the mkfile */
  126. S_INTERNAL, /* an internal mk variable (e.g., stem, target) */
  127. };
  128. extern int debug;
  129. extern int nflag, tflag, iflag, kflag, aflag, mflag;
  130. extern int mkinline;
  131. extern char *infile;
  132. extern int nreps;
  133. extern char *explain;
  134. extern char *termchars;
  135. extern char *shell;
  136. extern char *shellname;
  137. extern char *shflags;
  138. extern int IWS;
  139. #define SYNERR(l) (fprint(2, "mk: %s:%d: syntax error; ", infile, ((l)>=0)?(l):mkinline))
  140. #define RERR(r) (fprint(2, "mk: %s:%d: rule error; ", (r)->file, (r)->line))
  141. #define NAMEBLOCK 1000
  142. #define BIGBLOCK 20000
  143. #define SEP(c) (((c)==' ')||((c)=='\t')||((c)=='\n'))
  144. #define WORDCHR(r) ((r) > ' ' && !utfrune("!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", (r)))
  145. #define DEBUG(x) (debug&(x))
  146. #define D_PARSE 0x01
  147. #define D_GRAPH 0x02
  148. #define D_EXEC 0x04
  149. #define LSEEK(f,o,p) seek(f,o,p)
  150. #define PERCENT(ch) (((ch) == '%') || ((ch) == '&'))
  151. #include "fns.h"