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