--- hexchat-2.12.4/data/pkgconfig/Makefile.am
+++ hexchat-2.12.4/data/pkgconfig/Makefile.am
@@ -1,4 +1,7 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 pkgcfgdir = $(pkgconfigdir)
 pkgcfg_DATA = hexchat-plugin.pc
 
 EXTRA_DIST = hexchat-plugin.pc.in
--- hexchat-2.12.4/data/Makefile.am
+++ hexchat-2.12.4/data/Makefile.am
@@ -1,5 +1,8 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 SUBDIRS =
 
 if DO_PLUGIN
 SUBDIRS += pkgconfig
 endif
--- hexchat-2.12.4/data/misc/Makefile.am
+++ hexchat-2.12.4/data/misc/Makefile.am
@@ -1,5 +1,7 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
 
 appdatadir = $(datadir)/appdata
 appdata_in_files =
 
 if DO_GTK
--- hexchat-2.12.4/data/icons/Makefile.am
+++ hexchat-2.12.4/data/icons/Makefile.am
@@ -1,5 +1,8 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 icon_DATA = hexchat.png
 icondir = $(datadir)/icons/hicolor/48x48/apps
 
 hicolor_DATA = hexchat.svg
 hicolordir = $(datadir)/icons/hicolor/scalable/apps
--- hexchat-2.12.4/data/man/Makefile.am
+++ hexchat-2.12.4/data/man/Makefile.am
@@ -1,3 +1,6 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 man_MANS = hexchat.1
 
 EXTRA_DIST = hexchat.1.in
--- hexchat-2.12.4/Makefile.am
+++ hexchat-2.12.4/Makefile.am
@@ -1,6 +1,8 @@
 ## Process this file with automake to produce Makefile.in
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
 
 ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = po src plugins data
 
--- hexchat-2.12.4/configure.ac
+++ hexchat-2.12.4/configure.ac
@@ -621,23 +621,23 @@ AX_APPEND_COMPILE_FLAGS([\
 	-Werror=declaration-after-statement \
 	-Werror=missing-include-dirs \
 	-Werror=date-time \
 	-Werror=implicit-function-declaration \
 	-Werror=pointer-arith \
-])
+], hexchat_def_CFLAGS)
 
 AS_IF([test "$stack_protector" = "yes"], [
 	AX_APPEND_COMPILE_FLAGS([ \
 		-fstack-protector-strong \
-	])
+	], [hexchat_def_CFLAGS])
 ])
 
 AX_APPEND_LINK_FLAGS([ \
 	-pie \
 	-Wl,-z,relro \
 	-Wl,-z,now \
-])
+], [hexchat_def_LDFLAGS])
 
 dnl *********************************************************************
 dnl ** FUNCTIONS/LIBS/CFLAGS ********************************************
 dnl *********************************************************************
 
@@ -687,10 +687,12 @@ dnl freebsd needs this
 LIBS="$LIBS $INTLLIBS"
 
 GUI_LIBS="$GUI_LIBS $COMMON_LIBS"
 
 dnl make these visible to all Makefiles
+AC_SUBST(hexchat_def_CFLAGS)
+AC_SUBST(hexchat_def_LDFLAGS)
 AC_SUBST(GUI_LIBS)
 AC_SUBST(GUI_CFLAGS)
 AC_SUBST(COMMON_LIBS)
 AC_SUBST(COMMON_CFLAGS)
 AC_SUBST(PERL_CFLAGS)
--- hexchat-2.12.4/src/common/Makefile.am
+++ hexchat-2.12.4/src/common/Makefile.am
@@ -1,6 +1,8 @@
 ## Process this file with automake to produce Makefile.in
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
 
 include $(top_srcdir)/m4/clang-analyze.am
 
 noinst_LIBRARIES = libhexchatcommon.a
 
@@ -62,11 +64,11 @@ noinst_PROGRAMS = make-te
 
 libhexchatcommon_a_SOURCES = cfgfiles.c chanopt.c ctcp.c dcc.c hexchat.c \
 	history.c ignore.c inbound.c marshal.c modes.c network.c notify.c \
 	outbound.c plugin.c plugin-identd.c plugin-timer.c proto-irc.c server.c servlist.c \
 	$(ssl_c) text.c tree.c url.c userlist.c util.c
