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