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