-libhexchatcommon_a_CFLAGS = $(LIBPROXY_CFLAGS)
+libhexchatcommon_a_CFLAGS = $(LIBPROXY_CFLAGS) $(hexchat_def_CFLAGS)
 
 textenums.h: textevents.h
 
 textevents.h: $(srcdir)/textevents.in make-te
 	$(AM_V_GEN) ./make-te < $< > $@ 2> textenums.h
--- hexchat-2.12.4/src/common/dbus/Makefile.am
+++ hexchat-2.12.4/src/common/dbus/Makefile.am
@@ -1,5 +1,8 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 noinst_LIBRARIES = libhexchatdbus.a
 libhexchatdbus_a_SOURCES =			\
 	dbus-plugin.c				\
 	dbus-plugin.h				\
 	dbus-client.c				\
--- hexchat-2.12.4/src/Makefile.am
+++ hexchat-2.12.4/src/Makefile.am
@@ -1,6 +1,8 @@
 ## Process this file with automake to produce Makefile.in
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
 
 EXTRA_DIST = version-script
 
 if DO_TEXT
 text_fe = fe-text
--- hexchat-2.12.4/src/fe-text/Makefile.am
+++ hexchat-2.12.4/src/fe-text/Makefile.am
@@ -1,5 +1,8 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 localedir = $(datadir)/locale
 
 bin_PROGRAMS = hexchat-text
 
 AM_CPPFLAGS = $(COMMON_CFLAGS) -DLOCALEDIR=\"$(localedir)\"
--- hexchat-2.12.4/src/fe-gtk/Makefile.am
+++ hexchat-2.12.4/src/fe-gtk/Makefile.am
@@ -1,5 +1,7 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
 
 include $(top_srcdir)/m4/clang-analyze.am
 
 localedir = $(datadir)/locale
 
@@ -31,11 +33,11 @@ endif
 if USE_LIBNOTIFY
 notify_c = notifications/notification-libnotify.c
 else
 if HAVE_GTK_MAC
 notify_c = notifications/notification-osx.m
-hexchat_LDFLAGS = -framework Foundation
+hexchat_LDFLAGS = -framework Foundation @hexchat_def_LDFLAGS@
 else
 notify_c = notifications/notification-dummy.c
 endif
 endif
 
--- hexchat-2.12.4/src/htm/Makefile.am
+++ hexchat-2.12.4/src/htm/Makefile.am
@@ -1,5 +1,8 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 theme_SCRIPTS = thememan.exe thememan
 themedir = $(bindir)
 
 mdtool_verbose = $(mdtool_verbose_$(V))
 mdtool_verbose_ = $(mdtool_verbose_$(AM_DEFAULT_VERBOSITY))
--- hexchat-2.12.4/plugins/fishlim/Makefile.am
+++ hexchat-2.12.4/plugins/fishlim/Makefile.am
@@ -1,10 +1,13 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 EXTRA_DIST = LICENSE fish.h irc.h keystore.h plugin_hexchat.h dh1080.h
 
 libdir = $(hexchatlibdir)
 
 lib_LTLIBRARIES = fishlim.la
 fishlim_la_SOURCES = fish.c irc.c keystore.c plugin_hexchat.c dh1080.c
-fishlim_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module
+fishlim_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module @hexchat_def_LDFLAGS@
 fishlim_la_LIBADD = $(GLIB_LIBS) $(OPENSSL_LIBS)
 fishlim_la_CPPFLAGS = -I$(top_srcdir)/src/common
-fishlim_la_CFLAGS = $(GLIB_CFLAGS) $(OPENSSL_CFLAGS)
+fishlim_la_CFLAGS = $(GLIB_CFLAGS) $(OPENSSL_CFLAGS) @hexchat_def_CFLAGS@
--- hexchat-2.12.4/plugins/Makefile.am
+++ hexchat-2.12.4/plugins/Makefile.am
@@ -1,5 +1,8 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 if DO_LUA
 lua = lua
 endif
 
 if DO_PYTHON
--- hexchat-2.12.4/plugins/lua/Makefile.am
+++ hexchat-2.12.4/plugins/lua/Makefile.am
@@ -1,9 +1,12 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 libdir = $(hexchatlibdir)
 
 lib_LTLIBRARIES = lua.la
 lua_la_SOURCES = lua.c
-lua_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module
+lua_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module @hexchat_def_LDFLAGS@
 lua_la_LIBADD = $(LUA_LIBS) $(GLIB_LIBS)
 lua_la_CPPFLAGS = -I$(top_srcdir)/src/common
