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