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