Title update
[asterisk/asterisk.git] / main / Makefile
1 #
2 # Asterisk -- An open source telephony toolkit.
3 #
4 # Makefile to build main Asterisk binary
5 #
6 # Copyright (C) 1999-2006, Digium, Inc.
7 #
8 # Mark Spencer <markster@digium.com>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 -include $(ASTTOPDIR)/menuselect.makeopts $(ASTTOPDIR)/menuselect.makedeps $(ASTTOPDIR)/makeopts.embed_rules $(ASTTOPDIR)/makeopts
15
16 all: asterisk
17
18 include $(ASTTOPDIR)/Makefile.moddir_rules
19
20 # Must include the extra ast_expr2.c, ast_expr2f.c, in case they need to be regenerated (because to force regeneration, we delete them)
21 SRC:=$(wildcard *.c) ast_expr2.c ast_expr2f.c
22 ifeq ($(AST_ASTERISKSSL),yes)
23 SRC:=$(filter-out libasteriskssl.c,$(SRC))
24 endif
25 OBJSFILTER=fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o
26 OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o))
27
28 # we need to link in the objects statically, not as a library, because
29 # otherwise modules will not have them available if none of the static
30 # objects use it.
31 OBJS+=stdtime/localtime.o
32
33 ASTSSL_LIBS:=$(OPENSSL_LIB)
34 AST_LIBS+=$(BKTR_LIB)
35 AST_LIBS+=$(LIBXML2_LIB)
36 AST_LIBS+=$(SQLITE3_LIB)
37 AST_LIBS+=$(ASTSSL_LIBS)
38
39 ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc linux-gnueabi kfreebsd-gnu linux-gnueabihf),)
40   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
41   AST_LIBS+=-ldl
42   endif
43   ifneq (x$(CAP_LIB),x)
44     AST_LIBS+=$(CAP_LIB)
45   endif
46   AST_LIBS+=-lpthread $(EDITLINE_LIB) -lm -lresolv
47 else
48   AST_LIBS+=$(EDITLINE_LIB) -lm
49 endif
50
51 ifneq ($(findstring BETTER_BACKTRACES,$(MENUSELECT_CFLAGS)),)
52   AST_LIBS+=$(BFD_LIB)
53 endif
54
55 ifneq ($(findstring darwin,$(OSARCH)),)
56   AST_LIBS+=-lresolv
57   ASTLINK=-Xlinker -macosx_version_min -Xlinker 10.4 -Xlinker -undefined -Xlinker dynamic_lookup -force_flat_namespace
58   ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
59     ASTLINK+=/usr/lib/bundle1.o
60   endif
61 else
62 # These are used for all but Darwin
63   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
64     ASTLINK+=-Wl,--export-dynamic
65   else
66     ASTLINK+=${GC_LDFLAGS}
67   endif
68   ifneq ($(findstring BSD,$(OSARCH)),)
69     LDFLAGS+=-L/usr/local/lib
70   endif
71 endif
72
73 ifeq ($(OSARCH),FreeBSD)
74   # -V is understood by BSD Make, not by GNU make.
75   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
76   AST_LIBS+=$(shell if test $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
77   AST_LIBS+=-lcrypto
78 endif
79
80 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
81   AST_LIBS+=-lminires -ldl
82   ASTLINK+=-shared -Wl,--out-implib,libasterisk.a
83 endif
84 ifeq ($(OSARCH),NetBSD)
85   AST_LIBS+=-lpthread -lcrypto -lm -L/usr/pkg/lib $(EDITLINE_LIB)
86 endif
87
88 ifeq ($(OSARCH),OpenBSD)
89   AST_LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIB)
90 endif
91
92 ifeq ($(OSARCH),SunOS)
93   AST_LIBS+=-lpthread -ldl -lrt -lnsl -lsocket -lresolv
94   ASTSSL_LIBS+=-L/opt/ssl/lib -L/usr/local/ssl/lib
95   ASTLINK=
96 endif
97
98 ifneq ($(findstring USE_HOARD_ALLOCATOR,$(MENUSELECT_CFLAGS)),)
99   ifneq ($(HOARD_LIB),)
100     AST_LIBS+=$(HOARD_LIB)
101   endif
102 endif
103
104 ifeq ($(GNU_LD),1)
105 ASTLINK+=-Wl,--version-script,asterisk.exports
106   ifeq ($(HAVE_DYNAMIC_LIST),1)
107   ASTLINK+=-Wl,--dynamic-list,asterisk.dynamics
108   endif
109 endif
110
111 .PHONY: CHECK_SUBDIR
112 CHECK_SUBDIR:   # do nothing, just make sure that we recurse in the subdir/
113
114 editline/libedit.a: CHECK_SUBDIR
115         cd editline && test -f config.h || CFLAGS="$(PTHREAD_CFLAGS) $(subst $(ASTTOPDIR),../../,$(_ASTCFLAGS:-Werror=) $(ASTCFLAGS))" LDFLAGS="$(_ASTLDFLAGS) $(ASTLDFLAGS)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM) --with-ncurses=$(NCURSES_DIR) --with-curses=$(CURSES_DIR) --with-termcap=$(TERMCAP_DIR) --with-tinfo=$(TINFO_DIR)
116         $(MAKE) -C editline libedit.a
117
118 ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
119 ast_expr2.c ast_expr2.h: ast_expr2.y
120 else
121 ast_expr2.c ast_expr2.h:
122 endif
123         $(ECHO_PREFIX) echo "   [BISON] $< -> $@"
124         $(CMD_PREFIX) $(BISON) -o $@ -d --name-prefix=ast_yy ast_expr2.y
125
126 ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
127 ast_expr2f.c: ast_expr2.fl
128 else
129 ast_expr2f.c:
130 endif
131         $(ECHO_PREFIX) echo "   [FLEX] $< -> $@"
132         $(CMD_PREFIX) $(FLEX) -o $@ ast_expr2.fl
133         $(CMD_PREFIX) sed 's@#if __STDC_VERSION__ >= 199901L@#if !defined __STDC_VERSION__ || __STDC_VERSION__ >= 199901L@' $@ > $@.fix
134         $(CMD_PREFIX) echo "#include \"asterisk.h\"" > $@
135         $(CMD_PREFIX) echo >> $@
136         $(CMD_PREFIX) cat $@.fix >> $@
137         $(CMD_PREFIX) rm $@.fix
138
139 ast_expr2f.o: _ASTCFLAGS+=-Wno-unused
140
141 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
142         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c
143         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c
144         $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o -lm
145         rm ast_expr2.o ast_expr2f.o
146
147 ifneq ($(LIBEDIT_INTERNAL),no)
148 LIBEDIT_OBJ=editline/libedit.a
149 LIBEDIT_INCLUDE=-I. -Ieditline
150 endif
151
152 db.o: _ASTCFLAGS+=$(SQLITE3_INCLUDE)
153 asterisk.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
154 cli.o: _ASTCFLAGS+=$(LIBEDIT_INCLUDE)
155
156 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
157 http.o: _ASTCFLAGS+=$(GMIME_INCLUDE)
158 endif
159
160 stdtime/localtime.o: _ASTCFLAGS+=$(AST_NO_STRICT_OVERFLOW) -Wno-format-nonliteral
161
162 AST_EMBED_LDSCRIPTS:=$(sort $(EMBED_LDSCRIPTS))
163 AST_EMBED_LDFLAGS:=$(foreach dep,$(EMBED_LDFLAGS),$(value $(dep)))
164 AST_EMBED_LIBS:=$(foreach dep,$(EMBED_LIBS),$(value $(dep)))
165 OBJS:=$(sort $(OBJS))
166
167 ifneq ($(wildcard ../channels/h323/Makefile.ast),)
168   include ../channels/h323/Makefile.ast
169 else
170   H323LDFLAGS=
171   H323LDLIBS=
172 endif
173
174 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
175 MAIN_TGT:=asterisk.dll
176 asterisk: cygload
177         mv cygload.exe asterisk.exe
178
179 cygload: asterisk.dll
180 else
181 MAIN_TGT:=asterisk
182 endif
183
184 ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
185 GMIMELDFLAGS+=$(GMIME_LIB)
186 endif
187
188 $(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\"
189
190 libasteriskssl.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
191
192 ifeq ($(AST_ASTERISKSSL),yes)
193 # The ABI *version* of the asteriskssl library; don't change this unless there truly is a
194 # non-backwards-compatible ABI change in the library
195 ASTSSL_SO_VERSION=1
196
197 ASTSSL_LDLIBS=-L. -lasteriskssl
198
199 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
200 ASTSSL_LIB:=libasteriskssl.so
201
202 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTLDFLAGS+=-Wl,-soname=$(ASTSSL_LIB).$(ASTSSL_SO_VERSION)
203 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\"
204 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): LIBS+=$(ASTSSL_LIBS)
205 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SO_SUPPRESS_SYMBOLS=-Wl,--version-script,libasteriskssl.exports,--warn-common
206 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): SOLINK=$(DYLINK)
207
208 # These rules are duplicated from $(ASTTOPDIR)/Makefile.rules because the library name
209 # being built does not match the "%.so" pattern; there are also additional steps
210 # required to build a proper shared library (as opposed to the 'loadable module'
211 # type that are built by the standard rules)
212 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION): libasteriskssl.o
213 ifeq ($(GNU_LD),1)
214         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script libasteriskssl "$(LINKER_SYMBOL_PREFIX)" "$(ASTTOPDIR)"
215 endif
216         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
217         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
218 ifneq ($(LDCONFIG),)
219         $(LDCONFIG) $(LDCONFIG_FLAGS) .
220 endif
221
222 $(ASTSSL_LIB): $(ASTSSL_LIB).$(ASTSSL_SO_VERSION)
223         $(LN) -sf $< $@
224
225 else # Darwin
226 ASTSSL_LIB:=libasteriskssl.dylib
227
228 $(ASTSSL_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskssl\"
229 $(ASTSSL_LIB): LIBS+=$(ASTSSL_LIBS)
230 $(ASTSSL_LIB): SOLINK=$(DYLINK)
231
232 # Special rules for building a shared library (not a dynamically loadable module)
233 $(ASTSSL_LIB): libasteriskssl.o
234         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
235         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(CC_LDFLAGS_SO) $^ $(CC_LIBS)
236 endif
237
238 endif
239
240 tcptls.o: _ASTCFLAGS+=$(OPENSSL_INCLUDE)
241
242 $(MAIN_TGT): $(OBJS) $(ASTSSL_LIB) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS)
243         @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
244         $(ECHO_PREFIX) echo "   [LD] $(OBJS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) -> $@"
245 ifneq ($(findstring chan_h323,$(MENUSELECT_CHANNELS)),)
246         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
247 else
248         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $(OBJS) $(ASTSSL_LDLIBS) $(LIBEDIT_OBJ) $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS) $(GMIMELDFLAGS) $(LIBEDIT_LIB)
249 endif
250
251 ifeq ($(GNU_LD),1)
252 $(MAIN_TGT): asterisk.exports
253 asterisk.exports: asterisk.exports.in
254         $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_version_script asterisk $(LINKER_SYMBOL_PREFIX)
255 endif
256
257 bininstall:
258         $(INSTALL) -m 755 $(MAIN_TGT) "$(DESTDIR)$(ASTSBINDIR)/"
259 ifeq ($(AST_ASTERISKSSL),yes)
260 ifeq ($(findstring darwin,$(OSARCH)),) # not Darwin
261         $(INSTALL) -m 755 $(ASTSSL_LIB).$(ASTSSL_SO_VERSION) "$(DESTDIR)$(ASTLIBDIR)/"
262         $(LN) -sf "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB).$(ASTSSL_SO_VERSION)" "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB)"
263 else # Darwin
264         $(INSTALL) -m 755 $(ASTSSL_LIB) "$(DESTDIR)$(ASTLIBDIR)/"
265 endif
266 ifneq ($(LDCONFIG),)
267         $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/"
268 endif
269 endif
270         $(LN) -sf asterisk "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
271
272 binuninstall:
273         rm -f "$(DESTDIR)$(ASTSBINDIR)/$(MAIN_TGT)"
274         rm -f "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
275         rm -f "$(DESTDIR)$(ASTLIBDIR)/$(ASTSSL_LIB).$(ASTSSL_SO_VERSION)"
276 ifneq ($(LDCONFIG),)
277         $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/"
278 endif
279
280 clean::
281         rm -f asterisk libasteriskssl.o
282 ifeq ($(AST_ASTERISKSSL),yes)
283         rm -f $(ASTSSL_LIB) $(ASTSSL_LIB).*
284 endif
285         rm -f asterisk.exports libasteriskssl.exports
286         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
287         @$(MAKE) -C stdtime clean
288         rm -f libresample/src/*.o