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