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