01017847e57f62ef0be2303d6de526a22d3f4897
[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
262 #FLEXVER_GT_2_5_31=$(shell ./vercomp.sh flex \>= 2.5.31)
263 #BISONVER=$(shell bison --version | grep \^bison | egrep -o '[0-9]+\.[-0-9.]+[a-z]?' )
264 #BISONVERGE_85=$(shell ./vercomp.sh bison \>= 1.85 )
265
266 ifeq (${FLEXVER_GT_2_5_31},true)
267 FLEXOBJS=ast_expr2.o ast_expr2f.o
268 else
269 FLEXOBJS=ast_expr.o
270 endif
271
272 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
273         translate.o file.o say.o pbx.o cli.o md5.o term.o \
274         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
275         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ${FLEXOBJS}  \
276         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
277         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
278         utils.o config_old.o plc.o jitterbuf.o dnsmgr.o
279 ifeq (${OSARCH},Darwin)
280 OBJS+=poll.o dlfcn.o
281 ASTLINK=-Wl,-dynamic
282 SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
283 else
284 ASTLINK=-Wl,-E 
285 SOLINK=-shared -Xlinker -x
286 endif
287 ifeq (${OSARCH},SunOS)
288 OBJS+=strcompat.o
289 ASTLINK=
290 SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
291 endif
292
293 INSTALL=install
294
295 _all: all
296         @echo " +--------- Asterisk Build Complete ---------+"  
297         @echo " + Asterisk has successfully been built, but +"  
298         @echo " + cannot be run before being installed by   +"  
299         @echo " + running:                                  +"  
300         @echo " +                                           +"
301         @echo " +               $(MAKE) install                +"  
302         @echo " +-------------------------------------------+"  
303
304 all: cleantest depend asterisk subdirs 
305
306 ifneq ($(wildcard tags),)
307 all: tags
308 endif
309
310 ifneq ($(wildcard TAGS),)
311 all: TAGS
312 endif
313
314 noclean: depend asterisk subdirs
315
316 editline/config.h:
317         cd editline && unset CFLAGS LIBS && ./configure ; \
318
319 editline/libedit.a: FORCE
320         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
321         $(MAKE) -C editline libedit.a
322
323 db1-ast/libdb1.a: FORCE
324         @if [ -d db1-ast ]; then \
325                 $(MAKE) -C db1-ast libdb1.a ; \
326         else \
327                 echo "You need to do a cvs update -d not just cvs update"; \
328                 exit 1; \
329         fi
330
331 ifneq ($(wildcard .depend),)
332 include .depend
333 endif
334
335 ifneq ($(wildcard .tags-depend),)
336 include .tags-depend
337 endif
338
339 .PHONY: _version
340
341 _version: 
342         if [ -d CVS ] && [ ! -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
343
344 .version: _version
345
346 .y.c:
347 #       @if (($(BISONVERGE_85) = false)); then \
348 #               echo ================================================================================= ;\
349 #               echo NOTE: you may have trouble if you do not have bison-1.85 or higher installed! ;\
350 #               echo NOTE: you can pick up a copy at: http://ftp.gnu.org/ or its mirrors ;\
351 #               echo NOTE: You Have: $(BISONVER) ;\
352 #               echo ================================================================================; \
353 #       else \
354 #               echo EXCELLENT-- You have Bison version $(BISONVER), this should work just fine...;\
355 #       fi
356         bison -v -d --name-prefix=ast_yy $< -o $@
357
358 ast_expr.o: ast_expr.c
359 #       @echo NOTE:
360 #       @echo NOTE:
361 #       @echo NOTE: Using older version of ast_expr. To use the newer version,
362 #       @echo NOTE: Upgrade to flex 2.5.31 or higher, which can be found at http://
363 #       @echo NOTE:  http://sourceforge.net/project/showfiles.php?group_id=72099
364 #       @echo NOTE:
365 #       @echo NOTE:
366         $(CC) -c $(CPPFLAGS) $(CFLAGS) ast_expr.c
367
368 ast_expr2.o: ast_expr2.c
369
370 ast_expr2f.o: ast_expr2f.c
371
372 ast_expr2f.c: ast_expr2.fl
373         flex ast_expr2.fl
374
375 cli.o: cli.c build.h
376
377 asterisk.o: asterisk.c build.h
378
379 testexpr2 :
380         flex ast_expr2.fl
381         bison -v -d --name-prefix=ast_yy -o ast_expr2.c ast_expr2.y
382         gcc -g -c -DSTANDALONE ast_expr2f.c
383         gcc -g -c -DSTANDALONE ast_expr2.c
384         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
385         rm ast_expr2.c ast_expr2.o ast_expr2f.o ast_expr2f.c
386
387 manpage: asterisk.8.gz
388
389 asterisk.8.gz: asterisk.sgml
390         rm -f asterisk.8
391         docbook2man asterisk.sgml
392         mv ./*.8 asterisk.8
393         gzip asterisk.8
394
395 asterisk.pdf: asterisk.sgml
396         docbook2pdf asterisk.sgml
397
398 asterisk.ps: asterisk.sgml
399         docbook2ps asterisk.sgml
400
401 asterisk.html: asterisk.sgml
402         docbook2html asterisk.sgml
403         mv r1.html asterisk.html
404
405 asterisk.txt: asterisk.sgml
406         docbook2txt asterisk.sgml
407
408 ifneq ($(strip $(ASTERISKVERSION)),)
409 build.h: .version
410         ./make_build_h
411 else
412 build.h:
413         ./make_build_h
414 endif
415
416 stdtime/libtime.a: FORCE
417         @if [ -d stdtime ]; then \
418                 $(MAKE) -C stdtime libtime.a ; \
419         else \
420                 echo "You need to do a cvs update -d not just cvs update"; \
421                 exit 1; \
422         fi
423
424 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
425         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
426
427 muted: muted.o
428         $(CC) -o muted muted.o
429
430 subdirs: 
431         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
432
433 clean:
434         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
435         rm -f *.o *.so asterisk .depend
436         rm -f build.h 
437         rm -f ast_expr.c
438         rm -f .version
439         rm -f .tags-depend .tags-sources tags TAGS
440         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
441         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
442         $(MAKE) -C db1-ast clean
443         $(MAKE) -C stdtime clean
444
445 datafiles: all
446         sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig
447         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
448         for x in sounds/digits/*.gsm; do \
449                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
450                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
451                 else \
452                         echo "No description for $$x"; \
453                         exit 1; \
454                 fi; \
455         done
456         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
457         for x in sounds/dictate/*.gsm; do \
458                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
459                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
460                 else \
461                         echo "No description for $$x"; \
462                         exit 1; \
463                 fi; \
464         done
465         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
466         for x in sounds/letters/*.gsm; do \
467                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
468                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
469                 else \
470                         echo "No description for $$x"; \
471                         exit 1; \
472                 fi; \
473         done
474         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
475         for x in sounds/phonetic/*.gsm; do \
476                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
477                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
478                 else \
479                         echo "No description for $$x"; \
480                         exit 1; \
481                 fi; \
482         done
483         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 \
484                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
485                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
486                 else \
487                         echo "No description for $$x"; \
488                         exit 1; \
489                 fi; \
490         done
491         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
492         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
493         for x in images/*.jpg; do \
494                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
495         done
496         mkdir -p $(DESTDIR)$(AGI_DIR)
497
498 update: 
499         @if [ -d CVS ]; then \
500                 if [ -f patches/.applied ]; then \
501                         patches=`cat patches/.applied`; \
502                 fi; \
503                 if ! [ -z "$$patches" ]; then \
504                         for x in $$patches; do \
505                                 echo "Unapplying $$x..."; \
506                                 patch -R -p0 < patches/$$x; \
507                         done; \
508                         rm -f patches/.applied; \
509                 fi ; \
510                 echo "Updating from CVS..." ; \
511                 cvs -q -z3 update -Pd | tee update.out; \
512                 rm -f .version; \
513                 if [ `grep -c ^C update.out` -gt 0 ]; then \
514                         echo ; echo "The following files have conflicts:" ; \
515                         grep ^C update.out | cut -d' ' -f2- ; \
516                 fi ; \
517                 rm -f update.out; \
518                 if ! [ -z "$$patches" ]; then \
519                         for x in $$patches; do \
520                                 if [ -f patches/$$x ]; then \
521                                         echo "Applying patch $$x..."; \
522                                         patch -p0 < patches/$$x; \
523                                         echo $$x >> patches/.applied; \
524                                 else \
525                                         echo "Patch $$x no longer relevant"; \
526                                 fi; \
527                         done; \
528                 fi; \
529         else \
530                 echo "Not CVS";  \
531         fi
532
533 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
534 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
535
536 bininstall: all
537         mkdir -p $(DESTDIR)$(MODULES_DIR)
538         mkdir -p $(DESTDIR)$(ASTSBINDIR)
539         mkdir -p $(DESTDIR)$(ASTETCDIR)
540         mkdir -p $(DESTDIR)$(ASTBINDIR)
541         mkdir -p $(DESTDIR)$(ASTSBINDIR)
542         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
543         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
544         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
545         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
546         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
547         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
548         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
549         install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
550         install -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/     
551         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
552                 install -m 755 contrib/scripts/safe_asterisk $(DESTDIR)$(ASTSBINDIR)/ ;\
553         fi
554         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
555         install -d $(DESTDIR)$(ASTHEADERDIR)
556         install -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
557         if [ -n "$(OLDHEADERS)" ]; then \
558                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
559         fi
560         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
561         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
562         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
563         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
564         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
565         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
566         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
567         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
568         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
569         install -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
570         install -m 644 asterisk.8.gz $(DESTDIR)$(ASTMANDIR)/man8
571         if [ -d contrib/firmware/iax ]; then \
572                 install -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
573         else \
574                 echo "You need to do cvs update -d not just cvs update" ; \
575         fi 
576         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
577         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
578         @echo " +---- Asterisk Installation Complete -------+"  
579         @echo " +                                           +"
580         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
581         @echo " +                                           +"
582         @echo " + Asterisk has successfully been installed. +"  
583         @echo " + If you would like to install the sample   +"  
584         @echo " + configuration files (overwriting any      +"
585         @echo " + existing config files), run:              +"  
586         @echo " +                                           +"
587         @echo " +               $(MAKE) samples                +"
588         @echo " +                                           +"
589         @echo " +-----------------  or ---------------------+"
590         @echo " +                                           +"
591         @echo " + You can go ahead and install the asterisk +"
592         @echo " + program documentation now or later run:   +"
593         @echo " +                                           +"
594         @echo " +              $(MAKE) progdocs                +"
595         @echo " +                                           +"
596         @echo " + **Note** This requires that you have      +"
597         @echo " + doxygen installed on your local system    +"
598         @echo " +-------------------------------------------+"
599         @$(MAKE) -s oldmodcheck
600
601 NEWMODS=$(notdir $(wildcard */*.so))
602 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
603
604 oldmodcheck:
605         @if [ -n "$(OLDMODS)" ]; then \
606                 echo " WARNING WARNING WARNING" ;\
607                 echo "" ;\
608                 echo " Your Asterisk modules directory, located at" ;\
609                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
610                 echo " contains modules that were not installed by this " ;\
611                 echo " version of Asterisk. Please ensure that these" ;\
612                 echo " modules are compatible with this version before" ;\
613                 echo " attempting to run Asterisk." ;\
614                 echo "" ;\
615                 for f in $(OLDMODS); do \
616                         echo "    $$f" ;\
617                 done ;\
618                 echo "" ;\
619                 echo " WARNING WARNING WARNING" ;\
620         fi
621
622 install: all datafiles bininstall
623
624 upgrade: all bininstall
625
626 adsi: all
627         mkdir -p $(DESTDIR)$(ASTETCDIR)
628         for x in configs/*.adsi; do \
629                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
630                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
631                 fi ; \
632         done
633
634 samples: all datafiles adsi
635         mkdir -p $(DESTDIR)$(ASTETCDIR)
636         for x in configs/*.sample; do \
637                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
638                         if [ "$(OVERWRITE)" = "y" ]; then \
639                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
640                                         echo "Config file $$x is unchanged"; \
641                                         continue; \
642                                 fi ; \
643                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
644                         else \
645                                 echo "Skipping config file $$x"; \
646                                 continue; \
647                         fi ;\
648                 fi ; \
649                 install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
650         done
651         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTETCDIR)/asterisk.conf ]; then \
652                 echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
653                 echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
654                 echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
655                 echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
656                 echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
657                 echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
658                 echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
659                 echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
660                 echo "" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
661                 echo "; Changing the following lines may compromise your security." >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
662                 echo ";[files]" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
663                 echo ";astctlpermissions = 0660" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
664                 echo ";astctlowner = root" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
665                 echo ";astctlgroup = apache" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
666                 echo ";astctl = asterisk.ctl" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
667         else \
668                 echo "Skipping asterisk.conf creation"; \
669         fi
670         for x in sounds/demo-*; do \
671                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
672                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
673                 else \
674                         echo "No description for $$x"; \
675                         exit 1; \
676                 fi; \
677         done
678         for x in sounds/*.mp3; do \
679                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
680         done
681         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
682         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
683         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
684         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
685                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
686         done
687         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
688         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
689                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
690         done
691
692 webvmail:
693         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
694         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
695         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
696         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
697         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
698         for x in images/*.gif; do \
699                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
700         done
701         @echo " +--------- Asterisk Web Voicemail ----------+"  
702         @echo " +                                           +"
703         @echo " + Asterisk Web Voicemail is installed in    +"
704         @echo " + your cgi-bin directory.  IT USES A SETUID +"
705         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
706         @echo " + THAT, UNINSTALL IT!                       +"
707         @echo " +                                           +"
708         @echo " +-------------------------------------------+"  
709
710 mailbox:
711         ./contrib/scripts/addmailbox 
712
713 spec: 
714         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
715
716 rpm: __rpm
717
718 __rpm: _version spec
719         rm -rf /tmp/asterisk ; \
720         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
721         $(MAKE) DESTDIR=/tmp/asterisk install ; \
722         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
723         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
724         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
725         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
726
727 progdocs:
728         doxygen contrib/asterisk-ng-doxygen
729
730 mpg123:
731         @wget -V >/dev/null || (echo "You need wget" ; false )
732         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
733         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
734         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
735
736 config:
737         if [ -d /etc/rc.d/init.d ]; then \
738                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
739                 /sbin/chkconfig --add asterisk; \
740         elif [ -d /etc/init.d ]; then \
741                 install -m 755 init.asterisk /etc/init.d/asterisk; \
742         fi 
743
744 dont-optimize:
745         $(MAKE) OPTIMIZE= K6OPT= install
746
747 valgrind: dont-optimize
748
749 depend: .depend
750         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
751
752 .depend:
753         ./mkdep ${CFLAGS} `ls *.c`
754
755 .tags-depend:
756         @echo -n ".tags-depend: " > $@
757         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
758         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
759         @find ${SUBDIRS} -name \*.c -printf "\t%p \\\\\n" >> $@
760         @find ${SUBDIRS} -name \*.h -printf "\t%p \\\\\n" >> $@
761         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
762         @echo >> $@
763
764 .tags-sources:
765         @rm -f $@
766         @find . -maxdepth 1 -name \*.c -print >> $@
767         @find . -maxdepth 1 -name \*.h -print >> $@
768         @find ${SUBDIRS} -name \*.c -print >> $@
769         @find ${SUBDIRS} -name \*.h -print >> $@
770         @find include -name \*.h -print >> $@
771
772 tags: .tags-depend .tags-sources
773         ctags -L .tags-sources -o $@
774
775 ctags: tags
776
777 TAGS: .tags-depend .tags-sources
778         etags -o $@ `cat .tags-sources`
779
780 etags: TAGS
781
782 FORCE:
783
784 %_env:
785         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
786
787 env:
788         env
789
790 # If the cleancount has been changed, force a make clean.
791 # .cleancount is the global clean count, and .lastclean is the 
792 # last clean count we had
793 # We can avoid this by making noclean
794
795 cleantest:
796         if ! cmp -s .cleancount .lastclean ; then \
797                 $(MAKE) clean; cp -f .cleancount .lastclean;\
798         fi
799
800 patchlist:
801         @echo "Experimental Patches:"
802         @for x in patches/*; do \
803                 patch=`basename $$x`; \
804                 if [ "$$patch" = "CVS" ]; then \
805                         continue; \
806                 fi; \
807                 if grep -q ^$$patch$$ patches/.applied; then \
808                         echo "$$patch (applied)"; \
809                 else \
810                         echo "$$patch (available)"; \
811                 fi; \
812         done
813
814 apply: 
815         @if [ -z "$(PATCH)" ]; then \
816                 echo "Usage: make PATCH=<patchname> apply"; \
817         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
818                 echo "Patch $(PATCH) is already applied"; \
819         elif [ -f "patches/$(PATCH)" ]; then \
820                 echo "Applying patch $(PATCH)"; \
821                 patch -p0 < patches/$(PATCH); \
822                 echo "$(PATCH)" >> patches/.applied; \
823         else \
824                 echo "No such patch $(PATCH) in patches directory"; \
825         fi
826
827 unapply: 
828         @if [ -z "$(PATCH)" ]; then \
829                 echo "Usage: make PATCH=<patchname> unapply"; \
830         elif ! grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
831                 echo "Patch $(PATCH) is not applied"; \
832         elif [ -f "patches/$(PATCH)" ]; then \
833                 echo "Un-applying patch $(PATCH)"; \
834                 patch -p0 -R < patches/$(PATCH); \
835                 rm -f patches/.tmpapplied || :; \
836                 mv patches/.applied patches/.tmpapplied; \
837                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
838                 rm -f patches/.tmpapplied; \
839         else \
840                 echo "No such patch $(PATCH) in patches directory"; \
841         fi