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