Esempio n. 1
0
static gboolean
amp_module_node_write (AmpNode *node, AmpNode *amp_parent, AmpProject *project, GError **error)
{
	AnjutaProjectNode *parent = ANJUTA_PROJECT_NODE (amp_parent);

	if ((parent != NULL) && (anjuta_project_node_get_node_type (parent) == ANJUTA_PROJECT_TARGET))
	{
		AnjutaProjectNode *group = anjuta_project_node_parent (parent);
		AnjutaProjectPropertyInfo *group_cpp;
		AnjutaProjectPropertyInfo *target_cpp;
		AnjutaProjectPropertyInfo *target_lib;
		gchar *lib_flags;
		gchar *cpp_flags;
		gint type;

		group_cpp = amp_node_get_property_info_from_token (group, AM_TOKEN__CPPFLAGS, 0);

		type = anjuta_project_node_get_full_type (parent) & (ANJUTA_PROJECT_ID_MASK | ANJUTA_PROJECT_TYPE_MASK);
		switch (type)
		{
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_PROGRAM:
			target_lib = amp_node_get_property_info_from_token (parent, AM_TOKEN_TARGET_LDADD, 0);
			break;
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_STATICLIB:
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_SHAREDLIB:
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_LT_MODULE:
			target_lib = amp_node_get_property_info_from_token (parent, AM_TOKEN_TARGET_LIBADD, 0);
			break;
		default:
			break;
		}
		target_cpp = amp_node_get_property_info_from_token (parent, AM_TOKEN_TARGET_CPPFLAGS, 0);

		lib_flags = g_strconcat ("$(", anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node)), "_LIBS)", NULL);
		cpp_flags = g_strconcat ("$(", anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node)), "_CFLAGS)", NULL);

		if (!amp_node_property_has_flags (group, group_cpp->id, cpp_flags) && !amp_node_property_has_flags (ANJUTA_PROJECT_NODE (parent), target_cpp->id, cpp_flags))
		{
			AnjutaProjectProperty *prop;
			prop = amp_node_property_add_flags (group, group_cpp->id, cpp_flags);
			amp_project_update_am_property (project, group, prop);
		}

		if (!amp_node_property_has_flags (parent, target_lib->id, lib_flags))
		{
			AnjutaProjectProperty *prop;
			prop = amp_node_property_add_flags (parent, target_lib->id, lib_flags);
			amp_project_update_am_property (project, parent, prop);
		}

		g_free (lib_flags);
		g_free (cpp_flags);

		return TRUE;
	}
	else
	{
		return amp_module_node_create_token (project, AMP_MODULE_NODE (node), error);
	}
}
Esempio n. 2
0
gboolean
mkp_project_reload (MkpProject *project, GError **error)
{
	GFile *root_file;
	GFile *make_file;
	const gchar **makefile;
	MkpGroup *group;
	gboolean ok = TRUE;

	/* Unload current project */
	root_file = g_object_ref (project->root_file);
	mkp_project_unload (project);
	project->root_file = root_file;
	DEBUG_PRINT ("reload project %p root file %p", project, project->root_file);

	/* shortcut hash tables */
	project->groups = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	project->files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, g_object_unref);
	project->variables = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)mkp_variable_free);

	/* Initialize rules data */
	mkp_project_init_rules (project);

	/* Initialize list styles */
	project->space_list = anjuta_token_style_new (NULL, " ", "\n", NULL, 0);
	project->arg_list = anjuta_token_style_new (NULL, ", ", ",\n ", ")", 0);

	/* Find make file */
	for (makefile = valid_makefiles; *makefile != NULL; makefile++)
	{
		if (file_type (root_file, *makefile) == G_FILE_TYPE_REGULAR)
		{
			make_file = g_file_get_child (root_file, *makefile);
			break;
		}
	}
	if (make_file == NULL)
	{
		g_set_error (error, IANJUTA_PROJECT_ERROR,
					 IANJUTA_PROJECT_ERROR_DOESNT_EXIST,
			   _("Project doesn't exist or invalid path"));

		return FALSE;
	}

	/* Create group */
	group = MKP_GROUP(mkp_group_new (root_file));
	anjuta_project_node_append (ANJUTA_PROJECT_NODE(project), ANJUTA_PROJECT_NODE(group));
	g_hash_table_insert (project->groups, g_file_get_uri (root_file), group);

	/* Parse make file */
	project_load_makefile (project, make_file, group, error);
	g_object_unref (make_file);

	monitors_setup (project);


	return ok;
}
Esempio n. 3
0
static gboolean
amp_target_node_erase (AmpNode *target, AmpNode *parent, AmpProject *project, GError **error)
{
	gboolean ok;
	GList * token_list;

	token_list = amp_target_node_get_all_token (AMP_TARGET_NODE (target));
	ok = amp_target_node_delete_token (project, AMP_TARGET_NODE (target), token_list, error);
	g_list_free (token_list);

	/* Remove installation directory variable if the removed target was the
	 * only one using it */
	if (ok)
	{
		AnjutaProjectNode *node;
		const gchar *installdir;
		AnjutaProjectProperty *prop;
		gboolean used = FALSE;

		prop = amp_node_get_property_from_token (ANJUTA_PROJECT_NODE (target), AM_TOKEN__PROGRAMS, 6);
		installdir = prop->value;

		for (node = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (parent)); node != NULL; node = anjuta_project_node_next_sibling (node))
		{
			if (node != ANJUTA_PROJECT_NODE (target))
			{
				prop = amp_node_get_property_from_token (node, AM_TOKEN__PROGRAMS, 6);
				if ((prop != NULL) && (g_strcmp0 (installdir, prop->value) == 0))
				{
					used = TRUE;
					break;
				}
			}
		}

		if (!used)
		{
			GList *item;

			for (item = anjuta_project_node_get_properties (ANJUTA_PROJECT_NODE (parent)); item != NULL; item = g_list_next (item))
			{
				AmpProperty *prop = (AmpProperty *)item->data;

				if ((((AmpPropertyInfo *)prop->base.info)->token_type == AM_TOKEN_DIR) && (g_strcmp0 (prop->base.name, installdir) == 0))
				{
					/* Remove directory variable */
					anjuta_token_remove_list (anjuta_token_list (prop->token));
					amp_group_node_update_makefile (AMP_GROUP_NODE (parent), prop->token);
					break;
				}
			}
		}
	};

	return ok;
}
Esempio n. 4
0
static gboolean
amp_package_node_load (AmpNode *node, AmpNode *parent, AmpProject *project, GError **error)
{
	GList* deps;
	GList* dep;
	GList* include_dirs = NULL;

	deps = anjuta_pkg_config_list_dependencies (anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node)),
	                                            error);
	for (dep = deps; dep != NULL; dep = g_list_next (dep))
	{
		/* Create a package node for the depedencies */
		AnjutaProjectNode *pkg;

		pkg = ANJUTA_PROJECT_NODE (amp_package_node_new (dep->data));
		anjuta_project_node_append (ANJUTA_PROJECT_NODE (node), pkg);
	}
	anjuta_util_glist_strings_free (deps);

	if (*error != NULL)
	{
		g_warning ("Error getting dependencies: %s", (*error)->message);
		g_error_free (*error);
		*error = NULL;
	}

	if ((include_dirs = anjuta_pkg_config_get_directories (anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node)),
	                                                       TRUE, error)))
	{
		GList* include_dir;

		for (include_dir = include_dirs; include_dir != NULL; include_dir = g_list_next (include_dir))
		{
			GList* children = NULL;
			GList* file = NULL;
			GFile* dir = g_file_new_for_path (include_dir->data);

			anjuta_util_list_all_dir_children (&children, dir);
			for (file = g_list_first (children); file != NULL; file = g_list_next (file))
			{
				/* Create a source for files */
				AnjutaProjectNode *source;

				source = amp_node_new_valid (ANJUTA_PROJECT_NODE (parent), ANJUTA_PROJECT_SOURCE, (GFile *)file->data, NULL, NULL);
				anjuta_project_node_append (ANJUTA_PROJECT_NODE (node), source);
				g_object_unref ((GObject *)file->data);
			}
			g_list_free (children);
			g_object_unref (dir);
		}
	}
	anjuta_util_glist_strings_free (include_dirs);

	return TRUE;
}
Esempio n. 5
0
gboolean
amp_module_node_create_token (AmpProject  *project, AmpModuleNode *module, GError **error)
{
	gboolean after;
	AnjutaToken *token;
	AnjutaToken *prev;
	AnjutaToken *next;
	AnjutaProjectNode *sibling;

	/* Add in configure.ac */
	/* Find a sibling if possible */
	prev = NULL;
	after = TRUE;
	for (sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (module)); sibling != NULL; sibling = anjuta_project_node_prev_sibling (sibling))
	{
		if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_MODULE)
		{
			prev = amp_module_node_get_token (AMP_MODULE_NODE (sibling));
			if (prev != NULL)
			{
				prev = anjuta_token_list (prev);
				break;
			}
		}
	}
	if (prev == NULL)
	{
		after = FALSE;
		for (sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (module)); sibling != NULL; sibling = anjuta_project_node_next_sibling (sibling))
		{
			if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_MODULE)
			{
				prev = amp_module_node_get_token (AMP_MODULE_NODE (sibling));
				if (prev != NULL)
				{
					prev = anjuta_token_list (prev);
					break;
				}
			}
		}
	}

	token = amp_project_write_module_list (project, anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (module)), after, prev);
	next = anjuta_token_next (token);
	next = anjuta_token_next (next);
	next = anjuta_token_next (next);
	amp_module_node_add_token (module, next);

	amp_project_update_configure (project, token);

	return TRUE;
}
Esempio n. 6
0
void
mkp_project_unload (MkpProject *project)
{
	AnjutaProjectNode *node;

	monitors_remove (project);

	/* project data */
	if (project->root_file) g_object_unref (project->root_file);
	project->root_file = NULL;

	/* Remove all children */
	while ((node = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (project))) != NULL)
	{
		g_object_unref (node);
	}

	/* shortcut hash tables */
	if (project->groups) g_hash_table_destroy (project->groups);
	project->groups = NULL;
	if (project->files) g_hash_table_destroy (project->files);
	project->files = NULL;
	if (project->variables) g_hash_table_destroy (project->variables);
	project->variables = NULL;

	mkp_project_free_rules (project);

	/* List styles */
	if (project->space_list) anjuta_token_style_free (project->space_list);
	if (project->arg_list) anjuta_token_style_free (project->arg_list);
}
Esempio n. 7
0
gboolean
amp_package_node_delete_token (AmpProject  *project, AmpPackageNode *package, GError **error)
{
	AnjutaProjectNode *module;
	AnjutaToken *token;

	/* Get parent module */
	module = anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (package), ANJUTA_PROJECT_MODULE);
	if (module == NULL)
	{
		return FALSE;
	}

	token = amp_package_node_get_token (package);
	if (token != NULL)
	{
		AnjutaToken *args;
		AnjutaTokenStyle *style;

		args = anjuta_token_list (token);

		/* Try to use the same style than the current target list */
		style = anjuta_token_style_new_from_base (project->ac_space_list);
		anjuta_token_style_update (style, args);

		anjuta_token_remove_word (token);

		anjuta_token_style_format (style, args);
		anjuta_token_style_free (style);

		amp_project_update_configure (project, args);
	}

	return TRUE;
}
Esempio n. 8
0
AnjutaProjectNode*
dir_group_node_new (GFile *file, GObject *emitter)
{
	AnjutaDirGroupNode *group = NULL;

	group = g_object_new (ANJUTA_TYPE_DIR_GROUP_NODE, NULL);
	group->base.type = ANJUTA_PROJECT_GROUP;
	group->base.native_properties = NULL;
	group->base.custom_properties = NULL;
	group->base.file = g_object_ref (file);
	group->base.name = NULL;
	group->base.state = ANJUTA_PROJECT_CAN_ADD_GROUP |
						ANJUTA_PROJECT_CAN_ADD_SOURCE |
						ANJUTA_PROJECT_CAN_REMOVE |
						ANJUTA_PROJECT_REMOVE_FILE;

	group->emitter = emitter;

	/* Connect monitor if file exist */
	if (g_file_query_exists (file, NULL))
	{
		group->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);

		g_signal_connect (G_OBJECT (group->monitor),
							"changed",
							G_CALLBACK (on_file_changed),
							group);
	}

	return ANJUTA_PROJECT_NODE (group);
}
Esempio n. 9
0
gboolean
amp_group_node_delete_token (AmpProject  *project, AmpGroupNode *group, GError **error)
{
	GList *item;
	AnjutaProjectNode *parent;

	/* Get parent group */
	parent =  anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (group), ANJUTA_PROJECT_GROUP);
	if (parent == NULL) return FALSE;

	for (item = amp_group_node_get_token (group, AM_GROUP_TOKEN_SUBDIRS); item != NULL; item = g_list_next (item))
	{
		AnjutaToken *token = (AnjutaToken *)item->data;
		AnjutaTokenStyle *style;
		AnjutaToken *list;

		list = anjuta_token_list (token);

		/* Try to use the same style than the current target list */
		style = anjuta_token_style_new_from_base (project->am_space_list);
		anjuta_token_style_update (style, list);

		anjuta_token_remove_word (token);
		anjuta_token_style_format (style, list);
		anjuta_token_style_free (style);

		/* Remove whole variable if empty */
		if (anjuta_token_first_word (list) == NULL)
		{
			anjuta_token_remove_list (anjuta_token_list (list));
		}

		amp_group_node_update_makefile (AMP_GROUP_NODE (parent), list);
	}

	/* Remove from configure file */
	for (item = amp_group_node_get_token (group, AM_GROUP_TOKEN_CONFIGURE); item != NULL; item = g_list_next (item))
	{
		AnjutaToken *token = (AnjutaToken *)item->data;
		AnjutaToken *args;
		AnjutaTokenStyle *style;

		args = anjuta_token_list (token);

		/* Try to use the same style than the current group list */
		style = anjuta_token_style_new_from_base (project->ac_space_list);
		anjuta_token_style_update (style, args);

		anjuta_token_remove_word (token);

		anjuta_token_style_format (style, args);
		anjuta_token_style_free (style);

		amp_project_update_configure (project, args);
	}

	return TRUE;
}
Esempio n. 10
0
gboolean
mkp_project_load (MkpProject  *project,
	GFile *directory,
	GError     **error)
{
	g_return_val_if_fail (directory != NULL, FALSE);

	return mkp_project_load_root (project, ANJUTA_PROJECT_NODE(project), error) != NULL;
}
Esempio n. 11
0
static AnjutaProjectNode*
project_load_makefile (MkpProject *project, GFile *file, MkpGroup *parent, GError **error)
{
	MkpScanner *scanner;
	AnjutaToken *arg;
	AnjutaTokenFile *tfile;
	AnjutaToken *parse;
	gboolean ok;
	GError *err = NULL;

	/* Parse makefile */
	DEBUG_PRINT ("Parse: %s", g_file_get_uri (file));
	tfile = anjuta_token_file_new (file);
	g_hash_table_insert (project->files, g_object_ref (file), g_object_ref (tfile));
	arg = anjuta_token_file_load (tfile, NULL);
	scanner = mkp_scanner_new (project);
	parse = mkp_scanner_parse_token (scanner, arg, &err);
	ok = parse != NULL;
	mkp_scanner_free (scanner);
	if (!ok)
	{
		if (err != NULL)
		{
			g_set_error_literal (error, IANJUTA_PROJECT_ERROR,
						IANJUTA_PROJECT_ERROR_PROJECT_MALFORMED,
						err->message);
			g_error_free (err);
		}
		else
		{
			g_set_error (error, IANJUTA_PROJECT_ERROR,
						IANJUTA_PROJECT_ERROR_PROJECT_MALFORMED,
						"%s",
						_("Unable to parse make file"));
		}

		return NULL;
	}

	/* Load target */
	mkp_project_enumerate_targets (project, ANJUTA_PROJECT_NODE(parent));

	return ANJUTA_PROJECT_NODE(parent);
}
Esempio n. 12
0
AnjutaProjectNode*
amp_source_node_new (GFile *file, AnjutaProjectNodeType type)
{
	AmpSourceNode *node = NULL;

	node = g_object_new (AMP_TYPE_SOURCE_NODE, NULL);
	node->base.file = g_object_ref (file);
	node->base.type = ANJUTA_PROJECT_SOURCE | type;

	return ANJUTA_PROJECT_NODE (node);
}
Esempio n. 13
0
AnjutaProjectNode*
mkp_object_new (const gchar *name)
{
	MkpObject *node = NULL;

	node = g_object_new (MKP_TYPE_OBJECT, NULL);
	node->base.name = g_strdup (name);
	node->base.type = ANJUTA_PROJECT_OBJECT;
	node->base.state = 0;

	return ANJUTA_PROJECT_NODE(node);
}
Esempio n. 14
0
AnjutaProjectNode*
mkp_target_new (const gchar *name, AnjutaProjectNodeType type)
{
	MkpTarget *target = NULL;

	target = g_object_new (MKP_TYPE_TARGET, NULL);
	target->base.name = g_strdup (name);
	target->base.type = ANJUTA_PROJECT_TARGET;
	target->base.state = 0;

	return ANJUTA_PROJECT_NODE(target);
}
Esempio n. 15
0
AnjutaProjectNode*
dir_root_node_new (GFile *file)
{
	AnjutaDirRootNode *root = NULL;

	root = g_object_new (ANJUTA_TYPE_DIR_ROOT_NODE, NULL);
	root->base.type = ANJUTA_PROJECT_ROOT;
	root->base.custom_properties = NULL;
	root->base.native_properties = NULL;
	root->base.file = g_file_dup (file);
	root->base.name = NULL;

	return ANJUTA_PROJECT_NODE (root);
}
Esempio n. 16
0
static AnjutaProjectNode *
project_node_new (MkpProject *project, AnjutaProjectNode *parent, AnjutaProjectNodeType type, GFile *file, const gchar *name, GError **error)
{
	AnjutaProjectNode *node = NULL;

	switch (type & ANJUTA_PROJECT_TYPE_MASK) {
		case ANJUTA_PROJECT_ROOT:
		case ANJUTA_PROJECT_GROUP:
			node = ANJUTA_PROJECT_NODE (mkp_group_new (file));
			break;
		case ANJUTA_PROJECT_TARGET:
			node = ANJUTA_PROJECT_NODE (mkp_target_new (name, 0));
			break;
		case ANJUTA_PROJECT_SOURCE:
			node = ANJUTA_PROJECT_NODE (mkp_source_new (file));
			break;
		default:
			g_assert_not_reached ();
			break;
	}
	if (node != NULL) node->type = type;

	return node;
}
Esempio n. 17
0
static AnjutaProjectNode*
mkp_group_new (GFile *file)
{
	MkpGroup *group = g_object_new (MKP_TYPE_GROUP, NULL);;
	group->base.file = g_object_ref (file);

	group->base.type = ANJUTA_PROJECT_GROUP;
	group->base.properties = NULL;
	group->base.properties_info = NULL;
	group->base.name = NULL;
	group->base.state = 0;


	return ANJUTA_PROJECT_NODE(group);
}
Esempio n. 18
0
static gboolean
iproject_load_node (IAnjutaProject *obj, AnjutaProjectNode *node, GError **err)
{
	if (node == NULL) node = ANJUTA_PROJECT_NODE (obj);


	if (mkp_project_load_node (MKP_PROJECT (obj), node, err) != NULL) {
		(MKP_PROJECT(obj))->loading--;
		g_signal_emit_by_name (MKP_PROJECT(obj), "node-loaded", node, err);

		return TRUE;
	}

	return  FALSE;
}
Esempio n. 19
0
AnjutaProjectNode*
mkp_source_new (GFile *file)
{
	MkpSource *source = NULL;

	source = g_object_new (MKP_TYPE_SOURCE, NULL);
	source->base.file = g_object_ref (file);
	source->base.type = ANJUTA_PROJECT_SOURCE;
	source->base.properties = NULL;
	source->base.properties_info = NULL;
	source->base.name = NULL;
	source->base.state = 0;

	return ANJUTA_PROJECT_NODE (source);
}
Esempio n. 20
0
AnjutaTokenFile*
amp_group_node_set_makefile (AmpGroupNode *group, GFile *makefile, AmpProject *project)
{
	if (group->makefile != NULL) g_object_unref (group->makefile);
	if (group->tfile != NULL) anjuta_token_file_free (group->tfile);
	if (makefile != NULL)
	{
		AnjutaToken *token;
		AmpAmScanner *scanner;
		AnjutaProjectNode *source;

		group->makefile = g_object_ref (makefile);
		group->tfile = anjuta_token_file_new (makefile);
		source = amp_source_node_new (makefile, ANJUTA_PROJECT_PROJECT | ANJUTA_PROJECT_FRAME | ANJUTA_PROJECT_READ_ONLY);
		anjuta_project_node_append (ANJUTA_PROJECT_NODE (group), source);

		token = anjuta_token_file_load (group->tfile, NULL);
		amp_project_add_file (project, makefile, group->tfile);

		amp_group_node_update_preset_variable (group);

		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,
						      									G_FILE_MONITOR_NONE,
						       									NULL,
						       									NULL);
		if (group->monitor != NULL)
		{
			g_signal_connect (G_OBJECT (group->monitor),
					  "changed",
					  G_CALLBACK (on_group_monitor_changed),
					  group);
		}
	}
	else
	{
		group->makefile = NULL;
		group->tfile = NULL;
		group->make_token = NULL;
		if (group->monitor) g_object_unref (group->monitor);
		group->monitor = NULL;
	}

	return group->tfile;
}
Esempio n. 21
0
AnjutaProjectNode*
dir_source_node_new (GFile *file)
{
	AnjutaDirSourceNode *source = NULL;

	source = g_object_new (ANJUTA_TYPE_DIR_SOURCE_NODE, NULL);
	source->base.type = ANJUTA_PROJECT_SOURCE;
	source->base.native_properties = NULL;
	source->base.custom_properties = NULL;
	source->base.name = NULL;
	source->base.file = g_file_dup (file);
	source->base.state = ANJUTA_PROJECT_CAN_REMOVE |
						ANJUTA_PROJECT_REMOVE_FILE;

	return ANJUTA_PROJECT_NODE (source);
}
Esempio n. 22
0
AmpTargetNode*
amp_target_node_new (const gchar *name, AnjutaProjectNodeType type, const gchar *install, gint flags)
{
	AmpTargetNode *node;

	node = g_object_new (AMP_TYPE_TARGET_NODE, NULL);
	amp_target_node_set_type (node, type);
	node->base.name = g_strdup (name);
	if ((install == NULL) && ((type & ANJUTA_PROJECT_ID_MASK) == ANJUTA_PROJECT_DATA)) {
		node->install = g_strdup (name);
	}
	else {
		node->install = g_strdup (install);
	}
	node->flags = flags;

	amp_node_property_add_mandatory (ANJUTA_PROJECT_NODE (node));

	return node;
}
Esempio n. 23
0
static gboolean
amp_group_node_save (AmpNode *group, AmpNode *parent, AmpProject *project, GError **error)
{
	AnjutaTokenFile *tfile;
	AnjutaProjectNode *child;
	gboolean ok = TRUE;
	GFile *directory;

	/* Check if Makefile.am is missing, it happens in po directory by example */
	if (AMP_GROUP_NODE (group)->makefile == NULL) return FALSE;
	
	/* Create directory */
	directory = g_file_get_parent (AMP_GROUP_NODE (group)->makefile);
	g_file_make_directory (directory, NULL, NULL);
	g_object_unref (directory);

	/* Save group */
	tfile = AMP_GROUP_NODE (group)->tfile;
	if (tfile == NULL)
	{
		/* Create an empty makefile */
		g_file_replace_contents (AMP_GROUP_NODE (group)->makefile, "", 0, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, NULL);

		return TRUE;
	}

	if (anjuta_token_file_is_dirty (tfile))
	{
		if (!anjuta_token_file_save (tfile, error)) return FALSE;
	}

	/* Save all children */
	for (child = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (group)); child != NULL; child = anjuta_project_node_next_sibling (child))
	{
		/* Try to save all children even if some fail */
		if (!amp_node_save (AMP_NODE (child), group, project, error)) ok = FALSE;
	}

	return ok;
}
Esempio n. 24
0
static AnjutaToken *
amp_project_write_property_list (AmpGroupNode *group, AnjutaProjectNode *node, AmpPropertyInfo *info)
{
	AnjutaToken *pos;
	gchar *name;

	if (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_GROUP)
	{
		/* Group property */
		name = g_strdup (info->suffix);

		pos = anjuta_token_find_group_property_position (AMP_GROUP_NODE (node), info->token_type);
	}
	else
	{
		/* Target property */
		gchar *canon_name;

		canon_name = canonicalize_automake_variable (anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node)));
		name = g_strconcat (canon_name, info->suffix, NULL);
		g_free (canon_name);

		pos = anjuta_token_find_target_property_position (AMP_TARGET_NODE (node), info->token_type);
	}

	pos = anjuta_token_insert_token_list (FALSE, pos,
    			info->token_type, NULL,
    			ANJUTA_TOKEN_NAME, name,
    			ANJUTA_TOKEN_SPACE, " ",
    			ANJUTA_TOKEN_OPERATOR, "=",
            	ANJUTA_TOKEN_SPACE, " ",
    			ANJUTA_TOKEN_LIST, NULL,
            	ANJUTA_TOKEN_SPACE, " ",
    			NULL);

	g_free (name);

	return anjuta_token_last_item (pos);
}
Esempio n. 25
0
static void
on_group_monitor_changed (GFileMonitor *monitor,
											GFile *file,
											GFile *other_file,
											GFileMonitorEvent event_type,
											gpointer data)
{
	AnjutaProjectNode *node = ANJUTA_PROJECT_NODE (data);
	AnjutaProjectNode *root;

	switch (event_type) {
		case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
		case G_FILE_MONITOR_EVENT_CHANGED:
		case G_FILE_MONITOR_EVENT_DELETED:
			/* project can be NULL, if the node is dummy node because the
			 * original one is reloaded. */
			root = anjuta_project_node_root (node);
			if (root != NULL) g_signal_emit_by_name (G_OBJECT (root), "file-changed", data);
			break;
		default:
			break;
	}
}
Esempio n. 26
0
gboolean
amp_source_node_delete_token (AmpProject  *project, AmpSourceNode *source, GError **error)
{
	AnjutaProjectNode *group;
	AnjutaToken *token;

	/* Get parent group */
	group = anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (source), ANJUTA_PROJECT_GROUP);
	if (group == NULL) return FALSE;

	token = amp_source_node_get_token (source);
	if (token != NULL)
	{
		AnjutaTokenStyle *style;
		AnjutaToken *list;

		list = anjuta_token_list (token);

		/* Try to use the same style than the current target list */
		style = anjuta_token_style_new_from_base (project->am_space_list);
		anjuta_token_style_update (style, list);

		anjuta_token_remove_word (token);
		anjuta_token_style_format (style, list);
		anjuta_token_style_free (style);

		/* Remove whole variable if empty */
		if (anjuta_token_first_word (list) == NULL)
		{
			anjuta_token_remove_list (anjuta_token_list (list));
		}

		amp_group_node_update_makefile (AMP_GROUP_NODE (group), list);
	}

	return TRUE;
}
Esempio n. 27
0
static gboolean
amp_module_node_erase (AmpNode *node, AmpNode *amp_parent, AmpProject *project, GError **error)
{
	AnjutaProjectNode *parent = ANJUTA_PROJECT_NODE (amp_parent);

	if ((parent != NULL) && (anjuta_project_node_get_node_type (parent) == ANJUTA_PROJECT_TARGET))
	{
		AnjutaProjectNode *group = anjuta_project_node_parent (parent);
		AnjutaProjectProperty *prop;
		AnjutaProjectPropertyInfo *group_cpp;
		AnjutaProjectPropertyInfo *target_cpp;
		AnjutaProjectPropertyInfo *target_lib;
		gchar *lib_flags;
		gchar *cpp_flags;
		gint type;

		lib_flags = g_strconcat ("$(", anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node)), "_LIBS)", NULL);
		cpp_flags = g_strconcat ("$(", anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node)), "_CFLAGS)", NULL);

		group_cpp = amp_node_get_property_info_from_token (group, AM_TOKEN__CPPFLAGS, 0);
		if (amp_node_property_has_flags (group, group_cpp->id, cpp_flags))
		{
			/* Remove flags in group variable if not more target has this module */
			gboolean used = FALSE;
			AnjutaProjectNode *target;

			for (target = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (group)); target != NULL; target = anjuta_project_node_next_sibling (target))
			{
				if (anjuta_project_node_get_node_type (target) == ANJUTA_PROJECT_TARGET)
				{
					AnjutaProjectNode *module;

					for (module = anjuta_project_node_first_child (target); module != NULL; module = anjuta_project_node_next_sibling (module))
					{
						if ((anjuta_project_node_get_node_type (module) == ANJUTA_PROJECT_MODULE) &&
						    (module != ANJUTA_PROJECT_NODE (node)) &&
						    (strcmp (anjuta_project_node_get_name (module), anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (node))) == 0))
						{
							used = TRUE;
							break;
						}
					}
				}
				if (used) break;
			}

			if (!used)
			{
				AnjutaProjectProperty *prop;

				prop = amp_node_property_remove_flags (group, group_cpp->id, cpp_flags);
				if (prop != NULL) amp_project_update_am_property (project, group, prop);
			}
		}

		type = anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (parent)) & (ANJUTA_PROJECT_ID_MASK | ANJUTA_PROJECT_TYPE_MASK);
		switch (type)
		{
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_PROGRAM:
			target_lib = amp_node_get_property_info_from_token (parent, AM_TOKEN_TARGET_LDADD, 0);
			break;
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_STATICLIB:
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_SHAREDLIB:
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_LT_MODULE:
			target_lib = amp_node_get_property_info_from_token (parent, AM_TOKEN_TARGET_LIBADD, 0);
			break;
		default:
			target_lib = NULL;
			break;
		}
		target_cpp = amp_node_get_property_info_from_token (parent, AM_TOKEN_TARGET_CPPFLAGS, 0);

		prop = amp_node_property_remove_flags (parent, target_cpp->id, cpp_flags);
		if (prop != NULL) amp_project_update_am_property (project, parent, prop);
		prop = amp_node_property_remove_flags (parent, target_lib->id, lib_flags);
		if (prop != NULL) amp_project_update_am_property (project, parent, prop);

		g_free (lib_flags);
		g_free (cpp_flags);

		return TRUE;
	}
	else
	{
		return amp_module_node_delete_token (project, AMP_MODULE_NODE (node), error);
	}
}
Esempio n. 28
0
static AmpNode *
amp_target_node_copy (AmpNode *old_node)
{
	AmpNode *new_node;
	
	new_node = AMP_NODE_CLASS (amp_target_node_parent_class)->copy (old_node);
	amp_target_node_set_type (AMP_TARGET_NODE (new_node), anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (old_node)));

	return new_node;
}
Esempio n. 29
0
/* 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)->properties; item != NULL; item = g_list_next (item))
	{
		AmpProperty *prop = (AmpProperty *)item->data;

		custom = ((AmpPropertyInfo *)prop->base.info)->flags & AM_PROPERTY_PREFIX_OBJECT;
		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);
					}
				}
			}
		}
	}
}
Esempio n. 30
0
/* Find if pkg-config modules are used in group targets */
static gboolean
project_load_group_module (AmpProject *project, AmpGroupNode *group)
{
	AnjutaProjectNode *target;
	AnjutaProjectProperty *prop;
	gchar **group_cpp = NULL;

	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))
	{
		gint type = anjuta_project_node_get_full_type (target) & (ANJUTA_PROJECT_ID_MASK | ANJUTA_PROJECT_TYPE_MASK);
		gchar **target_lib = NULL;
		gchar **target_cpp = NULL;

		prop = NULL;
		switch (type)
		{
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_PROGRAM:
			prop = amp_node_get_property_from_token (target, AM_TOKEN_TARGET_LDADD, 0);
			break;
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_STATICLIB:
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_SHAREDLIB:
		case ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_LT_MODULE:
			prop = amp_node_get_property_from_token (target, AM_TOKEN_TARGET_LIBADD, 0);
			break;
		default:
			break;
		}
		if (prop && (prop->value != NULL)) target_lib = g_strsplit_set (prop->value, " \t", 0);

		/* Check if targets use libraries */
		if (target_lib != NULL)
		{
			AnjutaProjectNode *module;

			prop = amp_node_get_property_from_token (target, AM_TOKEN_TARGET_CPPFLAGS, 0);
			if (prop && (prop->value != NULL)) target_cpp = g_strsplit_set (prop->value, " \t", 0);

			for (module = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (project)); module != NULL; module = anjuta_project_node_next_sibling (module))
			{
				if (anjuta_project_node_get_node_type (module) == ANJUTA_PROJECT_MODULE)
				{
					const gchar *name = anjuta_project_node_get_name (module);
					gchar *lib_flags = g_strconcat ("$(", name, "_LIBS)", NULL);
					gchar **flags;

					for (flags = target_lib; *flags != NULL; flags++)
					{

						if (strcmp (*flags, lib_flags) == 0)
						{
							gchar *cpp_flags = g_strconcat ("$(", name, "_CFLAGS)", NULL);
							gchar **cflags;
							gboolean found = FALSE;

							if (group_cpp != NULL)
							{
								for (cflags = group_cpp; *cflags != NULL; cflags++)
								{
									if (strcmp (*cflags, cpp_flags) == 0)
									{
										found = TRUE;
										break;
									}
								}
							}
							if ((target_cpp != NULL) && !found)
							{
								for (cflags = target_cpp; *cflags != NULL; cflags++)
								{
									if (strcmp (*cflags, cpp_flags) == 0)
									{
										found = TRUE;
										break;
									}
								}
							}
							if (found)
							{
								/* Add new module */
								AnjutaProjectNode *new_module;

								new_module = amp_node_new_valid (target, ANJUTA_PROJECT_MODULE, NULL, name, NULL);
								anjuta_project_node_append (target, new_module);
							}
							g_free (cpp_flags);
						}
					}
					g_free (lib_flags);
				}
			}
			g_strfreev (target_cpp);
			g_strfreev (target_lib);
		}
	}
	g_strfreev (group_cpp);

	return TRUE;
}