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