issue #5633
[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 endif
295
296 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),)
297   ASTCFLAGS+=-DZAPTEL_OPTIMIZATIONS
298 endif
299
300 LIBEDIT=editline/libedit.a
301
302 ifneq ($(wildcard .version),)
303   ASTERISKVERSION=$(shell cat .version)
304   ASTERISKVERSIONNUM=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
305   RPMVERSION=$(shell sed 's/[-\/:]/_/g' .version)
306 else
307   RPMVERSION=unknown
308 endif
309
310 ifneq ($(wildcard CVS),)
311   ASTERISKVERSIONNUM=999999
312   ifneq ($(wildcard CVS/Tag),)
313     ASTERISKVERSION=$(shell echo "CVS-`sed 's/^T//g' CVS/Tag`-`date +"%D-%T"`")
314   else
315     ASTERISKVERSION=CVS HEAD
316   endif
317 else
318   ASTERISKVERSIONNUM=000000
319 endif
320
321 ASTCFLAGS+= $(DEBUG_THREADS)
322 ASTCFLAGS+= $(TRACE_FRAMES)
323 ASTCFLAGS+= $(MALLOC_DEBUG)
324 ASTCFLAGS+= $(BUSYDETECT)
325 ASTCFLAGS+= $(OPTIONS)
326 ASTCFLAGS+= -fomit-frame-pointer 
327 SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
328
329 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
330         translate.o file.o say.o pbx.o cli.o md5.o term.o \
331         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
332         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o \
333         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
334         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
335         utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
336         netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
337         cryptostub.o
338
339 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sys/poll.h),)
340   OBJS+= poll.o
341   ASTCFLAGS+=-DPOLLCOMPAT
342 endif
343
344 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/dlfcn.h),)
345   OBJS+= dlfcn.o
346   ASTCFLAGS+=-DDLFCNCOMPAT
347 endif
348
349 ifeq ($(OSARCH),Linux)
350   LIBS+=-ldl -lpthread -lncurses -lm -lresolv  #-lnjamd
351 else
352   LIBS+=-lncurses -lm
353 endif
354
355 ifeq ($(OSARCH),Darwin)
356   LIBS+=-lresolv
357   ASTCFLAGS+=-D__Darwin__
358   AUDIO_LIBS=-framework CoreAudio
359   ASTLINK=-Wl,-dynamic
360   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
361 else
362 #These are used for all but Darwin
363   ASTLINK=-Wl,-E 
364   SOLINK=-shared -Xlinker -x
365 endif
366
367 ifeq ($(OSARCH),FreeBSD)
368   LIBS+=-lcrypto
369 endif
370
371 ifeq ($(OSARCH),NetBSD)
372   LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
373 endif
374
375 ifeq ($(OSARCH),OpenBSD)
376   LIBS+=-lcrypto -lpthread -lm -lncurses
377 endif
378
379 ifeq ($(OSARCH),SunOS)
380   LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
381   OBJS+=strcompat.o
382   ASTLINK=
383   SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
384 endif
385
386 ifeq ($(MAKETOPLEVEL),$(MAKELEVEL))
387   CFLAGS+=$(ASTCFLAGS)
388 endif
389
390 LIBS+=-lssl
391
392 INSTALL=install
393
394 _all: all
395         @echo " +--------- Asterisk Build Complete ---------+"  
396         @echo " + Asterisk has successfully been built, but +"  
397         @echo " + cannot be run before being installed by   +"  
398         @echo " + running:                                  +"  
399         @echo " +                                           +"
400         @echo " +               $(MAKE) install                +"  
401         @echo " +-------------------------------------------+"  
402
403 all: cleantest depend asterisk subdirs 
404
405 #ifneq ($(wildcard tags),)
406 ctags: tags
407 #endif
408
409 ifneq ($(wildcard TAGS),)
410 all: TAGS
411 endif
412
413 noclean: depend asterisk subdirs
414
415 editline/config.h:
416         cd editline && unset CFLAGS LIBS && ./configure ; \
417
418 editline/libedit.a: FORCE
419         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
420         $(MAKE) -C editline libedit.a
421
422 db1-ast/libdb1.a: FORCE
423         @if [ -d db1-ast ]; then \
424                 $(MAKE) -C db1-ast libdb1.a ; \
425         else \
426                 echo "You need to do a cvs update -d not just cvs update"; \
427                 exit 1; \
428         fi
429
430 ifneq ($(wildcard .depend),)
431   include .depend
432 endif
433
434 ifneq ($(wildcard .tags-depend),)
435   include .tags-depend
436 endif
437
438 ast_expr2.c:
439         bison -d --name-prefix=ast_yy ast_expr2.y -o ast_expr2.c
440
441 ast_expr2f.c:
442         flex --full ast_expr2.fl
443
444 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
445         gcc -g -c -DSTANDALONE ast_expr2f.c
446         gcc -g -c -DSTANDALONE ast_expr2.c
447         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
448         rm ast_expr2.o ast_expr2f.o 
449
450 manpage: asterisk.8
451
452 asterisk.8: asterisk.sgml
453         rm -f asterisk.8
454         docbook2man asterisk.sgml
455         mv ./*.8 asterisk.8
456
457 asterisk.pdf: asterisk.sgml
458         docbook2pdf asterisk.sgml
459
460 asterisk.ps: asterisk.sgml
461         docbook2ps asterisk.sgml
462
463 asterisk.html: asterisk.sgml
464         docbook2html asterisk.sgml
465         mv r1.html asterisk.html
466
467 asterisk.txt: asterisk.sgml
468         docbook2txt asterisk.sgml
469
470 defaults.h: FORCE
471         build_tools/make_defaults_h > $@.tmp
472         if cmp -s $@.tmp $@ ; then echo ; else \
473                 mv $@.tmp $@ ; \
474         fi
475         rm -f $@.tmp
476
477 include/asterisk/version.h: FORCE
478         build_tools/make_version_h > $@.tmp
479         if cmp -s $@.tmp $@ ; then echo; else \
480                 mv $@.tmp $@ ; \
481         fi
482         rm -f $@.tmp
483
484 stdtime/libtime.a: FORCE
485         @if [ -d stdtime ]; then \
486                 $(MAKE) -C stdtime libtime.a ; \
487         else \
488                 echo "You need to do a cvs update -d not just cvs update"; \
489                 exit 1; \
490         fi
491
492 cygwin_a:
493         $(MAKE) -C cygwin all
494
495 asterisk: $(CYGLOADER) editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
496         build_tools/make_build_h > include/asterisk/build.h.tmp
497         if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \
498                 mv include/asterisk/build.h.tmp include/asterisk/build.h ; \
499         fi
500         rm -f include/asterisk/build.h.tmp
501         $(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
502         $(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
503
504 muted: muted.o
505         $(CC) $(AUDIO_LIBS) -o muted muted.o
506
507 subdirs: 
508         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
509
510 clean:
511         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
512         rm -f *.o *.so asterisk .depend
513         rm -f defaults.h
514         rm -f include/asterisk/build.h
515         rm -f include/asterisk/version.h
516         rm -f .tags-depend .tags-sources tags TAGS
517         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
518         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
519         $(MAKE) -C db1-ast clean
520         $(MAKE) -C stdtime clean
521
522 datafiles: all
523         if test $$(id -u) = 0; then sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
524         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
525         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/priv-callerintros
526         for x in sounds/digits/*.gsm; do \
527                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
528                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
529                 else \
530                         echo "No description for $$x"; \
531                         exit 1; \
532                 fi; \
533         done
534         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
535         for x in sounds/dictate/*.gsm; do \
536                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
537                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
538                 else \
539                         echo "No description for $$x"; \
540                         exit 1; \
541                 fi; \
542         done
543         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
544         for x in sounds/letters/*.gsm; do \
545                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
546                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
547                 else \
548                         echo "No description for $$x"; \
549                         exit 1; \
550                 fi; \
551         done
552         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
553         for x in sounds/phonetic/*.gsm; do \
554                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
555                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
556                 else \
557                         echo "No description for $$x"; \
558                         exit 1; \
559                 fi; \
560         done
561         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 \
562                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
563                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
564                 else \
565                         echo "No description for $$x"; \
566                         exit 1; \
567                 fi; \
568         done
569         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
570         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
571         for x in images/*.jpg; do \
572                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
573         done
574         mkdir -p $(DESTDIR)$(AGI_DIR)
575
576 update: 
577         @if [ -d CVS ]; then \
578                 if [ -f patches/.applied ]; then \
579                         patches=`cat patches/.applied`; \
580                 fi; \
581                 if [ ! -z "$$patches" ]; then \
582                         for x in $$patches; do \
583                                 echo "Unapplying $$x..."; \
584                                 patch -R -p0 < patches/$$x; \
585                         done; \
586                         rm -f patches/.applied; \
587                 fi ; \
588                 echo "Updating from CVS..." ; \
589                 cvs -q -z3 update -Pd | tee update.out; \
590                 rm -f .version; \
591                 if [ `grep -c ^C update.out` -gt 0 ]; then \
592                         echo ; echo "The following files have conflicts:" ; \
593                         grep ^C update.out | cut -d' ' -f2- ; \
594                 fi ; \
595                 rm -f update.out; \
596                 if [ ! -z "$$patches" ]; then \
597                         for x in $$patches; do \
598                                 if [ -f patches/$$x ]; then \
599                                         echo "Applying patch $$x..."; \
600                                         patch -p0 < patches/$$x; \
601                                         echo $$x >> patches/.applied; \
602                                 else \
603                                         echo "Patch $$x no longer relevant"; \
604                                 fi; \
605                         done; \
606                 fi; \
607         else \
608                 echo "Not CVS";  \
609         fi
610
611 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
612 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
613
614 bininstall: all
615         mkdir -p $(DESTDIR)$(MODULES_DIR)
616         mkdir -p $(DESTDIR)$(ASTSBINDIR)
617         mkdir -p $(DESTDIR)$(ASTETCDIR)
618         mkdir -p $(DESTDIR)$(ASTBINDIR)
619         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
620         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
621         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
622         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
623         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
624         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
625         if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
626         if [ -f cygwin/asterisk.exe ]; then $(INSTALL) -m 755 cygwin/asterisk.exe $(DESTDIR)$(ASTSBINDIR)/; fi
627         if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
628         ln -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
629         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
630         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/  
631         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
632                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
633                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
634         fi
635         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
636         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
637         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
638         if [ -n "$(OLDHEADERS)" ]; then \
639                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
640         fi
641         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
642         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
643         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
644         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
645         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
646         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
647         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
648         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
649         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
650         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
651         $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
652         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
653         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
654         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
655         if [ -d contrib/firmware/iax ]; then \
656                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
657         else \
658                 echo "You need to do cvs update -d not just cvs update" ; \
659         fi 
660         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
661         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
662         @echo " +---- Asterisk Installation Complete -------+"  
663         @echo " +                                           +"
664         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
665         @echo " +                                           +"
666         @echo " + Asterisk has successfully been installed. +"  
667         @echo " + If you would like to install the sample   +"  
668         @echo " + configuration files (overwriting any      +"
669         @echo " + existing config files), run:              +"  
670         @echo " +                                           +"
671         @echo " +               $(MAKE) samples                +"
672         @echo " +                                           +"
673         @echo " +-----------------  or ---------------------+"
674         @echo " +                                           +"
675         @echo " + You can go ahead and install the asterisk +"
676         @echo " + program documentation now or later run:   +"
677         @echo " +                                           +"
678         @echo " +              $(MAKE) progdocs                +"
679         @echo " +                                           +"
680         @echo " + **Note** This requires that you have      +"
681         @echo " + doxygen installed on your local system    +"
682         @echo " +-------------------------------------------+"
683         @$(MAKE) -s oldmodcheck
684
685 NEWMODS=$(notdir $(wildcard */*.so))
686 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
687
688 oldmodcheck:
689         @if [ -n "$(OLDMODS)" ]; then \
690                 echo " WARNING WARNING WARNING" ;\
691                 echo "" ;\
692                 echo " Your Asterisk modules directory, located at" ;\
693                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
694                 echo " contains modules that were not installed by this " ;\
695                 echo " version of Asterisk. Please ensure that these" ;\
696                 echo " modules are compatible with this version before" ;\
697                 echo " attempting to run Asterisk." ;\
698                 echo "" ;\
699                 for f in $(OLDMODS); do \
700                         echo "    $$f" ;\
701                 done ;\
702                 echo "" ;\
703                 echo " WARNING WARNING WARNING" ;\
704         fi
705
706 install: all datafiles bininstall
707         @if [ -x /usr/sbin/asterisk-post-install ]; then \
708                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
709         fi
710
711 upgrade: all bininstall
712
713 adsi:
714         mkdir -p $(DESTDIR)$(ASTETCDIR)
715         for x in configs/*.adsi; do \
716                 if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
717                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
718                 fi ; \
719         done
720
721 samples: adsi
722         mkdir -p $(DESTDIR)$(ASTETCDIR)
723         for x in configs/*.sample; do \
724                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
725                         if [ "$(OVERWRITE)" = "y" ]; then \
726                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
727                                         echo "Config file $$x is unchanged"; \
728                                         continue; \
729                                 fi ; \
730                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
731                         else \
732                                 echo "Skipping config file $$x"; \
733                                 continue; \
734                         fi ;\
735                 fi ; \
736                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
737         done
738         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
739                 ( \
740                 echo "[directories]" ; \
741                 echo "astetcdir => $(ASTETCDIR)" ; \
742                 echo "astmoddir => $(MODULES_DIR)" ; \
743                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
744                 echo "astagidir => $(AGI_DIR)" ; \
745                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
746                 echo "astrundir => $(ASTVARRUNDIR)" ; \
747                 echo "astlogdir => $(ASTLOGDIR)" ; \
748                 echo "" ; \
749                 echo "; Changing the following lines may compromise your security." ; \
750                 echo ";[files]" ; \
751                 echo ";astctlpermissions = 0660" ; \
752                 echo ";astctlowner = root" ; \
753                 echo ";astctlgroup = apache" ; \
754                 echo ";astctl = asterisk.ctl" ; \
755                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
756         else \
757                 echo "Skipping asterisk.conf creation"; \
758         fi
759         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
760         for x in sounds/demo-*; do \
761                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
762                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
763                 else \
764                         echo "No description for $$x"; \
765                         exit 1; \
766                 fi; \
767         done
768         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
769         for x in sounds/*.mp3; do \
770                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
771         done
772         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
773         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
774         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
775         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
776                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
777         done
778         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
779         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
780                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
781         done
782
783 webvmail:
784         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
785         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
786         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
787         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
788         for x in images/*.gif; do \
789                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
790         done
791         @echo " +--------- Asterisk Web Voicemail ----------+"  
792         @echo " +                                           +"
793         @echo " + Asterisk Web Voicemail is installed in    +"
794         @echo " + your cgi-bin directory:                   +"
795         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
796         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
797         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
798         @echo " +                                           +"
799         @echo " + Other static items have been stored in:   +"
800         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
801         @echo " +                                           +"
802         @echo " + If these paths do not match your httpd    +"
803         @echo " + installation, correct the definitions     +"
804         @echo " + in your Makefile of HTTP_CGIDIR and       +"
805         @echo " + HTTP_DOCSDIR                              +"
806         @echo " +                                           +"
807         @echo " +-------------------------------------------+"  
808
809 spec: 
810         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
811
812 rpm: __rpm
813
814 __rpm: include/asterisk/version.h spec
815         rm -rf /tmp/asterisk ; \
816         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
817         $(MAKE) DESTDIR=/tmp/asterisk install ; \
818         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
819         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
820         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
821         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
822
823 progdocs:
824         doxygen contrib/asterisk-ng-doxygen
825
826 mpg123:
827         @wget -V >/dev/null || (echo "You need wget" ; false )
828         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
829         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
830         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
831
832 config:
833         if [ -d /etc/rc.d/init.d ]; then \
834                 $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
835                 /sbin/chkconfig --add asterisk; \
836         elif [ -d /etc/init.d ]; then \
837                 $(INSTALL) -m 755 init.asterisk /etc/init.d/asterisk; \
838         fi 
839
840 dont-optimize: install
841
842 valgrind: dont-optimize
843
844 depend: include/asterisk/version.h .depend defaults.h 
845         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
846
847 .depend: include/asterisk/version.h
848         build_tools/mkdep $(CFLAGS) $(wildcard *.c)
849
850 .tags-depend:
851         @echo -n ".tags-depend: " > $@
852         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
853         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
854         @find $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@
855         @find $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@
856         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
857         @echo >> $@
858
859 .tags-sources:
860         @rm -f $@
861         @find . -maxdepth 1 -name \*.c -print >> $@
862         @find . -maxdepth 1 -name \*.h -print >> $@
863         @find $(SUBDIRS) -name \*.c -print >> $@
864         @find $(SUBDIRS) -name \*.h -print >> $@
865         @find include -name \*.h -print >> $@
866
867 tags: .tags-depend .tags-sources
868         ctags -L .tags-sources -o $@
869
870 ctags: tags
871
872 TAGS: .tags-depend .tags-sources
873         etags -o $@ `cat .tags-sources`
874
875 etags: TAGS
876
877 FORCE:
878
879 %_env:
880         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
881
882 env:
883         env
884
885 # If the cleancount has been changed, force a make clean.
886 # .cleancount is the global clean count, and .lastclean is the 
887 # last clean count we had
888 # We can avoid this by making noclean
889
890 cleantest:
891         if cmp -s .cleancount .lastclean ; then echo ; else \
892                 $(MAKE) clean; cp -f .cleancount .lastclean;\
893         fi
894
895 patchlist:
896         @echo "Experimental Patches:"
897         @for x in patches/*; do \
898                 patch=`basename $$x`; \
899                 if [ "$$patch" = "CVS" ]; then \
900                         continue; \
901                 fi; \
902                 if grep -q ^$$patch$$ patches/.applied; then \
903                         echo "$$patch (applied)"; \
904                 else \
905                         echo "$$patch (available)"; \
906                 fi; \
907         done
908
909 apply: 
910         @if [ -z "$(PATCH)" ]; then \
911                 echo "Usage: make PATCH=<patchname> apply"; \
912         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
913                 echo "Patch $(PATCH) is already applied"; \
914         elif [ -f "patches/$(PATCH)" ]; then \
915                 echo "Applying patch $(PATCH)"; \
916                 patch -p0 < patches/$(PATCH); \
917                 echo "$(PATCH)" >> patches/.applied; \
918         else \
919                 echo "No such patch $(PATCH) in patches directory"; \
920         fi
921
922 unapply: 
923         @if [ -z "$(PATCH)" ]; then \
924                 echo "Usage: make PATCH=<patchname> unapply"; \
925         elif grep -v -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
926                 echo "Patch $(PATCH) is not applied"; \
927         elif [ -f "patches/$(PATCH)" ]; then \
928                 echo "Un-applying patch $(PATCH)"; \
929                 patch -p0 -R < patches/$(PATCH); \
930                 rm -f patches/.tmpapplied || :; \
931                 mv patches/.applied patches/.tmpapplied; \
932                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
933                 rm -f patches/.tmpapplied; \
934         else \
935                 echo "No such patch $(PATCH) in patches directory"; \
936         fi
937