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