Makefile 8.4 KB

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