1#include "internal.h"
2
3#include <ctype.h>
4#include <string.h>
5
6void
7initspecialtargets(struct SpecialTargets *targets)
8{
9 targets->posix = 0;
10 memset(&targets->phony, 0, sizeof(targets->phony));
11 targets->recipeprefix = '\t';
12 targets->export_all = 0;
13}
14
15void
16updatespecialassign(struct SpecialTargets *targets, const char *lhs, const char *rhs)
17{
18 size_t i;
19
20 if (strcmp(lhs, ".RECIPEPREFIX") != 0)
21 return;
22 for (i = 0; rhs[i] && isspace((unsigned char)rhs[i]); i++)
23 ;
24 if (rhs[i])
25 targets->recipeprefix = rhs[i];
26}
27
28int
29handlespecialrule(struct SpecialTargets *targets, const struct RuleNode *rule)
30{
31 size_t i;
32
33 if (rule->targets.n == 1 && strcmp(rule->targets.v[0], ".POSIX") == 0) {
34 targets->posix = 1;
35 return 1;
36 }
37 if (rule->targets.n == 1 && strcmp(rule->targets.v[0], ".PHONY") == 0) {
38 for (i = 0; i < rule->prereqs.n; i++) {
39 if (!hasword(&targets->phony, rule->prereqs.v[i]))
40 addstr(&targets->phony, rule->prereqs.v[i]);
41 }
42 return 1;
43 }
44 if (rule->targets.n == 1 && strcmp(rule->targets.v[0], ".EXPORT_ALL_VARIABLES") == 0) {
45 targets->export_all = 1;
46 return 1;
47 }
48 return 0;
49}