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