Skip to content
Snippets Groups Projects
Commit c5e8f501 authored by George Joseph's avatar George Joseph
Browse files

pjproject_bundled: Add MALLOC_DEBUG capability

pjproject_bundled will now use the asterisk memory debugging APIs
if MALLOC_DEBUG is turned on in menuselect.

Because this required stubs for the executable programs and the python
bindings, some Makefile reorganization was needed to properly handle
the dependencies.  As a result, the makefile now individually makes
each of the pjproject libraries separately instead of making them all
in 1 shot.  The only visible change is that there are separate status
lines printed for each library instead oif 1 for all libs.  Also, the
making of the pjproject dependency files was eliminated.  They're not
needed for building unless you're actively modifying pjproject source
files and it makes the build process faster.  Finally, any issues with
parallel builds should be resolved again making the build faster.

Change-Id: Icc5e3d658fbfb00e0a46b44c66dcc2522d5171b0
parent 55e8c9ef
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ SUBMAKE?=$(MAKE) --quiet --no-print-directory
ECHO_PREFIX?=@
CMD_PREFIX?=@
QUIET_CONFIGURE=-q
REALLY_QUIET=&>/dev/null
REALLY_QUIET=>/dev/null 2>&1
else
SUBMAKE?=$(MAKE)
ECHO_PREFIX?=@\#
......
......@@ -2,3 +2,4 @@ source/
**.bz2
build.mak
pjproject.symbols
.rebuild_needed
.SUFFIXES:
.PHONY: _all all _install install clean distclean echo_cflags configure
include ../versions.mak
......@@ -40,18 +39,28 @@ ifeq ($(SPECIAL_TARGETS),)
include ../../Makefile.rules
include Makefile.rules
include build.mak
include source/user.mak
include source/build.mak
CF := $(filter-out -W%,$(CC_CFLAGS))
CF := $(filter-out -I%,$(CF))
export CFLAGS += $(CF)
export LDFLAGS += $(CC_LDFLAGS)
TARGETS := pjproject.symbols
ifeq ($(findstring TEST_FRAMEWORK,$(MENUSELECT_CFLAGS)),TEST_FRAMEWORK)
TARGETS += source/pjsip-apps/bin/pjsua-$(TARGET_NAME)
apps := source/pjsip-apps/bin/pjsua-$(TARGET_NAME) source/pjsip-apps/bin/pjsystest-$(TARGET_NAME)
TARGETS += $(apps)
ifneq ($(PYTHONDEV_LIB),)
TARGETS += source/pjsip-apps/src/python/build/_pjsua.so
TARGETS += source/pjsip-apps/src/python/_pjsua.so
endif
endif
ifeq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),MALLOC_DEBUG)
CF += -DMALLOC_DEBUG
MALLOC_DEBUG = yes
$(apps): export LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
$(apps): source/pjsip-apps/lib/libasterisk_malloc_debug.a
source/pjsip-apps/src/python/_pjsua.so: LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/lib/libasterisk_malloc_debug.a
endif
TARGETS += pjproject.symbols
export CFLAGS += $(CF)
export LDFLAGS += $(CC_LDFLAGS)
else
all install:
endif
......@@ -73,8 +82,8 @@ $(TMPDIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2 : ../versions.mak
source/.unpacked: $(TMPDIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
$(ECHO_PREFIX) Unpacking $<
-@rm -rf source &>/dev/null
-@mkdir source &>/dev/null
-@rm -rf source >/dev/null 2>&1
-@mkdir source >/dev/null 2>&1
$(CMD_PREFIX) tar --strip-components=1 -C source -xjf $<
$(ECHO_PREFIX) Applying patches
$(CMD_PREFIX) ./apply_patches $(QUIET_CONFIGURE) ./patches ./source
......@@ -84,11 +93,11 @@ source/user.mak: source/.unpacked ./patches/user.mak
$(ECHO_PREFIX) Applying user.mak
$(CMD_PREFIX) cp -f ./patches/user.mak ./source/
source/pjlib/include/pj/config_site.h: source/.unpacked ./patches/config_site.h
$(ECHO_PREFIX) Applying config_site.h
$(CMD_PREFIX) cp -f ./patches/config_site.h ./source/pjlib/include/pj/
source/pjlib/include/pj/%.h : ./patches/%.h
$(ECHO_PREFIX) Applying custom include file $<
$(CMD_PREFIX) cp -f $< ./source/pjlib/include/pj/
build.mak: source/.unpacked source/pjlib/include/pj/config_site.h source/user.mak Makefile.rules
build.mak: source/.unpacked $(addprefix source/pjlib/include/pj/,$(notdir $(wildcard ./patches/*.h))) source/user.mak Makefile.rules
$(ECHO_PREFIX) Configuring with $(PJPROJECT_CONFIG_OPTS)
$(CMD_PREFIX) (cd source ; autoconf aconfigure.ac > aconfigure && ./aconfigure $(QUIET_CONFIGURE) $(PJPROJECT_CONFIG_OPTS))
@sed -r -e "/prefix|export PJ_SHARED_LIBRARIES|MACHINE_NAME|OS_NAME|HOST_NAME|CC_NAME|CROSS_COMPILE|LINUX_POLL/d" source/build.mak > build.mak
......@@ -98,29 +107,53 @@ configure: build.mak
echo_cflags: build.mak
@echo $(PJ_CFLAGS)
source/pjlib/build/.pjlib-$(TARGET_NAME).depend: build.mak
$(ECHO_PREFIX) "Making dependencies"
+$(CMD_PREFIX) $(SUBMAKE) -C source dep
.rebuild_needed: ../../menuselect.makeopts
$(ECHO_PREFIX) Rebuilding
$(CMD_PREFIX)$(MAKE) clean $(REALLY_QUIET)
@touch .rebuild_needed
menuselect: ../../menuselect.makeopts ../../makeopts
-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build) || :
-$(CMD_PREFIX) rm -rf pjproject.symbols
libpj%.a: .rebuild_needed build.mak
$(ECHO_PREFIX) Compiling lib $(@F)
$(CMD_PREFIX)$(MAKE) -C $(dir $(shell dirname $@))/build $(@F) $(REALLY_QUIET)
source/pjlib/lib/libpj-$(TARGET_NAME).a: menuselect source/pjlib/build/.pjlib-$(TARGET_NAME).depend
$(ECHO_PREFIX) Compiling libs
+$(CMD_PREFIX) $(SUBMAKE) -C source lib $(REALLY_QUIET)
# We need to compile pjlib, then pjlib-util, then the rest
# so we separate them out and create the dependencies
PJLIB_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpj-,$(lib)),$(lib),))
PJLIB_UTIL_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpjlib-util,$(lib)),$(lib),))
LIB_FILES = $(filter-out $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES),$(PJ_LIB_FILES))
ALL_LIB_FILES = $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES) $(LIB_FILES)
pjproject.symbols: source/pjlib/lib/libpj-$(TARGET_NAME).a
$(PJLIB_UTIL_LIB_FILES): $(PJLIB_LIB_FILES)
$(LIB_FILES): $(PJLIB_UTIL_LIB_FILES)
pjproject.symbols: $(ALL_LIB_FILES)
$(ECHO_PREFIX) Generating symbols
$(CMD_PREFIX) nm -Pog $(PJ_LIB_FILES) | sed -n -r -e "s/.+: ([pP][jJ][^ ]+) .+/\1/gp" | sort -u > pjproject.symbols
$(CMD_PREFIX) nm -Pog $(ALL_LIB_FILES) | sed -n -r -e "s/.+: ([pP][jJ][^ ]+) .+/\1/gp" | sort -u > pjproject.symbols
source/pjsip-apps/src/asterisk_malloc_debug.c: patches/asterisk_malloc_debug.c
$(ECHO_PREFIX) Copying $< to $@
$(CMD_PREFIX) cp -f $< $@
source/pjsip-apps/lib/asterisk_malloc_debug.o: source/pjsip-apps/src/asterisk_malloc_debug.c .rebuild_needed
$(ECHO_PREFIX) Compiling asterisk debug malloc stubs
$(CMD_PREFIX) $(CC) -fPIC $(PJ_CFLAGS) -c $< -o $@
source/pjsip-apps/bin/pjsua-$(TARGET_NAME): source/pjlib/lib/libpj-$(TARGET_NAME).a
$(ECHO_PREFIX) Compiling apps
$(CMD_PREFIX) $(SUBMAKE) -C source/pjsip-apps/build pjsua pjsystest $(REALLY_QUIET)
source/pjsip-apps/lib/libasterisk_malloc_debug.a: source/pjsip-apps/lib/asterisk_malloc_debug.o
$(ECHO_PREFIX) Creating archive $(@F)
$(CMD_PREFIX) ar qs $@ $< >/dev/null 2>&1
source/pjsip-apps/src/python/build/_pjsua.so: source/pjlib/lib/libpj-$(TARGET_NAME).a
$(apps): APP = $(filter pj%,$(subst -, ,$(notdir $@)))
$(apps): pjproject.symbols
$(ECHO_PREFIX) Compiling $(APP)
$(CMD_PREFIX) +$(MAKE) -C source/pjsip-apps/build $(filter pj%,$(subst -, ,$(notdir $@))) $(REALLY_QUIET)
source/pjsip-apps/src/python/_pjsua.o: source/pjsip-apps/src/python/_pjsua.c $(apps)
$(ECHO_PREFIX) Compiling python bindings
$(CMD_PREFIX) (cd source/pjsip-apps/src/python ; MAKE=$(MAKE) python setup.py build --build-platlib=./build $(REALLY_QUIET))
$(CMD_PREFIX) $(CC) -o $@ -c $< $(PYTHONDEV_INCLUDE) $(CFLAGS) $(PJ_CFLAGS)
source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/src/python/_pjsua.o
$(ECHO_PREFIX) Linking python bindings $(@F)
$(CMD_PREFIX) gcc -shared -pthread -o $@ $< $(LDFLAGS) $(PJ_LDFLAGS) $(APP_LDLIBS) $(PYTHONDEV_LIB) $(REALLY_QUIET)
_all: $(TARGETS)
......@@ -133,10 +166,10 @@ ifneq ($(findstring source/pjsip-apps/bin/pjsua-$(TARGET_NAME),$(TARGETS)),)
$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsua-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsua"
$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsystest-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsystest"
endif
ifneq ($(findstring source/pjsip-apps/src/python/build/_pjsua.so,$(TARGETS)),)
ifneq ($(findstring _pjsua.so,$(TARGETS)),)
$(ECHO_PREFIX) Installing python bindings
$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/build/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
$(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/build/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
$(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
$(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
endif
uninstall:
......@@ -145,10 +178,14 @@ uninstall:
clean:
$(ECHO_PREFIX) Cleaning
-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build ; rm -rf source/pjsip-apps/bin/* ) || :
+-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean || : ;\
rm -rf source/pjsip-apps/bin/* || : ;\
find source -name *.a -delete ;\
find source -name *.o -delete ;\
find source -name *.so -delete ; ) || :
-$(CMD_PREFIX) rm -rf pjproject.symbols
distclean:
$(ECHO_PREFIX) Distcleaning
-$(CMD_PREFIX) rm -rf source pjproject.symbols pjproject-*.tar.bz2 build.mak
-$(CMD_PREFIX) rm -rf source pjproject.symbols pjproject-*.tar.bz2 build.mak .rebuild_needed
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2016, Digium, Inc
*
* George Joseph <gjoseph@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
{
va_list ap;
int rc = 0;
va_start(ap, format);
rc = vasprintf(strp, format, ap);
va_end(ap);
return rc;
}
void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
{
return calloc(nmemb, size);
}
void __ast_free(void *ptr, const char *file, int lineno, const char *func)
{
free(ptr);
}
void *__ast_malloc(size_t size, const char *file, int lineno, const char *func)
{
return malloc(size);
}
void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
{
return realloc(ptr, size);
}
char *__ast_strdup(const char *s, const char *file, int lineno, const char *func)
{
return strdup(s);
}
char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func)
{
return strndup(s, n);
}
int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
{
return vasprintf(strp, format, ap);
}
/*
* Copyright (C) 2016 George Joseph <gjoseph@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
#ifndef ASTERISK_MALLOC_DEBUG_H_
#define ASTERISK_MALLOC_DEBUG_H_
/* Include these now to prevent them from messing up MALLOC_DEBUG */
#include <sys/types.h>
#include <pj/compat/string.h>
#include <pj/compat/stdarg.h>
#include <pj/compat/malloc.h>
#ifdef __cplusplus
extern "C" {
#endif
int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
__attribute__((format(printf, 5, 6)));
void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
void __ast_free(void *ptr, const char *file, int lineno, const char *func);
void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
__attribute__((format(printf, 2, 0)));
/* Undefine any macros */
#undef asprintf
#undef calloc
#undef free
#undef malloc
#undef realloc
#undef strdup
#undef strndup
#undef vasprintf
/* Provide our own definitions */
#define asprintf(a, b, c...) \
__ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
#define calloc(a,b) \
__ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define free(a) \
__ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define malloc(a) \
__ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define realloc(a,b) \
__ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define strdup(a) \
__ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define strndup(a,b) \
__ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define vasprintf(a,b,c) \
__ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#ifdef __cplusplus
}
#endif
#endif /* ASTERISK_MALLOC_DEBUG_H_ */
......@@ -4,6 +4,14 @@
#include <sys/select.h>
/*
* Since both pjproject and asterisk source files will include config_site.h,
* we need to make sure that only pjproject source files include asterisk_malloc_debug.h.
*/
#if defined(MALLOC_DEBUG) && !defined(_ASTERISK_ASTMM_H)
#include "asterisk_malloc_debug.h"
#endif
/*
* Defining PJMEDIA_HAS_SRTP to 0 does NOT disable Asterisk's ability to use srtp.
* It only disables the pjmedia srtp transport which Asterisk doesn't use.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment