[anjuta] am-project: Expand variables in configure.ac



commit d04c11e25391027a8cb4026aff181a33c4bc3212
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sat Oct 8 12:36:56 2011 +0200

    am-project: Expand variables in configure.ac

 plugins/am-project/ac-parser.y          |   85 +++++++++++++++++++++++++++----
 plugins/am-project/ac-scanner.h         |    4 ++
 plugins/am-project/ac-scanner.l         |   38 ++++++++++++++
 plugins/am-project/am-parser.y          |   31 ++++++++++-
 plugins/am-project/am-project-private.h |    7 ++-
 plugins/am-project/am-project.c         |   17 ++++++
 plugins/am-project/am-project.h         |    4 +-
 plugins/am-project/am-scanner.h         |   12 +++--
 plugins/am-project/am-scanner.l         |   49 +++++++++++++++++-
 plugins/am-project/amp-group.c          |   70 ++++++++++----------------
 plugins/am-project/amp-group.h          |    2 +-
 plugins/am-project/tests/variable.at    |   45 ++++++++++++++++-
 12 files changed, 297 insertions(+), 67 deletions(-)
---
diff --git a/plugins/am-project/ac-parser.y b/plugins/am-project/ac-parser.y
index 1ddf99c..fc9dd03 100644
--- a/plugins/am-project/ac-parser.y
+++ b/plugins/am-project/ac-parser.y
@@ -23,7 +23,7 @@
 
 #include <stdlib.h>
 
-//#define YYDEBUG 1
+#define YYDEBUG 1
 
 #include "libanjuta/anjuta-debug.h"
 
