Add ability to set high ToS bits as non-root on Linux using libcap (issue #7047 repor...
[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
30
31 # we need to link in the objects statically, not as a library, because
32 # otherwise modules will not have them available if none of the static
33 # objects use it.
34 OBJS+=stdtime/localtime.o
35
36 # At the moment say.o is an optional component which can be overridden
37 # by a module.
38 OBJS+=say.o
39
40 ifeq ($(wildcard /usr/include/sys/poll.h),)
41   OBJS+=poll.o
42   ASTCFLAGS+=-DPOLLCOMPAT
43 endif
44
45 ifeq ($(wildcard /usr/include/dlfcn.h),)
46   OBJS+=dlfcn.o
47 endif
48
49 ifneq ($(findstring $(OSARCH), linux-gnu uclinux ),)
50   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
51   AST_LIBS+=-ldl
52   endif
53   ifneq (x$(CAP_LIB),x)
54     AST_LIBS+=$(CAP_LIB)
55   endif
56   AST_LIBS+=-lpthread $(EDITLINE_LIB) -lm -lresolv
57 else
58   AST_LIBS+=$(EDITLINE_LIB) -lm
59 endif
60
61 ifneq ($(findstring darwin,$(OSARCH)),)
62   AST_LIBS+=-lresolv
63   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
64     ASTLINK=-Wl,-dynamic
65   endif
66 else
67 # These are used for all but Darwin
68   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
69     ASTLINK+=-Wl,--export-dynamic
70   else
71     ASTLINK+=${GC_LDFLAGS}
72   endif
73   ifneq ($(findstring BSD,$(OSARCH)),)
74     LDFLAGS+=-L/usr/local/lib
75   endif
76 endif
77
78 ifeq ($(OSARCH),FreeBSD)
79   AST_LIBS+=-lcrypto
80 endif
81
82 ifeq ($(OSARCH),NetBSD)
83   AST_LIBS+=-lpthread -lcrypto -lm -L/usr/pkg/lib $(EDITLINE_LIB)
84 endif
85
86 ifeq ($(OSARCH),OpenBSD)
87   AST_LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIB)
88 endif
89
90 ifeq ($(OSARCH),SunOS)
91   AST_LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L/opt/ssl/lib -L/usr/local/ssl/lib
92   ASTLINK=
93 endif
94
95 editline/libedit.a:
96         cd editline && unset CFLAGS AST_LIBS && test -f config.h || CFLAGS="$(OPTIMIZE)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM)
97         $(MAKE) -C editline libedit.a
98
99 db1-ast/libdb1.a:
100         CFLAGS="$(ASTCFLAGS)" $(MAKE) -C db1-ast libdb1.a
101
102 ast_expr2.c ast_expr2.h:
103         bison -o $@ -d --name-prefix=ast_yy ast_expr2.y
104
105 ast_expr2f.c:
106         flex -o $@ --full ast_expr2.fl
107
108 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
109         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c
110         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c
111         $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o
112         rm ast_expr2.o ast_expr2f.o 
113
114 channel.o: CFLAGS+=$(ZAPTEL_INCLUDE)
115
116 AST_EMBED_LDSCRIPTS:=$(sort $(EMBED_LDSCRIPTS))
117 AST_EMBED_LDFLAGS:=$(foreach dep,$(EMBED_LDFLAGS),$(value $(dep)))
118 AST_EMBED_LIBS:=$(foreach dep,$(EMBED_LIBS),$(value $(dep)))
119 OBJS:=$(sort $(OBJS))
120
121 ifneq ($(wildcard ../channels/h323/Makefile.ast),)
122   include ../channels/h323/Makefile.ast
123 else
124   H323LDFLAGS=
125   H323LDLIBS=
126 endif
127
128 asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS)
129         @$(ASTTOPDIR)/build_tools/make_build_h > $(ASTTOPDIR)/include/asterisk/build.h.tmp
130         @if cmp -s $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; then echo ; else \
131                 mv $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; \
132         fi
133         @rm -f $(ASTTOPDIR)/include/asterisk/build.h.tmp
134         @$(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
135         $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
136         $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(LDFLAGS) $(H323LDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS)
137         @$(ASTTOPDIR)/build_tools/strip_nonapi $@
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