# Helpful functions
# call with $(call function,...)
tolower = $(shell echo $(1) | tr '[:upper:]' '[:lower:]')
+# Takes a list of MENUSELECT_CFLAG Id and returns CFLAGS to declare
+# the ones which are enabled.
+get_menuselect_cflags=$(patsubst %,-D%,$(filter $1,$(MENUSELECT_CFLAGS)))
.PHONY: dist-clean
TMP=`${GREP} -e "^MENUSELECT_CFLAGS" menuselect.makeopts | sed 's/MENUSELECT_CFLAGS\=//g' | sed 's/-D//g'`
for x in ${TMP}; do
- echo "#define ${x} 1"
if test "${x}" = "AO2_DEBUG" \
-o "${x}" = "BETTER_BACKTRACES" \
-o "${x}" = "BUILD_NATIVE" \
+ -o "${x}" = "COMPILE_DOUBLE" \
+ -o "${x}" = "DEBUG_CHAOS" \
-o "${x}" = "DEBUG_SCHEDULER" \
-o "${x}" = "DETECT_DEADLOCKS" \
-o "${x}" = "DONT_OPTIMIZE" \
-o "${x}" = "DUMP_SCHEDULER" \
-o "${x}" = "LOTS_OF_SPANS" \
- -o "${x}" = "LOW_MEMORY" \
-o "${x}" = "MALLOC_DEBUG" \
-o "${x}" = "RADIO_RELAX" \
-o "${x}" = "REBUILD_PARSERS" \
- -o "${x}" = "REF_DEBUG" ; then
- # These aren't ABI affecting options, keep them out of AST_BUILDOPTS
+ -o "${x}" = "REF_DEBUG" \
+ -o "${x}" = "USE_HOARD_ALLOCATOR" ; then
+ # These options are only for specific sources and have no effect on public ABI.
+ # Keep them out of buildopts.h so ccache does not invalidate all sources.
+ continue
+ fi
+
+ echo "#define ${x} 1"
+ if test "${x}" = "LOW_MEMORY" ; then
+ # LOW_MEMORY isn't an ABI affecting option but it is used in many sources
+ # so it gets defined globally but is not included in AST_BUILTOPTS.
continue
fi
if test "x${BUILDOPTS}" != "x" ; then
$(call MOD_ADD_C,chan_dahdi,$(wildcard dahdi/*.c) sig_analog.c sig_pri.c sig_ss7.c)
$(call MOD_ADD_C,chan_misdn,misdn_config.c misdn/isdn_lib.c misdn/isdn_msg_parser.c)
+chan_dahdi.o: _ASTCFLAGS+=$(call get_menuselect_cflags,LOTS_OF_SPANS)
chan_mgcp.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
chan_unistim.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
chan_phone.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
int aco_init(void); /*!< Provided by config_options.c */
int dns_core_init(void); /*!< Provided by dns_core.c */
+/*!
+ * \brief Initialize malloc debug phase 1.
+ *
+ * \note Must be called first thing after forking.
+ *
+ * \return Nothing
+ */
+void load_astmm_phase_1(void);
+
+/*!
+ * \brief Initialize malloc debug phase 2.
+ *
+ * \return Nothing
+ */
+void load_astmm_phase_2(void);
+
/*!
* \brief Initialize the bridging system.
* \since 12.0.0
#define _ASTERISK_ASTMM_H
/* IWYU pragma: private, include "asterisk.h" */
-#if defined(MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2)
-#define __AST_DEBUG_MALLOC
-
-void __ast_mm_init_phase_1(void);
-void __ast_mm_init_phase_2(void);
-#endif
-
void *ast_std_malloc(size_t size) attribute_malloc;
void *ast_std_calloc(size_t nmemb, size_t size) attribute_malloc;
void *ast_std_realloc(void *ptr, size_t size);
$(CMD_PREFIX) cat $@.fix >> $@
$(CMD_PREFIX) rm $@.fix
-ast_expr2f.o: _ASTCFLAGS+=-Wno-unused
-cdr.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
+ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
+GMIMELDFLAGS+=$(GMIME_LIB)
+GMIMECFLAGS+=$(GMIME_INCLUDE)
+endif
+
+# Alter CFLAGS for specific sources
+stdtime/localtime.o: _ASTCFLAGS+=$(AST_NO_STRICT_OVERFLOW) -Wno-format-nonliteral
-db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
asterisk.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
-json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
+ast_expr2f.o: _ASTCFLAGS+=-Wno-unused
+astmm.o: _ASTCFLAGS+=$(call get_menuselect_cflags,MALLOC_DEBUG DEBUG_CHAOS)
+astobj2.o astobj2_container.o astobj2_hash.o astobj2_rbtree.o: _ASTCFLAGS+=$(call get_menuselect_cflags,AO2_DEBUG)
+backtrace.o: _ASTCFLAGS+=$(call get_menuselect_cflags,BETTER_BACKTRACES)
bucket.o: _ASTCFLAGS+=$(URIPARSER_INCLUDE)
+cdr.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
crypt.o: _ASTCFLAGS+=$(CRYPT_INCLUDE)
+db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
+dsp.o: _ASTCFLAGS+=$(call get_menuselect_cflags,RADIO_RELAX)
+http.o: _ASTCFLAGS+=$(GMIMECFLAGS)
+iostream.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
+json.o: _ASTCFLAGS+=$(JANSSON_INCLUDE)
+lock.o: _ASTCFLAGS+=$(call get_menuselect_cflags,DETECT_DEADLOCKS)
+options.o: _ASTCFLAGS+=$(call get_menuselect_cflags,REF_DEBUG)
+sched.o: _ASTCFLAGS+=$(call get_menuselect_cflags,DEBUG_SCHEDULER DUMP_SCHEDULER)
+tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) -Wno-deprecated-declarations
uuid.o: _ASTCFLAGS+=$(UUID_INCLUDE)
-ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
-http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)
-endif
-
-stdtime/localtime.o: _ASTCFLAGS+=$(AST_NO_STRICT_OVERFLOW) -Wno-format-nonliteral
OBJS:=$(sort $(OBJS))
MAIN_TGT:=asterisk
endif
-ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
-GMIMELDFLAGS+=$(GMIME_LIB)
-endif
-
$(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\" -DAST_IN_CORE
$(MOD_OBJS): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)
endif
-iostream.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
-tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE) -Wno-deprecated-declarations
-
$(MAIN_TGT): $(OBJS) $(MOD_OBJS) $(ASTSSL_LIB) $(ASTPJ_LIB)
@$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
$(ECHO_PREFIX) echo " [LD] $(OBJS) $(MOD_OBJS) -> $@"
* an Asterisk instance, and that there isn't one already running. */
multi_thread_safe = 1;
-#if defined(__AST_DEBUG_MALLOC)
- __ast_mm_init_phase_1();
-#endif /* defined(__AST_DEBUG_MALLOC) */
+ load_astmm_phase_1();
/* Check whether high prio was succesfully set by us or some
* other incantation. */
pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
-#if defined(__AST_DEBUG_MALLOC)
- __ast_mm_init_phase_2();
-#endif /* defined(__AST_DEBUG_MALLOC) */
+ load_astmm_phase_2();
ast_cli_register_multiple(cli_asterisk_shutdown, ARRAY_LEN(cli_asterisk_shutdown));
ast_cli_register_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk));
#define ASTMM_LIBC ASTMM_IGNORE
#include "asterisk.h"
+#include "asterisk/_private.h"
#include "asterisk/logger.h"
/*!
#define ast_log_safe ast_log
#endif
+#if defined(MALLOC_DEBUG) && !defined(STANDALONE) && !defined(STANDALONE2)
+#define __AST_DEBUG_MALLOC
+#endif
+
#define MALLOC_FAILURE_MSG \
ast_log_safe(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file)
}
}
-/*!
- * \brief Initialize malloc debug phase 1.
- *
- * \note Must be called first thing in main().
- *
- * \return Nothing
- */
-void __ast_mm_init_phase_1(void)
+void load_astmm_phase_1(void)
{
atexit(mm_atexit_final);
}
ast_cli_unregister_multiple(cli_memory, ARRAY_LEN(cli_memory));
}
-/*!
- * \brief Initialize malloc debug phase 2.
- *
- * \return Nothing
- */
-void __ast_mm_init_phase_2(void)
+void load_astmm_phase_2(void)
{
char filename[PATH_MAX];
#else /* !defined(__AST_DEBUG_MALLOC) */
+void load_astmm_phase_1(void)
+{
+}
+
+void load_astmm_phase_2(void)
+{
+}
+
void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
{
DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
include $(ASTTOPDIR)/Makefile.moddir_rules
+test_astobj2.o: _ASTCFLAGS+=$(call get_menuselect_cflags,AO2_DEBUG)
test_strings.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION) $(AST_NO_STRINGOP_TRUNCATION)
test_voicemail_api.o: _ASTCFLAGS+=$(AST_NO_FORMAT_TRUNCATION)
ifeq ($(AST_DEVMODE),yes)
CF += -DPJPROJECT_BUNDLED_ASSERTIONS=yes
endif
- ifeq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),MALLOC_DEBUG)
- CF += -DMALLOC_DEBUG
- endif
MALLOC_DEBUG_LIBS = source/pjsip-apps/lib/libasterisk_malloc_debug.a
MALLOC_DEBUG_LDFLAGS = -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS)),)
$(CMD_PREFIX) cp "$<" "$@"
+extconf.o: _ASTCFLAGS+=$(call get_menuselect_cflags,DETECT_DEADLOCKS)
extconf.o: extconf.c
conf2ael: LIBS+=$(AST_CLANG_BLOCKS_LIBS)