@@ -128,6 +128,8 @@
 
 %{
 
+//amp_ac_yydebug = 1;
+
 static gint
 amp_ac_autoconf_macro (AnjutaToken *token)
 {
@@ -187,19 +189,47 @@ file:
 	;
 
 line:
-	end_statement
-	| spaces end_statement
-    | statement end_statement
-    | spaces statement end_statement
+	optional_spaces end_statement
+    | optional_spaces statement end_statement
     ;
 
+
+definition:
+	NAME optional_spaces EQUAL value {
+        $$ = anjuta_token_new_static (ANJUTA_TOKEN_DEFINITION, NULL);
+		if ($2) anjuta_token_set_type ($2, ANJUTA_TOKEN_NEXT);
+        anjuta_token_merge ($$, $1);
+        anjuta_token_merge ($$, $2);
+        anjuta_token_merge ($$, $3);
+        anjuta_token_merge ($$, $4);
+        amp_ac_scanner_update_variable (scanner, $$);
+	}
+	;
+
 statement:
-	statement_token
-	| statement statement_token
-	| statement SPACE
+	definition
+	| other_statement
+	;
+
+other_statement:
+	no_name_token
+	| no_name_token value
+	| NAME optional_spaces
+	| NAME optional_spaces no_equal_token
+	| NAME optional_spaces no_equal_token value
 	;
 
-statement_token:
+value:
+	value_token {
+		$$ = anjuta_token_new_static (ANJUTA_TOKEN_LIST, NULL);
+		anjuta_token_merge ($$, $1);
+	}
+	| value value_token {
+		anjuta_token_merge ($1, $2);
+	}
+	;
+
+value_token:
     shell_string
     | args_token
 	| macro
@@ -209,13 +239,38 @@ statement_token:
     | NAME
     | VARIABLE
     | WORD
+	| SPACE
     ;
 
+no_name_token:
+    shell_string
+    | args_token
+	| macro
+    | EQUAL
+    | LOWER
+    | GREATER
+    | VARIABLE
+    | WORD
+    ;
+
+no_equal_token:
+    shell_string
+    | args_token
+	| macro
+    | LOWER
+    | GREATER
+    | NAME
+    | VARIABLE
+    | WORD
+    ;
+
+
 macro:
     include
 	| ac_macro_with_arg
 	| ac_macro_without_arg
     | ac_init
+	| ac_subst
 	| pkg_check_modules
 	| obsolete_ac_output
 	| ac_output
@@ -326,6 +381,16 @@ ac_init:
 		anjuta_token_merge ($$, $2);
         amp_ac_scanner_load_properties (scanner, $1, $2);
     }
+	;
+
+ac_subst:
+	AC_SUBST arg_list {
+		$$ = anjuta_token_new_static (AC_TOKEN_AC_SUBST, NULL);
+		anjuta_token_merge ($$, $1);
+		anjuta_token_merge ($$, $2);
+        amp_ac_scanner_subst_variable (scanner, $2);
+	}
+	;
 
 ac_output:
 	AC_OUTPUT {
@@ -755,6 +820,7 @@ any_macro:
     | OBSOLETE_AC_OUTPUT
     | PKG_CHECK_MODULES
     | AC_INIT
+	| AC_SUBST
     | ac_macro_with_arg_token
     | ac_macro_without_arg_token
     ;
@@ -790,7 +856,6 @@ ac_macro_with_arg_token:
 	| AC_EGREP_HEADER
 	| AC_PREREQ
 	| IT_PROG_INTLTOOL
-	| AC_SUBST
 	| AM_INIT_AUTOMAKE
 	| AM_GLIB_GNU_GETTEXT
 	| LT_INIT
diff --git a/plugins/am-project/ac-scanner.h b/plugins/am-project/ac-scanner.h
index 9ca4ca1..18b3851 100644
--- a/plugins/am-project/ac-scanner.h
+++ b/plugins/am-project/ac-scanner.h
@@ -44,6 +44,8 @@ void amp_ac_scanner_load_module (AmpAcScanner *scanner, AnjutaToken *module);
 void amp_ac_scanner_load_config (AmpAcScanner *scanner, AnjutaToken *list);
 void amp_ac_scanner_load_properties (AmpAcScanner *scanner, AnjutaToken *macro, AnjutaToken *args);
 void amp_ac_scanner_include (AmpAcScanner *scanner, AnjutaToken *list);
+void amp_ac_scanner_update_variable (AmpAcScanner *scanner, AnjutaToken *variable);
+void amp_ac_scanner_subst_variable (AmpAcScanner *scanner, AnjutaToken *list);
 
 void amp_ac_yyerror (YYLTYPE *loc, AmpAcScanner *scanner, char const *s);
 
@@ -103,6 +105,8 @@ enum
 	AC_TOKEN_AC_OUTPUT,
 	AC_TOKEN_LAST_ORDERED_MACRO,
 
+	AC_TOKEN_AC_SUBST,
+
 	AC_TOKEN_SPACE_LIST,
 	AC_TOKEN_OPEN_STRING,
 	AC_TOKEN_CLOSE_STRING
diff --git a/plugins/am-project/ac-scanner.l b/plugins/am-project/ac-scanner.l
index 28d27a9..44b1773 100644
--- a/plugins/am-project/ac-scanner.l
+++ b/plugins/am-project/ac-scanner.l
@@ -52,6 +52,8 @@ struct _AmpAcScanner
     AnjutaToken *parsed;
 
 	gboolean eof;		/* TRUE to emit EOF at the end */
+
+	GHashTable *variables;
 };
 
 
@@ -316,6 +318,39 @@ amp_ac_scanner_include (AmpAcScanner *scanner, AnjutaToken *list)
 	g_object_unref (file);
 }
 
+void
+amp_ac_scanner_update_variable (AmpAcScanner *scanner, AnjutaToken *variable)
+{
+	AnjutaToken *arg;
+	char *name = NULL;
+	AnjutaToken *value = NULL;
+
+	arg = anjuta_token_first_word (variable);
+	name = g_strstrip (anjuta_token_evaluate (arg));
+	value = anjuta_token_nth_word (variable, 2);
+
+	g_hash_table_insert (scanner->variables, name, value);
+}
+
+void
+amp_ac_scanner_subst_variable (AmpAcScanner *scanner, AnjutaToken *list)
+{
+	AnjutaToken *arg;
+	char *name = NULL;
+	AnjutaToken *value = NULL;
+
+	arg = anjuta_token_first_word (list);
+	name = g_strstrip (anjuta_token_evaluate (arg));
+	value = anjuta_token_nth_word (list, 2);
+	if (value == NULL)
+	{
+		value = g_hash_table_lookup (scanner->variables, name);
+	}
+
+	amp_project_add_subst_variable (scanner->project, name, value);
+}
+
+
 /* Public functions
  *---------------------------------------------------------------------------*/
 
