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); } }
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; }
GList * anjuta_pm_project_get_packages (AnjutaPmProject *project) { AnjutaProjectNode *module; GHashTable *all; GList *packages; g_return_val_if_fail (project != NULL, NULL); all = g_hash_table_new (g_str_hash, g_str_equal); for (module = anjuta_project_node_first_child (project->root); module != NULL; module = anjuta_project_node_next_sibling (module)) { if (anjuta_project_node_get_node_type(module) == ANJUTA_PROJECT_MODULE) { AnjutaProjectNode *package; for (package = anjuta_project_node_first_child (module); package != NULL; package = anjuta_project_node_next_sibling (package)) { if (anjuta_project_node_get_node_type (package) == ANJUTA_PROJECT_PACKAGE) { g_hash_table_replace (all, (gpointer)anjuta_project_node_get_name (package), NULL); } } } } packages = g_hash_table_get_keys (all); g_hash_table_destroy (all); return packages; }
static void list_root (IAnjutaProject *project, AnjutaProjectNode *root) { print ("ROOT (%s): %s", no_id ? "" : "0", anjuta_project_node_get_name (root)); list_property (project, root, 1); list_children (project, root, root, 0, "0"); }
static AnjutaToken * amp_target_add_in_list (AmpProject *project, AnjutaToken *list, AnjutaProjectNode *target, gboolean after, AnjutaToken* sibling) { AnjutaTokenStyle *style; AnjutaToken *token; AmpGroupNode *parent; g_return_val_if_fail (list != NULL, NULL); /* Get parent target */ parent = AMP_GROUP_NODE (anjuta_project_node_parent_type (target, ANJUTA_PROJECT_GROUP)); style = anjuta_token_style_new_from_base (project->am_space_list); anjuta_token_style_update (style, list); token = anjuta_token_new_string (ANJUTA_TOKEN_ARGUMENT | ANJUTA_TOKEN_ADDED, anjuta_project_node_get_name (target)); if (after) { anjuta_token_insert_word_after (list, sibling, token); } else { anjuta_token_insert_word_before (list, sibling, token); } /* Try to use the same style than the current target list */ anjuta_token_style_format (style, list); anjuta_token_style_free (style); amp_group_node_update_makefile (parent, token); amp_target_node_add_token (AMP_TARGET_NODE (target), ANJUTA_TOKEN_ARGUMENT, token); return token; }
static void list_module (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode *module, gint indent, const gchar *path) { print ("%*sMODULE (%s): %s", indent * INDENT, "", no_id ? "" : path, anjuta_project_node_get_name (module)); list_property (project, module, indent + 1); list_children (project, root, module, indent, path); }
static void list_target (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode *target, gint indent, const gchar *path) { print ("%*sTARGET (%s): %s", indent * INDENT, "", no_id ? "" : path, anjuta_project_node_get_name (target)); list_property (project, target, indent + 1); list_children (project, root, target, indent, path); }
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; }
static gboolean find_module (AnjutaProjectNode *node, gpointer data) { gboolean found = FALSE; if (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_MODULE) { const gchar *name = anjuta_project_node_get_name (node); found = g_strcmp0 (name, (const gchar *)data) == 0; } return found; }
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); }
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); } }
gboolean amp_package_node_create_token (AmpProject *project, AmpPackageNode *package, GError **error) { AmpModuleNode *module; AnjutaProjectNode *sibling; gboolean after; AnjutaToken *token; AnjutaToken *prev; AnjutaToken *args; /* Get parent module */ module = AMP_MODULE_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (package), ANJUTA_PROJECT_MODULE)); if (module == NULL) return FALSE; /* Add in configure.ac */ /* Find a sibling if possible */ if ((sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (package))) != NULL) { prev = amp_package_node_get_token (AMP_PACKAGE_NODE (sibling)); after = TRUE; args = anjuta_token_list (prev); } else if ((sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (package))) != NULL) { prev = amp_package_node_get_token (AMP_PACKAGE_NODE (sibling)); after = FALSE; args = anjuta_token_list (prev); } else { prev = NULL; args = NULL; } /* Check if a valid source variable is already defined */ if (args == NULL) { args = amp_module_node_get_token (module); } if (args != NULL) { AnjutaTokenStyle *style; const gchar *name; name = anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (package)); style = anjuta_token_style_new_from_base (project->ac_space_list); //anjuta_token_style_update (style, args); token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name); if (after) { anjuta_token_insert_word_after (args, prev, token); } else { anjuta_token_insert_word_before (args, prev, token); } /* Try to use the same style than the current target list */ anjuta_token_style_format (style, args); anjuta_token_style_free (style); amp_project_update_configure (project, token); amp_package_node_add_token (package, token); } return TRUE; }
/* 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; }
gboolean amp_target_node_create_token (AmpProject *project, AmpTargetNode *target, GError **error) { AnjutaToken *args; AnjutaToken *var; AnjutaToken *prev; AmpNodeInfo *info; gchar *targetname; const gchar *name; GList *last; AnjutaProjectNode *sibling; AmpGroupNode *parent; gboolean after; /* Get parent target */ parent = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP)); info = (AmpNodeInfo *)amp_project_get_type_info (project, anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (target))); name = anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (target)); /* Find a sibling if possible */ after = TRUE; for (sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (target)); sibling != NULL; sibling = anjuta_project_node_prev_sibling (sibling)) { if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_TARGET) break; } if (sibling == NULL) { after = FALSE; for (sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (target)); sibling != NULL; sibling = anjuta_project_node_next_sibling (sibling)) { if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_TARGET) break; } } if (sibling == NULL) after = TRUE; /* Add in Makefile.am */ targetname = g_strconcat (amp_target_node_get_install_directory (target) != NULL ? amp_target_node_get_install_directory (target) : info->install, "_", info->prefix, NULL); // Get token corresponding to sibling and check if the target are compatible args = NULL; var = NULL; prev = NULL; if (sibling != NULL) { last = amp_target_node_get_token (AMP_TARGET_NODE (sibling), ANJUTA_TOKEN_ARGUMENT); if (last != NULL) { AnjutaToken *token = (AnjutaToken *)last->data; /* Check that the sibling is of the same kind */ token = anjuta_token_list (token); if (token != NULL) { token = anjuta_token_list (token); var = token; if (token != NULL) { token = anjuta_token_first_item (token); if (token != NULL) { gchar *value; value = anjuta_token_evaluate (token); if ((value != NULL) && (strcmp (targetname, value) == 0)) { g_free (value); prev = (AnjutaToken *)last->data; args = anjuta_token_list (prev); } } } } } } /* Check if a valid target variable is already defined */ if (args == NULL) { for (last = amp_group_node_get_token (parent, AM_GROUP_TARGET); last != NULL; last = g_list_next (last)) { gchar *value = anjuta_token_evaluate (anjuta_token_first_word ((AnjutaToken *)last->data)); if ((value != NULL) && (strcmp (targetname, value) == 0)) { g_free (value); args = anjuta_token_last_item ((AnjutaToken *)last->data); break; } g_free (value); } } if (args == NULL) { args = amp_project_write_target (parent, info->token, targetname, FALSE, NULL); } g_free (targetname); switch (anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (target)) & ANJUTA_PROJECT_ID_MASK) { case ANJUTA_PROJECT_SHAREDLIB: case ANJUTA_PROJECT_STATICLIB: case ANJUTA_PROJECT_LT_MODULE: case ANJUTA_PROJECT_PROGRAM: amp_target_add_in_list (project, args, ANJUTA_PROJECT_NODE (target), after, prev); break; default: if (args != NULL) { amp_target_node_add_token (target, AM_TOKEN__SOURCES, args); } break; } return TRUE; }
static void list_package (IAnjutaProject *project, AnjutaProjectNode *root, AnjutaProjectNode *package, gint indent, const gchar *path) { print ("%*sPACKAGE (%s): %s", indent * INDENT, "", no_id ? "" : path, anjuta_project_node_get_name (package)); list_property (project, package, indent + 1); }
gboolean amp_group_node_create_token (AmpProject *project, AmpGroupNode *group, GError **error) { GFile *directory; GFile *makefile; AnjutaToken *list; gchar *basename; AnjutaTokenFile* tfile; AnjutaProjectNode *sibling; AmpGroupNode *parent; gboolean after; const gchar *name; /* Get parent target */ name = anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (group)); parent = AMP_GROUP_NODE (anjuta_project_node_parent_type(ANJUTA_PROJECT_NODE (group), ANJUTA_PROJECT_GROUP)); if (parent != NULL) { directory = g_file_get_child (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (parent)), name); } else { /* Used only when adding root group (a group named . in an empty project) */ parent = group; directory = g_object_ref (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (parent))); } /* Find a sibling if possible */ after = TRUE; for (sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (group)); sibling != NULL; sibling = anjuta_project_node_prev_sibling (sibling)) { if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_GROUP) break; } if (sibling == NULL) { after = FALSE; for (sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (group)); sibling != NULL; sibling = anjuta_project_node_next_sibling (sibling)) { if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_GROUP) break; } } if (sibling == NULL) after = TRUE; /* Create Makefile.am */ basename = amp_group_node_get_makefile_name (parent); if (basename != NULL) { makefile = g_file_get_child (directory, basename); g_free (basename); } else { makefile = g_file_get_child (directory, "Makefile.am"); } /* Add in configure */ list = NULL; if (sibling) list = amp_group_node_get_first_token (AMP_GROUP_NODE (sibling), AM_GROUP_TOKEN_CONFIGURE); if (list == NULL) list= amp_group_node_get_first_token (parent, AM_GROUP_TOKEN_CONFIGURE); if (list != NULL) list = anjuta_token_list (list); if (list == NULL) { list = amp_project_write_config_list (project); list = anjuta_token_next (list); } if (list != NULL) { gchar *relative_make; gchar *ext; AnjutaToken *prev = NULL; AnjutaToken *token; if (sibling) { prev = amp_group_node_get_first_token (AMP_GROUP_NODE (sibling), AM_GROUP_TOKEN_CONFIGURE); /*if ((prev != NULL) && after) { prev = anjuta_token_next_word (prev); }*/ } //prev_token = (AnjutaToken *)token_list->data; relative_make = g_file_get_relative_path (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (project)), makefile); ext = relative_make + strlen (relative_make) - 3; if (strcmp (ext, ".am") == 0) { *ext = '\0'; } token = amp_project_write_config_file (project, list, after, prev, relative_make); amp_group_node_add_token (AMP_GROUP_NODE (group), token, AM_GROUP_TOKEN_CONFIGURE); g_free (relative_make); } /* Add in Makefile.am */ if (sibling == NULL) { list = anjuta_token_find_group_property_position (parent, AM_TOKEN_SUBDIRS); if (list != NULL) { list = anjuta_token_insert_token_list (FALSE, list, AM_TOKEN_SUBDIRS, "SUBDIRS", ANJUTA_TOKEN_SPACE, " ", ANJUTA_TOKEN_OPERATOR, "=", ANJUTA_TOKEN_LIST, NULL, ANJUTA_TOKEN_LAST, NULL, NULL); list = anjuta_token_next (anjuta_token_next ( anjuta_token_next (list))); } } else { AnjutaToken *prev; prev = amp_group_node_get_first_token (AMP_GROUP_NODE (sibling), AM_GROUP_TOKEN_SUBDIRS); list = anjuta_token_list (prev); } if (list != NULL) { AnjutaToken *token; AnjutaToken *prev; AnjutaTokenStyle *style; style = anjuta_token_style_new_from_base (project->am_space_list); anjuta_token_style_update (style, list); if (sibling) { prev = amp_group_node_get_first_token (AMP_GROUP_NODE (sibling), AM_GROUP_TOKEN_SUBDIRS); } token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name); if (after) { anjuta_token_insert_word_after (list, prev, token); } else { anjuta_token_insert_word_before (list, prev, token); } /* Try to use the same style than the current group list */ anjuta_token_style_format (style, list); anjuta_token_style_free (style); amp_group_node_update_makefile (parent, token); amp_group_node_add_token (group, token, AM_GROUP_TOKEN_SUBDIRS); } tfile = amp_group_node_set_makefile (group, makefile, project); amp_project_add_file (project, makefile, tfile); return TRUE; }
gboolean amp_source_node_create_token (AmpProject *project, AmpSourceNode *source, GError **error) { AmpGroupNode *group; AmpTargetNode *target; AnjutaProjectNode *sibling; gboolean after; AnjutaToken *token; AnjutaToken *prev; AnjutaToken *args; gchar *relative_name; /* Get parent target */ target = AMP_TARGET_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (source), ANJUTA_PROJECT_TARGET)); if (target == NULL) return FALSE; group = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP)); relative_name = get_relative_path (anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (group)), anjuta_project_node_get_file (ANJUTA_PROJECT_NODE (source))); /* Add in Makefile.am */ /* Find a sibling if possible */ after = TRUE; for (sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (source)); sibling != NULL; sibling = anjuta_project_node_prev_sibling (sibling)) { if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_SOURCE) { break; } else if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_OBJECT) { sibling = anjuta_project_node_first_child (sibling); break; } } if (sibling == NULL) { after = FALSE; for (sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (source)); sibling != NULL; sibling = anjuta_project_node_next_sibling (sibling)) { if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_SOURCE) { break; } else if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_OBJECT) { sibling = anjuta_project_node_first_child (sibling); break; } } } if (sibling == NULL) { after = TRUE; prev = NULL; args = NULL; } else { prev = amp_source_node_get_token (AMP_SOURCE_NODE (sibling)); args = anjuta_token_list (prev); } /* Check if a valid source variable is already defined */ if (args == NULL) { GList *last; for (last = amp_target_node_get_token (target, AM_TOKEN__SOURCES); last != NULL; last = g_list_next (last)) { args = anjuta_token_last_item ((AnjutaToken *)last->data); break; } if (last == NULL) { for (last = amp_target_node_get_token (target, AM_TOKEN__DATA); last != NULL; last = g_list_next (last)) { args = anjuta_token_last_item ((AnjutaToken *)last->data); break; } } } if (args == NULL) { gchar *target_var; gchar *canon_name; AnjutaToken *var; canon_name = canonicalize_automake_variable (anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (target))); target_var = g_strconcat (canon_name, "_SOURCES", NULL); var = anjuta_token_find_target_property_position (target, AM_TOKEN__SOURCES); if (var == NULL) var = anjuta_token_find_target_property_position (target, AM_TOKEN__DATA); args = anjuta_token_insert_token_list (FALSE, var, ANJUTA_TOKEN_LIST, NULL, ANJUTA_TOKEN_NAME, target_var, ANJUTA_TOKEN_SPACE, " ", ANJUTA_TOKEN_OPERATOR, "=", ANJUTA_TOKEN_LIST, NULL, ANJUTA_TOKEN_SPACE, " ", NULL); args = anjuta_token_last_item (args); g_free (target_var); } if (args != NULL) { AnjutaTokenStyle *style; style = anjuta_token_style_new_from_base (project->am_space_list); anjuta_token_style_update (style, args); token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, relative_name); if (after) { anjuta_token_insert_word_after (args, prev, token); } else { anjuta_token_insert_word_before (args, prev, token); } /* Try to use the same style than the current target list */ anjuta_token_style_format (style, args); anjuta_token_style_free (style); amp_group_node_update_makefile (group, token); amp_source_node_add_token (source, token); } return TRUE; }