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