@@ -388,6 +423,8 @@ amp_ac_scanner_new (AmpProject *project)
 
     scanner->project = project;
 
+	scanner->variables = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL);
+
 	return scanner;
 };
 
@@ -396,6 +433,7 @@ amp_ac_scanner_free (AmpAcScanner *scanner)
 {
 	g_return_if_fail (scanner != NULL);
 
+	g_hash_table_remove_all (scanner->variables);
     yylex_destroy(scanner->scanner);
 
 	g_free (scanner);
diff --git a/plugins/am-project/am-parser.y b/plugins/am-project/am-parser.y
index d002224..f1a3bd1 100644
--- a/plugins/am-project/am-parser.y
+++ b/plugins/am-project/am-parser.y
@@ -376,6 +376,10 @@ head:
 		$$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
 		anjuta_token_merge ($$, $1);
 	}
+	| ac_variable {
+		$$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
+		anjuta_token_merge ($$, $1);
+	}
 	| variable {
 		$$ = anjuta_token_new_static (ANJUTA_TOKEN_NAME, NULL);
 		anjuta_token_merge ($$, $1);
@@ -392,6 +396,9 @@ head:
 	| head variable {
 		anjuta_token_merge ($1, $2);
 	}
+	| head ac_variable {
+		anjuta_token_merge ($1, $2);
+	}
 	;
 
 next_head:
@@ -415,6 +422,9 @@ next_head:
 	| next_head variable {
 		anjuta_token_merge ($1, $2);
 	}
+	| next_head ac_variable {
+		anjuta_token_merge ($1, $2);
+	}
 	;
 
 value:
@@ -426,12 +436,19 @@ value:
 		$$ = anjuta_token_new_static (ANJUTA_TOKEN_ARGUMENT, NULL);
 		anjuta_token_merge ($$, $1);
 	}
+	| ac_variable {
+		$$ = anjuta_token_new_static (ANJUTA_TOKEN_ARGUMENT, NULL);
+		anjuta_token_merge ($$, $1);
+	}
 	| value value_token {
 		anjuta_token_merge ($1, $2);
 	}
 	| value variable {
 		anjuta_token_merge ($1, $2);
 	}
+	| value ac_variable {
+		anjuta_token_merge ($1, $2);
+	}
 	;
 
 prerequisite:
@@ -441,16 +458,24 @@ prerequisite:
 name_prerequisite:
 	prerequisite_token
 	| variable
+	| ac_variable
 	| name_prerequisite prerequisite_token
 	| name_prerequisite variable
+	| name_prerequisite ac_variable
 	;
 
 variable:
