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