e565d6b932a55af102ac717d4a132950ea5504f3
[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
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 .PHONY: ast_expr
356
357 build_tools/vercomp: build_tools/vercomp.c
358         $(HOST_CC) -o $@ $<
359
360 ast_expr: build_tools/vercomp
361         $(MAKE) ast_expr.a
362
363 ifeq ($(MAKECMDGOALS),ast_expr.a)
364 FLEXVER_GT_2_5_31=$(shell build_tools/vercomp flex \>= 2.5.31)
365 BISONVER_GE_1_85=$(shell build_tools/vercomp bison \>= 1.85 )
366 endif
367
368 ifeq ($(FLEXVER_GT_2_5_31),true)
369 FLEXOBJS=ast_expr2.o ast_expr2f.o
370 else
371 FLEXOBJS=ast_expr.o
372 endif
373
374 ast_expr.o:: ast_expr.c
375         @echo "================================================================================="
376         @echo "NOTE: Using older version of expression parser. To use the newer version,"
377         @echo "NOTE: upgrade to flex 2.5.31 or higher, which can be found at"
378         @echo "NOTE: http://sourceforge.net/project/showfiles.php?group_id=72099"
379         @echo "================================================================================="
380
381 ast_expr.o:: ast_expr.c
382
383 ifeq ($(BISONVER_GE_1_85),false)
384 .y.c:
385         @echo "================================================================================="
386         @echo "NOTE: You may have trouble if you do not have bison-1.85 or higher installed!"
387         @echo "NOTE: You can pick up a copy at: http://ftp.gnu.org or its mirrors"
388         @echo "NOTE: You have:"
389         @bison --version
390         @echo "================================================================================"
391         bison -v -d --name-prefix=ast_yy $< -o $@
392 else
393 .y.c:
394         bison -v -d --name-prefix=ast_yy $< -o $@
395 endif
396
397 ast_expr2f.c: ast_expr2.fl
398         flex ast_expr2.fl
399
400 ast_expr.a: $(FLEXOBJS)
401         @rm -f $@
402         ar r $@ $(FLEXOBJS)
403         ranlib $@
404
405 testexpr2 :
406         flex ast_expr2.fl
407         bison -v -d --name-prefix=ast_yy -o ast_expr2.c ast_expr2.y
408         gcc -g -c -DSTANDALONE ast_expr2f.c
409         gcc -g -c -DSTANDALONE ast_expr2.c
410         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
411         rm ast_expr2.c ast_expr2.o ast_expr2f.o ast_expr2f.c
412
413 manpage: asterisk.8.gz
414
415 asterisk.8.gz: asterisk.sgml
416         rm -f asterisk.8
417         docbook2man asterisk.sgml
418         mv ./*.8 asterisk.8
419         gzip asterisk.8
420
421 asterisk.pdf: asterisk.sgml
422         docbook2pdf asterisk.sgml
423
424 asterisk.ps: asterisk.sgml
425         docbook2ps asterisk.sgml
426
427 asterisk.html: asterisk.sgml
428         docbook2html asterisk.sgml
429         mv r1.html asterisk.html
430
431 asterisk.txt: asterisk.sgml
432         docbook2txt asterisk.sgml
433
434 defaults.h: FORCE
435         build_tools/make_defaults_h > $@.tmp
436         if cmp -s $@.tmp $@ ; then echo ; else \
437                 mv $@.tmp $@ ; \
438         fi
439         rm -f $@.tmp
440
441
442 include/asterisk/build.h:
443         build_tools/make_build_h > $@.tmp
444         if cmp -s $@.tmp $@ ; then echo ; else \
445                 mv $@.tmp $@ ; \
446         fi
447         rm -f $@.tmp
448
449 # only force 'build.h' to be made for a non-'install' run
450 ifeq ($(findstring install,$(MAKECMDGOALS)),)
451 include/asterisk/build.h: FORCE
452 endif
453
454 include/asterisk/version.h: FORCE
455         build_tools/make_version_h > $@.tmp
456         if cmp -s $@.tmp $@ ; then echo; else \
457                 mv $@.tmp $@ ; \
458         fi
459         rm -f $@.tmp
460
461 stdtime/libtime.a: FORCE
462         @if [ -d stdtime ]; then \
463                 $(MAKE) -C stdtime libtime.a ; \
464         else \
465                 echo "You need to do a cvs update -d not just cvs update"; \
466                 exit 1; \
467         fi
468
469 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS) ast_expr
470         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) ast_expr.a $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
471
472 muted: muted.o
473         $(CC) $(AUDIO_LIBS) -o muted muted.o
474
475 subdirs: 
476         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
477
478 clean:
479         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
480         rm -f *.o *.so asterisk .depend
481         rm -f defaults.h
482         rm -f include/asterisk/build.h
483         rm -f include/asterisk/version.h
484         rm -f ast_expr.c ast_expr.h ast_expr.output
485         rm -f ast_expr2.c ast_expr2f.c ast_expr2.h ast_expr2.output
486         rm -f ast_expr.a build_tools/vercomp
487         rm -f .version
488         rm -f .tags-depend .tags-sources tags TAGS
489         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
490         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
491         $(MAKE) -C db1-ast clean
492         $(MAKE) -C stdtime clean
493
494 datafiles: all
495         sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig
496         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
497         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/priv-callerintros
498         for x in sounds/digits/*.gsm; do \
499                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
500                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
501                 else \
502                         echo "No description for $$x"; \
503                         exit 1; \
504                 fi; \
505         done
506         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
507         for x in sounds/dictate/*.gsm; do \
508                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
509                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
510                 else \
511                         echo "No description for $$x"; \
512                         exit 1; \
513                 fi; \
514         done
515         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
516         for x in sounds/letters/*.gsm; do \
517                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
518                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
519                 else \
520                         echo "No description for $$x"; \
521                         exit 1; \
522                 fi; \
523         done
524         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
525         for x in sounds/phonetic/*.gsm; do \
526                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
527                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
528                 else \
529                         echo "No description for $$x"; \
530                         exit 1; \
531                 fi; \
532         done
533         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 \
534                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
535                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
536                 else \
537                         echo "No description for $$x"; \
538                         exit 1; \
539                 fi; \
540         done
541         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
542         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
543         for x in images/*.jpg; do \
544                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
545         done
546         mkdir -p $(DESTDIR)$(AGI_DIR)
547
548 update: 
549         @if [ -d CVS ]; then \
550                 if [ -f patches/.applied ]; then \
551                         patches=`cat patches/.applied`; \
552                 fi; \
553                 if [ ! -z "$$patches" ]; then \
554                         for x in $$patches; do \
555                                 echo "Unapplying $$x..."; \
556                                 patch -R -p0 < patches/$$x; \
557                         done; \
558                         rm -f patches/.applied; \
559                 fi ; \
560                 echo "Updating from CVS..." ; \
561                 cvs -q -z3 update -Pd | tee update.out; \
562                 rm -f .version; \
563                 if [ `grep -c ^C update.out` -gt 0 ]; then \
564                         echo ; echo "The following files have conflicts:" ; \
565                         grep ^C update.out | cut -d' ' -f2- ; \
566                 fi ; \
567                 rm -f update.out; \
568                 if [ ! -z "$$patches" ]; then \
569                         for x in $$patches; do \
570                                 if [ -f patches/$$x ]; then \
571                                         echo "Applying patch $$x..."; \
572                                         patch -p0 < patches/$$x; \
573                                         echo $$x >> patches/.applied; \
574                                 else \
575                                         echo "Patch $$x no longer relevant"; \
576                                 fi; \
577                         done; \
578                 fi; \
579         else \
580                 echo "Not CVS";  \
581         fi
582
583 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
584 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
585
586 bininstall: all
587         mkdir -p $(DESTDIR)$(MODULES_DIR)
588         mkdir -p $(DESTDIR)$(ASTSBINDIR)
589         mkdir -p $(DESTDIR)$(ASTETCDIR)
590         mkdir -p $(DESTDIR)$(ASTBINDIR)
591         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
592         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
593         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
594         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
595         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
596         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
597         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
598         install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
599         install -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/     
600         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
601                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
602         fi
603         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
604         install -d $(DESTDIR)$(ASTHEADERDIR)
605         install -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
606         if [ -n "$(OLDHEADERS)" ]; then \
607                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
608         fi
609         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
610         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
611         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
612         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
613         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
614         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
615         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
616         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
617         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
618         install -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
619         install -m 644 asterisk.8.gz $(DESTDIR)$(ASTMANDIR)/man8
620         install -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
621         install -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
622         install -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
623         if [ -d contrib/firmware/iax ]; then \
624                 install -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
625         else \
626                 echo "You need to do cvs update -d not just cvs update" ; \
627         fi 
628         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
629         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
630         @echo " +---- Asterisk Installation Complete -------+"  
631         @echo " +                                           +"
632         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
633         @echo " +                                           +"
634         @echo " + Asterisk has successfully been installed. +"  
635         @echo " + If you would like to install the sample   +"  
636         @echo " + configuration files (overwriting any      +"
637         @echo " + existing config files), run:              +"  
638         @echo " +                                           +"
639         @echo " +               $(MAKE) samples                +"
640         @echo " +                                           +"
641         @echo " +-----------------  or ---------------------+"
642         @echo " +                                           +"
643         @echo " + You can go ahead and install the asterisk +"
644         @echo " + program documentation now or later run:   +"
645         @echo " +                                           +"
646         @echo " +              $(MAKE) progdocs                +"
647         @echo " +                                           +"
648         @echo " + **Note** This requires that you have      +"
649         @echo " + doxygen installed on your local system    +"
650         @echo " +-------------------------------------------+"
651         @$(MAKE) -s oldmodcheck
652
653 NEWMODS=$(notdir $(wildcard */*.so))
654 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
655
656 oldmodcheck:
657         @if [ -n "$(OLDMODS)" ]; then \
658                 echo " WARNING WARNING WARNING" ;\
659                 echo "" ;\
660                 echo " Your Asterisk modules directory, located at" ;\
661                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
662                 echo " contains modules that were not installed by this " ;\
663                 echo " version of Asterisk. Please ensure that these" ;\
664                 echo " modules are compatible with this version before" ;\
665                 echo " attempting to run Asterisk." ;\
666                 echo "" ;\
667                 for f in $(OLDMODS); do \
668                         echo "    $$f" ;\
669                 done ;\
670                 echo "" ;\
671                 echo " WARNING WARNING WARNING" ;\
672         fi
673
674 install: all datafiles bininstall
675
676 upgrade: all bininstall
677
678 adsi: all
679         mkdir -p $(DESTDIR)$(ASTETCDIR)
680         for x in configs/*.adsi; do \
681                 if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
682                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
683                 fi ; \
684         done
685
686 samples: all datafiles adsi
687         mkdir -p $(DESTDIR)$(ASTETCDIR)
688         for x in configs/*.sample; do \
689                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
690                         if [ "$(OVERWRITE)" = "y" ]; then \
691                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
692                                         echo "Config file $$x is unchanged"; \
693                                         continue; \
694                                 fi ; \
695                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
696                         else \
697                                 echo "Skipping config file $$x"; \
698                                 continue; \
699                         fi ;\
700                 fi ; \
701                 install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
702         done
703         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTETCDIR)/asterisk.conf ]; then \
704                 echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
705                 echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
706                 echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
707                 echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
708                 echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
709                 echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
710                 echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
711                 echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
712                 echo "" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
713                 echo "; Changing the following lines may compromise your security." >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
714                 echo ";[files]" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
715                 echo ";astctlpermissions = 0660" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
716                 echo ";astctlowner = root" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
717                 echo ";astctlgroup = apache" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
718                 echo ";astctl = asterisk.ctl" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
719         else \
720                 echo "Skipping asterisk.conf creation"; \
721         fi
722         for x in sounds/demo-*; do \
723                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
724                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
725                 else \
726                         echo "No description for $$x"; \
727                         exit 1; \
728                 fi; \
729         done
730         for x in sounds/*.mp3; do \
731                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
732         done
733         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
734         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
735         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
736         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
737                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
738         done
739         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
740         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
741                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
742         done
743
744 webvmail:
745         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
746         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
747         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
748         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
749         for x in images/*.gif; do \
750                 install -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
751         done
752         @echo " +--------- Asterisk Web Voicemail ----------+"  
753         @echo " +                                           +"
754         @echo " + Asterisk Web Voicemail is installed in    +"
755         @echo " + your cgi-bin directory:                   +"
756         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
757         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
758         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
759         @echo " +                                           +"
760         @echo " + Other static items have been stored in:   +"
761         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
762         @echo " +                                           +"
763         @echo " + If these paths do not match your httpd    +"
764         @echo " + installation, correct the definitions     +"
765         @echo " + in your Makefile of HTTP_CGIDIR and       +"
766         @echo " + HTTP_DOCSDIR                              +"
767         @echo " +                                           +"
768         @echo " +-------------------------------------------+"  
769
770 spec: 
771         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
772
773 rpm: __rpm
774
775 __rpm: include/asterisk/version.h spec
776         rm -rf /tmp/asterisk ; \
777         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
778         $(MAKE) DESTDIR=/tmp/asterisk install ; \
779         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
780         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
781         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
782         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
783
784 progdocs:
785         doxygen contrib/asterisk-ng-doxygen
786
787 mpg123:
788         @wget -V >/dev/null || (echo "You need wget" ; false )
789         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
790         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
791         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
792
793 config:
794         if [ -d /etc/rc.d/init.d ]; then \
795                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
796                 /sbin/chkconfig --add asterisk; \
797         elif [ -d /etc/init.d ]; then \
798                 install -m 755 init.asterisk /etc/init.d/asterisk; \
799         fi 
800
801 dont-optimize:
802         $(MAKE) OPTIMIZE= K6OPT= install
803
804 valgrind: dont-optimize
805
806 depend: include/asterisk/build.h include/asterisk/version.h .depend defaults.h 
807         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
808
809 .depend: include/asterisk/version.h
810         build_tools/mkdep ${CFLAGS} $(filter-out ast_expr.c,$(wildcard *.c))
811         build_tools/mkdep -a -d ${CFLAGS} ast_expr.c
812
813 .tags-depend:
814         @echo -n ".tags-depend: " > $@
815         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
816         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
817         @find ${SUBDIRS} -name \*.c -printf "\t%p \\\\\n" >> $@
818         @find ${SUBDIRS} -name \*.h -printf "\t%p \\\\\n" >> $@
819         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
820         @echo >> $@
821
822 .tags-sources:
823         @rm -f $@
824         @find . -maxdepth 1 -name \*.c -print >> $@
825         @find . -maxdepth 1 -name \*.h -print >> $@
826         @find ${SUBDIRS} -name \*.c -print >> $@
827         @find ${SUBDIRS} -name \*.h -print >> $@
828         @find include -name \*.h -print >> $@
829
830 tags: .tags-depend .tags-sources
831         ctags -L .tags-sources -o $@
832
833 ctags: tags
834
835 TAGS: .tags-depend .tags-sources
836         etags -o $@ `cat .tags-sources`
837
838 etags: TAGS
839
840 FORCE:
841
842 %_env:
843         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
844
845 env:
846         env
847
848 # If the cleancount has been changed, force a make clean.
849 # .cleancount is the global clean count, and .lastclean is the 
850 # last clean count we had
851 # We can avoid this by making noclean
852
853 cleantest:
854         if cmp -s .cleancount .lastclean ; then echo ; else \
855                 $(MAKE) clean; cp -f .cleancount .lastclean;\
856         fi
857
858 patchlist:
859         @echo "Experimental Patches:"
860         @for x in patches/*; do \
861                 patch=`basename $$x`; \
862                 if [ "$$patch" = "CVS" ]; then \
863                         continue; \
864                 fi; \
865                 if grep -q ^$$patch$$ patches/.applied; then \
866                         echo "$$patch (applied)"; \
867                 else \
868                         echo "$$patch (available)"; \
869                 fi; \
870         done
871
872 apply: 
873         @if [ -z "$(PATCH)" ]; then \
874                 echo "Usage: make PATCH=<patchname> apply"; \
875         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
876                 echo "Patch $(PATCH) is already applied"; \
877         elif [ -f "patches/$(PATCH)" ]; then \
878                 echo "Applying patch $(PATCH)"; \
879                 patch -p0 < patches/$(PATCH); \
880                 echo "$(PATCH)" >> patches/.applied; \
881         else \
882                 echo "No such patch $(PATCH) in patches directory"; \
883         fi
884
885 unapply: 
886         @if [ -z "$(PATCH)" ]; then \
887                 echo "Usage: make PATCH=<patchname> unapply"; \
888         elif grep -v -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
889                 echo "Patch $(PATCH) is not applied"; \
890         elif [ -f "patches/$(PATCH)" ]; then \
891                 echo "Un-applying patch $(PATCH)"; \
892                 patch -p0 -R < patches/$(PATCH); \
893                 rm -f patches/.tmpapplied || :; \
894                 mv patches/.applied patches/.tmpapplied; \
895                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
896                 rm -f patches/.tmpapplied; \
897         else \
898                 echo "No such patch $(PATCH) in patches directory"; \
899         fi