3504b547bcde90668e57b959a6f348d843d00192
[asterisk/asterisk.git] / main / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
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
15
16 all: asterisk
17
18 include $(ASTTOPDIR)/Makefile.moddir_rules
19
20 RESAMPLE_OBJS:=libresample/src/resample.o libresample/src/resamplesubs.o libresample/src/filterkit.o
21
22 OBJS= tcptls.o io.o sched.o logger.o frame.o loader.o config.o channel.o \
23         translate.o file.o pbx.o cli.o md5.o term.o \
24         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
25         cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
26         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
27         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
28         utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
29         netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
30         cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
31         strcompat.o threadstorage.o dial.o event.o adsistub.o audiohook.o \
32         astobj2.o hashtab.o global_datastores.o $(RESAMPLE_OBJS) version.o
33
34 # we need to link in the objects statically, not as a library, because
35 # otherwise modules will not have them available if none of the static
36 # objects use it.
37 OBJS+=stdtime/localtime.o
38
39 # At the moment say.o is an optional component which can be overridden
40 # by a module.
41 OBJS+=say.o
42
43 AST_LIBS += $(SSL_LIB)
44 AST_LIBS += $(BKTR_LIB)
45
46 ifeq ($(POLL_AVAILABLE),)
47   OBJS+=poll.o
48 endif
49
50 ifeq ($(wildcard /usr/include/dlfcn.h),)
51   OBJS+=dlfcn.o
52 endif
53
54 ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc ),)
55   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
56   AST_LIBS+=-ldl
57   endif
58   ifneq (x$(CAP_LIB),x)
59     AST_LIBS+=$(CAP_LIB)
60   endif
61   AST_LIBS+=-lpthread $(EDITLINE_LIB) -lm -lresolv
62 else
63   AST_LIBS+=$(EDITLINE_LIB) -lm
64 endif
65
66 ifneq ($(findstring darwin,$(OSARCH)),)
67   AST_LIBS+=-lresolv
68   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
69     ASTLINK=-Wl,-dynamic
70   endif
71 else
72 # These are used for all but Darwin
73   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
74     ASTLINK+=-Wl,--export-dynamic
75   else
76     ASTLINK+=${GC_LDFLAGS}
77   endif
78   ifneq ($(findstring BSD,$(OSARCH)),)
79     LDFLAGS+=-L/usr/local/lib
80   endif
81 endif
82
83 ifeq ($(OSARCH),FreeBSD)
84   # -V is understood by BSD Make, not by GNU make.
85   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
86   AST_LIBS+=$(shell if test $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
87   AST_LIBS+=-lcrypto
88 endif
89
90 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
91   AST_LIBS+=-lminires -ldl
92   ASTLINK+= -shared -Wl,--out-implib,libasterisk.a
93 endif
94 ifeq ($(OSARCH),NetBSD)
95   AST_LIBS+=-lpthread -lcrypto -lm -L/usr/pkg/lib $(EDITLINE_LIB)
96 endif
97
98 ifeq ($(OSARCH),OpenBSD)
99   AST_LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIB)
100 endif
101
102 ifeq ($(OSARCH),SunOS)
103   AST_LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L/opt/ssl/lib -L/usr/local/ssl/lib
104   ASTLINK=
105 endif
106
107 CHECK_SUBDIR:   # do nothing, just make sure that we recurse in the subdir/
108
109 editline/libedit.a: CHECK_SUBDIR
110         cd editline && test -f config.h || CFLAGS="$(PTHREAD_CFLAGS) $(ASTCFLAGS:-Werror=)" LDFLAGS="$(ASTLDFLAGS)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM) --with-ncurses=$(NCURSES_DIR) --with-curses=$(CURSES_DIR) --with-termcap=$(TERMCAP_DIR) --with-tinfo=$(TINFO_DIR)
111         $(MAKE) -C editline libedit.a
112
113 db1-ast/libdb1.a: CHECK_SUBDIR
114         CFLAGS="$(ASTCFLAGS)" LDFLAGS="$(ASTLDFLAGS)" $(MAKE) -C db1-ast libdb1.a
115
116 ast_expr2.c ast_expr2.h:
117         bison -o $@ -d --name-prefix=ast_yy ast_expr2.y
118
119 ast_expr2f.c:
120         flex -o $@ --full ast_expr2.fl # moved the correction of yyfree into the flex input file itself.
121         sed 's@#if __STDC_VERSION__ >= 199901L@#if !defined __STDC_VERSION__ || __STDC_VERSION__ >= 199901L@' ast_expr2f.c > zz
122         mv zz ast_expr2f.c
123
124 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
125         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c
126         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c
127         $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o -lm
128         rm ast_expr2.o ast_expr2f.o 
129
130 channel.o: ASTCFLAGS+=$(ZAPTEL_INCLUDE)
131
132 AST_EMBED_LDSCRIPTS:=$(sort $(EMBED_LDSCRIPTS))
133 AST_EMBED_LDFLAGS:=$(foreach dep,$(EMBED_LDFLAGS),$(value $(dep)))
134 AST_EMBED_LIBS:=$(foreach dep,$(EMBED_LIBS),$(value $(dep)))
135 OBJS:=$(sort $(OBJS))
136
137 ifneq ($(wildcard ../channels/h323/Makefile.ast),)
138   include ../channels/h323/Makefile.ast
139 else
140   H323LDFLAGS=
141   H323LDLIBS=
142 endif
143
144 minimime/libmmime.a: CHECK_SUBDIR
145         @cd minimime && $(MAKE) libmmime.a
146
147 ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
148 MAIN_TGT:=asterisk.dll
149 asterisk: cygload
150         mv cygload.exe asterisk.exe
151
152 cygload: asterisk.dll
153 else
154 MAIN_TGT:=asterisk
155 endif
156
157 $(MAIN_TGT): $(OBJS) editline/libedit.a db1-ast/libdb1.a minimime/libmmime.a $(AST_EMBED_LDSCRIPTS)
158         @$(CC) -c -o buildinfo.o $(ASTCFLAGS) buildinfo.c
159         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
160 ifneq ($(findstring chan_h323,$(MENUSELECT_CHANNELS)),)
161         $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS)
162 else
163         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS)
164 endif
165         @$(ASTTOPDIR)/build_tools/strip_nonapi $@
166
167 clean::
168         rm -f asterisk
169         rm -f db1-ast/.*.d
170         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
171         @$(MAKE) -C db1-ast clean
172         @$(MAKE) -C stdtime clean
173         @$(MAKE) -C minimime clean
174         rm -f libresample/src/*.o