Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
void
mkp_project_enumerate_targets (MkpProject *project, AnjutaProjectNode *parent)
{
	GHashTableIter iter;
	gpointer key;
	MkpRule *rule;

	/* Check pattern rules */
	for (g_hash_table_iter_init (&iter, project->rules); g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&rule);)
	{
		if (rule->phony) continue;

		if (g_hash_table_lookup (project->suffix, rule->name))
		{
			/* Single suffix rule */
			rule->pattern = TRUE;
			rule->part = NULL;
		}
		else
		{
			GString *pattern = g_string_sized_new (16);
			GList *suffix;
			GList *src;

			/* Check double suffix rule */
			suffix = g_hash_table_get_keys (project->suffix);

			for (src = g_list_first (suffix); src != NULL; src = g_list_next (src))
			{
				GList *obj;

				for (obj = g_list_first (suffix); obj != NULL; obj = g_list_next (obj))
				{
					g_string_assign (pattern, src->data);
					g_string_append (pattern, obj->data);

					if (strcmp (pattern->str, rule->name) == 0)
					{
						rule->pattern = TRUE;
						rule->part = rule->name + strlen (src->data);
						break;
					}
				}
				if (rule->pattern) break;
			}

			g_string_free (pattern, TRUE);
			g_list_free (suffix);
		}
	}

	/* Create new target */
	for (g_hash_table_iter_init (&iter, project->rules); g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&rule);)
	{
		MkpTarget *target;
		AnjutaToken *prerequisite;
		AnjutaToken *arg;

		//g_message ("rule =%s=", rule->name);
		if (rule->phony || rule->pattern) continue;

		/* Create target */
		target = MKP_TARGET(mkp_target_new (rule->name, ANJUTA_PROJECT_UNKNOWN));
		mkp_target_add_token (target, rule->rule);
		anjuta_project_node_append (parent, ANJUTA_PROJECT_NODE(target));

		/* Get prerequisite */
		prerequisite = anjuta_token_first_word (rule->rule);
		if (prerequisite != NULL) prerequisite = anjuta_token_next_word (prerequisite);
		if (prerequisite != NULL) prerequisite = anjuta_token_next_word (prerequisite);

		/* Add prerequisite */
		for (arg = anjuta_token_first_word (prerequisite); arg != NULL; arg = anjuta_token_next_word (arg))
		{
			AnjutaProjectNode *node;
			gchar *name;
			GList *dependencies;

			name = anjuta_token_evaluate (arg);
			if (name != NULL)
			{
				name = g_strstrip (name);
				dependencies = mkp_project_find_dependencies (project, name, parent, 0);
				if (dependencies == NULL)
				{
					/* Add only one object node */
					node = mkp_object_new (name);
					node->type = ANJUTA_PROJECT_OBJECT | ANJUTA_PROJECT_PROJECT;
					anjuta_project_node_append (ANJUTA_PROJECT_NODE(target), ANJUTA_PROJECT_NODE(node));
					g_free (name);
				}
				else
				{
					GFile *src_file;
					gchar *name;

					AnjutaProjectNode *parent = (AnjutaProjectNode *)target;
					while (g_list_next (dependencies) != NULL)
					{
						/* Create object nodes */
						name = (gchar *)dependencies->data;
						node = mkp_object_new (name);
						node->type = ANJUTA_PROJECT_OBJECT | ANJUTA_PROJECT_PROJECT;
						anjuta_project_node_append (parent, node);
						g_free (name);
						parent = node;
						dependencies = g_list_delete_link (dependencies, dependencies);
					}

					/* Create source node */
					name = (gchar *)dependencies->data;
					src_file = g_file_get_child (project->root_file, name);
					node = mkp_source_new (src_file);
					node->type = ANJUTA_PROJECT_SOURCE | ANJUTA_PROJECT_PROJECT;
					g_object_unref (src_file);
					anjuta_project_node_append (parent, node);
					g_free (name);
					g_list_free (dependencies);
				}
			}
		}
	}
}