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