[anjuta] am-project: Prefix object name with target name if the target has custom properties



commit 9785baf8706911efbca824b7987043f88c235eae
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sun Jun 5 17:08:01 2011 +0200

    am-project: Prefix object name with target name if the target has custom properties

 plugins/am-project/am-project-private.h |    1 +
 plugins/am-project/am-project.c         |    3 +
 plugins/am-project/am-properties.c      |   36 ++++++++--------
 plugins/am-project/amp-target.c         |   68 +++++++++++++++++++++++++++++++
 plugins/am-project/amp-target.h         |    1 +
 5 files changed, 91 insertions(+), 18 deletions(-)
---
diff --git a/plugins/am-project/am-project-private.h b/plugins/am-project/am-project-private.h
index 080eef6..9154262 100644
--- a/plugins/am-project/am-project-private.h
+++ b/plugins/am-project/am-project-private.h
@@ -33,6 +33,7 @@ typedef enum {
 	AM_PROPERTY_IN_MAKEFILE = 1 << 1,
 	AM_PROPERTY_DIRECTORY = 1 << 2,						/* Directory property (having dir suffix) */
 	AM_PROPERTY_DISABLE_FOLLOWING = 1 << 3,		/* Disable following property if true */
+	AM_PROPERTY_COMPILATION_FLAG = 1 << 4			/* Target compilation flags, need a specific object */
 } AmpPropertyFlag;
 
 
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 32f6038..f32713e 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -906,6 +906,7 @@ project_load_target (AmpProject *project, AnjutaProjectNode *parent, AnjutaToken
 					anjuta_project_node_append (ANJUTA_PROJECT_NODE (target), child);
 					g_object_unref (child);
 				}
+				amp_target_changed (target);
 				g_free (orig_key);
 				amp_target_node_free (orphan);
 			}
@@ -1062,6 +1063,7 @@ project_load_sources (AmpProject *project, AnjutaProjectNode *group, AnjutaToken
 
 			g_free (value);
 		}
+		amp_target_changed (target);
 	}
 
 	g_object_unref (group_file);
@@ -1232,6 +1234,7 @@ project_load_target_properties (AmpProject *project, AnjutaProjectNode *parent,
 		/* Add property to target */
 		amp_node_property_add (parent, prop);
 		amp_target_node_add_token (AMP_TARGET_NODE (parent), type, variable);
+		amp_target_changed (AMP_TARGET_NODE (parent));
 	}
 
 	return NULL;
diff --git a/plugins/am-project/am-properties.c b/plugins/am-project/am-properties.c
index 151ae69..f1686da 100644
--- a/plugins/am-project/am-properties.c
+++ b/plugins/am-project/am-properties.c
@@ -392,7 +392,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional C preprocessor flags for this target.")},
 		AM_TOKEN_TARGET_CPPFLAGS,	0, "_CPPFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("C compiler flags:"),
@@ -400,7 +400,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional C compiler flags for this target.")},
 		AM_TOKEN_TARGET_CFLAGS, 0, 	"_CFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("C++ compiler flags:"),
@@ -408,7 +408,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,	
 			N_("Additional C++ compiler flags for this target.")},
 		AM_TOKEN_TARGET_CXXFLAGS,	0, "_CXXFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Java compiler flags:"),
@@ -416,7 +416,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Java compiler flags for this target.")},
 		AM_TOKEN_TARGET_JAVACFLAGS, 0, "_JAVACFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Vala compiler flags:"),
@@ -424,7 +424,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE, 
 			N_("Additional Vala compiler flags for this target.")},
 		AM_TOKEN_TARGET_VALAFLAGS,0, "_VALAFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Fortran compiler flags:"),	
@@ -432,7 +432,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Fortran compiler flags for this target.")},
 		AM_TOKEN_TARGET_FCFLAGS, 0, "_FCFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Objective C compiler flags:"),
@@ -440,7 +440,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Objective C compiler flags for this target.")},
 		AM_TOKEN_TARGET_OBJCFLAGS, 0, "_OBJCFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Lex/Flex flags:"),
@@ -448,7 +448,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Lex or Flex lexical analyser generator flags for this target.")},
 		AM_TOKEN_TARGET_LFLAGS, 0, "_LFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Yacc/Bison flags:"),
@@ -456,7 +456,7 @@ static AmpProperty AmpProgramTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Yacc or Bison parser generator flags for this target.")},
 		AM_TOKEN_TARGET_YFLAGS,	0, 	"_YFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Additional dependencies:"),
@@ -549,7 +549,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional C preprocessor flags for this target.")},
 		AM_TOKEN_TARGET_CPPFLAGS,	0, "_CPPFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("C compiler flags:"),
@@ -557,7 +557,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional C compiler flags for this target.")},
 		AM_TOKEN_TARGET_CFLAGS, 0, 	"_CFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("C++ compiler flags:"),
@@ -565,7 +565,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,	
 			N_("Additional C++ compiler flags for this target.")},
 		AM_TOKEN_TARGET_CXXFLAGS,	0, "_CXXFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Java compiler flags:"),
