ensure that cross-compiler info is removed from the enviroment before configuring...
[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 ifneq ($(wildcard $(ASTTOPDIR)/menuselect.makeopts),)
15   include $(ASTTOPDIR)/menuselect.makeopts
16   include $(ASTTOPDIR)/menuselect.makedeps
17 endif
18
19 ifneq ($(wildcard $(ASTTOPDIR)/makeopts.embed_rules),)
20   include $(ASTTOPDIR)/makeopts.embed_rules
21 endif
22
23 all: asterisk
24
25 include $(ASTTOPDIR)/Makefile.moddir_rules
26
27 OBJS=   io.o sched.o logger.o frame.o loader.o config.o channel.o \
28         translate.o file.o pbx.o cli.o md5.o term.o \
29         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
30         cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
31         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
32         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
33         utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
34         netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
35         cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o
36
37 # we need to link in the objects statically, not as a library, because
38 # otherwise modules will not have them available if none of the static
39 # objects use it.
40 OBJS+=stdtime/localtime.o
41
42 # At the moment say.o is an optional component which can be overridden
43 # by a module.
44 OBJS+=say.o
45
46 ifeq ($(wildcard /usr/include/sys/poll.h),)
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 ),)
55   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
56   AST_LIBS+=-ldl
57   endif
58   AST_LIBS+=-lpthread $(EDITLINE_LIB) -lm -lresolv
59 else
60   AST_LIBS+=$(EDITLINE_LIB) -lm
61 endif
62
63 ifneq ($(findstring darwin,$(OSARCH)),)
64   AST_LIBS+=-lresolv
65   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
66     ASTLINK=-Wl,-dynamic
67   endif
68   # Mac on Intel CoreDuo does not need poll compatibility layer
69   ifneq ($(PROC),i386)
70     OBJS+=poll.o
71     ASTCFLAGS+=-DPOLLCOMPAT
72   endif
73 else
74 # These are used for all but Darwin
75   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
76     ASTLINK+=-Wl,--export-dynamic
77   else
78     ASTLINK+=${GC_LDFLAGS}
79   endif
80   ifneq ($(findstring BSD,$(OSARCH)),)
81     LDFLAGS+=-L/usr/local/lib
82   endif
83 endif
84
85 ifeq ($(OSARCH),FreeBSD)
86   AST_LIBS+=-lcrypto
87 endif
88
89 ifeq ($(OSARCH),NetBSD)
90   AST_LIBS+=-lpthread -lcrypto -lm -L/usr/pkg/lib $(EDITLINE_LIB)
91 endif
92
93 ifeq ($(OSARCH),OpenBSD)
94   AST_LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIB)
95 endif
96
97 ifeq ($(OSARCH),SunOS)
98   AST_LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L/opt/ssl/lib -L/usr/local/ssl/lib
99   OBJS+=strcompat.o
100   ASTLINK=
101 endif
102
103 editline/libedit.a:
104         cd editline && unset CFLAGS AST_LIBS && test -f config.h || CFLAGS="$(OPTIMIZE)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM)
105         $(MAKE) -C editline libedit.a
106
107 db1-ast/libdb1.a:
108         CFLAGS="$(ASTCFLAGS)" $(MAKE) -C db1-ast libdb1.a
109
110 ast_expr2.c ast_expr2.h:
111         bison -o $@ -d --name-prefix=ast_yy ast_expr2.y
112
113 ast_expr2f.c:
114         flex -o $@ --full ast_expr2.fl
115
116 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
117         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c
118         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c
119         $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o
120         rm ast_expr2.o ast_expr2f.o 
121
122 channel.o: CFLAGS+=$(ZAPTEL_INCLUDE)
123
124 AST_EMBED_LDSCRIPTS:=$(sort $(EMBED_LDSCRIPTS))
125 AST_EMBED_LDFLAGS:=$(foreach dep,$(EMBED_LDFLAGS),$(value $(dep)))
126 AST_EMBED_LIBS:=$(foreach dep,$(EMBED_LIBS),$(value $(dep)))
127 OBJS:=$(sort $(OBJS))
128
129 asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS)
130         @$(ASTTOPDIR)/build_tools/make_build_h > $(ASTTOPDIR)/include/asterisk/build.h.tmp
131         @if cmp -s $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; then echo ; else \
132                 mv $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; \
133         fi
134         @rm -f $(ASTTOPDIR)/include/asterisk/build.h.tmp
135         @$(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
136         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
137         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o asterisk $(ASTLINK) $(AST_EMBED_LDFLAGS) $(LDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS)
138
139 clean::
140         rm -f asterisk
141         rm -f .depend
142         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
143         @$(MAKE) -C db1-ast clean
144         @$(MAKE) -C stdtime clean