6f68919c0f8b98a58c4f88996c103d1fc01fedc1
[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         @if [ -d db1-ast ]; then \
458                 $(MAKE) -C db1-ast libdb1.a ; \
459         else \
460                 echo "You need to do a cvs update -d not just cvs update"; \
461                 exit 1; \
462         fi
463
464 ifneq ($(wildcard .depend),)
465   include .depend
466 endif
467
468 ifneq ($(wildcard .tags-depend),)
469   include .tags-depend
470 endif
471
472 ast_expr2.c:
473         bison -d --name-prefix=ast_yy ast_expr2.y -o ast_expr2.c
474
475 ast_expr2f.c:
476         flex --full ast_expr2.fl
477
478 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
479         gcc -g -c -DSTANDALONE ast_expr2f.c
480         gcc -g -c -DSTANDALONE ast_expr2.c
481         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
482         rm ast_expr2.o ast_expr2f.o 
483
484 manpage: asterisk.8
485
486 asterisk.8: asterisk.sgml
487         rm -f asterisk.8
488         docbook2man asterisk.sgml
489         mv ./*.8 asterisk.8
490
491 asterisk.pdf: asterisk.sgml
492         docbook2pdf asterisk.sgml
493
494 asterisk.ps: asterisk.sgml
495         docbook2ps asterisk.sgml
496
497 asterisk.html: asterisk.sgml
498         docbook2html asterisk.sgml
499         mv r1.html asterisk.html
500
501 asterisk.txt: asterisk.sgml
502         docbook2txt asterisk.sgml
503
504 defaults.h: FORCE
505         build_tools/make_defaults_h > $@.tmp
506         if cmp -s $@.tmp $@ ; then echo ; else \
507                 mv $@.tmp $@ ; \
508         fi
509         rm -f $@.tmp
510
511 include/asterisk/version.h: FORCE
512         build_tools/make_version_h > $@.tmp
513         if cmp -s $@.tmp $@ ; then echo; else \
514                 mv $@.tmp $@ ; \
515         fi
516         rm -f $@.tmp
517
518 stdtime/libtime.a: FORCE
519         @if [ -d stdtime ]; then \
520                 $(MAKE) -C stdtime libtime.a ; \
521         else \
522                 echo "You need to do a cvs update -d not just cvs update"; \
523                 exit 1; \
524         fi
525
526 cygwin_a:
527         $(MAKE) -C cygwin all
528
529 asterisk: $(CYGLOADER) editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
530         build_tools/make_build_h > include/asterisk/build.h.tmp
531         if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \
532                 mv include/asterisk/build.h.tmp include/asterisk/build.h ; \
533         fi
534         rm -f include/asterisk/build.h.tmp
535         $(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
536         $(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
537
538 muted: muted.o
539         $(CC) $(AUDIO_LIBS) -o muted muted.o
540
541 subdirs: 
542         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
543
544 clean:
545         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
546         rm -f *.o *.so asterisk .depend
547         rm -f defaults.h
548         rm -f include/asterisk/build.h
549         rm -f include/asterisk/version.h
550         rm -f .tags-depend .tags-sources tags TAGS
551         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
552         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
553         $(MAKE) -C db1-ast clean
554         $(MAKE) -C stdtime clean
555
556 datafiles: all
557         if [ x`whoami` = xroot ]; then sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
558         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
559         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/priv-callerintros
560         for x in sounds/digits/*.gsm; do \
561                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
562                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
563                 else \
564                         echo "No description for $$x"; \
565                         exit 1; \
566                 fi; \
567         done
568         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
569         for x in sounds/dictate/*.gsm; do \
570                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
571                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
572                 else \
573                         echo "No description for $$x"; \
574                         exit 1; \
575                 fi; \
576         done
577         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
578         for x in sounds/letters/*.gsm; do \
579                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
580                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
581                 else \
582                         echo "No description for $$x"; \
583                         exit 1; \
584                 fi; \
585         done
586         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
587         for x in sounds/phonetic/*.gsm; do \
588                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
589                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
590                 else \
591                         echo "No description for $$x"; \
592                         exit 1; \
593                 fi; \
594         done
595         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 \
596                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
597                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
598                 else \
599                         echo "No description for $$x"; \
600                         exit 1; \
601                 fi; \
602         done
603         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
604         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
605         for x in images/*.jpg; do \
606                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
607         done
608         mkdir -p $(DESTDIR)$(AGI_DIR)
609
610 update: 
611         @if [ -d .svn ]; then \
612                 echo "Updating from Subversion..." ; \
613                 svn update | tee update.out; \
614                 rm -f .version; \
615                 if [ `grep -c ^C update.out` -gt 0 ]; then \
616                         echo ; echo "The following files have conflicts:" ; \
617                         grep ^C update.out | cut -b4- ; \
618                 fi ; \
619                 rm -f update.out; \
620         elif [ -d CVS ]; then \
621                 echo "Updating from CVS..." ; \
622                 cvs -q -z3 update -Pd | tee update.out; \
623                 rm -f .version; \
624                 if [ `grep -c ^C update.out` -gt 0 ]; then \
625                         echo ; echo "The following files have conflicts:" ; \
626                         grep ^C update.out | cut -d' ' -f2- ; \
627                 fi ; \
628                 rm -f update.out; \
629         else \
630                 echo "Not under version control";  \
631         fi
632
633 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
634 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
635
636 bininstall: all
637         mkdir -p $(DESTDIR)$(MODULES_DIR)
638         mkdir -p $(DESTDIR)$(ASTSBINDIR)
639         mkdir -p $(DESTDIR)$(ASTETCDIR)
640         mkdir -p $(DESTDIR)$(ASTBINDIR)
641         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
642         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
643         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
644         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
645         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
646         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
647         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
648         if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
649         if [ -f cygwin/asterisk.exe ]; then $(INSTALL) -m 755 cygwin/asterisk.exe $(DESTDIR)$(ASTSBINDIR)/; fi
650         if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
651         ln -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
652         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
653         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/  
654         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
655                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
656                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
657         fi
658         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
659         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
660         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
661         if [ -n "$(OLDHEADERS)" ]; then \
662                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
663         fi
664         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
665         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
666         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
667         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
668         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
669         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
670         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
671         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
672         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
673         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
674         $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
675         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
676         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
677         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
678         if [ -d contrib/firmware/iax ]; then \
679                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
680         else \
681                 echo "You need to do cvs update -d not just cvs update" ; \
682         fi 
683         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
684         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
685         @echo " +---- Asterisk Installation Complete -------+"  
686         @echo " +                                           +"
687         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
688         @echo " +                                           +"
689         @echo " + Asterisk has successfully been installed. +"  
690         @echo " + If you would like to install the sample   +"  
691         @echo " + configuration files (overwriting any      +"
692         @echo " + existing config files), run:              +"  
693         @echo " +                                           +"
694         @echo " +               $(MAKE) samples                +"
695         @echo " +                                           +"
696         @echo " +-----------------  or ---------------------+"
697         @echo " +                                           +"
698         @echo " + You can go ahead and install the asterisk +"
699         @echo " + program documentation now or later run:   +"
700         @echo " +                                           +"
701         @echo " +              $(MAKE) progdocs                +"
702         @echo " +                                           +"
703         @echo " + **Note** This requires that you have      +"
704         @echo " + doxygen installed on your local system    +"
705         @echo " +-------------------------------------------+"
706         @$(MAKE) -s oldmodcheck
707
708 NEWMODS=$(notdir $(wildcard */*.so))
709 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
710
711 oldmodcheck:
712         @if [ -n "$(OLDMODS)" ]; then \
713                 echo " WARNING WARNING WARNING" ;\
714                 echo "" ;\
715                 echo " Your Asterisk modules directory, located at" ;\
716                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
717                 echo " contains modules that were not installed by this " ;\
718                 echo " version of Asterisk. Please ensure that these" ;\
719                 echo " modules are compatible with this version before" ;\
720                 echo " attempting to run Asterisk." ;\
721                 echo "" ;\
722                 for f in $(OLDMODS); do \
723                         echo "    $$f" ;\
724                 done ;\
725                 echo "" ;\
726                 echo " WARNING WARNING WARNING" ;\
727         fi
728
729 install: all datafiles bininstall
730         @if [ -x /usr/sbin/asterisk-post-install ]; then \
731                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
732         fi
733
734 upgrade: all bininstall
735
736 adsi:
737         mkdir -p $(DESTDIR)$(ASTETCDIR)
738         for x in configs/*.adsi; do \
739                 if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
740                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
741                 fi ; \
742         done
743
744 samples: adsi
745         mkdir -p $(DESTDIR)$(ASTETCDIR)
746         for x in configs/*.sample; do \
747                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
748                         if [ "$(OVERWRITE)" = "y" ]; then \
749                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
750                                         echo "Config file $$x is unchanged"; \
751                                         continue; \
752                                 fi ; \
753                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
754                         else \
755                                 echo "Skipping config file $$x"; \
756                                 continue; \
757                         fi ;\
758                 fi ; \
759                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
760         done
761         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
762                 ( \
763                 echo "[directories]" ; \
764                 echo "astetcdir => $(ASTETCDIR)" ; \
765                 echo "astmoddir => $(MODULES_DIR)" ; \
766                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
767                 echo "astagidir => $(AGI_DIR)" ; \
768                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
769                 echo "astrundir => $(ASTVARRUNDIR)" ; \
770                 echo "astlogdir => $(ASTLOGDIR)" ; \
771                 echo "" ; \
772                 echo "; Changing the following lines may compromise your security." ; \
773                 echo ";[files]" ; \
774                 echo ";astctlpermissions = 0660" ; \
775                 echo ";astctlowner = root" ; \
776                 echo ";astctlgroup = apache" ; \
777                 echo ";astctl = asterisk.ctl" ; \
778                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
779         else \
780                 echo "Skipping asterisk.conf creation"; \
781         fi
782         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
783         for x in sounds/demo-*; do \
784                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
785                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
786                 else \
787                         echo "No description for $$x"; \
788                         exit 1; \
789                 fi; \
790         done
791         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
792         for x in sounds/*.mp3; do \
793                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
794         done
795         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
796         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
797         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
798         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
799                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
800         done
801         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
802         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
803                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
804         done
805
806 webvmail:
807         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
808         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
809         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
810         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
811         for x in images/*.gif; do \
812                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
813         done
814         @echo " +--------- Asterisk Web Voicemail ----------+"  
815         @echo " +                                           +"
816         @echo " + Asterisk Web Voicemail is installed in    +"
817         @echo " + your cgi-bin directory:                   +"
818         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
819         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
820         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
821         @echo " +                                           +"
822         @echo " + Other static items have been stored in:   +"
823         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
824         @echo " +                                           +"
825         @echo " + If these paths do not match your httpd    +"
826         @echo " + installation, correct the definitions     +"
827         @echo " + in your Makefile of HTTP_CGIDIR and       +"
828         @echo " + HTTP_DOCSDIR                              +"
829         @echo " +                                           +"
830         @echo " +-------------------------------------------+"  
831
832 spec: 
833         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
834
835 rpm: __rpm
836
837 __rpm: include/asterisk/version.h spec
838         rm -rf /tmp/asterisk ; \
839         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
840         $(MAKE) DESTDIR=/tmp/asterisk install ; \
841         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
842         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
843         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
844         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
845
846 progdocs:
847         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
848         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
849
850 mpg123:
851         @wget -V >/dev/null || (echo "You need wget" ; false )
852         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
853         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
854         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
855
856 config:
857         if [ -d /etc/rc.d/init.d ]; then \
858                 $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
859                 /sbin/chkconfig --add asterisk; \
860         elif [ -d /etc/init.d ]; then \
861                 $(INSTALL) -m 755 init.asterisk /etc/init.d/asterisk; \
862         fi 
863
864 dont-optimize: install
865
866 valgrind: dont-optimize
867
868 depend: include/asterisk/version.h .depend defaults.h 
869         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
870
871 .depend: include/asterisk/version.h
872         build_tools/mkdep $(CFLAGS) $(wildcard *.c)
873
874 .tags-depend:
875         @echo -n ".tags-depend: " > $@
876         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
877         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
878         @find $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@
879         @find $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@
880         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
881         @echo >> $@
882
883 .tags-sources:
884         @rm -f $@
885         @find . -maxdepth 1 -name \*.c -print >> $@
886         @find . -maxdepth 1 -name \*.h -print >> $@
887         @find $(SUBDIRS) -name \*.c -print >> $@
888         @find $(SUBDIRS) -name \*.h -print >> $@
889         @find include -name \*.h -print >> $@
890
891 tags: .tags-depend .tags-sources
892         ctags -L .tags-sources -o $@
893
894 ctags: tags
895
896 TAGS: .tags-depend .tags-sources
897         etags -o $@ `cat .tags-sources`
898
899 etags: TAGS
900
901 FORCE:
902
903 %_env:
904         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
905
906 env:
907         env
908
909 # If the cleancount has been changed, force a make clean.
910 # .cleancount is the global clean count, and .lastclean is the 
911 # last clean count we had
912 # We can avoid this by making noclean
913
914 cleantest:
915         if cmp -s .cleancount .lastclean ; then echo ; else \
916                 $(MAKE) clean; cp -f .cleancount .lastclean;\
917         fi
918
919 _uninstall:
920         rm -f $(DESTDIR)$(MODULES_DIR)/*
921         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
922         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
923         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
924         rm -rf $(DESTDIR)$(ASTHEADERDIR)
925         rm -rf $(DESTDIR)$(ASTVARLIBDIR)/sounds
926         rm -rf $(DESTDIR)$(ASTVARLIBDIR)/firmware
927         rm -rf $(DESTDIR)$(ASTMANDIR)/man8
928         for x in $(SUBDIRS); do $(MAKE) -C $$x uninstall || exit 1 ; done
929
930 uninstall: _uninstall
931         @echo " +--------- Asterisk Uninstall Complete -----+"  
932         @echo " + Asterisk binaries, sounds, man pages,     +"  
933         @echo " + headers, modules, and firmware builds,    +"  
934         @echo " + have all been uninstalled.                +"  
935         @echo " +                                           +"
936         @echo " + To remove ALL traces of Asterisk,         +"
937         @echo " + including configuration, spool            +"
938         @echo " + directories, and logs, run the following  +"
939         @echo " + command:                                  +"
940         @echo " +                                           +"
941         @echo " +            $(MAKE) uninstall-all             +"  
942         @echo " +-------------------------------------------+"  
943
944
945 uninstall-all: _uninstall
946         rm -rf $(DESTDIR)$(ASTLIBDIR)
947         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
948         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
949         rm -rf $(DESTDIR)$(ASTETCDIR)
950         rm -rf $(DESTDIR)$(ASTLOGDIR)
951