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