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