-	variable_token {
+	VARIABLE {
 		amp_am_scanner_parse_variable (scanner, $$);
 	}
 	;
 
+ac_variable:
+	MACRO {
+		amp_am_scanner_parse_ac_variable (scanner, $$);
+	}
+	;
+
 /* Tokens
  *----------------------------------------------------------------------------*/
 
@@ -525,14 +550,14 @@ word_token:
 
 
 name_token:
-	MACRO
-	| NAME
+	NAME
 	| CHARACTER
 	| ORDER
 	;
 
 variable_token:
 	VARIABLE
+	| MACRO
 	;
 
 automake_token:
diff --git a/plugins/am-project/am-project-private.h b/plugins/am-project/am-project-private.h
index 9154262..e340736 100644
--- a/plugins/am-project/am-project-private.h
+++ b/plugins/am-project/am-project-private.h
@@ -57,7 +57,7 @@ struct _AmpProject {
 
 	/* File monitor */
 	GFileMonitor *monitor;
-	
+
 	AnjutaToken			*ac_init;
 	AnjutaToken			*args;
 
@@ -68,9 +68,12 @@ struct _AmpProject {
 	GHashTable		*groups;
 	GHashTable		*configs;		/* Config file from configure_file */
 
+
+	GHashTable		*ac_variables;
+
 	/* Number of not loaded node */
 	gint				loading;
-	
+
 	/* Keep list style */
 	AnjutaTokenStyle *ac_space_list;
 	AnjutaTokenStyle *am_space_list;
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index a504767..8168c85 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -1645,6 +1645,7 @@ amp_project_load_root (AmpProject *project, GError **error)
 	configure_token_file = amp_project_set_configure (project, configure_file);
 	amp_project_add_file (project, configure_file, configure_token_file);
 	arg = anjuta_token_file_load (configure_token_file, NULL);
+	g_hash_table_remove_all (project->ac_variables);
 	scanner = amp_ac_scanner_new (project);
 	project->configure_token = amp_ac_scanner_parse_token (scanner, NULL, arg, 0, configure_file, &err);
 	amp_ac_scanner_free (scanner);
@@ -2034,6 +2035,19 @@ amp_project_add_file (AmpProject *project, GFile *file, AnjutaTokenFile* token)
 	g_object_weak_ref (G_OBJECT (token), remove_config_file, project);
 }
 
+void
+amp_project_add_subst_variable (AmpProject *project, const gchar *name, AnjutaToken *value)
+{
+	g_hash_table_insert (project->ac_variables, (gchar *)name, value);
+}
+
+AnjutaToken *
+amp_project_get_subst_variable_token (AmpProject *project, const gchar *name)
+{
+	return g_hash_table_lookup (project->ac_variables, name);
+}
+
+
 gboolean
 amp_project_is_busy (AmpProject *project)
 {
@@ -2460,6 +2474,8 @@ amp_project_dispose (GObject *object)
 	project->groups = NULL;
 	if (project->configs) g_hash_table_destroy (project->configs);
 	project->configs = NULL;
+	if (project->ac_variables) g_hash_table_destroy (project->ac_variables);
+	project->ac_variables = NULL;
 
 	if (project->queue) pm_command_queue_free (project->queue);
 	project->queue = NULL;
@@ -2490,6 +2506,7 @@ amp_project_init (AmpProject *project)
 	project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 	project->files = NULL;
 	project->configs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, (GDestroyNotify)amp_config_file_free);
+	project->ac_variables = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL);
 
 	/* Default style */
 	project->am_space_list = NULL;
diff --git a/plugins/am-project/am-project.h b/plugins/am-project/am-project.h
index 775a924..f3b0ab0 100644
--- a/plugins/am-project/am-project.h
+++ b/plugins/am-project/am-project.h
@@ -94,6 +94,9 @@ GFile* amp_project_get_file (AmpProject *project);
 gboolean amp_project_is_busy (AmpProject *project);
 
 void amp_project_add_file (AmpProject *project, GFile *file, AnjutaTokenFile* token);
+void amp_project_add_subst_variable (AmpProject *project, const gchar *name, AnjutaToken *value);
+AnjutaToken *amp_project_get_subst_variable_token (AmpProject *project, const gchar *name);
+
 
 AmpGroupNode* amp_project_add_group (AmpProject  *project, AmpGroupNode *parent, const gchar *name, GError **error);
 AmpGroupNode* amp_project_add_sibling_group (AmpProject  *project, AmpGroupNode *parent, const gchar *name, gboolean after, AmpGroupNode *sibling, GError **error);
@@ -125,7 +128,6 @@ AnjutaProjectNode *amp_node_prev_sibling (AnjutaProjectNode *node);
 GFile *amp_group_node_get_directory (AmpGroupNode *group);
 gchar *amp_group_node_get_id (AmpGroupNode *group);
 void amp_group_node_update_variable (AmpGroupNode *group, AnjutaToken *variable);
-AnjutaToken* amp_group_node_get_variable_token (AmpGroupNode *group, AnjutaToken *variable);
 
 const gchar *amp_target_node_get_name (AmpTargetNode *target);
 gchar *amp_target_node_get_id (AmpTargetNode *target);
diff --git a/plugins/am-project/am-scanner.h b/plugins/am-project/am-scanner.h
index 870e254..e77b4bf 100644
--- a/plugins/am-project/am-scanner.h
+++ b/plugins/am-project/am-scanner.h
@@ -2,17 +2,17 @@
 /*
  * am-scanner.h
  * Copyright (C) SÃbastien Granjoux 2009 <seb sfo free fr>
- * 
+ *
  * main.c is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * main.c is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -47,6 +47,8 @@ void amp_am_scanner_update_variable (AmpAmScanner *scanner, AnjutaToken *variabl
 
 void amp_project_set_am_variable (AmpProject* project, AmpGroupNode* group, AnjutaToken *variable, GHashTable *orphan_properties);
 
+void amp_am_scanner_parse_variable (AmpAmScanner *scanner, AnjutaToken *variable);
+void amp_am_scanner_parse_ac_variable (AmpAmScanner *scanner, AnjutaToken *variable);
 
 void amp_am_yyerror (YYLTYPE *loc, AmpAmScanner *scanner, char const *s);
 
@@ -78,7 +80,7 @@ typedef enum
 	AM_TOKEN__OBJCFLAGS,
 	AM_TOKEN__LFLAGS,
 	AM_TOKEN__YFLAGS,
-	
+
 	AM_TOKEN_FIRST_ORDERED_TARGET_MACRO,
 	AM_TOKEN__SOURCES,
 	AM_TOKEN_TARGET_CPPFLAGS,
@@ -97,7 +99,7 @@ typedef enum
 	AM_TOKEN_LAST_ORDERED_TARGET_MACRO,
 
 	AM_TOKEN_LAST_ORDERED_MACRO,
-		
+
 } AmTokenType;
 
 G_END_DECLS
diff --git a/plugins/am-project/am-scanner.l b/plugins/am-project/am-scanner.l
index f1f717d..4a36c94 100644
--- a/plugins/am-project/am-scanner.l
+++ b/plugins/am-project/am-scanner.l
@@ -20,6 +20,7 @@
 %{
 
 #include "am-scanner.h"
+#include "amp-group.h"
 #include "am-parser.h"
 #include "amp-node.h"
 #include "amp-target.h"
@@ -53,6 +54,7 @@ struct _AmpAmScanner
 	AmpProject *project;
 	AmpGroupNode *group;
 	GHashTable *orphan_properties;
+	GHashTable *ac_variables;
 	GList *am_variables;
 	GList *variables;
 	gboolean eof;		/* TRUE to emit EOF at the end */
@@ -484,11 +486,56 @@ amp_am_scanner_update_variable (AmpAmScanner *scanner, AnjutaToken *variable)
 void
 amp_am_scanner_parse_variable (AmpAmScanner *scanner, AnjutaToken *variable)
 {
+	guint length;
+	gchar *string;
+	const gchar *name;
 	AnjutaToken *value;
 
 	anjuta_token_set_type (variable, ANJUTA_TOKEN_VARIABLE);
 
-	value = amp_group_node_get_variable_token (scanner->group, variable);
+	string = anjuta_token_evaluate(variable);
+	length = strlen (string);
+	if (string[1] == '(')
+	{
+		string[length - 1] = '\0';
+		name = string + 2;
+	}
+	else
+	{
+		string[2] = '\0';
+		name = string + 1;
+	}
+	value = amp_group_node_get_variable_token (scanner->group, name);
+	if (value == NULL)
+	{
+		value = amp_project_get_subst_variable_token (scanner->project, name);
+	}
+	g_free (string);
+
+	if (value != NULL)
+	{
+		amp_am_scanner_parse_token (scanner, variable, value, NULL, NULL);
+	}
+}
+
+void
+amp_am_scanner_parse_ac_variable (AmpAmScanner *scanner, AnjutaToken *variable)
+{
+	guint length;
+	gchar *string;
+	const gchar *name;
+	AnjutaToken *value;
+
+	anjuta_token_set_type (variable, ANJUTA_TOKEN_VARIABLE);
+
+	string = anjuta_token_evaluate(variable);
+	length = strlen (string);
+	/* Remove @ surrounding the variable name */
+	name = string + 1;
+	string[length - 1] = '\0';
+	value = amp_project_get_subst_variable_token (scanner->project, name);
+	g_free (string);
+
 	if (value != NULL)
 	{
 		amp_am_scanner_parse_token (scanner, variable, value, NULL, NULL);
diff --git a/plugins/am-project/amp-group.c b/plugins/am-project/amp-group.c
index 4fd771b..f6d86fa 100644
--- a/plugins/am-project/amp-group.c
+++ b/plugins/am-project/amp-group.c
@@ -81,7 +81,7 @@ error_set (GError **error, gint code, const gchar *message)
                 }
         }
 }
