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