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