-                                                      
+
 /* Private functions
  *---------------------------------------------------------------------------*/
 
@@ -95,7 +95,7 @@ project_load_group_module (AmpProject *project, AmpGroupNode *group)
 
 	prop = amp_node_get_property_from_token (ANJUTA_PROJECT_NODE (group), AM_TOKEN__CPPFLAGS, 0);
 	if (prop && (prop->value != NULL)) group_cpp = g_strsplit_set (prop->value, " \t", 0);
-	
+
 	/* Check all targets */
 	for (target = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (group)); target != NULL; target = anjuta_project_node_next_sibling (target))
 	{
@@ -178,7 +178,7 @@ project_load_group_module (AmpProject *project, AmpGroupNode *group)
 					}
 					g_free (lib_flags);
 				}
-			}		
+			}
 			g_strfreev (target_cpp);
 			g_strfreev (target_lib);
 		}
@@ -238,7 +238,7 @@ project_load_makefile (AmpProject *project, AmpGroupNode *group)
 	tfile = amp_group_node_set_makefile (group, makefile, project);
 
 	project_load_group_module (project, group);
-	
+
 	return group;
 }
 
@@ -252,8 +252,8 @@ amp_variable_new (gchar *name, AnjutaTokenType assign, AnjutaToken *value)
     AmpVariable *variable = NULL;
 
 	g_return_val_if_fail (name != NULL, NULL);
