diff options
Diffstat (limited to 'src/plugin.c')
-rw-r--r-- | src/plugin.c | 516 |
1 files changed, 333 insertions, 183 deletions
diff --git a/src/plugin.c b/src/plugin.c index 3b2e54f..576fa0e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -45,7 +45,7 @@ #define CONFIGURE_COMMAND "/configure" #define AUTOGEN_COMMAND "/autogen.sh" -#define CROSS_COMMAND "--host=%s" +#define CROSS_COMMAND "CONFIGURE_FLAGS" #define DEPLOY_COMMAND "rsync " \ "-e 'ssh -o \"CheckHostIP no\" " \ @@ -55,11 +55,14 @@ #define LOCAL_GDB_COMMAND "%s-gdb -x %s %s" -#define GDB_SCRIPT "set solib-absolute-prefix %s\n" \ +#define GDB_SCRIPT "set solib-search-path %s\n" \ "target remote %s:2345\n" #define OPROFILEUI_COMMAND "oprofile-viewer -h %s -s %s" +#define SYSROOT "sysroots" +#define TMPDIR "tmp/" + static gpointer anjuta_plugin_sdk_parent_class; /* Callback prototypes needed for actions */ @@ -709,7 +712,8 @@ do_local_gdb (AnjutaPluginSdk *sp) gchar *cmd = NULL; GError *error = NULL; gchar *cur_dir = NULL; - gchar *gdb_prefix = NULL; + gchar *gdb_path = NULL; + const gchar* env_value; /* * create a temporary files and write the client side gdb commands to it, @@ -723,10 +727,18 @@ do_local_gdb (AnjutaPluginSdk *sp) return; } - gdb_prefix = g_build_filename (sp->sdk_root, sp->triplet, NULL); - script_contents = g_strdup_printf (GDB_SCRIPT, gdb_prefix, + //we use search path here according to latest SDK structure changes. + //path is extracted from environment settings PATH! And, ':' should be replaced + //with ';' + env_value = g_getenv ("PATH"); + gdb_path = g_strdup(env_value); + gdb_path = g_strdelimit(gdb_path, ":", ';'); + + script_contents = g_strdup_printf (GDB_SCRIPT, gdb_path, beaver_target_get_ip_address (sp->target)); + g_debug("gdb search path %s\n", script_contents); + channel = g_io_channel_unix_new (fd); status = g_io_channel_write_chars (channel, script_contents, -1, NULL, &error); @@ -747,7 +759,7 @@ do_local_gdb (AnjutaPluginSdk *sp) g_io_channel_unref (channel); g_free (script_contents); - g_free (gdb_prefix); + g_free (gdb_path); terminal = anjuta_shell_get_interface (ANJUTA_PLUGIN (sp)->shell, IAnjutaTerminal, &error); @@ -760,7 +772,7 @@ do_local_gdb (AnjutaPluginSdk *sp) return; } - cmd = g_strdup_printf (LOCAL_GDB_COMMAND, sp->triplet, + cmd = g_strdup_printf (LOCAL_GDB_COMMAND, sp->target_triplet, script_name, sp->gdb_local_path); cur_dir = g_get_current_dir (); child_pid = ianjuta_terminal_execute_command (terminal, cur_dir, cmd, @@ -771,7 +783,7 @@ do_local_gdb (AnjutaPluginSdk *sp) * compatibility */ if (child_pid < 0) - g_warning("Error happned while launching local gdb command\n"); + g_warning("Error happened while launching local gdb command\n"); else if (error != NULL) { g_warning ("Error whilst launching local gdb command: %s", error->message); @@ -865,6 +877,7 @@ action_remote_profile_activate_cb (GtkAction *action, gpointer userdata) AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; gchar *cmd = NULL; gchar *search_path = NULL; + const gchar *env_value; if (!sp->oprofileui_launcher) { @@ -873,7 +886,13 @@ action_remote_profile_activate_cb (GtkAction *action, gpointer userdata) (GCallback)oprofileui_launcher_child_exited_cb, sp); } - search_path = g_build_filename (sp->sdk_root, sp->triplet, NULL); + //we use search path here according to latest SDK structure changes. + //path is extracted from environment settings PATH! And, ':' should be replaced + //with ';' + env_value = g_getenv ("PATH"); + search_path = g_strdup(env_value); + search_path = g_strdelimit(search_path, ":", ';'); + cmd = g_strdup_printf (OPROFILEUI_COMMAND, beaver_target_get_ip_address (sp->target), search_path); @@ -906,7 +925,9 @@ remote_gdb_launcher_child_exited_cb (AnjutaLauncher *launcher, gint child_pid, { AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; - if (sp->triplet && sp->sdk_root && + if (sp->target_triplet && + ((sp->poky_mode == POKY_MODE_TOOLCHAIN && sp->sdk_root) || + (sp->poky_mode == POKY_MODE_FULL && sp->poky_root)) && beaver_target_get_state (sp->target) == TARGET_STATE_READY) { gtk_action_set_sensitive (sp->remote_debug_action, TRUE); @@ -947,133 +968,165 @@ message_view_buffer_flushed_cb (IAnjutaMessageView *view, gchar *data, data, "", NULL); } -static gchar * -get_host_component () +/* When new environment variables to be set are stored, + * we need to set each one saved in the hash table. Note + * one special thing: PATH need to be merged with the old + * PATH, otherwise, all useful system paths will be lost! + */ +static void +set_new_env(GHashTable *old_hash_configs, GHashTable *hash_configs) { - struct utsname res; - gchar *os = NULL; - gchar *host_component = NULL; + GHashTableIter iter; + gpointer key, value; + gchar *temp, *oldpath, *newpath; + size_t length; + const gchar *env_value; - uname (&res); - os = g_ascii_strdown (res.sysname, -1); - host_component = g_strdup_printf("%s-%s", res.machine, os); + if (!hash_configs) + { + g_warning("ERROR while set new environment variables," + "to be set variables are NULL!"); + return; + } + if (!old_hash_configs) + { + g_warning("ERROR while set new environment variables," + "old environment hash table can't be NULL"); + return; + } - g_free (os); + g_hash_table_iter_init (&iter, hash_configs); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + /* do something with key and value */ + if (key) + { + /* Do something special for $PATH, we need to + * merge the old path before setting the new path! + */ + if (strcmp(key, "PATH") == 0) + { + temp = g_strrstr((gchar *)value, "$PATH"); + if (!temp) + length = (size_t)(strlen((gchar *)value)); + else + length = (size_t)(strlen((gchar *)value) - strlen(temp)); + oldpath = (gchar *)g_hash_table_lookup(old_hash_configs, key); + if(oldpath && temp) + { + temp = g_strndup((gchar *)value, length); + newpath = g_strconcat(temp, oldpath, NULL);\ + g_setenv((gchar*)key, newpath, 1); + g_debug("SET ENV key %s, value %s", (gchar*)key, (gchar*)newpath); + g_free(newpath); + g_free(temp); + } + else + g_setenv((gchar*)key, (gchar*)value, 1); + } + else + { + g_setenv((gchar*)key, (gchar*)value, 1); + g_debug("SET ENV key %s, value %s", (gchar*)key, (gchar*)value); + } - return host_component; + } + } } -/* Update the path to remove or include our sdk bin directory */ -static void +/* First retrieves new environment variables from the + * configuration files, save it to the hash table and + * then iterate the hash table and set each of the new + * environment variable */ +void update_path (AnjutaPluginSdk *sp) { - const gchar *path; - gchar *new_path_component = NULL; - GArray *path_array = NULL; - char **pathv = NULL; - int i = 0; - gchar *poky_scripts_dir = NULL; - gchar *poky_host_sysroots_bin_dir = NULL; - gchar *poky_host_sysroots_usr_bin_dir = NULL; - gchar *host_component = NULL; - - /* Create new versions of path bits */ - if (sp->poky_mode == POKY_MODE_TOOLCHAIN) - { - if (sp->triplet != NULL && sp->sdk_root != NULL) - new_path_component = g_build_filename (sp->sdk_root, "bin", NULL); - } else { - if (sp->poky_root) - { - host_component = get_host_component (); - poky_scripts_dir = g_build_filename (sp->poky_root, "scripts", NULL); - poky_host_sysroots_usr_bin_dir = g_build_filename (sp->poky_root, "build", "tmp", - "sysroots", host_component, "usr", "bin", NULL); - poky_host_sysroots_bin_dir = g_build_filename (sp->poky_root, "build", "tmp", - "sysroots", host_component, "bin", NULL); - g_free (host_component); - } - } - - /* get current path. do not free */ - path = g_getenv ("PATH"); - - /* split old path up */ - pathv = g_strsplit (path, ":", -1); + gchar *temp, *config_filename; + + temp = g_strconcat(ENV_SCRIPT_FILE_PREFIX, sp->target_triplet, NULL); + + if ((sp->poky_mode == POKY_MODE_TOOLCHAIN) && + sp->target_triplet && sp->sdk_root) + config_filename = g_build_filename (sp->sdk_root,temp, NULL); + else if ((sp->poky_mode == POKY_MODE_FULL) && sp->poky_root) + config_filename = g_build_filename(sp->poky_root, TMPDIR, temp, NULL); + + g_debug("read ENV script, filename %s", config_filename); + update_env_hash(config_filename, sp->env_hash, &sp->old_env_hash); + g_debug("Set new ENV according to script file!"); + set_new_env(sp->old_env_hash, sp->env_hash); + g_free(temp); + g_free(config_filename); +} - /* Convert it into a GArray */ - path_array = g_array_sized_new (TRUE, FALSE, sizeof (gchar *), - g_strv_length (pathv)); - path_array = g_array_insert_vals (path_array, 0, pathv, - g_strv_length (pathv)); +/* Before restore the environment variables to the + * old one before running poky SDK plugins, we need + * to unset some newly set environment variables. + * PATH need not to be unset since it must exist + */ +static void +unset_env(GHashTable *old_hash_configs) +{ + GHashTableIter iter; + gpointer key, value; - /* Remove old versions */ - for (i = 0; i < path_array->len; i++) + if (!old_hash_configs || g_hash_table_size (old_hash_configs) <= 0) { - gchar *tmp = g_array_index (path_array, gchar *, i); - - if ((sp->path_component && g_str_equal (tmp, sp->path_component)) || - (sp->poky_scripts_dir && g_str_equal (tmp, sp->poky_scripts_dir)) || - (sp->poky_host_sysroots_bin_dir - && g_str_equal (tmp, sp->poky_host_sysroots_bin_dir)) || - (sp->poky_host_sysroots_usr_bin_dir - && g_str_equal (tmp, sp->poky_host_sysroots_usr_bin_dir))) - { - path_array = g_array_remove_index (path_array, i); - i--; /* because we've deleted something */ - } + g_warning("Error while trying to unset environment variables" + "old config hash table can't be NULL!"); + return; } - if (sp->poky_mode == POKY_MODE_TOOLCHAIN) + g_hash_table_iter_init (&iter, old_hash_configs); + while (g_hash_table_iter_next (&iter, &key, &value)) { - /* Add the new path component */ - if (new_path_component) - path_array = g_array_prepend_val (path_array, new_path_component); - } else { - if (poky_scripts_dir) - path_array = g_array_prepend_val (path_array, poky_scripts_dir); - - if (poky_host_sysroots_bin_dir) - path_array = g_array_prepend_val (path_array, poky_host_sysroots_bin_dir); - - if (poky_host_sysroots_usr_bin_dir) - path_array = g_array_prepend_val (path_array, poky_host_sysroots_usr_bin_dir); + /* PATH is always needed */ + if (key && (strcmp(key, "PATH") != 0)) + g_unsetenv((gchar*)key); } - - /* Create our new path */ - path = g_strjoinv (":", (gchar **)path_array->data); - setenv ("PATH", path, 1); - - /* Save the components */ - g_free (sp->path_component); - g_free (sp->poky_scripts_dir); - g_free (sp->poky_host_sysroots_bin_dir); - g_free (sp->poky_host_sysroots_usr_bin_dir); - - sp->path_component = new_path_component; - sp->poky_scripts_dir = poky_scripts_dir; - sp->poky_host_sysroots_bin_dir = poky_host_sysroots_bin_dir; - sp->poky_host_sysroots_usr_bin_dir = poky_host_sysroots_usr_bin_dir; - - g_array_free (path_array, TRUE); - g_strfreev (pathv); } -/* - * Add/remove/update the environment to reflect changes to the sdk root or - * triplet +/* Restore old envrionment variable settings before running + * Poky SDK plugin, if anjuta is launching another anjuta + * as its sub process, something might be very tricky, yet + * seems we have no good solution here. For avoid obvious + * mistake, I only restore PATH although all other keys/values + * are actually saved for later use. */ -static void cleanup_environment (AnjutaPluginSdk *sp) { - update_path (sp); - - /* unset environment keys */ - unsetenv ("PKG_CONFIG_SYSROOT_DIR"); - unsetenv ("PKG_CONFIG_PATH"); - unsetenv ("CONFIG_SITE"); + GHashTableIter iter; + gpointer key, value; + + if (!sp->old_env_hash || g_hash_table_size (sp->old_env_hash) <= 0) + { + g_warning("Error while restore ENV: No backup ENV hash created!"); + return; + } + + unset_env(sp->old_env_hash); + + //Note: If anjuta is creating a new project, it is a sub-process. + //we might have problem here since the old environment is set-up + //by its parent anjuta poky plugin. So that we can only set up + //$PATH here for avoid mistakes. Yet I have to say this is not a good + //solution since users might set CC, CXXFLAGS... + g_hash_table_iter_init (&iter, sp->old_env_hash); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + /* Restore old environment variables */ + if (key && (strcmp(key, "PATH") == 0)) + { + g_setenv((gchar*)key, (gchar*)value, 1); + g_debug("Restore ENV key %s, value %s", (gchar*)key, (gchar*)value); + } + } } +/* When get new valid environment variable settings, set new + * env. Otherwise, switch back to the old environment setting + * before running Poky SDK Plugin! + */ static void update_environment (AnjutaPluginSdk *sp) { @@ -1081,55 +1134,16 @@ update_environment (AnjutaPluginSdk *sp) gchar *pkg_config_usr_path = NULL; gchar *pkg_config_path = NULL; - - if (sp->triplet == NULL || - (sp->poky_mode == POKY_MODE_TOOLCHAIN && sp->sdk_root == NULL) || - (sp->poky_mode == POKY_MODE_FULL && sp->poky_root == NULL)) + if (!sp->target_triplet || + (sp->poky_mode == POKY_MODE_TOOLCHAIN && !sp->sdk_root) || + (sp->poky_mode == POKY_MODE_FULL && !sp->poky_root)) { + g_warning("No valid poky environment settings, restore old ENV!"); cleanup_environment (sp); return; } - + cleanup_environment (sp); update_path (sp); - - if (sp->poky_mode == POKY_MODE_TOOLCHAIN) - { - tmp = g_build_filename (sp->sdk_root, sp->triplet, NULL); - setenv ("PKG_CONFIG_SYSROOT_DIR", tmp, 1); - g_free (tmp); - - pkg_config_path = g_build_filename (sp->sdk_root, sp->triplet, "lib", - "pkgconfig", NULL); - pkg_config_usr_path = g_build_filename (sp->sdk_root, sp->triplet, "usr", - "lib", "pkgconfig", NULL); - tmp = g_strdup_printf ("%s:%s", pkg_config_usr_path, pkg_config_path); - - setenv ("PKG_CONFIG_PATH", tmp, 1); - g_free (pkg_config_path); - g_free (pkg_config_usr_path); - g_free (tmp); - - tmp = g_build_filename (sp->sdk_root, "site-config", NULL); - setenv ("CONFIG_SITE", tmp, 1); - g_free (tmp); - } else { - tmp = g_build_filename (sp->poky_root, "build", "tmp", "staging", - sp->triplet, NULL); - setenv ("PKG_CONFIG_SYSROOT_DIR", tmp, 1); - g_free (tmp); - - pkg_config_usr_path = g_build_filename (sp->poky_root, "build", "tmp", - "staging", sp->triplet, "usr", "lib", "pkgconfig", NULL); - pkg_config_path = g_build_filename (sp->poky_root, "build", "tmp", - "staging", sp->triplet, "lib", "pkgconfig", NULL); - tmp = g_strdup_printf ("%s:%s", pkg_config_usr_path, pkg_config_path); - setenv ("PKG_CONFIG_PATH", tmp, 1); - g_free (pkg_config_path); - g_free (pkg_config_usr_path); - g_free (tmp); - - unsetenv ("CONFIG_SITE"); - } } static void @@ -1259,28 +1273,71 @@ setup_target (AnjutaPluginSdk *sp) update_state (sp); } +/* GtkWidget combo_box is weird since we can't clear existing + * text even if the text items below are all removed and the + * active text is actually out-of-date. So sometimes, Anjuta + * preference can't sense the text property changes. We need + * to manually call the triplet text change callback at the + * needed point. + * The main task of this callback is to update plugin's target + * and host triplet + */ +static void +triplet_changed(AnjutaPluginSdk *sp) +{ + + g_free (sp->target_triplet); + sp->target_triplet = NULL; + + sp->target_triplet = anjuta_preferences_get (sp->prefs, PREFS_PROP_TRIPLET); + g_debug("New target triplet %s!", sp->target_triplet); + + if (!sp->target_triplet) + return; + + /* A NULL value set into anjuta perference will be returned as + * empty string */ + if (strlen(sp->target_triplet) <=0) + { + sp->target_triplet = NULL; + return; + } +} + static void sdk_root_preference_notify_cb (AnjutaPreferences *pref, const gchar *key, const gchar *value, gpointer userdata) { AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + GtkWidget *target_combo; g_free (sp->sdk_root); sp->sdk_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_SDK_ROOT); + //update target_combo show items + g_free(sp->target_archs); + sp->target_archs = beaver_util_get_archs(sp->sdk_root); + anjuta_preferences_set(pref, PREFS_PROP_TARGET_ARCHS, sp->target_archs); + + target_combo = (GtkWidget *)g_object_get_data(G_OBJECT(pref), PREFS_PROP_TARGET_COMBO); + g_object_set_data(G_OBJECT(target_combo), OBJ_PROP_TARGET_ARCHS, sp->target_archs); + + update_combo_box(target_combo, sp->target_archs); + triplet_changed(sp); update_environment (sp); + } + + static void triplet_preference_notify_cb (AnjutaPreferences *pref, const gchar *key, const gchar *value, gpointer userdata) { AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; - - g_free (sp->triplet); - sp->triplet = anjuta_preferences_get (sp->prefs, PREFS_PROP_TRIPLET); - + triplet_changed(sp); update_environment (sp); + } static void @@ -1318,10 +1375,29 @@ poky_mode_preference_notify_cb (AnjutaPreferences *pref, const gchar *key, const gboolean value, gpointer userdata) { AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + GtkWidget *target_combo; + gchar *dir; sp->poky_mode = anjuta_preferences_get_bool (sp->prefs, PREFS_PROP_POKY_MODE); + g_free(sp->target_archs); + if (sp->poky_mode == POKY_MODE_TOOLCHAIN && sp->sdk_root != NULL) + sp->target_archs = beaver_util_get_archs(sp->sdk_root); + else if (sp->poky_mode == POKY_MODE_FULL && sp->poky_root != NULL) + { + dir = g_build_filename(sp->poky_root, TMPDIR, NULL); + sp->target_archs = beaver_util_get_archs(dir); + g_free(dir); + } + anjuta_preferences_set(pref, PREFS_PROP_TARGET_ARCHS, sp->target_archs); + + target_combo = (GtkWidget *)g_object_get_data(G_OBJECT(pref), PREFS_PROP_TARGET_COMBO); + g_object_set_data(G_OBJECT(target_combo), OBJ_PROP_TARGET_ARCHS, sp->target_archs); + + update_combo_box(target_combo, sp->target_archs); + triplet_changed(sp); update_environment (sp); + } static void @@ -1329,11 +1405,22 @@ poky_root_preference_notify_cb (AnjutaPreferences *pref, const gchar *key, const gchar *value, gpointer userdata) { AnjutaPluginSdk *sp = (AnjutaPluginSdk *)userdata; + GtkWidget *target_combo; g_free (sp->poky_root); sp->poky_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_POKY_ROOT); + g_free(sp->target_archs); + sp->target_archs = beaver_util_get_archs(sp->poky_root); + + anjuta_preferences_set(pref, PREFS_PROP_TARGET_ARCHS, sp->target_archs); + target_combo = (GtkWidget *)g_object_get_data(G_OBJECT(pref), PREFS_PROP_TARGET_COMBO); + g_object_set_data(G_OBJECT(target_combo), OBJ_PROP_TARGET_ARCHS, sp->target_archs); + + update_combo_box(target_combo, sp->target_archs); + triplet_changed(sp); update_environment (sp); + } static void @@ -1437,7 +1524,11 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) GError *error = NULL; gchar *kernel = NULL; gchar *rootfs = NULL; + gchar *env_filename = NULL; + gchar *temp = NULL; + + g_debug("Activate poky SDK plugin"); ui = anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin)->shell, NULL); sp->action_group = anjuta_ui_add_action_group_entries (ui, "ActionGroupSdk", @@ -1502,7 +1593,8 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) PREFS_PROP_TARGET_IP, target_ip_preference_notify_cb, sp, NULL); sp->sdk_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_SDK_ROOT); - sp->triplet = anjuta_preferences_get (sp->prefs, PREFS_PROP_TRIPLET); + + sp->target_triplet = anjuta_preferences_get (sp->prefs, PREFS_PROP_TRIPLET); sp->poky_root = anjuta_preferences_get (sp->prefs, PREFS_PROP_POKY_ROOT); @@ -1510,6 +1602,26 @@ anjuta_plugin_sdk_activate (AnjutaPlugin *plugin) sp->target_mode = anjuta_preferences_get_bool (sp->prefs, PREFS_PROP_TARGET_MODE); setup_target (sp); + + /* key and value must be freed when destroy the hash table + * since they are both dynamically allocated when parsing + * config files! + */ + + sp->env_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + + if (sp->poky_mode == POKY_MODE_TOOLCHAIN && sp->sdk_root != NULL) + sp->target_archs = beaver_util_get_archs(sp->sdk_root); + else if (sp->poky_mode == POKY_MODE_FULL && sp->poky_root != NULL) + { + temp = g_build_filename(sp->poky_root, TMPDIR, NULL); + sp->target_archs = beaver_util_get_archs(temp); + g_free(temp); + } + + g_debug("When activate, architecture is %s", sp->target_archs); + anjuta_preferences_set(sp->prefs, PREFS_PROP_TARGET_ARCHS, sp->target_archs); + update_environment (sp); sp->project_root_uri_watch = anjuta_plugin_add_watch (plugin, @@ -1534,6 +1646,7 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) GError *error = NULL; IAnjutaMessageManager *msg_manager = NULL; + g_warning("begin deactivate!"); cleanup_environment (sp); ui = anjuta_shell_get_ui (plugin->shell, NULL); @@ -1620,31 +1733,37 @@ anjuta_plugin_sdk_deactivate (AnjutaPlugin *plugin) sp->target = NULL; } + /* * Must set these to NULL because the plugin object might get reused after * deactivation. */ - g_free (sp->sdk_root); - g_free (sp->triplet); + g_free (sp->target_triplet); g_free (sp->poky_root); - + g_hash_table_destroy(sp->env_hash); + g_hash_table_destroy(sp->old_env_hash); g_free (sp->project_root_uri); g_free (sp->path_component); g_free (sp->gdb_local_path); g_free (sp->gdb_remote_command); g_free (sp->remote_command); + g_free(sp->target_archs); sp->sdk_root = NULL; - sp->triplet = NULL; + sp->target_triplet = NULL; sp->poky_root = NULL; + sp->target_archs = NULL; + sp->old_env_hash = NULL; + sp->env_hash = NULL; + + sp->env_hash = NULL; sp->project_root_uri = NULL; sp->path_component = NULL; sp->gdb_local_path = NULL; sp->gdb_remote_command = NULL; sp->remote_command = NULL; - return TRUE; } @@ -1723,37 +1842,68 @@ static gboolean anjuta_environment_override (IAnjutaEnvironment *obj, gchar **dirp, gchar ***argvp, gchar ***envp, GError **err) { AnjutaPluginSdk *sp = (AnjutaPluginSdk *)obj; - gchar **new_argv; + gchar **new_argv, **vstr; + const gchar* configure_flags; + gchar* temp; gsize length = g_strv_length (*argvp); - int i; + gint i, paramcount = 0; if (length < 1) return FALSE; - if (!sp->triplet) // no override for cross command - return TRUE; - + //we only override autogen and configure related params if (g_str_has_suffix(*argvp[0], CONFIGURE_COMMAND) || - g_str_has_suffix(*argvp[0], AUTOGEN_COMMAND)) { - new_argv = g_new (gchar*, length + 2); + g_str_has_suffix(*argvp[0], AUTOGEN_COMMAND)) + { + configure_flags = g_getenv(CROSS_COMMAND); + + if (!configure_flags) + { + g_error("Error while getting configuration flags!"); + return FALSE; + } + + //please make sure that configure flags are splited by + //only a " ". My parser is not very clever! + vstr = g_strsplit(configure_flags, " ", 0); + if (!vstr) + { + g_error("Error while parsing CONFIGURE_FLAGS!"); + return FALSE; + } + + paramcount = g_strv_length (vstr); + + new_argv = g_new (gchar*, length + paramcount + 1); + if (!new_argv) { g_error("Error while allocate args when do environment override!"); + g_strfreev(vstr); return FALSE; } - + /* First copy the command */ new_argv[0] = g_strconcat(*(argvp[0]), NULL); - new_argv[1] = g_strdup_printf (CROSS_COMMAND, sp->triplet); + g_free(*(argvp[0])); - for (i = 0; i < length; i++) { - if (i) - new_argv[1 + i] = g_strconcat(*(*argvp + i), NULL); - g_free(*(*argvp + i)); + /* Insert the newly override parameters */ + for (i = 0; i < paramcount; i++) + { + new_argv[i + 1] = g_strdup (vstr[i]); } + g_strfreev(vstr); + for (i = 1; i < length; i++) + { + /* copy original parameters, the first one need not to be copied! */ + new_argv[paramcount + i] = g_strconcat(*(*argvp + i), NULL); + g_free(*(*argvp + i)); + } /* args must be NULL terminated */ - new_argv[length+1] = NULL; + new_argv[length + paramcount] = NULL; + g_free (*argvp); *argvp = new_argv; + } return TRUE; |