Add per-user limits to chan_sip
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999, Mark Spencer
7 #
8 # Mark Spencer <markster@linux-support.net>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 .EXPORT_ALL_VARIABLES:
15
16 OSARCH=$(shell uname -s)
17
18 # Pentium Pro Optimize
19 PROC=i686
20 # Pentium Optimize
21 #PROC=i586
22 #PROC=k6
23 #PROC=ppc
24 ifeq (${OSARCH},Linux)
25 PROC=$(shell uname -m)
26 endif
27 PWD=$(shell pwd)
28
29 ######### More GSM codec optimization
30 ######### Uncomment to enable MMXTM optimizations for x86 architecture CPU's
31 ######### which support MMX instructions.  This should be newer pentiums,
32 ######### ppro's, etc, as well as the AMD K6 and K7.  
33 #K6OPT  = -DK6OPT
34
35 #Tell gcc to optimize the asterisk's code
36 OPTIMIZE=-O6
37
38 #Include debug symbols in the executables (-g) and profiling info (-pg)
39 DEBUG=-g #-pg
40
41 # Optional debugging parameters
42 DEBUG_THREADS = #-DDO_CRASH -DDEBUG_THREADS
43
44 # Uncomment next one to enable ast_frame tracing (for debugging)
45 TRACE_FRAMES = #-DTRACE_FRAMES
46
47 # Uncomment next one to enable malloc debugging
48 # You can view malloc debugging with:
49 #   *CLI> show memory allocations [filename]
50 #   *CLI> show memory summary [filename]
51 #
52 MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
53
54 # Where to install asterisk after compiling
55 # Default -> leave empty
56 INSTALL_PREFIX=
57
58 # Original busydetect routine
59 BUSYDETECT = -DBUSYDETECT
60
61 # Improved busydetect routine, comment the previous one if you use this one
62 BUSYDETECT+= #-DBUSYDETECT_MARTIN 
63 # Detect the busy signal looking only at tone lengths
64 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
65 BUSYDETECT+= #-DBUSYDETECT_TONEONLY
66 # Inforce the detection of busy singal (get rid of false hangups)
67 # Don't use together with -DBUSYDETECT_TONEONLY
68 BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
69
70 ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
71 ASTVARLIBDIR=$(INSTALL_PREFIX)/var/lib/asterisk
72 ASTETCDIR=$(INSTALL_PREFIX)/etc/asterisk
73 ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
74 ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
75 ASTHEADERDIR=$(INSTALL_PREFIX)/usr/include/asterisk
76 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
77 ASTBINDIR=$(INSTALL_PREFIX)/usr/bin
78 ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
79 ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
80
81
82 MODULES_DIR=$(ASTLIBDIR)/modules
83 AGI_DIR=$(ASTVARLIBDIR)/agi-bin
84
85 INCLUDE=-Iinclude -I../include
86 CFLAGS=-pipe  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
87 CFLAGS+=$(OPTIMIZE)
88 CFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
89 CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
90 ifeq (${OSARCH},OpenBSD)
91 CFLAGS+=-pthread
92 endif
93
94 CFLAGS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
95
96 LIBEDIT=editline/libedit.a
97
98 ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; fi)
99 HTTPDIR=$(shell if [ -d /var/www ]; then echo "/var/www"; else echo "/home/httpd"; fi)
100 RPMVERSION=$(shell if [ -f .version ]; then sed 's/[-\/:]/_/g' .version; else echo "unknown" ; fi)
101 CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\"
102 CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
103 CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\"
104 CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\"
105 CFLAGS+=-DASTVARLIBDIR=\"$(ASTVARLIBDIR)\"
106 CFLAGS+=-DASTVARRUNDIR=\"$(ASTVARRUNDIR)\"
107 CFLAGS+=-DASTSPOOLDIR=\"$(ASTSPOOLDIR)\"
108 CFLAGS+=-DASTLOGDIR=\"$(ASTLOGDIR)\"
109 CFLAGS+=-DASTCONFPATH=\"$(ASTCONFPATH)\"
110 CFLAGS+=-DASTMODDIR=\"$(MODULES_DIR)\"
111 CFLAGS+=-DASTAGIDIR=\"$(AGI_DIR)\"
112
113 CFLAGS+= $(DEBUG_THREADS)
114 CFLAGS+= $(TRACE_FRAMES)
115 CFLAGS+= $(MALLOC_DEBUG)
116 CFLAGS+= $(BUSYDETECT)
117 CFLAGS+=# -fomit-frame-pointer 
118 SUBDIRS=res channels pbx apps codecs formats agi cdr astman
119 ifeq (${OSARCH},Linux)
120 LIBS=-ldl
121 endif
122 LIBS+=-lpthread -lncurses -lm -lresolv  #-lnjamd
123 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
124         translate.o file.o say.o pbx.o cli.o md5.o term.o \
125         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
126         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
127         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
128         astmm.o enum.o srv.o
129 CC=gcc
130 INSTALL=install
131
132 _all: all
133         @echo " +--------- Asterisk Build Complete ---------+"  
134         @echo " + Asterisk has successfully been built, but +"  
135         @echo " + cannot be run before being installed by   +"  
136         @echo " + running:                                  +"  
137         @echo " +                                           +"
138         @echo " +               $(MAKE) install                +"  
139         @echo " +-------------------------------------------+"  
140
141 all: depend asterisk subdirs
142
143 editline/config.h:
144         @if [ -d editline ]; then \
145                 cd editline && unset CFLAGS LIBS && ./configure ; \
146         else \
147                 echo "You need to do a cvs update -d not just cvs update"; \
148                 exit 1; \
149         fi
150
151 editline/libedit.a: editline/config.h
152         $(MAKE) -C editline libedit.a
153
154 db1-ast/libdb1.a: 
155         @if [ -d db1-ast ]; then \
156                 $(MAKE) -C db1-ast libdb1.a ; \
157         else \
158                 echo "You need to do a cvs update -d not just cvs update"; \
159                 exit 1; \
160         fi
161
162 include .depend
163
164 _version: 
165         if [ -d CVS ] && ! [ -f .version ]; then echo "CVS-`date +"%D-%T"`" > .version; fi 
166
167 .version: _version
168
169 .y.c:
170         bison $< --name-prefix=ast_yy -o $@
171
172 ast_expr.o: ast_expr.c
173
174 cli.o: cli.c build.h
175
176 ifneq ($(strip $(ASTERISKVERSION)),)
177 asterisk.o: asterisk.c .version
178
179 build.h: .version
180         ./make_build_h
181 else
182 build.h:
183         ./make_build_h
184 endif
185
186 asterisk: .version build.h editline/libedit.a db1-ast/libdb1.a $(OBJS)
187         $(CC) $(DEBUG) -o asterisk -rdynamic $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a
188
189 subdirs: 
190         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
191
192 clean:
193         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
194         rm -f *.o *.so asterisk .depend
195         rm -f build.h 
196         rm -f ast_expr.c
197         @if [ -e editline/Makefile ]; then $(MAKE) -C editline clean ; fi
198         $(MAKE) -C db1-ast clean
199
200 datafiles: all
201         mkdir -p $(ASTVARLIBDIR)/sounds/digits
202         for x in sounds/digits/*.gsm; do \
203                 if grep -q "^%`basename $$x`%" sounds.txt; then \
204                         install $$x $(ASTVARLIBDIR)/sounds/digits ; \
205                 else \
206                         echo "No description for $$x"; \
207                         exit 1; \
208                 fi; \
209         done
210         for x in sounds/vm-* sounds/transfer* sounds/pbx-* sounds/ss-* sounds/beep* sounds/dir-* sounds/conf-* sounds/agent-* sounds/invalid* sounds/tt-* sounds/auth-* sounds/privacy-*; do \
211                 if grep -q "^%`basename $$x`%" sounds.txt; then \
212                         install $$x $(ASTVARLIBDIR)/sounds ; \
213                 else \
214                         echo "No description for $$x"; \
215                         exit 1; \
216                 fi; \
217         done
218         mkdir -p $(ASTVARLIBDIR)/mohmp3
219         mkdir -p $(ASTVARLIBDIR)/images
220         for x in images/*.jpg; do \
221                 install $$x $(ASTVARLIBDIR)/images ; \
222         done
223         mkdir -p $(AGI_DIR)
224
225 update: 
226         @if [ -d CVS ]; then \
227                 echo "Updating from CVS..." ; \
228                 cvs -q update -Pd; \
229                 rm -f .version; \
230         else \
231                 echo "Not CVS";  \
232         fi
233
234 bininstall: all
235         mkdir -p $(MODULES_DIR)
236         mkdir -p $(ASTSBINDIR)
237         mkdir -p $(ASTETCDIR)
238         mkdir -p $(ASTBINDIR)
239         mkdir -p $(ASTSBINDIR)
240         mkdir -p $(ASTVARRUNDIR)
241         mkdir -p $(ASTSPOOLDIR)/voicemail
242         install -m 755 asterisk $(ASTSBINDIR)/
243         install -m 755 astgenkey $(ASTSBINDIR)/
244         install -m 755 safe_asterisk $(ASTSBINDIR)/
245         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
246         install -d $(ASTHEADERDIR)
247         install include/asterisk/*.h $(ASTHEADERDIR)
248         rm -f $(ASTVARLIBDIR)/sounds/vm
249         rm -f $(ASTVARLIBDIR)/sounds/voicemail
250         if [ ! -h $(ASTSPOOLDIR)/vm ] && [ -d $(ASTSPOOLDIR)/vm ]; then \
251                 mv $(ASTSPOOLDIR)/vm $(ASTSPOOLDIR)/voicemail/default; \
252         else \
253                 mkdir -p $(ASTSPOOLDIR)/voicemail/default; \
254                 rm -f $(ASTSPOOLDIR)/vm; \
255         fi
256         ln -s $(ASTSPOOLDIR)/voicemail/default $(ASTSPOOLDIR)/vm
257         rm -f $(ASTMODULESDIR)/chan_ixj.so
258         rm -f $(ASTMODULESDIR)/chan_tor.so
259         mkdir -p $(ASTVARLIBDIR)/sounds
260         mkdir -p $(ASTLOGDIR)/cdr-csv
261         mkdir -p $(ASTVARLIBDIR)/keys
262         install -m 644 keys/iaxtel.pub $(ASTVARLIBDIR)/keys
263         ( cd $(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
264         ( cd $(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
265         @echo " +---- Asterisk Installation Complete -------+"  
266         @echo " +                                           +"
267         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
268         @echo " +                                           +"
269         @echo " + Asterisk has successfully been installed. +"  
270         @echo " + If you would like to install the sample   +"  
271         @echo " + configuration files (overwriting any      +"
272         @echo " + existing config files), run:              +"  
273         @echo " +                                           +"
274         @echo " +               $(MAKE) samples                +"
275         @echo " +                                           +"
276         @echo " +-----------------  or ---------------------+"
277         @echo " +                                           +"
278         @echo " + You can go ahead and install the asterisk +"
279         @echo " + program documentation now or later run:   +"
280         @echo " +                                           +"
281         @echo " +              $(MAKE) progdocs                +"
282         @echo " +                                           +"
283         @echo " + **Note** This requires that you have      +"
284         @echo " + doxygen installed on your local system    +"
285         @echo " +-------------------------------------------+"
286
287 install: all datafiles bininstall
288
289 upgrade: all bininstall
290
291 adsi: all
292         mkdir -p $(ASTETCDIR)
293         for x in configs/*.adsi; do \
294                 if ! [ -f $(ASTETCDIRX)/$$x ]; then \
295                         install -m 644 $$x $(ASTETCDIR)/`basename $$x` ; \
296                 fi ; \
297         done
298
299 samples: all datafiles adsi
300         mkdir -p $(ASTETCDIR)
301         for x in configs/*.sample; do \
302                 if [ -f $(ASTETCDIR)/`basename $$x .sample` ]; then \
303                         mv -f $(ASTETCDIR)/`basename $$x .sample` $(ASTETCDIR)/`basename $$x .sample`.old ; \
304                 fi ; \
305                 install $$x $(ASTETCDIR)/`basename $$x .sample` ;\
306         done
307         echo "[directories]" > $(ASTETCDIR)/asterisk.conf
308         echo "astetcdir => $(ASTETCDIR)" >> $(ASTETCDIR)/asterisk.conf
309         echo "astmoddir => $(MODULES_DIR)" >> $(ASTETCDIR)/asterisk.conf
310         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(ASTETCDIR)/asterisk.conf
311         echo "astagidir => $(AGI_DIR)" >> $(ASTETCDIR)/asterisk.conf
312         echo "astspooldir => $(ASTSPOOLDIR)" >> $(ASTETCDIR)/asterisk.conf
313         echo "astrundir => $(ASTVARRUNDIR)" >> $(ASTETCDIR)/asterisk.conf
314         echo "astlogdir => $(ASTLOGDIR)" >> $(ASTETCDIR)/asterisk.conf
315         for x in sounds/demo-*; do \
316                 if grep -q "^%`basename $$x`%" sounds.txt; then \
317                         install $$x $(ASTVARLIBDIR)/sounds ; \
318                 else \
319                         echo "No description for $$x"; \
320                         exit 1; \
321                 fi; \
322         done
323         for x in sounds/*.mp3; do \
324                 install $$x $(ASTVARLIBDIR)/mohmp3 ; \
325         done
326         mkdir -p $(ASTSPOOLDIR)/voicemail/default/1234/INBOX
327         :> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm
328         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
329                 cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm ; \
330         done
331         :> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
332         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
333                 cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm ; \
334         done
335
336 webvmail:
337         @[ -d $(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
338         @[ -d $(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
339         @[ -d $(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
340         install -m 4755 -o root -g root vmail.cgi $(HTTPDIR)/cgi-bin/vmail.cgi
341         mkdir -p $(HTTPDIR)/html/_asterisk
342         for x in images/*.gif; do \
343                 install -m 644 $$x $(HTTPDIR)/html/_asterisk/; \
344         done
345         @echo " +--------- Asterisk Web Voicemail ----------+"  
346         @echo " +                                           +"
347         @echo " + Asterisk Web Voicemail is installed in    +"
348         @echo " + your cgi-bin directory.  IT USES A SETUID +"
349         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
350         @echo " + THAT, UNINSTALL IT!                       +"
351         @echo " +                                           +"
352         @echo " +-------------------------------------------+"  
353
354 mailbox:
355         ./addmailbox 
356         
357
358 rpm: __rpm
359
360 __rpm: _version
361         rm -rf /tmp/asterisk ; \
362         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
363         $(MAKE) INSTALL_PREFIX=/tmp/asterisk install ; \
364         $(MAKE) INSTALL_PREFIX=/tmp/asterisk samples ; \
365         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
366         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
367         cp -f redhat/rpmrc /tmp/asterisk/ ; \
368         cp -f redhat/rpmmacros /tmp/asterisk/ ; \
369         sed "s/Version:/Version: $(RPMVERSION)/g" redhat/asterisk.spec > /tmp/asterisk/asterisk.spec ; \
370         rpm --rcfile /usr/lib/rpm/rpmrc:/tmp/asterisk/rpmrc -bb /tmp/asterisk/asterisk.spec ; \
371         mv /tmp/asterisk/redhat/RPMS/i386/asterisk* ./ ; \
372         rm -rf /tmp/asterisk
373
374 progdocs:
375         doxygen asterisk-ng-doxygen
376
377 config:
378         if [ -d /etc/rc.d/init.d ]; then \
379                 install -m 755 init.asterisk /etc/rc.d/init.d/asterisk; \
380                 /sbin/chkconfig --add asterisk; \
381         elif [ -d /etc/init.d ]; then \
382                 install -m 755 init.asterisk /etc/init.d/asterisk; \
383         fi 
384
385         
386 dont-optimize:
387         $(MAKE) OPTIMIZE= K6OPT= install
388
389 valgrind: dont-optimize
390
391 depend: .depend
392         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
393
394 .depend:
395         ./mkdep ${CFLAGS} `ls *.c`
396