-	
-	variable = g_slice_new0(AmpVariable); 
+
+	variable = g_slice_new0(AmpVariable);
 	variable->name = g_strdup (name);
 	variable->assign = assign;
 	variable->value = value;
@@ -265,7 +265,7 @@ static void
 amp_variable_free (AmpVariable *variable)
 {
 	g_free (variable->name);
-	
+
     g_slice_free (AmpVariable, variable);
 }
 
@@ -298,7 +298,7 @@ amp_group_node_get_token (AmpGroupNode *group, AmpGroupNodeTokenCategory categor
 	return group->tokens[category];
 }
 
-GList * 
+GList *
 amp_group_node_get_all_token (AmpGroupNode *group)
 {
 	gint i;
@@ -308,7 +308,7 @@ amp_group_node_get_all_token (AmpGroupNode *group)
 	{
 		tokens = g_list_concat (tokens, g_list_copy (group->tokens[i]));
 	}
-	
+
 	return tokens;
 }
 
@@ -316,7 +316,7 @@ AnjutaToken*
 amp_group_node_get_first_token (AmpGroupNode *group, AmpGroupNodeTokenCategory category)
 {
 	GList *list;
-	
+
 	list = amp_group_node_get_token (group, category);
 	if (list == NULL) return NULL;
 
@@ -362,18 +362,18 @@ amp_group_node_set_makefile (AmpGroupNode *group, GFile *makefile, AmpProject *p
 	{
 		AnjutaToken *token;
 		AmpAmScanner *scanner;
-		
+
 		group->makefile = g_object_ref (makefile);
 		group->tfile = anjuta_token_file_new (makefile);
 
 		token = anjuta_token_file_load (group->tfile, NULL);
 		amp_project_add_file (project, makefile, group->tfile);
-			
+
 		scanner = amp_am_scanner_new (project, group);
 		group->make_token = amp_am_scanner_parse_token (scanner, anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL), token, makefile, NULL);
 		amp_am_scanner_free (scanner);
 
-		group->monitor = g_file_monitor_file (makefile, 
+		group->monitor = g_file_monitor_file (makefile,
 						      									G_FILE_MONITOR_NONE,
 						       									NULL,
 						       									NULL);
@@ -419,8 +419,8 @@ gchar *
 amp_group_node_get_makefile_name (AmpGroupNode *group)
 {
 	gchar *basename = NULL;
-	
-	if (group->makefile != NULL) 
+
+	if (group->makefile != NULL)
 	{
 		basename = g_file_get_basename (group->makefile);
 	}
@@ -439,7 +439,7 @@ amp_group_node_update_node (AmpGroupNode *group, AmpGroupNode *new_group)
 		g_object_unref (group->monitor);
 		group->monitor = NULL;
 	}
-	if (group->makefile != NULL)	
+	if (group->makefile != NULL)
 	{
 		g_object_unref (group->makefile);
 		group->monitor = NULL;
@@ -461,10 +461,10 @@ amp_group_node_update_node (AmpGroupNode *group, AmpGroupNode *new_group)
 	hash = group->variables;
 	group->variables = new_group->variables;
 	new_group->variables = hash;
-	
+
 	if (group->makefile != NULL)
 	{
-		group->monitor = g_file_monitor_file (group->makefile, 
+		group->monitor = g_file_monitor_file (group->makefile,
 					      									G_FILE_MONITOR_NONE,
 					       									NULL,
 					       									NULL);
@@ -505,27 +505,11 @@ amp_group_node_update_variable (AmpGroupNode *group, AnjutaToken *variable)
 }
 
 AnjutaToken*
-amp_group_node_get_variable_token (AmpGroupNode *group, AnjutaToken *variable)
+amp_group_node_get_variable_token (AmpGroupNode *group, const gchar *name)
 {
-	guint length;
-	gchar *string;
-	const gchar *name;
 	AmpVariable *var;
-		
-	string = anjuta_token_evaluate(variable);
-	length = strlen (string);
-	if (string[1] == '(')
-	{
-		string[length - 1] = '\0';
-		name = string + 2;
-	}
-	else
-	{
-		string[2] = '\0';
-		name = string + 1;
-	}
+
 	var = g_hash_table_lookup (group->variables, name);
-	g_free (string);
 
 	return var != NULL ? var->value : NULL;
 }
@@ -543,16 +527,16 @@ AmpGroupNode*
 amp_group_node_new (GFile *file, gboolean dist_only)
 {
 	AmpGroupNode *node = NULL;
-	
+
 	node = g_object_new (AMP_TYPE_GROUP_NODE, NULL);
 	node->base.file = g_object_ref (file);
 	node->dist_only = dist_only;
 	memset (node->tokens, 0, sizeof (node->tokens));
 
-    return node;	
+    return node;
 }
 
-AmpGroupNode* 
+AmpGroupNode*
 amp_group_node_new_valid (GFile *file, gboolean dist_only, GError **error)
 {
 	gchar *name;
@@ -600,7 +584,7 @@ amp_group_node_load (AmpNode *group, AmpNode *parent, AmpProject *project, GErro
 {
 	if (project_load_makefile (project, AMP_GROUP_NODE (group)) == NULL)
 	{
-		g_set_error (error, IANJUTA_PROJECT_ERROR, 
+		g_set_error (error, IANJUTA_PROJECT_ERROR,
 					IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
 			_("Project doesn't exist or invalid path"));
 
@@ -693,7 +677,7 @@ amp_group_node_dispose (GObject *object)
 
 	if (node->monitor) g_object_unref (node->monitor);
 	node->monitor = NULL;
-	
+
 	G_OBJECT_CLASS (amp_group_node_parent_class)->dispose (object);
 }
 
@@ -702,7 +686,7 @@ amp_group_node_finalize (GObject *object)
 {
 	AmpGroupNode *node = AMP_GROUP_NODE (object);
 	gint i;
-	
+
 	g_list_foreach (node->base.custom_properties, (GFunc)amp_property_free, NULL);
 	if (node->tfile) anjuta_token_file_free (node->tfile);
 	if (node->makefile) g_object_unref (node->makefile);
@@ -721,7 +705,7 @@ amp_group_node_class_init (AmpGroupNodeClass *klass)
 {
 	GObjectClass* object_class = G_OBJECT_CLASS (klass);
 	AmpNodeClass* node_class;
-	
+
 	object_class->finalize = amp_group_node_finalize;
 	object_class->dispose = amp_group_node_dispose;
 
diff --git a/plugins/am-project/amp-group.h b/plugins/am-project/amp-group.h
index 80650a4..9baff92 100644
--- a/plugins/am-project/amp-group.h
+++ b/plugins/am-project/amp-group.h
@@ -74,7 +74,7 @@ AnjutaTokenFile *amp_group_node_get_make_token_file (AmpGroupNode *group);
 gchar *amp_group_node_get_makefile_name (AmpGroupNode *group);
 gboolean amp_group_node_update_makefile (AmpGroupNode *group, AnjutaToken *token);
 void amp_group_node_update_variable (AmpGroupNode *group, AnjutaToken *variable);
-AnjutaToken* amp_group_node_get_variable_token (AmpGroupNode *group, AnjutaToken *variable);
+AnjutaToken* amp_group_node_get_variable_token (AmpGroupNode *group, const gchar *name);
 AmpGroupNode* amp_group_node_new_valid (GFile *file, gboolean dist_only, GError **error);
 AmpGroupNode* amp_group_node_new (GFile *file, gboolean dist_only);
 void amp_group_node_free (AmpGroupNode *node);
diff --git a/plugins/am-project/tests/variable.at b/plugins/am-project/tests/variable.at
index d4dba6c..7b6c837 100644
--- a/plugins/am-project/tests/variable.at
+++ b/plugins/am-project/tests/variable.at
@@ -1,4 +1,47 @@
-AT_SETUP([Variable in Makefile.am])
+AT_SETUP([Variable in Makefile.am and configure.ac])
+
+
+
+AS_MKDIR_P([variable_ac1])
+AT_DATA([variable_ac1/configure.ac],
+[[
+TARGETS=target1
+AC_SUBST(TARGETS)
+AC_CONFIG_FILES(Makefile)
+]])
+AT_DATA([variable_ac1/Makefile.am],
+[[
+bin_PROGRAMS = $(TARGETS)
+]])
+AT_DATA([expect],
+[[    GROUP (): variable_ac1
+        TARGET (): target1
+            PROPERTY (Installation directory): bindir
+]])
+AT_PARSER_CHECK([load variable_ac1 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
+AS_MKDIR_P([variable_ac2])
+AT_DATA([variable_ac2/configure.ac],
+[[TARGETS=target1
+AC_SUBST(TARGETS)
+AC_CONFIG_FILES(Makefile)
+]])
+AT_DATA([variable_ac2/Makefile.am],
+[[
+bin_PROGRAMS = @TARGETS@
+]])
+AT_DATA([expect],
+[[    GROUP (): variable_ac2
+        TARGET (): target1
+            PROPERTY (Installation directory): bindir
+]])
+AT_PARSER_CHECK([load variable_ac2 \
+		 list])
+AT_CHECK([diff -b output expect])
 
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]