pjproject_bundled: Make build single threaded
[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 ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),MALLOC_DEBUG)
65             CF += -DMALLOC_DEBUG
66             MALLOC_DEBUG = yes
67             $(apps): export LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
68             $(apps): source/pjsip-apps/lib/libasterisk_malloc_debug.a
69             source/pjsip-apps/src/python/_pjsua.so: LDFLAGS += -L$(PJDIR)/pjsip-apps/lib -Wl,-whole-archive -lasterisk_malloc_debug -Wl,-no-whole-archive
70             source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/lib/libasterisk_malloc_debug.a
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 verify_tarball
93         ($(SHELL_ECHO_PREFIX) Verifying $(TARBALL) &&\
94         tarball_sum=$$($(CAT) $(TARBALL) | $(MD5) | $(SED) -n -r -e "s/^([^ ]+)\s+.*/\1/gp") ;\
95         required_sum=$$($(SED) -n -r -e "s/^([^ ]+)\s+$(TARBALL_FILE)/\1/gp" $(PJMD5SUM)) ;\
96         if [ "$$tarball_sum" != "$$required_sum" ] ; then $(SHELL_ECHO_PREFIX) Verify failed ; exit 1 ;\
97         else $(SHELL_ECHO_PREFIX) Verify successful ; exit 0 ; fi; )
98 endef
99
100 define download_from_pjproject
101         ($(SHELL_ECHO_PREFIX) Downloading $(TARBALL_URL) to $(TARBALL) ;\
102         $(DOWNLOAD_TO_STDOUT) $(call DOWNLOAD_TIMEOUT,5,10) $(TARBALL_URL) > $(TARBALL) &&\
103         $(SHELL_ECHO_PREFIX) Downloading $(PJPROJECT_URL)/MD5SUM to $(PJMD5SUM) &&\
104         $(DOWNLOAD_TO_STDOUT) $(call DOWNLOAD_TIMEOUT,5,10) $(PJPROJECT_URL)/MD5SUM.TXT > $(PJMD5SUM) &&\
105         $(verify_tarball))
106 endef
107
108 .DELETE_ON_ERROR:
109
110 DOWNLOAD_DIR := $(or $(EXTERNALS_CACHE_DIR),$(TMPDIR),$(wildcard /tmp),.)
111 TARBALL_FILE = pjproject-$(PJPROJECT_VERSION).tar.bz2
112 TARBALL = $(DOWNLOAD_DIR)/$(TARBALL_FILE)
113 TARBALL_URL = $(PJPROJECT_URL)/$(TARBALL_FILE)
114 PJMD5SUM = $(patsubst %.tar.bz2,%.md5,$(TARBALL))
115
116 $(TARBALL): ../versions.mak
117         $(CMD_PREFIX) $(download_from_pjproject) || (rm -rf $@ ;\
118         $(SHELL_ECHO_PREFIX) Retrying download ; $(download_from_pjproject))
119
120 source/.unpacked: $(DOWNLOAD_DIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2
121         ($(verify_tarball)) || (rm -rf $@ ;\
122         $(SHELL_ECHO_PREFIX) Retrying download ; $(download_from_pjproject))
123         $(ECHO_PREFIX) Unpacking $<
124         -@rm -rf source pjproject-* >/dev/null 2>&1
125         $(CMD_PREFIX) $(TAR) -xjf $<
126         @mv pjproject-$(PJPROJECT_VERSION) source
127         $(ECHO_PREFIX) Applying patches
128         $(CMD_PREFIX) ./apply_patches $(QUIET_CONFIGURE) patches source
129         -@touch source/.unpacked
130
131 source/version.mak: source/.unpacked
132
133 source/user.mak: source/.unpacked patches/user.mak
134         $(ECHO_PREFIX) Applying user.mak
135         $(CMD_PREFIX) cp -f patches/user.mak source/
136
137 source/pjlib/include/pj/%.h: patches/%.h
138         $(ECHO_PREFIX) Applying custom include file $<
139         $(CMD_PREFIX) cp -f $< source/pjlib/include/pj/
140
141 .rebuild_needed: $(wildcard ../../makeopts) $(wildcard ../../menuselect.makeopts)
142         $(ECHO_PREFIX) Rebuilding
143         $(CMD_PREFIX) $(MAKE) clean $(REALLY_QUIET)
144
145 source/build.mak: Makefile.rules source/version.mak source/user.mak $(addprefix source/pjlib/include/pj/,$(notdir $(wildcard patches/*.h))) .rebuild_needed
146         $(ECHO_PREFIX) Configuring with $(PJPROJECT_CONFIG_OPTS)
147         $(CMD_PREFIX) (cd source ; ./aconfigure $(QUIET_CONFIGURE) $(PJPROJECT_CONFIG_OPTS))
148
149 build.mak: source/build.mak
150         $(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
151
152 configure: source/build.mak
153
154 echo_cflags: source/build.mak
155         @echo $(PJ_CFLAGS)
156
157 libpj%.a: source/build.mak
158         $(ECHO_PREFIX) Compiling lib $(@F)
159         $(CMD_PREFIX) $(MAKE) -C $(dir $(shell dirname $@))/build $(@F) $(REALLY_QUIET)
160
161 # pjsua needs resample and g711 to successfully run the testsuite
162 libresample%.a: source/build.mak
163         $(ECHO_PREFIX) Compiling lib $(@F)
164         $(CMD_PREFIX) $(MAKE) -C $(dir $(shell dirname $@))/build/resample all $(REALLY_QUIET)
165
166 # We need to compile pjlib, then pjlib-util, then the rest
167 # so we separate them out and create the dependencies
168 PJLIB_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpj-,$(lib)),$(lib),))
169 PJLIB_UTIL_LIB_FILES = $(foreach lib,$(PJ_LIB_FILES),$(if $(findstring libpjlib-util,$(lib)),$(lib),))
170 PJSIP_LIB_FILES = $(filter-out $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES) $(APP_THIRD_PARTY_LIB_FILES),$(PJ_LIB_FILES))
171 ALL_LIB_FILES = $(PJLIB_LIB_FILES) $(PJLIB_UTIL_LIB_FILES) $(PJSIP_LIB_FILES)
172
173 $(PJLIB_UTIL_LIB_FILES): $(PJLIB_LIB_FILES)
174 $(PJSIP_LIB_FILES): $(PJLIB_UTIL_LIB_FILES)
175
176 pjproject.symbols: $(ALL_LIB_FILES)
177         $(ECHO_PREFIX) Generating symbols
178         $(CMD_PREFIX) $(NM) -Pog $(ALL_LIB_FILES) | $(SED) -n -r -e "s/.+: ([pP][jJ][^ ]+) .+/\1/gp" | sort -u > pjproject.symbols
179
180 source/pjsip-apps/src/asterisk_malloc_debug.c: patches/asterisk_malloc_debug.c
181         $(ECHO_PREFIX) Copying $< to $@
182         $(CMD_PREFIX) cp -f $< $@
183
184 source/pjsip-apps/lib/asterisk_malloc_debug.o: source/pjsip-apps/src/asterisk_malloc_debug.c .rebuild_needed
185         $(ECHO_PREFIX) Compiling asterisk debug malloc stubs
186         $(CMD_PREFIX) $(CC) -fPIC  $(PJ_CFLAGS) -c $< -o $@
187
188 source/pjsip-apps/lib/libasterisk_malloc_debug.a: source/pjsip-apps/lib/asterisk_malloc_debug.o
189         $(ECHO_PREFIX) Creating archive $(@F)
190         $(CMD_PREFIX) ar qs $@ $< >/dev/null 2>&1
191
192 $(apps): APP = $(filter pj%,$(subst -, ,$(notdir $@)))
193 $(apps): pjproject.symbols $(APP_THIRD_PARTY_LIB_FILES)
194         $(ECHO_PREFIX) Compiling $(APP)
195         $(CMD_PREFIX) +$(MAKE) -C source/pjsip-apps/build $(filter pj%,$(subst -, ,$(notdir $@))) $(REALLY_QUIET)
196
197 source/pjsip-apps/src/python/_pjsua.o: source/pjsip-apps/src/python/_pjsua.c $(apps)
198         $(ECHO_PREFIX) Compiling python bindings
199         $(CMD_PREFIX) $(CC) -o $@ -c $< $(PYTHONDEV_INCLUDE) $(CFLAGS) $(PJ_CFLAGS)
200
201 source/pjsip-apps/src/python/_pjsua.so: source/pjsip-apps/src/python/_pjsua.o
202         $(ECHO_PREFIX) Linking python bindings $(@F)
203         $(CMD_PREFIX) gcc -shared -pthread -o $@ $< $(LDFLAGS) $(PJ_LDFLAGS) $(APP_LDLIBS) $(PYTHONDEV_LIB) $(REALLY_QUIET)
204
205 _install: _all
206         @if [ ! -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject" ]; then \
207                 $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject"; \
208         fi;
209 ifneq ($(findstring source/pjsip-apps/bin/pjsua-$(TARGET_NAME),$(TARGETS)),)
210         $(ECHO_PREFIX) Installing apps
211         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsua-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsua"
212         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsystest-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsystest"
213 endif
214 ifneq ($(findstring _pjsua.so,$(TARGETS)),)
215         $(ECHO_PREFIX) Installing python bindings
216         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
217         $(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
218 endif
219
220 uninstall:
221         $(ECHO_PREFIX) Uninstalling apps and python bindings
222         $(CMD_PREFIX) rm -rf "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject"
223
224 clean:
225         $(ECHO_PREFIX) Cleaning
226         +-$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean || : ;\
227                 rm -rf source/pjsip-apps/bin/* || : ;\
228                 find source -name *.a | xargs rm -rf  ;\
229                 find source -name *.o | xargs rm -rf  ;\
230                 find source -name *.so  | xargs rm -rf ; ) || :
231         -$(CMD_PREFIX) rm -rf pjproject.symbols
232
233 distclean:
234         $(ECHO_PREFIX) Distcleaning
235         -$(CMD_PREFIX) rm -rf source pjproject.symbols pjproject-*.tar.bz2 build.mak .rebuild_needed