allow users of RTP to know when the peer endpoint is (apparently) behind a NAT
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999-2005, Mark Spencer
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 .EXPORT_ALL_VARIABLES:
15
16 # Create OPTIONS variable
17 OPTIONS=
18 # If cross compiling, define these to suit
19 # CROSS_COMPILE=/opt/montavista/pro/devkit/arm/xscale_be/bin/xscale_be-
20 # CROSS_COMPILE_BIN=/opt/montavista/pro/devkit/arm/xscale_be/bin/
21 # CROSS_COMPILE_TARGET=/opt/montavista/pro/devkit/arm/xscale_be/target
22 CC=$(CROSS_COMPILE)gcc
23 HOST_CC=gcc
24 # CROSS_ARCH=Linux
25 # CROSS_PROC=arm
26 # SUB_PROC=xscale # or maverick
27
28 ifeq ($(CROSS_COMPILE),)
29   OSARCH=$(shell uname -s)
30   OSREV=$(shell uname -r)
31 else
32   OSARCH=$(CROSS_ARCH)
33   OSREV=$(CROSS_REV)
34 endif
35
36 # Remember the MAKELEVEL at the top
37 MAKETOPLEVEL?=$(MAKELEVEL)
38
39 ######### More GSM codec optimization
40 ######### Uncomment to enable MMXTM optimizations for x86 architecture CPU's
41 ######### which support MMX instructions.  This should be newer pentiums,
42 ######### ppro's, etc, as well as the AMD K6 and K7.  
43 #K6OPT  = -DK6OPT
44
45 #Overwite config files on "make samples"
46 OVERWRITE=y
47
48 #Tell gcc to optimize the code
49 OPTIMIZE+=-O6
50
51 #Include debug symbols in the executables (-g) and profiling info (-pg)
52 DEBUG=-g #-pg
53
54 # If you are running a radio application, define RADIO_RELAX so that the DTMF
55 # will be received more reliably
56 #OPTIONS += -DRADIO_RELAX
57
58 # If you don't have a lot of memory (e.g. embedded Asterisk), define LOW_MEMORY
59 # to reduce the size of certain static buffers
60
61 #ifneq ($(CROSS_COMPILE),)
62 #OPTIONS += -DLOW_MEMORY
63 #endif
64
65 # Optional debugging parameters
66 DEBUG_THREADS = #-DDUMP_SCHEDULER #-DDEBUG_SCHEDULER #-DDEBUG_THREADS #-DDO_CRASH #-DDETECT_DEADLOCKS
67
68 # Uncomment next one to enable ast_frame tracing (for debugging)
69 TRACE_FRAMES = #-DTRACE_FRAMES
70
71 # Uncomment next one to enable malloc debugging
72 # You can view malloc debugging with:
73 #   *CLI> show memory allocations [filename]
74 #   *CLI> show memory summary [filename]
75 #
76 MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
77
78 # Where to install asterisk after compiling
79 # Default -> leave empty
80 INSTALL_PREFIX=
81
82 # Staging directory
83 # Files are copied here temporarily during the install process
84 # For example, make DESTDIR=/tmp/asterisk woud put things in
85 # /tmp/asterisk/etc/asterisk
86 DESTDIR=
87
88 # Original busydetect routine
89 BUSYDETECT = #-DBUSYDETECT
90
91 # Improved busydetect routine, comment the previous one if you use this one
92 BUSYDETECT+= #-DBUSYDETECT_MARTIN 
93 # Detect the busy signal looking only at tone lengths
94 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
95 BUSYDETECT+= #-DBUSYDETECT_TONEONLY
96 # Inforce the detection of busy singal (get rid of false hangups)
97 # Don't use together with -DBUSYDETECT_TONEONLY
98 BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
99
100 ifneq (${OSARCH},SunOS)
101   ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
102   ASTVARLIBDIR=$(INSTALL_PREFIX)/var/lib/asterisk
103   ASTETCDIR=$(INSTALL_PREFIX)/etc/asterisk
104   ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
105   ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
106   ASTHEADERDIR=$(INSTALL_PREFIX)/usr/include/asterisk
107   ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
108   ASTBINDIR=$(INSTALL_PREFIX)/usr/bin
109   ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
110   ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
111   ASTMANDIR=$(INSTALL_PREFIX)/usr/share/man
112   MODULES_DIR=$(ASTLIBDIR)/modules
113   AGI_DIR=$(ASTVARLIBDIR)/agi-bin
114 else
115   ASTLIBDIR=$(INSTALL_PREFIX)/opt/asterisk/lib
116   ASTVARLIBDIR=$(INSTALL_PREFIX)/var/opt/asterisk/lib
117   ASTETCDIR=$(INSTALL_PREFIX)/etc/opt/asterisk
118   ASTSPOOLDIR=$(INSTALL_PREFIX)/var/opt/asterisk/spool
119   ASTLOGDIR=$(INSTALL_PREFIX)/var/opt/asterisk/log
120   ASTHEADERDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/include/asterisk
121   ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
122   ASTBINDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/bin
123   ASTSBINDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/sbin
124   ASTVARRUNDIR=$(INSTALL_PREFIX)/var/opt/asterisk/run
125   ASTMANDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/share/man
126   MODULES_DIR=$(ASTLIBDIR)/modules
127   AGI_DIR=$(ASTVARLIBDIR)/agi-bin
128 endif
129
130 ASTCFLAGS=
131
132 # Pentium Pro Optimize
133 #PROC=i686
134
135 # Pentium & VIA processors optimize
136 #PROC=i586
137
138 #PROC=k6
139 #PROC=ppc
140
141 #Uncomment this to use the older DSP routines
142 #ASTCFLAGS+=-DOLD_DSP_ROUTINES
143
144 # Determine by a grep 'DocumentRoot' of your httpd.conf file
145 HTTP_DOCSDIR=/var/www/html
146 # Determine by a grep 'ScriptAlias' of your httpd.conf file
147 HTTP_CGIDIR=/var/www/cgi-bin
148
149 # If the file .asterisk.makeopts is present in your home directory, you can
150 # include all of your favorite Makefile options so that every time you download
151 # a new version of Asterisk, you don't have to edit the makefile to set them. 
152 # The file, /etc/asterisk.makeopts will also be included, but can be overridden
153 # by the file in your home directory.
154
155 ifneq ($(wildcard /etc/asterisk.makeopts),)
156   include /etc/asterisk.makeopts
157 endif
158
159 ifneq ($(wildcard ~/.asterisk.makeopts),)
160   include ~/.asterisk.makeopts
161 endif
162
163 ifeq (${OSARCH},Linux)
164   ifeq ($(CROSS_COMPILE),)
165     PROC?=$(shell uname -m)
166   else
167     PROC=$(CROSS_PROC)
168   endif
169
170   ifeq ($(PROC),x86_64)
171     # You must have GCC 3.4 to use k8, otherwise use athlon
172     PROC=k8
173     #PROC=athlon
174     OPTIONS+=-m64
175   endif
176
177   ifeq ($(PROC),sparc64)
178     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
179     #This works for even old (2.96) versions of gcc and provides a small boost either way.
180     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
181     #So we go lowest common available by gcc and go a step down, still a step up from
182     #the default as we now have a better instruction set to work with. - Belgarath
183     PROC=ultrasparc
184     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
185     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
186     OPTIONS+=-fomit-frame-pointer
187   endif
188
189   ifeq ($(PROC),arm)
190     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
191     ifeq ($(SUB_PROC),maverick)
192       OPTIONS+=-fsigned-char -mcpu=ep9312
193     else
194       ifeq ($(SUB_PROC),xscale)
195         OPTIONS+=-fsigned-char -msoft-float -mcpu=xscale
196       else
197         OPTIONS+=-fsigned-char -msoft-float 
198       endif
199     endif
200   endif
201   MPG123TARG=linux
202 endif
203
204 ifeq ($(findstring BSD,${OSARCH}),BSD)
205   PROC=$(shell uname -m)
206   ASTCFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
207 endif
208
209 PWD=$(shell pwd)
210 GREP=grep
211
212 ifeq (${OSARCH},SunOS)
213   GREP=/usr/xpg4/bin/grep
214   M4=/usr/local/bin/m4
215 endif
216
217 INCLUDE=-Iinclude -I../include
218 ASTCFLAGS+=-pipe  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
219 ASTCFLAGS+=$(OPTIMIZE)
220
221 ifneq ($(PROC),ultrasparc)
222   ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
223 endif
224
225 ifeq ($(PROC),ppc)
226   ASTCFLAGS+=-fsigned-char
227 endif
228
229 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/osp/osp.h),)
230   ASTCFLAGS+=-DOSP_SUPPORT -I$(CROSS_COMPILE_TARGET)/usr/include/osp
231 endif
232
233 ifeq (${OSARCH},FreeBSD)
234   BSDVERSION=$(shell make -V OSVERSION -f $(CROSS_COMPILE_TARGET)/usr/share/mk/bsd.port.subdir.mk)
235   ASTCFLAGS+=$(shell if test ${BSDVERSION} -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
236   LIBS+=$(shell if test  ${BSDVERSION} -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
237   ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/spandsp),)
238     ASTCFLAGS+=" -I$(CROSS_COMPILE_TARGET)/usr/local/include/spandsp"
239   endif
240   MPG123TARG=freebsd
241 endif # FreeBSD
242
243 ifeq (${OSARCH},NetBSD)
244   ASTCFLAGS+=-pthread
245   INCLUDE+=-I$(CROSS_COMPILE_TARGET)/usr/pkg/include
246   MPG123TARG=netbsd
247 endif
248
249 ifeq (${OSARCH},OpenBSD)
250   ASTCFLAGS+=-pthread
251 endif
252
253 ifeq (${OSARCH},SunOS)
254   ASTCFLAGS+=-Wcast-align -DSOLARIS
255   INCLUDE+=-Iinclude/solaris-compat -I$(CROSS_COMPILE_TARGET)/usr/local/ssl/include
256 endif
257
258 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/zaptel.h),)
259   ASTCFLAGS+=-DZAPTEL_OPTIMIZATIONS
260 endif
261
262 LIBEDIT=editline/libedit.a
263
264 ifneq ($(wildcard .version),)
265   ASTERISKVERSION=$(shell cat .version)
266   ASTERISKVERSIONNUM=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
267   RPMVERSION=$(shell sed 's/[-\/:]/_/g' .version)
268 else
269   RPMVERSION=unknown
270 endif
271
272 ifneq ($(wildcard CVS),)
273   ASTERISKVERSIONNUM=999999
274   ifneq ($(wildcard CVS/Tag),)
275     ASTERISKVERSION=$(shell echo "CVS-`sed 's/^T//g' CVS/Tag`-`date +"%D-%T"`")
276   else
277     ASTERISKVERSION=CVS HEAD
278   endif
279 else
280   ASTERISKVERSIONNUM=000000
281 endif
282
283 ASTCFLAGS+= $(DEBUG_THREADS)
284 ASTCFLAGS+= $(TRACE_FRAMES)
285 ASTCFLAGS+= $(MALLOC_DEBUG)
286 ASTCFLAGS+= $(BUSYDETECT)
287 ASTCFLAGS+= $(OPTIONS)
288 ASTCFLAGS+= -fomit-frame-pointer 
289 SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
290
291 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
292         translate.o file.o say.o pbx.o cli.o md5.o term.o \
293         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
294         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o \
295         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
296         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
297         utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
298         netsock.o slinfactory.o ast_expr2.o ast_expr2f.o
299
300 ifeq (${OSARCH},Linux)
301   LIBS=-ldl -lpthread -lncurses -lm -lresolv  #-lnjamd
302 else
303   LIBS+=-lncurses -lm
304 endif
305
306 ifeq (${OSARCH},Darwin)
307   LIBS+=-lresolv
308   ASTCFLAGS+=-D__Darwin__
309   AUDIO_LIBS=-framework CoreAudio
310   OBJS+=poll.o dlfcn.o
311   ASTLINK=-Wl,-dynamic
312   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
313 else
314 #These are used for all but Darwin
315   ASTLINK=-Wl,-E 
316   SOLINK=-shared -Xlinker -x
317 endif
318
319 ifeq (${OSARCH},FreeBSD)
320   LIBS+=-lcrypto
321 endif
322
323 ifeq (${OSARCH},NetBSD)
324   LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
325 endif
326
327 ifeq (${OSARCH},OpenBSD)
328   LIBS=-lcrypto -lpthread -lm -lncurses
329 endif
330
331 ifeq (${OSARCH},SunOS)
332   LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
333   OBJS+=strcompat.o
334   ASTLINK=
335   SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
336 endif
337
338 ifeq ($(MAKETOPLEVEL),$(MAKELEVEL))
339   CFLAGS+=$(ASTCFLAGS)
340 endif
341
342 LIBS+=-lssl
343
344 INSTALL=install
345
346 _all: all
347         @echo " +--------- Asterisk Build Complete ---------+"  
348         @echo " + Asterisk has successfully been built, but +"  
349         @echo " + cannot be run before being installed by   +"  
350         @echo " + running:                                  +"  
351         @echo " +                                           +"
352         @echo " +               $(MAKE) install                +"  
353         @echo " +-------------------------------------------+"  
354
355 all: cleantest depend asterisk subdirs 
356
357 #ifneq ($(wildcard tags),)
358 ctags: tags
359 #endif
360
361 ifneq ($(wildcard TAGS),)
362 all: TAGS
363 endif
364
365 noclean: depend asterisk subdirs
366
367 editline/config.h:
368         cd editline && unset CFLAGS LIBS && ./configure ; \
369
370 editline/libedit.a: FORCE
371         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
372         $(MAKE) -C editline libedit.a
373
374 db1-ast/libdb1.a: FORCE
375         @if [ -d db1-ast ]; then \
376                 $(MAKE) -C db1-ast libdb1.a ; \
377         else \
378                 echo "You need to do a cvs update -d not just cvs update"; \
379                 exit 1; \
380         fi
381
382 ifneq ($(wildcard .depend),)
383   include .depend
384 endif
385
386 ifneq ($(wildcard .tags-depend),)
387   include .tags-depend
388 endif
389
390 ast_expr2.c:
391         bison -d --name-prefix=ast_yy ast_expr2.y -o ast_expr2.c
392
393 ast_expr2f.c:
394         flex --full ast_expr2.fl
395
396 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
397         gcc -g -c -DSTANDALONE ast_expr2f.c
398         gcc -g -c -DSTANDALONE ast_expr2.c
399         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
400         rm ast_expr2.c ast_expr2.o ast_expr2f.o ast_expr2f.c
401
402 manpage: asterisk.8.gz
403
404 asterisk.8.gz: asterisk.sgml
405         rm -f asterisk.8
406         docbook2man asterisk.sgml
407         mv ./*.8 asterisk.8
408         gzip asterisk.8
409
410 asterisk.pdf: asterisk.sgml
411         docbook2pdf asterisk.sgml
412
413 asterisk.ps: asterisk.sgml
414         docbook2ps asterisk.sgml
415
416 asterisk.html: asterisk.sgml
417         docbook2html asterisk.sgml
418         mv r1.html asterisk.html
419
420 asterisk.txt: asterisk.sgml
421         docbook2txt asterisk.sgml
422
423 defaults.h: FORCE
424         build_tools/make_defaults_h > $@.tmp
425         if cmp -s $@.tmp $@ ; then echo ; else \
426                 mv $@.tmp $@ ; \
427         fi
428         rm -f $@.tmp
429
430 include/asterisk/build.h:
431         build_tools/make_build_h > $@.tmp
432         if cmp -s $@.tmp $@ ; then echo ; else \
433                 mv $@.tmp $@ ; \
434         fi
435         rm -f $@.tmp
436
437 # only force 'build.h' to be made for a non-'install' run
438 ifeq ($(findstring install,$(MAKECMDGOALS)),)
439 include/asterisk/build.h: FORCE
440 endif
441
442 include/asterisk/version.h: FORCE
443         build_tools/make_version_h > $@.tmp
444         if cmp -s $@.tmp $@ ; then echo; else \
445                 mv $@.tmp $@ ; \
446         fi
447         rm -f $@.tmp
448
449 stdtime/libtime.a: FORCE
450         @if [ -d stdtime ]; then \
451                 $(MAKE) -C stdtime libtime.a ; \
452         else \
453                 echo "You need to do a cvs update -d not just cvs update"; \
454                 exit 1; \
455         fi
456
457 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
458         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
459
460 muted: muted.o
461         $(CC) $(AUDIO_LIBS) -o muted muted.o
462
463 subdirs: 
464         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
465
466 clean:
467         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
468         rm -f *.o *.so asterisk .depend
469         rm -f defaults.h
470         rm -f include/asterisk/build.h
471         rm -f include/asterisk/version.h
472         rm -f .tags-depend .tags-sources tags TAGS
473         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
474         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
475         $(MAKE) -C db1-ast clean
476         $(MAKE) -C stdtime clean
477
478 datafiles: all
479         sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig
480         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
481         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/priv-callerintros
482         for x in sounds/digits/*.gsm; do \
483                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
484                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
485                 else \
486                         echo "No description for $$x"; \
487                         exit 1; \
488                 fi; \
489         done
490         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
491         for x in sounds/dictate/*.gsm; do \
492                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
493                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
494                 else \
495                         echo "No description for $$x"; \
496                         exit 1; \
497                 fi; \
498         done
499         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
500         for x in sounds/letters/*.gsm; do \
501                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
502                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
503                 else \
504                         echo "No description for $$x"; \
505                         exit 1; \
506                 fi; \
507         done
508         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
509         for x in sounds/phonetic/*.gsm; do \
510                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
511                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
512                 else \
513                         echo "No description for $$x"; \
514                         exit 1; \
515                 fi; \
516         done
517         for x in sounds/demo-* sounds/vm-* sounds/transfer* sounds/pbx-* sounds/ss-* sounds/beep* sounds/dir-* sounds/conf-* sounds/agent-* sounds/invalid* sounds/tt-* sounds/auth-* sounds/privacy-* sounds/queue-*; do \
518                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
519                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
520                 else \
521                         echo "No description for $$x"; \
522                         exit 1; \
523                 fi; \
524         done
525         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
526         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
527         for x in images/*.jpg; do \
528                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
529         done
530         mkdir -p $(DESTDIR)$(AGI_DIR)
531
532 update: 
533         @if [ -d CVS ]; then \
534                 if [ -f patches/.applied ]; then \
535                         patches=`cat patches/.applied`; \
536                 fi; \
537                 if [ ! -z "$$patches" ]; then \
538                         for x in $$patches; do \
539                                 echo "Unapplying $$x..."; \
540                                 patch -R -p0 < patches/$$x; \
541                         done; \
542                         rm -f patches/.applied; \
543                 fi ; \
544                 echo "Updating from CVS..." ; \
545                 cvs -q -z3 update -Pd | tee update.out; \
546                 rm -f .version; \
547                 if [ `grep -c ^C update.out` -gt 0 ]; then \
548                         echo ; echo "The following files have conflicts:" ; \
549                         grep ^C update.out | cut -d' ' -f2- ; \
550                 fi ; \
551                 rm -f update.out; \
552                 if [ ! -z "$$patches" ]; then \
553                         for x in $$patches; do \
554                                 if [ -f patches/$$x ]; then \
555                                         echo "Applying patch $$x..."; \
556                                         patch -p0 < patches/$$x; \
557                                         echo $$x >> patches/.applied; \
558                                 else \
559                                         echo "Patch $$x no longer relevant"; \
560                                 fi; \
561                         done; \
562                 fi; \
563         else \
564                 echo "Not CVS";  \
565         fi
566
567 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
568 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
569
570 bininstall: all
571         mkdir -p $(DESTDIR)$(MODULES_DIR)
572         mkdir -p $(DESTDIR)$(ASTSBINDIR)
573         mkdir -p $(DESTDIR)$(ASTETCDIR)
574         mkdir -p $(DESTDIR)$(ASTBINDIR)
575         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
576         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
577         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
578         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
579         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
580         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
581         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
582         install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
583         install -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/     
584         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
585                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
586         fi
587         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
588         install -d $(DESTDIR)$(ASTHEADERDIR)
589         install -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
590         if [ -n "$(OLDHEADERS)" ]; then \
591                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
592         fi
593         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
594         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
595         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
596         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
597         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
598         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
599         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
600         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
601         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
602         install -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
603         install -m 644 asterisk.8.gz $(DESTDIR)$(ASTMANDIR)/man8
604         install -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
605         install -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
606         install -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
607         if [ -d contrib/firmware/iax ]; then \
608                 install -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
609         else \
610                 echo "You need to do cvs update -d not just cvs update" ; \
611         fi 
612         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
613         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
614         @echo " +---- Asterisk Installation Complete -------+"  
615         @echo " +                                           +"
616         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
617         @echo " +                                           +"
618         @echo " + Asterisk has successfully been installed. +"  
619         @echo " + If you would like to install the sample   +"  
620         @echo " + configuration files (overwriting any      +"
621         @echo " + existing config files), run:              +"  
622         @echo " +                                           +"
623         @echo " +               $(MAKE) samples                +"
624         @echo " +                                           +"
625         @echo " +-----------------  or ---------------------+"
626         @echo " +                                           +"
627         @echo " + You can go ahead and install the asterisk +"
628         @echo " + program documentation now or later run:   +"
629         @echo " +                                           +"
630         @echo " +              $(MAKE) progdocs                +"
631         @echo " +                                           +"
632         @echo " + **Note** This requires that you have      +"
633         @echo " + doxygen installed on your local system    +"
634         @echo " +-------------------------------------------+"
635         @$(MAKE) -s oldmodcheck
636
637 NEWMODS=$(notdir $(wildcard */*.so))
638 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
639
640 oldmodcheck:
641         @if [ -n "$(OLDMODS)" ]; then \
642                 echo " WARNING WARNING WARNING" ;\
643                 echo "" ;\
644                 echo " Your Asterisk modules directory, located at" ;\
645                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
646                 echo " contains modules that were not installed by this " ;\
647                 echo " version of Asterisk. Please ensure that these" ;\
648                 echo " modules are compatible with this version before" ;\
649                 echo " attempting to run Asterisk." ;\
650                 echo "" ;\
651                 for f in $(OLDMODS); do \
652                         echo "    $$f" ;\
653                 done ;\
654                 echo "" ;\
655                 echo " WARNING WARNING WARNING" ;\
656         fi
657
658 install: all datafiles bininstall
659
660 upgrade: all bininstall
661
662 adsi:
663         mkdir -p $(DESTDIR)$(ASTETCDIR)
664         for x in configs/*.adsi; do \
665                 if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
666                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
667                 fi ; \
668         done
669
670 samples: adsi
671         mkdir -p $(DESTDIR)$(ASTETCDIR)
672         for x in configs/*.sample; do \
673                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
674                         if [ "$(OVERWRITE)" = "y" ]; then \
675                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
676                                         echo "Config file $$x is unchanged"; \
677                                         continue; \
678                                 fi ; \
679                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
680                         else \
681                                 echo "Skipping config file $$x"; \
682                                 continue; \
683                         fi ;\
684                 fi ; \
685                 install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
686         done
687         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTETCDIR)/asterisk.conf ]; then \
688                 echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
689                 echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
690                 echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
691                 echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
692                 echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
693                 echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
694                 echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
695                 echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
696                 echo "" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
697                 echo "; Changing the following lines may compromise your security." >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
698                 echo ";[files]" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
699                 echo ";astctlpermissions = 0660" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
700                 echo ";astctlowner = root" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
701                 echo ";astctlgroup = apache" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
702                 echo ";astctl = asterisk.ctl" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
703         else \
704                 echo "Skipping asterisk.conf creation"; \
705         fi
706         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
707         for x in sounds/demo-*; do \
708                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
709                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
710                 else \
711                         echo "No description for $$x"; \
712                         exit 1; \
713                 fi; \
714         done
715         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
716         for x in sounds/*.mp3; do \
717                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
718         done
719         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
720         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
721         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
722         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
723                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
724         done
725         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
726         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
727                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
728         done
729
730 webvmail:
731         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
732         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
733         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
734         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
735         for x in images/*.gif; do \
736                 install -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
737         done
738         @echo " +--------- Asterisk Web Voicemail ----------+"  
739         @echo " +                                           +"
740         @echo " + Asterisk Web Voicemail is installed in    +"
741         @echo " + your cgi-bin directory:                   +"
742         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
743         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
744         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
745         @echo " +                                           +"
746         @echo " + Other static items have been stored in:   +"
747         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
748         @echo " +                                           +"
749         @echo " + If these paths do not match your httpd    +"
750         @echo " + installation, correct the definitions     +"
751         @echo " + in your Makefile of HTTP_CGIDIR and       +"
752         @echo " + HTTP_DOCSDIR                              +"
753         @echo " +                                           +"
754         @echo " +-------------------------------------------+"  
755
756 spec: 
757         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
758
759 rpm: __rpm
760
761 __rpm: include/asterisk/version.h spec
762         rm -rf /tmp/asterisk ; \
763         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
764         $(MAKE) DESTDIR=/tmp/asterisk install ; \
765         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
766         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
767         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
768         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
769
770 progdocs:
771         doxygen contrib/asterisk-ng-doxygen
772
773 mpg123:
774         @wget -V >/dev/null || (echo "You need wget" ; false )
775         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
776         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
777         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
778
779 config:
780         if [ -d /etc/rc.d/init.d ]; then \
781                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
782                 /sbin/chkconfig --add asterisk; \
783         elif [ -d /etc/init.d ]; then \
784                 install -m 755 init.asterisk /etc/init.d/asterisk; \
785         fi 
786
787 dont-optimize:
788         $(MAKE) OPTIMIZE= K6OPT= install
789
790 valgrind: dont-optimize
791
792 depend: include/asterisk/build.h include/asterisk/version.h .depend defaults.h 
793         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
794
795 .depend: include/asterisk/version.h
796         build_tools/mkdep ${CFLAGS} $(wildcard *.c)
797
798 .tags-depend:
799         @echo -n ".tags-depend: " > $@
800         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
801         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
802         @find ${SUBDIRS} -name \*.c -printf "\t%p \\\\\n" >> $@
803         @find ${SUBDIRS} -name \*.h -printf "\t%p \\\\\n" >> $@
804         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
805         @echo >> $@
806
807 .tags-sources:
808         @rm -f $@
809         @find . -maxdepth 1 -name \*.c -print >> $@
810         @find . -maxdepth 1 -name \*.h -print >> $@
811         @find ${SUBDIRS} -name \*.c -print >> $@
812         @find ${SUBDIRS} -name \*.h -print >> $@
813         @find include -name \*.h -print >> $@
814
815 tags: .tags-depend .tags-sources
816         ctags -L .tags-sources -o $@
817
818 ctags: tags
819
820 TAGS: .tags-depend .tags-sources
821         etags -o $@ `cat .tags-sources`
822
823 etags: TAGS
824
825 FORCE:
826
827 %_env:
828         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
829
830 env:
831         env
832
833 # If the cleancount has been changed, force a make clean.
834 # .cleancount is the global clean count, and .lastclean is the 
835 # last clean count we had
836 # We can avoid this by making noclean
837
838 cleantest:
839         if cmp -s .cleancount .lastclean ; then echo ; else \
840                 $(MAKE) clean; cp -f .cleancount .lastclean;\
841         fi
842
843 patchlist:
844         @echo "Experimental Patches:"
845         @for x in patches/*; do \
846                 patch=`basename $$x`; \
847                 if [ "$$patch" = "CVS" ]; then \
848                         continue; \
849                 fi; \
850                 if grep -q ^$$patch$$ patches/.applied; then \
851                         echo "$$patch (applied)"; \
852                 else \
853                         echo "$$patch (available)"; \
854                 fi; \
855         done
856
857 apply: 
858         @if [ -z "$(PATCH)" ]; then \
859                 echo "Usage: make PATCH=<patchname> apply"; \
860         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
861                 echo "Patch $(PATCH) is already applied"; \
862         elif [ -f "patches/$(PATCH)" ]; then \
863                 echo "Applying patch $(PATCH)"; \
864                 patch -p0 < patches/$(PATCH); \
865                 echo "$(PATCH)" >> patches/.applied; \
866         else \
867                 echo "No such patch $(PATCH) in patches directory"; \
868         fi
869
870 unapply: 
871         @if [ -z "$(PATCH)" ]; then \
872                 echo "Usage: make PATCH=<patchname> unapply"; \
873         elif grep -v -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
874                 echo "Patch $(PATCH) is not applied"; \
875         elif [ -f "patches/$(PATCH)" ]; then \
876                 echo "Un-applying patch $(PATCH)"; \
877                 patch -p0 -R < patches/$(PATCH); \
878                 rm -f patches/.tmpapplied || :; \
879                 mv patches/.applied patches/.tmpapplied; \
880                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
881                 rm -f patches/.tmpapplied; \
882         else \
883                 echo "No such patch $(PATCH) in patches directory"; \
884         fi
885