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