Updated Spanish translation
[anjuta-git-plugin.git] / plugins / build / compile.c
blob6605acc0b27056cf95f48cfb51e125d0f6d4d912
1 /*
2 compile.c
3 Copyright (C) 2000 Kh. Naba Kumar Singh
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <signal.h>
28 #include <string.h>
30 #include <gnome.h>
31 #include "anjuta.h"
32 #include "launcher.h"
33 #include "message-manager.h"
34 #include "compile.h"
35 #include "build_file.h"
37 #if 0
39 void
40 compile_file_with_make ()
42 gchar* src_dir;
44 if(app->project_dbase->is_saved == FALSE
45 && app->project_dbase->project_is_open==TRUE)
47 gboolean ret;
48 ret = project_dbase_save_project(app->project_dbase);
49 if (ret == FALSE)
50 return;
53 src_dir = project_dbase_get_module_dir (app->project_dbase, MODULE_SOURCE);
54 if (src_dir)
56 gchar *prj_name, *cmd;
58 cmd = command_editor_get_command (app->command_editor, COMMAND_BUILD_MODULE);
59 if (cmd == NULL)
61 anjuta_warning (_("Unable to build module. Check Settings->Commands."));
62 g_free (src_dir);
63 return;
65 chdir (src_dir);
66 anjuta_set_execution_dir(src_dir);
67 g_free (src_dir);
69 if (build_execute_command (cmd) == FALSE)
71 g_free (cmd);
72 return;
74 anjuta_update_app_status (TRUE, _("Build Project"));
75 an_message_manager_clear (app->messages, MESSAGE_BUILD);
76 an_message_manager_append (app->messages, _("Building source directory of the Project: "),
77 MESSAGE_BUILD);
78 prj_name = project_dbase_get_proj_name (app->project_dbase);
79 an_message_manager_append (app->messages, prj_name, MESSAGE_BUILD);
80 an_message_manager_append (app->messages, "...\n", MESSAGE_BUILD);
81 an_message_manager_append (app->messages, cmd, MESSAGE_BUILD);
82 an_message_manager_append (app->messages, "\n", MESSAGE_BUILD);
83 an_message_manager_show (app->messages, MESSAGE_BUILD);
84 g_free (cmd);
85 g_free (prj_name);
87 else
89 /* Single file build */
90 build_file ();
94 #endif
96 void
97 compile_file (gboolean use_make)
99 gchar *dirname, *cmd, *buff;
100 TextEditor *te;
102 te = anjuta_get_current_text_editor ();
103 g_return_if_fail (te != NULL);
105 if (te->full_filename == NULL)
107 anjuta_warning (_("This file has not been saved. Save it first and then compile."));
108 return;
110 if (text_editor_is_saved(te) == FALSE)
112 if (text_editor_save_file (te, TRUE) == FALSE)
113 return;
116 #if 0 /* Skipping dependency check for file */
117 filename = g_strdup (te->full_filename);
118 ext = get_file_extension (filename);
119 if (ext)
121 *(ext) = 'o';
122 *(++ext) = '\0';
124 stat (te->full_filename, &st1);
125 flg = stat (filename, &st2);
126 if ((flg == 0) && (st2.st_mtime > st1.st_mtime))
128 anjuta_warning (_("The object file is up-to-date, there is no need to compile it again."));
129 g_free (filename);
130 return;
132 g_free (filename);
133 #endif
135 anjuta_set_file_properties (te->full_filename);
136 cmd = command_editor_get_command_file (app->command_editor,
137 use_make?COMMAND_MAKE_FILE:COMMAND_COMPILE_FILE, te->filename);
138 if (cmd == NULL)
140 anjuta_warning (_("No compile command has been specified for this type of file."));
141 return;
143 dirname = extract_directory (te->full_filename);
144 chdir (dirname);
145 anjuta_set_execution_dir(dirname);
146 g_free (dirname);
148 if (build_execute_command (cmd) == FALSE)
150 g_free (cmd);
151 return;
153 anjuta_update_app_status (TRUE, _("Compile"));
154 an_message_manager_clear (app->messages, MESSAGE_BUILD);
155 buff = g_strdup_printf (_("Compiling file: %s...\n"), te->filename);
156 an_message_manager_append (app->messages, buff, MESSAGE_BUILD);
157 an_message_manager_append (app->messages, cmd, MESSAGE_BUILD);
158 an_message_manager_append (app->messages, "\n", MESSAGE_BUILD);
159 an_message_manager_show (app->messages, MESSAGE_BUILD);
160 g_free (buff);
161 g_free (cmd);