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