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