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