Kaydet (Commit) 2d31d8f8 authored tarafından Colomban Wendling's avatar Colomban Wendling

make: Support for combined targets

üst 5bed3b58
...@@ -105,42 +105,19 @@ static void newMacro (vString *const name) ...@@ -105,42 +105,19 @@ static void newMacro (vString *const name)
makeSimpleTag (name, MakeKinds, K_MACRO); makeSimpleTag (name, MakeKinds, K_MACRO);
} }
static void newMacroFromDefine (vString *const name)
{
/* name is something like "define JAVAHPP_RULE", find the space and jump to the next char */
char *name_val = strchr (vStringValue (name), ' ');
if (name_val != NULL) {
vStringCopyS (name, name_val + 1);
makeSimpleTag (name, MakeKinds, K_MACRO);
}
}
static void readIdentifier (const int first, vString *const id) static void readIdentifier (const int first, vString *const id)
{ {
int depth = 0; int depth = 0;
int c = first; int c = first;
int c_prev = first;
int c_next = first;
vStringClear (id); vStringClear (id);
while (isIdentifier (c) || c == ' ' || (depth > 0 && c != EOF && c != '\n')) while (isIdentifier (c) || (depth > 0 && c != EOF && c != '\n'))
{ {
c_next = nextChar ();
if (c == '(' || c == '}') if (c == '(' || c == '}')
depth++; depth++;
else if (depth > 0 && (c == ')' || c == '}')) else if (depth > 0 && (c == ')' || c == '}'))
depth--; depth--;
if (depth < 1 && c == ' ') { vStringPut (id, c);
/* add the space character only if the previous and c = nextChar ();
* next character are valid identifiers */
if (isIdentifier (c_prev) && isIdentifier (c_next))
vStringPut (id, c);
}
else {
vStringPut (id, c);
}
c_prev = c;
c = c_next;
} }
fileUngetc (c); fileUngetc (c);
vStringTerminate (id); vStringTerminate (id);
...@@ -148,7 +125,7 @@ static void readIdentifier (const int first, vString *const id) ...@@ -148,7 +125,7 @@ static void readIdentifier (const int first, vString *const id)
static void findMakeTags (void) static void findMakeTags (void)
{ {
vString *name = vStringNew (); stringList *identifiers = stringListNew ();
boolean newline = TRUE; boolean newline = TRUE;
boolean in_define = FALSE; boolean in_define = FALSE;
boolean in_rule = FALSE; boolean in_rule = FALSE;
...@@ -169,6 +146,7 @@ static void findMakeTags (void) ...@@ -169,6 +146,7 @@ static void findMakeTags (void)
else else
in_rule = FALSE; in_rule = FALSE;
} }
stringListClear (identifiers);
variable_possible = (boolean)(!in_rule); variable_possible = (boolean)(!in_rule);
newline = FALSE; newline = FALSE;
} }
...@@ -178,74 +156,70 @@ static void findMakeTags (void) ...@@ -178,74 +156,70 @@ static void findMakeTags (void)
continue; continue;
else if (c == '#') else if (c == '#')
skipLine (); skipLine ();
else if (c == ':') else if (variable_possible && c == '?')
{
c = nextChar ();
fileUngetc (c);
variable_possible = (c == '=');
}
else if (variable_possible && c == ':' &&
stringListCount (identifiers) > 0)
{
c = nextChar ();
fileUngetc (c);
if (c != '=')
{
unsigned int i;
for (i = 0; i < stringListCount (identifiers); i++)
newTarget (stringListItem (identifiers, i));
stringListClear (identifiers);
in_rule = TRUE;
}
}
else if (variable_possible && c == '=' &&
stringListCount (identifiers) == 1)
{ {
variable_possible = TRUE; newMacro (stringListItem (identifiers, 0));
in_rule = TRUE; skipLine ();
in_rule = FALSE;
} }
else if (variable_possible && isIdentifier (c)) else if (variable_possible && isIdentifier (c))
{ {
vString *name = vStringNew ();
readIdentifier (c, name); readIdentifier (c, name);
if (strncmp (vStringValue (name), "endef", 5) == 0) stringListAdd (identifiers, name);
in_define = FALSE;
else if (in_define) if (stringListCount (identifiers) == 1)
skipLine ();
else if (strncmp (vStringValue (name), "define", 6) == 0 &&
isIdentifier (c))
{ {
in_define = TRUE; if (in_define && ! strcmp (vStringValue (name), "endef"))
c = skipToNonWhite (); in_define = FALSE;
newMacroFromDefine (name); else if (in_define)
skipLine (); skipLine ();
} else if (! strcmp (vStringValue (name), "define"))
else {
c = skipToNonWhite ();
if (strchr (":?+", c) != NULL)
{ {
boolean append = (boolean)(c == '+'); in_define = TRUE;
boolean was_colon = (c == ':'); c = skipToNonWhite ();
c = nextChar (); vStringClear (name);
if (was_colon) /* all remaining characters on the line are the name -- even spaces */
{ while (c != EOF && c != '\n')
if (c == '=')
{
newMacro (name);
in_rule = FALSE;
skipLine ();
}
else
{
fileUngetc (c);
in_rule = TRUE;
newTarget (name);
}
}
else if (append)
{ {
skipLine (); vStringPut (name, c);
continue; c = nextChar ();
} }
else if (c == '\n')
{
fileUngetc (c); fileUngetc (c);
} vStringTerminate (name);
} vStringStripTrailing (name);
else if (c == '=')
{
newMacro (name); newMacro (name);
in_rule = FALSE;
skipLine ();
}
else
{
fileUngetc (c);
} }
else if (! strcmp (vStringValue (name), "export"))
stringListClear (identifiers);
} }
} }
else else
variable_possible = FALSE; variable_possible = FALSE;
} }
vStringDelete (name); stringListDelete (identifiers);
} }
extern parserDefinition* MakefileParser (void) extern parserDefinition* MakefileParser (void)
......
...@@ -200,6 +200,7 @@ test_sources = \ ...@@ -200,6 +200,7 @@ test_sources = \
line_directives.c \ line_directives.c \
local.c \ local.c \
macros.c \ macros.c \
make-multi-target.mak \
make-target-with-parentheses.mak \ make-target-with-parentheses.mak \
make-variable-on-cmdline.mak \ make-variable-on-cmdline.mak \
masm.asm \ masm.asm \
......
all: foo bar
foo bar: baz
echo $@
baz:
echo $@
# format=tagmanager
all160
bar160
baz160
foo160
...@@ -8,7 +8,7 @@ E ...@@ -8,7 +8,7 @@ E
F655360 F655360
G655360 G655360
H655360 H655360
I655360
a.o160 a.o160
b.o160 b.o160
default160 default160
export I655360
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment