2 * build.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /** @file build.h Interface to the Build menu functionality. */
25 #define GEANY_BUILD_H 1
29 /* Order is important (see GBO_TO_GBG, GBO_TO_CMD below) */
30 /* * Geany Known Build Commands.
31 * These commands are named after their default use.
32 * Only these commands can currently have keybindings.
36 GEANY_GBO_COMPILE
, /* *< default compile file */
37 GEANY_GBO_BUILD
, /* *< default build file */
38 GEANY_GBO_MAKE_ALL
, /* *< default make */
39 GEANY_GBO_CUSTOM
, /* *< default make user specified target */
40 GEANY_GBO_MAKE_OBJECT
, /* *< default make object, make %e.o */
41 GEANY_GBO_EXEC
, /* *< default execute ./%e */
42 GEANY_GBO_COUNT
/* *< count of how many */
45 /** Groups of Build menu items. */
48 GEANY_GBG_FT
, /* *< filetype items */
49 GEANY_GBG_NON_FT
, /* *< non filetype items.*/
50 GEANY_GBG_EXEC
, /* *< execute items */
51 GEANY_GBG_COUNT
/* *< count of groups. */
54 /* include the fixed widgets in an array indexed by groups */
55 #define GBG_FIXED GEANY_GBG_COUNT
57 /* * Convert @c GeanyBuildType to @c GeanyBuildGroup.
59 * This macro converts @c GeanyBuildType enum values (the "known" commands)
60 * to the group they are part of.
62 * @param gbo the @c GeanyBuildType value.
64 * @return the @c GeanyBuildGroup group that @a gbo is in.
66 * Note this is a macro so that it can be used in static initialisers.
68 #define GBO_TO_GBG(gbo) ((gbo)>GEANY_GBO_EXEC?GEANY_GBG_COUNT:((gbo)>=GEANY_GBO_EXEC?GEANY_GBG_EXEC: \
69 ((gbo) >= GEANY_GBO_MAKE_ALL ? GEANY_GBG_NON_FT : GEANY_GBG_FT)))
71 /* * Convert @c GeanyBuildType to command index.
73 * This macro converts @c GeanyBuildType enum values (the "known" commands)
74 * to the index within the group.
76 * @param gbo the @c GeanyBuildType value.
78 * @return the index of the @a gbo command in its group.
80 * Note this is a macro so that it can be used in static initialisers.
82 #define GBO_TO_CMD(gbo) ((gbo)>=GEANY_GBO_COUNT?(gbo)-GEANY_GBO_COUNT:((gbo)>=GEANY_GBO_EXEC?(gbo)-GEANY_GBO_EXEC: \
83 ((gbo) >= GEANY_GBO_MAKE_ALL ? (gbo)-GEANY_GBO_MAKE_ALL : (gbo))))
85 enum GeanyBuildFixedMenuItems
97 /** Build menu item sources in increasing priority */
100 GEANY_BCS_DEF
, /* *< Default values. */
101 GEANY_BCS_FT
, /* *< System filetype values. */
102 GEANY_BCS_HOME_FT
, /* *< Filetypes in ~/.config/geany/filedefs */
103 GEANY_BCS_PREF
, /* *< Preferences file ~/.config/geany/geany.conf */
104 GEANY_BCS_PROJ_FT
, /* *< Project file filetype command */
105 GEANY_BCS_PROJ
, /* *< Project file if open. */
106 GEANY_BCS_COUNT
/* *< Count of sources. */
109 typedef struct GeanyBuildInfo
113 GPid pid
; /* process id of the spawned process */
116 gchar
*custom_target
;
120 extern GeanyBuildInfo build_info
;
122 /** The entries of a command for a menu item */
123 typedef enum GeanyBuildCmdEntries
125 GEANY_BC_LABEL
, /* *< The menu item label, _ marks mnemonic */
126 GEANY_BC_COMMAND
, /* *< The command to run. */
127 GEANY_BC_WORKING_DIR
, /* *< The directory to run in */
128 GEANY_BC_CMDENTRIES_COUNT
/* *< Count of entries */
129 } GeanyBuildCmdEntries
;
131 /* * The command for a menu item. */
132 typedef struct GeanyBuildCommand
134 /* * Pointers to g_string values of the command entries.
135 * Must be freed if the pointer is changed. */
136 gchar
*label
; /* *< Menu item label */
137 gchar
*command
; /* *< Command to run */
138 gchar
*working_dir
; /* *< working directory */
139 gboolean exists
; /* *< If the entries have valid values. */
140 gboolean changed
; /* *< Save on exit if @c changed, remove if not @c exist. */
141 gboolean old
; /* *< Converted from old format. */
144 typedef struct BuildMenuItems
147 GtkWidget
**menu_item
[GEANY_GBG_COUNT
+ 1]; /* +1 for fixed items */
150 /* a structure defining the destinations for a set of groups of commands & regex */
151 typedef struct BuildDestination
153 GeanyBuildCommand
**dst
[GEANY_GBG_COUNT
];
154 gchar
**fileregexstr
;
155 gchar
**nonfileregexstr
;
158 /* opaque pointers returned from build functions and passed back to them */
159 typedef struct BuildTableFields
*BuildTableData
;
162 void build_init(void);
164 void build_finalize(void);
166 /* menu configuration dialog functions */
167 GtkWidget
*build_commands_table(GeanyDocument
*doc
, GeanyBuildSource dst
, BuildTableData
*data
, GeanyFiletype
*ft
);
169 void build_read_project(GeanyFiletype
*ft
, BuildTableData build_properties
);
171 void build_free_fields(BuildTableData data
);
173 /* build response decode assistance function */
174 gboolean
build_parse_make_dir(const gchar
*string
, gchar
**prefix
);
176 /* build menu functions */
178 void build_menu_update(GeanyDocument
*doc
);
180 void build_toolbutton_build_clicked(GtkAction
*action
, gpointer user_data
);
182 void build_remove_menu_item(const GeanyBuildSource src
, const GeanyBuildGroup grp
, const gint cmd
);
184 GeanyBuildCommand
*build_get_menu_item(const GeanyBuildSource src
, const GeanyBuildGroup grp
, const guint cmd
);
186 const gchar
*build_get_current_menu_item(const GeanyBuildGroup grp
, const guint cmd
,
187 const GeanyBuildCmdEntries field
);
189 void build_set_menu_item(const GeanyBuildSource src
, const GeanyBuildGroup grp
,
190 const guint cmd
, const GeanyBuildCmdEntries field
, const gchar
*value
);
192 void build_activate_menu_item(const GeanyBuildGroup grp
, const guint cmd
);
194 BuildMenuItems
*build_get_menu_items(gint filetype_idx
);
196 /* load and store menu configuration */
197 void build_load_menu(GKeyFile
*config
, GeanyBuildSource dst
, gpointer ptr
);
199 void build_save_menu(GKeyFile
*config
, gpointer ptr
, GeanyBuildSource src
);
201 void build_set_group_count(GeanyBuildGroup grp
, gint count
);
203 guint
build_get_group_count(const GeanyBuildGroup grp
);
205 gchar
**build_get_regex(GeanyBuildGroup grp
, GeanyFiletype
*ft
, guint
*from
);