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