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