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