-lua_la_CFLAGS = $(GLIB_CFLAGS) $(LUA_CFLAGS)
+lua_la_CFLAGS = $(GLIB_CFLAGS) $(LUA_CFLAGS) @hexchat_def_CFLAGS@
 
--- hexchat-2.12.4/plugins/sysinfo/Makefile.am
+++ hexchat-2.12.4/plugins/sysinfo/Makefile.am
@@ -1,5 +1,8 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 libdir = $(hexchatlibdir)
 
 sources = sysinfo.c format.c shared/df.c
 
 if PLATFORM_OSX
@@ -10,8 +13,8 @@ endif
 
 EXTRA_DIST = osx unix win32 shared format.h sysinfo.h sysinfo-backend.h
 
 lib_LTLIBRARIES = sysinfo.la
 sysinfo_la_SOURCES = $(sources)
-sysinfo_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module
+sysinfo_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module @hexchat_def_LDFLAGS@
 sysinfo_la_LIBADD = $(LIBPCI_LIBS) $(GLIB_LIBS)
 AM_CPPFLAGS = -I$(top_srcdir)/src/common -I$(srcdir)/shared $(LIBPCI_CFLAGS) $(GLIB_CFLAGS)
--- hexchat-2.12.4/plugins/python/Makefile.am
+++ hexchat-2.12.4/plugins/python/Makefile.am
@@ -1,9 +1,12 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 libdir = $(hexchatlibdir)
 
 lib_LTLIBRARIES = python.la
 python_la_SOURCES = python.c
 python_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module
-python_la_LIBADD = $(PYTHON_LIBS) $(GLIB_LIBS)
+python_la_LIBADD = $(PYTHON_LIBS) $(GLIB_LIBS) @hexchat_def_LDFLAGS@
 python_la_CPPFLAGS = -I$(top_srcdir)/src/common $(PYTHON_CPPFLAGS)
-python_la_CFLAGS = $(GLIB_CFLAGS)
+python_la_CFLAGS = $(GLIB_CFLAGS) @hexchat_def_CFLAGS@
 
--- hexchat-2.12.4/plugins/checksum/Makefile.am
+++ hexchat-2.12.4/plugins/checksum/Makefile.am
@@ -1,8 +1,11 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
+
 libdir = $(hexchatlibdir)
 
 lib_LTLIBRARIES = checksum.la
 checksum_la_SOURCES = checksum.c
-checksum_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module
+checksum_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module @hexchat_def_LDFLAGS@
 checksum_la_LIBADD = $(GLIB_LIBS)
 checksum_la_CPPFLAGS = -I$(top_srcdir)/src/common
-checksum_la_CFLAGS = $(GLIB_CFLAGS)
+checksum_la_CFLAGS = $(GLIB_CFLAGS) @hexchat_def_CFLAGS@
--- hexchat-2.12.4/plugins/perl/Makefile.am
+++ hexchat-2.12.4/plugins/perl/Makefile.am
@@ -1,17 +1,19 @@
+AM_CFLAGS = @hexchat_def_CFLAGS@
+AM_LDFLAGS = @hexchat_def_LDFLAGS@
 
 EXTRA_DIST=generate_header lib/HexChat.pm lib/Xchat.pm lib/HexChat/Embed.pm lib/HexChat/List/Network.pm \
 	lib/HexChat/List/Network/Entry.pm lib/HexChat/List/Network/AutoJoin.pm lib/IRC.pm
 
 libdir = $(hexchatlibdir)
 
 lib_LTLIBRARIES = perl.la
 perl_la_SOURCES = perl.c
-perl_la_LDFLAGS = $(PERL_LDFLAGS) $(PLUGIN_LDFLAGS) -module
+perl_la_LDFLAGS = $(PERL_LDFLAGS) $(PLUGIN_LDFLAGS) -module @hexchat_def_LDFLAGS@
 perl_la_LIBADD = $(GLIB_LIBS)
 perl_la_CPPFLAGS = -I$(top_srcdir)/src/common
-perl_la_CFLAGS = $(PERL_CFLAGS) $(GLIB_CFLAGS)
+perl_la_CFLAGS = $(PERL_CFLAGS) $(GLIB_CFLAGS) @hexchat_def_CFLAGS@
 
 BUILT_SOURCES = hexchat.pm.h irc.pm.h
 CLEANFILES = $(BUILT_SOURCES)
 
 hexchat.pm.h irc.pm.h: lib/HexChat.pm lib/Xchat.pm lib/HexChat/Embed.pm \
