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