summary refs log tree commit diff stats
path: root/m4/ax_check_enable_debug.m4
blob: f99d75feb446b42f1b586516aef039723be4ae4c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# ===========================================================================
#   http://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html
# ===========================================================================
#
# SYNOPSIS
#
#   AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE])
#
# DESCRIPTION
#
#   Check for the presence of an --enable-debug option to configure, with
#   the specified default value used when the option is not present.  Return
#   the value in the variable $ax_enable_debug.
#
#   Specifying 'yes' adds '-g -O0' to the compilation flags for all
#   languages. Specifying 'info' adds '-g' to the compilation flags.
#   Specifying 'profile' adds '-g -pg' to the compilation flags and '-pg' to
#   the linking flags. Otherwise, nothing is added.
#
#   Define the variables listed in the second argument if debug is enabled,
#   defaulting to no variables.  Defines the variables listed in the third
#   argument if debug is disabled, defaulting to NDEBUG.  All lists of
#   variables should be space-separated.
#
#   If debug is not enabled, ensure AC_PROG_* will not add debugging flags.
#   Should be invoked prior to any AC_PROG_* compiler checks.
#
#   IS-RELEASE can be used to change the default to 'no' when making a
#   release.  Set IS-RELEASE to 'yes' or 'no' as appropriate. By default, it
#   uses the value of $ax_is_release, so if you are using the AX_IS_RELEASE
#   macro, there is no need to pass this parameter.
#
#     AX_IS_RELEASE([git-directory])
#     AX_CHECK_ENABLE_DEBUG()
#
# LICENSE
#
#   Copyright (c) 2011 Rhys Ulerich <rhys.ulerich@gmail.com>
#   Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved.

#serial 5

AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
    AC_BEFORE([$0],[AC_PROG_CC])dnl
    AC_BEFORE([$0],[AC_PROG_CXX])dnl
    AC_BEFORE([$0],[AC_PROG_F77])dnl
    AC_BEFORE([$0],[AC_PROG_FC])dnl

    AC_MSG_CHECKING(whether to enable debugging)

    ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))
    ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],,
                                                              [$ax_is_release],
                                                              [$4])))

    # If this is a release, override the default.
    AS_IF([test "$ax_enable_debug_is_release" = "yes"],
      [ax_enable_debug_default="no"])

    m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
    m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])

    AC_ARG_ENABLE(debug,
	[AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])],
	[],enable_debug=$ax_enable_debug_default)

    # empty mean debug yes
    AS_IF([test "x$enable_debug" = "x"],
      [enable_debug="yes"])

    # case of debug
    AS_CASE([$enable_debug],
      [yes],[
	AC_MSG_RESULT(yes)
	CFLAGS="${CFLAGS} -g -O0"
	CXXFLAGS="${CXXFLAGS} -g -O0"
	FFLAGS="${FFLAGS} -g -O0"
	FCFLAGS="${FCFLAGS} -g -O0"
	OBJCFLAGS="${OBJCFLAGS} -g -O0"
      ],
      [info],[
	AC_MSG_RESULT(info)
	CFLAGS="${CFLAGS} -g"
	CXXFLAGS="${CXXFLAGS} -g"
	FFLAGS="${FFLAGS} -g"
	FCFLAGS="${FCFLAGS} -g"
	OBJCFLAGS="${OBJCFLAGS} -g"
      ],
      [profile],[
	AC_MSG_RESULT(profile)
	CFLAGS="${CFLAGS} -g -pg"
	CXXFLAGS="${CXXFLAGS} -g -pg"
	FFLAGS="${FFLAGS} -g -pg"
	FCFLAGS="${FCFLAGS} -g -pg"
	OBJCFLAGS="${OBJCFLAGS} -g -pg"
	LDFLAGS="${LDFLAGS} -pg"
      ],
      [
	AC_MSG_RESULT(no)
	dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
	dnl by setting any unset environment flag variables
	AS_IF([test "x${CFLAGS+set}" != "xset"],
	  [CFLAGS=""])
	AS_IF([test "x${CXXFLAGS+set}" != "xset"],
	  [CXXFLAGS=""])
	AS_IF([test "x${FFLAGS+set}" != "xset"],
	  [FFLAGS=""])
	AS_IF([test "x${FCFLAGS+set}" != "xset"],
	  [FCFLAGS=""])
	AS_IF([test "x${OBJCFLAGS+set}" != "xset"],
	  [OBJCFLAGS=""])
      ])

    dnl Define various variables if debugging is disabled.
    dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
    AS_IF([test "x$enable_debug" = "xyes"],
      [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])],
      [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])])
    ax_enable_debug=$enable_debug
])
ll be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include <string.h> #include <stdio.h> #include <stdlib.h> #include "fe-gtk.h" #include "../common/hexchat.h" #define PLUGIN_C typedef struct session hexchat_context; #include "../common/hexchat-plugin.h" #include "../common/plugin.h" #include "../common/util.h" #include "../common/outbound.h" #include "../common/fe.h" #include "../common/hexchatc.h" #include "../common/cfgfiles.h" #include "gtkutil.h" #include "maingui.h" /* model for the plugin treeview */ enum { NAME_COLUMN, VERSION_COLUMN, FILE_COLUMN, DESC_COLUMN, N_COLUMNS }; static GtkWidget *plugin_window = NULL; static GtkWidget * plugingui_treeview_new (GtkWidget *box) { GtkListStore *store; GtkWidget *view; GtkTreeViewColumn *col; int col_id; store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); g_return_val_if_fail (store != NULL, NULL); view = gtkutil_treeview_new (box, GTK_TREE_MODEL (store), NULL, NAME_COLUMN, _("Name"), VERSION_COLUMN, _("Version"), FILE_COLUMN, _("File"), DESC_COLUMN, _("Description"), -1); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE); for (col_id=0; (col = gtk_tree_view_get_column (GTK_TREE_VIEW (view), col_id)); col_id++) gtk_tree_view_column_set_alignment (col, 0.5); return view; } static char * plugingui_getfilename (GtkTreeView *view) { GtkTreeModel *model; GtkTreeSelection *sel; GtkTreeIter iter; GValue file; char *str; memset (&file, 0, sizeof (file)); sel = gtk_tree_view_get_selection (view); if (gtk_tree_selection_get_selected (sel, &model, &iter)) { gtk_tree_model_get_value (model, &iter, FILE_COLUMN, &file); str = g_value_dup_string (&file); g_value_unset (&file); return str; } return NULL; } static void plugingui_close (GtkWidget * wid, gpointer a) { plugin_window = NULL; } extern GSList *plugin_list; void fe_pluginlist_update (void) { hexchat_plugin *pl; GSList *list; GtkTreeView *view; GtkListStore *store; GtkTreeIter iter; if (!plugin_window) return; view = g_object_get_data (G_OBJECT (plugin_window), "view"); store = GTK_LIST_STORE (gtk_tree_view_get_model (view)); gtk_list_store_clear (store); list = plugin_list; while (list) { pl = list->data; if (pl->version[0] != 0) { gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, NAME_COLUMN, pl->name, VERSION_COLUMN, pl->version, FILE_COLUMN, file_part (pl->filename), DESC_COLUMN, pl->desc, -1); } list = list->next; } } static void plugingui_load_cb (session *sess, char *file) { if (file) { char *buf = malloc (strlen (file) + 9); if (strchr (file, ' ')) sprintf (buf, "LOAD \"%s\"", file); else sprintf (buf, "LOAD %s", file); handle_command (sess, buf, FALSE); free (buf); } } void plugingui_load (void) { char *sub_dir; sub_dir = g_build_filename (get_xdir(), "addons", NULL); gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb, current_sess, sub_dir, "*."G_MODULE_SUFFIX";*.lua;*.pl;*.py;*.tcl;*.js", FRF_FILTERISINITIAL|FRF_EXTENSIONS); g_free (sub_dir); } static void plugingui_loadbutton_cb (GtkWidget * wid, gpointer unused) { plugingui_load (); } static void plugingui_unload (GtkWidget * wid, gpointer unused) { char *modname, *file, *buf; GtkTreeView *view; GtkTreeIter iter; view = g_object_get_data (G_OBJECT (plugin_window), "view"); if (!gtkutil_treeview_get_selected (view, &iter, NAME_COLUMN, &modname, FILE_COLUMN, &file, -1)) return; if (g_str_has_suffix (file, "."G_MODULE_SUFFIX)) { if (plugin_kill (modname, FALSE) == 2) fe_message (_("That plugin is refusing to unload.\n"), FE_MSG_ERROR); } else { /* let python.so or perl.so handle it */ buf = malloc (strlen (file) + 10); if (strchr (file, ' ')) sprintf (buf, "UNLOAD \"%s\"", file); else sprintf (buf, "UNLOAD %s", file); handle_command (current_sess, buf, FALSE); free (buf); } g_free (modname); g_free (file); } static void plugingui_reloadbutton_cb (GtkWidget *wid, GtkTreeView *view) { char *file = plugingui_getfilename(view); if (file) { char *buf = malloc (strlen (file) + 9); if (strchr (file, ' ')) sprintf (buf, "RELOAD \"%s\"", file); else sprintf (buf, "RELOAD %s", file); handle_command (current_sess, buf, FALSE); free (buf); g_free (file); } } void plugingui_open (void) { GtkWidget *view; GtkWidget *vbox, *hbox; if (plugin_window) { mg_bring_tofront (plugin_window); return; } plugin_window = mg_create_generic_tab ("Addons", _(DISPLAY_NAME": Plugins and Scripts"), FALSE, TRUE, plugingui_close, NULL, 500, 250, &vbox, 0); gtkutil_destroy_on_esc (plugin_window); view = plugingui_treeview_new (vbox); g_object_set_data (G_OBJECT (plugin_window), "view", view); hbox = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD); gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); gtk_box_pack_end (GTK_BOX (vbox), hbox, 0, 0, 0); gtkutil_button (hbox, GTK_STOCK_REVERT_TO_SAVED, NULL, plugingui_loadbutton_cb, NULL, _("_Load...")); gtkutil_button (hbox, GTK_STOCK_DELETE, NULL, plugingui_unload, NULL, _("_Unload")); gtkutil_button (hbox, GTK_STOCK_REFRESH, NULL, plugingui_reloadbutton_cb, view, _("_Reload")); fe_pluginlist_update (); gtk_widget_show_all (plugin_window); }