@@ -573,7 +573,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Java compiler flags for this target.")},
 		AM_TOKEN_TARGET_JAVACFLAGS, 0, "_JAVACFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Vala compiler flags:"),
@@ -581,7 +581,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE, 
 			N_("Additional Vala compiler flags for this target.")},
 		AM_TOKEN_TARGET_VALAFLAGS,0, "_VALAFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Fortran compiler flags:"),	
@@ -589,7 +589,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Fortran compiler flags for this target.")},
 		AM_TOKEN_TARGET_FCFLAGS, 0, "_FCFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Objective C compiler flags:"),
@@ -597,7 +597,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Objective C compiler flags for this target.")},
 		AM_TOKEN_TARGET_OBJCFLAGS, 0, "_OBJCFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Lex/Flex flags:"),
@@ -605,7 +605,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Lex or Flex lexical analyser generator flags for this target.")},
 		AM_TOKEN_TARGET_LFLAGS, 0, "_LFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Yacc/Bison flags:"),
@@ -613,7 +613,7 @@ static AmpProperty AmpLibraryTargetProperties[] = {
 			ANJUTA_PROJECT_PROPERTY_READ_WRITE,
 			N_("Additional Yacc or Bison parser generator flags for this target.")},
 		AM_TOKEN_TARGET_YFLAGS,	0, 	"_YFLAGS",
-		AM_PROPERTY_IN_MAKEFILE
+		AM_PROPERTY_IN_MAKEFILE | AM_PROPERTY_COMPILATION_FLAG
 	},
 	{
 		{N_("Additional dependencies:"),
diff --git a/plugins/am-project/amp-target.c b/plugins/am-project/amp-target.c
index 8f57199..00a3c67 100644
--- a/plugins/am-project/amp-target.c
+++ b/plugins/am-project/amp-target.c
@@ -267,6 +267,74 @@ amp_target_node_update_node (AmpTargetNode *node, AmpTargetNode *new_node)
 	new_node->tokens = NULL;
 }
 
+/* The target has changed which could change its children */
+void
+amp_target_changed (AmpTargetNode *node)
+{
+	GList *item;
+	gboolean custom = FALSE;
+
+	for (item = ANJUTA_PROJECT_NODE (node)->custom_properties; item != NULL; item = g_list_next (item))
+	{
+		AmpProperty *prop = (AmpProperty *)item->data;
+
+		custom = ((AmpProperty *)prop->base.native)->flags & AM_PROPERTY_COMPILATION_FLAG;
+		if (custom) break;
+	}
+
+	if (custom)
+	{
+		/* Update object name if the target has some custom properties */
+		AnjutaProjectNode *child;
+
+		for (child = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (node)); child != NULL; child = anjuta_project_node_next_sibling (child))
+		{
+			if (anjuta_project_node_get_node_type (child) == ANJUTA_PROJECT_OBJECT)
+			{
+				if (child->file != NULL)
+				{
+					AnjutaProjectNode *source = anjuta_project_node_first_child (child);
+
+					if (source != NULL)
+					{
+						gchar *obj_name;
+						const gchar *obj_ext;
+						
+						if (child->name != NULL)
+						{
+							g_free (child->name);
+							child->name = NULL;
+						}
+						obj_name = g_file_get_basename (child->file);
+						obj_ext = strrchr (obj_name, '.');
+						if ((obj_ext != NULL)  && (obj_ext != obj_name))
+						{
+							GFile *src_dir;
+							gchar *src_name;
+							gchar *src_ext;
+							gchar *new_name;
+							
+							src_dir = g_file_get_parent (source->file);
+							src_name = g_file_get_basename (source->file);
+							src_ext = strrchr (src_name, '.');
+							if ((src_ext != NULL) && (src_ext != src_name)) *src_ext = '\0';
+							new_name = g_strconcat (node->base.name, "-", src_name, obj_ext, NULL);
+
+							g_object_unref (child->file);
+							child->file = g_file_get_child (src_dir, new_name);
+
+							g_free (new_name);
+							g_free (src_name);
+							g_object_unref (src_dir);
+						}
+						g_free (obj_name);
+					}
+				}
+			}
+		}
+	}
+}
+
 AmpTargetNode*
 amp_target_node_new (const gchar *name, AnjutaProjectNodeType type, const gchar *install, gint flags)
 {
diff --git a/plugins/am-project/amp-target.h b/plugins/am-project/amp-target.h
index 38dd092..342605c 100644
--- a/plugins/am-project/amp-target.h
+++ b/plugins/am-project/amp-target.h
@@ -72,6 +72,7 @@ AmpTargetNode* amp_target_node_new (const gchar *name, AnjutaProjectNodeType typ
 AmpTargetNode* amp_target_node_new_valid (const gchar *name, AnjutaProjectNodeType type, const gchar *install, gint flags, GError **error);
 void amp_target_node_free (AmpTargetNode *node);
 void amp_target_node_update_node (AmpTargetNode *node, AmpTargetNode *new_node);
+void amp_target_changed (AmpTargetNode *node);
 
 G_END_DECLS
 



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