res_pjsip_outbound_authenticator_digest.c: Fix memory pool leak.
[asterisk/asterisk.git] / third-party / pjproject / Makefile
1 .PHONY: _all all _install install clean distclean echo_cflags configure
2
3 include ../versions.mak
4 export PJDIR := $(shell pwd -P)/source
5
6 SPECIAL_TARGETS :=
7
8 ifneq ($(findstring configure,$(MAKECMDGOALS))$(findstring echo_cflags,$(MAKECMDGOALS)),)
9 # Run from $(ASTTOPDIR)/configure
10     SPECIAL_TARGETS += configure
11 endif
12
13 ifeq ($(findstring echo_cflags,$(MAKECMDGOALS)),echo_cflags)
14     -include build.mak
15     ECHO_PREFIX=@\#
16 endif
17
18 ifeq ($(findstring clean,$(MAKECMDGOALS)),clean)
19 # clean or distclean
20     SPECIAL_TARGETS += clean
21 endif
22
23 ifneq ($(wildcard ../../makeopts),)
24     include ../../makeopts
25 endif
26
27 TARGETS = build.mak
28
29 ifeq ($(SPECIAL_TARGETS),)
30 # Run locally or from $(ASTTOPDIR)/Makefile.  All include files should be present
31     ifeq ($(wildcard ../../makeopts),)
32         $(error ASTTOPDIR/configure hasn't been run)
33     endif
34
35     ifeq ($(PJPROJECT_BUNDLED),yes)
36         ifneq ($(wildcard ../../menuselect.makeopts),)
37             include ../../menuselect.makeopts
38         else
39             $(warning ASTTOPDIR/menuselect hasn't been run yet.  Can't find debug options.)
40         endif
41
42         all: _all
43         install: _install
44
45         include source/user.mak
46         include source/version.mak
47         include source/build.mak
48         CF := $(filter-out -W%,$(CC_CFLAGS))
49         CF := $(filter-out -I%,$(CF))
50         ifeq ($(findstring TEST_FRAMEWORK,$(MENUSELECT_CFLAGS)),TEST_FRAMEWORK)
51             apps := source/pjsip-apps/bin/pjsua-$(TARGET_NAME) source/pjsip-apps/bin/pjsystest-$(TARGET_NAME)
52             TARGETS += $(apps)
53             ifneq ($(PYTHONDEV_LIB),)
54                 TARGETS += source/pjsip-apps/src/python/_pjsua.so
55             endif
56         endif
57         ifeq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),MALLOC_DEBUG)
58             CF += -DMALLOC_DEBUG
59             MALLOC_DEBUG = yes
60             $(apps): export LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
61             $(apps): source/pjsip-apps/lib/libasterisk_malloc_debug.a
62             source/pjsip-apps/src/python/_pjsua.so: LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
63             source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/lib/libasterisk_malloc_debug.a
64         endif
65         TARGETS += pjproject.symbols
66         export CFLAGS += $(CF)
67         export LDFLAGS += $(CC_LDFLAGS)
68     else
69         all install:
70     endif
71 endif
72
73 include ../../Makefile.rules
74 include ../Makefile.rules
75 include Makefile.rules
76
77 ECHO_PREFIX := $(ECHO_PREFIX) echo '[pjproject] '
78
79 _all: $(TARGETS)
80
81 DOWNLOAD_DIR := $(or $(EXTERNALS_CACHE_DIR),$(TMPDIR),$(wildcard /tmp),.)
82
83 $(DOWNLOAD_DIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2: ../versions.mak
84         $(ECHO_PREFIX) Downloading $(PJPROJECT_URL)/$(@F) to $@
85         $(CMD_PREFIX) $(DOWNLOAD_TO_STDOUT) $(PJPROJECT_URL)/$(@F) > $@
86
87 source/.unpacked: $(DOWNLOAD_DIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
88         $(ECHO_PREFIX) Unpacking $<
89         -@rm -rf source pjproject-* >/dev/null 2>&1
90         $(CMD_PREFIX) $(TAR) -xjf $<
91         @mv pjproject-$(PJPROJECT_VERSION) source
92         $(ECHO_PREFIX) Applying patches
93         $(CMD_PREFIX) ./apply_patches $(QUIET_CONFIGURE) patches source
94         -@touch source/.unpacked
95
96 source/version.mak: source/.unpacked
97
98 source/user.mak: source/.unpacked patches/user.mak
99         $(ECHO_PREFIX) Applying user.mak
100         $(CMD_PREFIX) cp -f patches/user.mak source/
101
102 source/pjlib/include/pj/%.h: patches/%.h
103         $(ECHO_PREFIX) Applying custom include file $<
104         $(CMD_PREFIX) cp -f $< source/pjlib/include/pj/
105
106 .rebuild_needed: $(wildcard ../../makeopts) $(wildcard ../../menuselect.makeopts)
107         $(ECHO_PREFIX) Rebuilding
108         $(CMD_PREFIX) $(MAKE) clean $(REALLY_QUIET)
109         @touch  .rebuild_needed
110
111 source/build.mak: Makefile.rules source/version.mak source/user.mak $(addprefix source/pjlib/include/pj/,$(notdir $(wildcard patches/*.h))) .rebuild_needed
112         $(ECHO_PREFIX) Configuring with $(PJPROJECT_CONFIG_OPTS)
113         $(CMD_PREFIX) (cd source ; ./aconfigure $(QUIET_CONFIGURE) $(PJPROJECT_CONFIG_OPTS))
114
115 build.mak: source/build.mak
116         $(CMD_PREFIX) $(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
117
118 configure: source/build.mak
119
120 echo_cflags: source/build.mak
121         @echo $(PJ_CFLAGS)
122
123 libpj%.a: source/build.mak
124         $(ECHO_PREFIX) Compiling lib $(@F)
125         $(CMD_PREFIX) $(MAKE) -C $(dir $(shell dirname $@))/build $(@F) $(REALLY_QUIET)
126         -@rm -rf .rebuild_needed
127
128 # pjsua needs resample and g711 to successfully run the testsuite
129 libresample%.a: .rebuild_needed source/build.mak
130         $(ECHO_PREFIX) Compiling lib $(@F)
131         $(CMD_PREFIX) $(MAKE) -C $(dir $(shell dirname $@))/build/resample all $(REALLY_QUIET)
132         -@rm -rf .rebuild_needed
133
134 # We need to compile pjlib, then pjlib-util, then the rest
135 # so we separate them out and create the dependencies
136 PJLIB_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpj-,$(lib)),$(lib),))
137 PJLIB_UTIL_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpjlib-util,$(lib)),$(lib),))
138 PJSIP_LIB_FILES = $(filter-out $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES) $(APP_THIRD_PARTY_LIB_FILES),$(PJ_LIB_FILES))
139 ALL_LIB_FILES = $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES) $(PJSIP_LIB_FILES)
140
141 $(PJLIB_UTIL_LIB_FILES): $(PJLIB_LIB_FILES)
142 $(PJSIP_LIB_FILES): $(PJLIB_UTIL_LIB_FILES)
143
144 pjproject.symbols: $(ALL_LIB_FILES)
145         $(ECHO_PREFIX) Generating symbols
146         $(CMD_PREFIX) $(NM) -Pog $(ALL_LIB_FILES) | $(SED) -n -r -e "s/.+: ([pP][jJ][^ ]+) .+/\1/gp" | sort -u > pjproject.symbols
147
148 source/pjsip-apps/src/asterisk_malloc_debug.c: patches/asterisk_malloc_debug.c
149         $(ECHO_PREFIX) Copying $< to $@
150         $(CMD_PREFIX) cp -f $< $@
151
152 source/pjsip-apps/lib/asterisk_malloc_debug.o: source/pjsip-apps/src/asterisk_malloc_debug.c .rebuild_needed
153         $(ECHO_PREFIX) Compiling asterisk debug malloc stubs
154         $(CMD_PREFIX) $(CC) -fPIC  $(PJ_CFLAGS) -c $< -o $@
155
156 source/pjsip-apps/lib/libasterisk_malloc_debug.a: source/pjsip-apps/lib/asterisk_malloc_debug.o
157         $(ECHO_PREFIX) Creating archive $(@F)
158         $(CMD_PREFIX) ar qs $@ $< >/dev/null 2>&1
159
160 $(apps): APP = $(filter pj%,$(subst -, ,$(notdir $@)))
161 $(apps): pjproject.symbols $(APP_THIRD_PARTY_LIB_FILES)
162         $(ECHO_PREFIX) Compiling $(APP)
163         $(CMD_PREFIX) +$(MAKE) -C source/pjsip-apps/build $(filter pj%,$(subst -, ,$(notdir $@))) $(REALLY_QUIET)
164
165 source/pjsip-apps/src/python/_pjsua.o: source/pjsip-apps/src/python/_pjsua.c $(apps)
166         $(ECHO_PREFIX) Compiling python bindings
167         $(CMD_PREFIX) $(CC) -o $@ -c $< $(PYTHONDEV_INCLUDE) $(CFLAGS) $(PJ_CFLAGS)
168
169 source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/src/python/_pjsua.o
170         $(ECHO_PREFIX) Linking python bindings $(@F)
171         $(CMD_PREFIX) gcc -shared -pthread -o $@ $< $(LDFLAGS) $(PJ_LDFLAGS) $(APP_LDLIBS) $(PYTHONDEV_LIB) $(REALLY_QUIET)
172
173 _install: _all
174         @if [ ! -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject" ]; then \
175                 $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject"; \
176         fi;
177 ifneq ($(findstring source/pjsip-apps/bin/pjsua-$(TARGET_NAME),$(TARGETS)),)
178         $(ECHO_PREFIX) Installing apps
179         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsua-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsua"
180         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsystest-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsystest"
181 endif
182 ifneq ($(findstring _pjsua.so,$(TARGETS)),)
183         $(ECHO_PREFIX) Installing python bindings
184         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
185         $(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
186 endif
187
188 uninstall:
189         $(ECHO_PREFIX) Uninstalling apps and python bindings
190         $(CMD_PREFIX) rm -rf "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject"
191
192 clean:
193         $(ECHO_PREFIX) Cleaning
194         +-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean || : ;\
195                 rm -rf source/pjsip-apps/bin/* || : ;\
196                 find source -name *.a -delete ;\
197                 find source -name *.o -delete ;\
198                 find source -name *.so -delete ; ) || :
199         -$(CMD_PREFIX) rm -rf pjproject.symbols
200
201 distclean:
202         $(ECHO_PREFIX) Distcleaning
203         -$(CMD_PREFIX) rm -rf source pjproject.symbols pjproject-*.tar.bz2 build.mak .rebuild_needed