build-system: Allow building with static pjproject
[asterisk/asterisk.git] / third-party / pjproject / Makefile
1 .SUFFIXES:
2 .PHONY: _all all _install install clean distclean echo_cflags configure
3
4 ifeq ($(MAKECMDGOALS),install)
5 include ../../makeopts
6 else
7 -include ../../makeopts
8 endif
9
10 include ../versions.mak
11 include ../Makefile.rules
12 include Makefile.rules
13
14 ECHO_PREFIX := $(ECHO_PREFIX) echo '[pjproject] '
15
16 ifeq ($(MAKECMDGOALS),echo_cflags)
17 -include build.mak
18 ECHO_PREFIX=@\#
19 endif
20
21 ifneq ($(PJPROJECT_BUNDLED),yes)
22 all install:
23         @echo '[pjproject] Not enabled'
24 else
25
26 ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
27 include build.mak
28 endif
29
30 all: _all
31 install: _install
32 endif
33
34 ifndef $(TMPDIR)
35 ifneq ($(wildcard /tmp),)
36 TMPDIR=/tmp
37 else
38 TMPDIR=.
39 endif
40 endif
41
42 $(TMPDIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2 : ../versions.mak
43         $(ECHO_PREFIX) Downloading $@ with $(DOWNLOAD)
44         $(CMD_PREFIX) $(DOWNLOAD) $(PJPROJECT_URL)/$(@F) > $@
45
46 source/user.mak source/pjlib/include/pj/config_site.h: $(TMPDIR)/pjproject-$(PJPROJECT_VERSION).tar.bz2 patches/config_site.h patches/user.mak 
47         $(ECHO_PREFIX) Unpacking $<
48         -@rm -rf source &>/dev/null
49         -@mkdir source &>/dev/null
50         $(CMD_PREFIX) tar --strip-components=1 -C source -xjf $<
51         $(ECHO_PREFIX) Applying patches and custom files
52         $(CMD_PREFIX) ./apply_patches $(QUIET_CONFIGURE) ./patches ./source
53         $(CMD_PREFIX) cp -f ./patches/config_site.h ./source/pjlib/include/pj/
54         $(CMD_PREFIX) cp -f ./patches/user.mak ./source/
55
56 build.mak: source/pjlib/include/pj/config_site.h source/user.mak Makefile.rules
57         $(ECHO_PREFIX) Configuring with $(PJPROJECT_CONFIG_OPTS)
58         $(CMD_PREFIX) (cd source ; autoconf aconfigure.ac > aconfigure && ./aconfigure $(QUIET_CONFIGURE) $(PJPROJECT_CONFIG_OPTS))
59         @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
60
61 configure: build.mak
62
63 echo_cflags: build.mak
64         @echo $(PJ_CFLAGS)
65
66 source/pjlib/build/.pjlib-$(TARGET_NAME).depend: build.mak
67         $(ECHO_PREFIX) "Making dependencies"
68         +$(CMD_PREFIX) $(SUBMAKE) -C source dep
69
70 source/pjlib/lib/libpj-$(TARGET_NAME).a: source/pjlib/build/.pjlib-$(TARGET_NAME).depend
71         $(ECHO_PREFIX) Compiling libs
72         +$(CMD_PREFIX) $(SUBMAKE) -C source lib $(REALLY_QUIET)
73
74 pjproject.symbols: source/pjlib/lib/libpj-$(TARGET_NAME).a
75         $(ECHO_PREFIX) Generating symbols
76         $(CMD_PREFIX) nm -Pog $(PJ_LIB_FILES) | sed -n -r -e "s/.+: ([pP][jJ][^ ]+) .+/\1/gp" | sort -u > pjproject.symbols
77
78 source/pjsip-apps/bin/pjsua-$(TARGET_NAME): source/pjlib/lib/libpj-$(TARGET_NAME).a
79         $(ECHO_PREFIX) Compiling apps
80         $(CMD_PREFIX) $(SUBMAKE) -C source/pjsip-apps/build pjsua pjsystest $(REALLY_QUIET)
81
82 source/pjsip-apps/src/python/build/_pjsua.so: source/pjlib/lib/libpj-$(TARGET_NAME).a
83         $(ECHO_PREFIX) Compiling python bindings
84         $(CMD_PREFIX) (cd source/pjsip-apps/src/python ; python setup.py build --build-platlib=./build $(REALLY_QUIET))
85
86 _all: pjproject.symbols source/pjsip-apps/bin/pjsua-$(TARGET_NAME) source/pjsip-apps/src/python/build/_pjsua.so
87
88 _install: _all
89         $(ECHO_PREFIX) Installing apps and python bindings
90         @if [ ! -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject" ]; then \
91                 $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject"; \
92         fi;
93         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsua-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsua"
94         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/bin/pjsystest-$(TARGET_NAME) "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/pjsystest"
95         $(CMD_PREFIX) $(INSTALL) -m 755 source/pjsip-apps/src/python/build/_pjsua.so "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
96         $(CMD_PREFIX) $(INSTALL) -m 644 source/pjsip-apps/src/python/build/pjsua.py "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject/"
97
98 uninstall:
99         $(ECHO_PREFIX) Uninstalling apps and python bindings
100         $(CMD_PREFIX) rm -rf "$(DESTDIR)$(ASTDATADIR)/third-party/pjproject"
101
102 clean:
103         $(ECHO_PREFIX) Cleaning
104         -$(CMD_PREFIX) test -d source && ($(SUBMAKE) -C source clean ; find source -name *.a -delete ; rm -rf source/pjsip-apps/src/python/build) || :
105         -$(CMD_PREFIX) rm -rf pjproject.symbols
106
107 distclean:
108         $(ECHO_PREFIX) Distcleaning
109         -$(CMD_PREFIX) rm -rf source pjproject.symbols pjproject-*.tar.bz2 build.mak
110