instead of using a for loop to call 'make install' on each subdirectory, use
[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 SUBDIRS_INSTALL:=$(patsubst %,%-install,$(SUBDIRS))
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 config.status: configure
375         @CFLAGS="" ./configure
376         @echo "****"
377         @echo "**** The configure script was just executed, so 'make' needs to be"
378         @echo "**** restarted."
379         @echo "****"
380         @exit 1
381
382 makeopts: configure
383         @CFLAGS="" ./configure
384         @echo "****"
385         @echo "**** The configure script was just executed, so 'make' needs to be"
386         @echo "**** restarted."
387         @echo "****"
388         @exit 1
389
390 menuselect.makeopts: build_tools/menuselect makeopts.xml
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 $(MOD_SUBDIRS): FORCE
485         @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $@
486
487 $(OTHER_SUBDIRS): FORCE 
488         @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $@
489
490 clean-depend:
491         @for x in $(SUBDIRS); do $(MAKE) -C $$x clean-depend || exit 1 ; done
492         rm -f .depend .tags-depend
493
494 clean: clean-depend
495         @for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
496         rm -f *.o *.so asterisk
497         rm -f defaults.h
498         rm -f include/asterisk/build.h
499         rm -f include/asterisk/version.h
500         rm -f .tags-sources tags TAGS
501         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
502         $(MAKE) -C db1-ast clean
503         $(MAKE) -C stdtime clean
504
505 distclean: dist-clean
506
507 dist-clean: clean
508         $(MAKE) -C mxml clean
509         $(MAKE) -C build_tools dist-clean
510         $(MAKE) -C sounds dist-clean
511         rm -f menuselect.makeopts makeopts makeopts.xml
512         rm -f config.log config.status
513         rm -f include/autoconfig.h
514         rm -f include/asterisk/buildopts.h
515
516 datafiles: all
517         if [ x`$(ID) -un` = xroot ]; then sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
518 # Should static HTTP be installed during make samples or even with its own target ala
519 # webvoicemail?  There are portions here that *could* be customized but might also be
520 # improved a lot.  I'll put it here for now.
521         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
522         for x in static-http/*; do \
523                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
524         done
525         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
526         for x in images/*.jpg; do \
527                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
528         done
529         mkdir -p $(DESTDIR)$(AGI_DIR)
530         $(MAKE) -C sounds install
531
532 update: 
533         @if [ -d .svn ]; then \
534                 echo "Updating from Subversion..." ; \
535                 svn update | tee update.out; \
536                 rm -f .version; \
537                 if [ `grep -c ^C update.out` -gt 0 ]; then \
538                         echo ; echo "The following files have conflicts:" ; \
539                         grep ^C update.out | cut -b4- ; \
540                 fi ; \
541                 rm -f update.out; \
542                 $(MAKE) clean-depend; \
543         else \
544                 echo "Not under version control";  \
545         fi
546
547 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
548 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
549
550 bininstall: all
551         mkdir -p $(DESTDIR)$(MODULES_DIR)
552         mkdir -p $(DESTDIR)$(ASTSBINDIR)
553         mkdir -p $(DESTDIR)$(ASTETCDIR)
554         mkdir -p $(DESTDIR)$(ASTBINDIR)
555         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
556         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
557         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
558         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
559         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
560         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
561         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
562         if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
563         if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
564         $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
565         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
566         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
567         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
568                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
569                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
570         fi
571         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
572         $(INSTALL) -m 644 include/asterisk.h $(DESTDIR)$(includedir)
573         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
574         if [ -n "$(OLDHEADERS)" ]; then \
575                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
576         fi
577         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
578         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
579         mkdir -p $(DESTDIR)$(ASTDATADIR)/keys
580         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
581         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
582         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
583         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
584         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
585         $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
586         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
587         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
588         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
589         $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
590
591 $(SUBDIRS_INSTALL):
592         @$(MAKE) -C $(@:-install=) install
593
594 NEWMODS=$(notdir $(wildcard */*.so))
595 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
596
597 oldmodcheck:
598         @if [ -n "$(OLDMODS)" ]; then \
599                 echo " WARNING WARNING WARNING" ;\
600                 echo "" ;\
601                 echo " Your Asterisk modules directory, located at" ;\
602                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
603                 echo " contains modules that were not installed by this " ;\
604                 echo " version of Asterisk. Please ensure that these" ;\
605                 echo " modules are compatible with this version before" ;\
606                 echo " attempting to run Asterisk." ;\
607                 echo "" ;\
608                 for f in $(OLDMODS); do \
609                         echo "    $$f" ;\
610                 done ;\
611                 echo "" ;\
612                 echo " WARNING WARNING WARNING" ;\
613         fi
614
615 install: all datafiles bininstall $(SUBDIRS_INSTALL)
616         @if [ -x /usr/sbin/asterisk-post-install ]; then \
617                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
618         fi
619         @echo " +---- Asterisk Installation Complete -------+"  
620         @echo " +                                           +"
621         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
622         @echo " +                                           +"
623         @echo " + Asterisk has successfully been installed. +"  
624         @echo " + If you would like to install the sample   +"  
625         @echo " + configuration files (overwriting any      +"
626         @echo " + existing config files), run:              +"  
627         @echo " +                                           +"
628         @echo " +               $(MAKE) samples                +"
629         @echo " +                                           +"
630         @echo " +-----------------  or ---------------------+"
631         @echo " +                                           +"
632         @echo " + You can go ahead and install the asterisk +"
633         @echo " + program documentation now or later run:   +"
634         @echo " +                                           +"
635         @echo " +              $(MAKE) progdocs                +"
636         @echo " +                                           +"
637         @echo " + **Note** This requires that you have      +"
638         @echo " + doxygen installed on your local system    +"
639         @echo " +-------------------------------------------+"
640         @$(MAKE) -s oldmodcheck
641
642 upgrade: all bininstall
643
644 adsi:
645         mkdir -p $(DESTDIR)$(ASTETCDIR)
646         for x in configs/*.adsi; do \
647                 if [ ! -f $(DESTDIR)$(ASTETCDIR)/$$x ]; then \
648                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
649                 fi ; \
650         done
651
652 samples: adsi
653         mkdir -p $(DESTDIR)$(ASTETCDIR)
654         for x in configs/*.sample; do \
655                 if [ -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ]; then \
656                         if [ "$(OVERWRITE)" = "y" ]; then \
657                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $$x ; then \
658                                         echo "Config file $$x is unchanged"; \
659                                         continue; \
660                                 fi ; \
661                                 mv -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`.old ; \
662                         else \
663                                 echo "Skipping config file $$x"; \
664                                 continue; \
665                         fi ;\
666                 fi ; \
667                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ;\
668         done
669         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
670                 ( \
671                 echo "[directories]" ; \
672                 echo "astetcdir => $(ASTETCDIR)" ; \
673                 echo "astmoddir => $(MODULES_DIR)" ; \
674                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
675                 echo "astdatadir => $(ASTDATADIR)" ; \
676                 echo "astagidir => $(AGI_DIR)" ; \
677                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
678                 echo "astrundir => $(ASTVARRUNDIR)" ; \
679                 echo "astlogdir => $(ASTLOGDIR)" ; \
680                 echo "" ; \
681                 echo "; Changing the following lines may compromise your security." ; \
682                 echo ";[files]" ; \
683                 echo ";astctlpermissions = 0660" ; \
684                 echo ";astctlowner = root" ; \
685                 echo ";astctlgroup = apache" ; \
686                 echo ";astctl = asterisk.ctl" ; \
687                 echo ";[options]" ; \
688                 echo ";internal_timing = yes" ; \
689                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
690         else \
691                 echo "Skipping asterisk.conf creation"; \
692         fi
693         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
694         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
695         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
696                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
697         done
698         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
699         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
700                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
701         done
702
703 webvmail:
704         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
705         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
706         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
707         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
708         for x in images/*.gif; do \
709                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
710         done
711         @echo " +--------- Asterisk Web Voicemail ----------+"  
712         @echo " +                                           +"
713         @echo " + Asterisk Web Voicemail is installed in    +"
714         @echo " + your cgi-bin directory:                   +"
715         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
716         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
717         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
718         @echo " +                                           +"
719         @echo " + Other static items have been stored in:   +"
720         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
721         @echo " +                                           +"
722         @echo " + If these paths do not match your httpd    +"
723         @echo " + installation, correct the definitions     +"
724         @echo " + in your Makefile of HTTP_CGIDIR and       +"
725         @echo " + HTTP_DOCSDIR                              +"
726         @echo " +                                           +"
727         @echo " +-------------------------------------------+"  
728
729 spec: 
730         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
731
732 rpm: __rpm
733
734 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
735         rm -rf /tmp/asterisk ; \
736         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
737         $(MAKE) DESTDIR=/tmp/asterisk install ; \
738         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
739         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
740         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
741         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
742
743 progdocs:
744         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
745         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
746
747 config:
748         @if [ "${OSARCH}" = "Linux" ]; then \
749                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
750                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
751                         /sbin/chkconfig --add asterisk; \
752                 elif [ -f /etc/debian_version ]; then \
753                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk; \
754                         /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; \
755                 elif [ -f /etc/gentoo-release ]; then \
756                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk /etc/init.d/asterisk; \
757                         /sbin/rc-update add asterisk default; \
758                 elif [ -f /etc/mandrake-release ]; then \
759                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk /etc/rc.d/init.d/asterisk; \
760                         /sbin/chkconfig --add asterisk; \
761                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
762                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk /etc/init.d/asterisk; \
763                         /sbin/chkconfig --add asterisk; \
764                 elif [ -f /etc/slackware-version ]; then \
765                         echo "Slackware is not currently supported, although an init script does exist for it." \
766                 else \
767                         echo "We could not install init scripts for your distribution."; \
768                 fi \
769         else \
770                 echo "We could not install init scripts for your operating system."; \
771         fi
772
773 dont-optimize: _all
774
775 valgrind: dont-optimize
776
777 depend: include/asterisk/version.h include/asterisk/buildopts.h .depend defaults.h 
778         @for x in $(MOD_SUBDIRS); do CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $$x depend || exit 1 ; done
779         @for x in $(OTHER_SUBDIRS); do CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $$x depend || exit 1 ; done
780
781 .depend: include/asterisk/version.h include/asterisk/buildopts.h defaults.h
782         build_tools/mkdep $(CFLAGS) $(wildcard *.c)
783
784 .tags-depend:
785         @echo -n ".tags-depend: " > $@
786         @$(FIND) . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
787         @$(FIND) . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
788         @$(FIND) $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@
789         @$(FIND) $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@
790         @$(FIND) include -name \*.h -printf "\t%p \\\\\n" >> $@
791         @echo >> $@
792
793 .tags-sources:
794         @rm -f $@
795         @$(FIND) . -maxdepth 1 -name \*.c -print >> $@
796         @$(FIND) . -maxdepth 1 -name \*.h -print >> $@
797         @$(FIND) $(SUBDIRS) -name \*.c -print >> $@
798         @$(FIND) $(SUBDIRS) -name \*.h -print >> $@
799         @$(FIND) include -name \*.h -print >> $@
800
801 tags: .tags-depend .tags-sources
802         ctags -L .tags-sources -o $@
803
804 ctags: tags
805
806 TAGS: .tags-depend .tags-sources
807         etags -o $@ `cat .tags-sources`
808
809 etags: TAGS
810
811 FORCE:
812
813 %_env:
814         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
815
816 sounds:
817         $(MAKE) -C sounds all
818
819 env:
820         env
821
822 # If the cleancount has been changed, force a make clean.
823 # .cleancount is the global clean count, and .lastclean is the 
824 # last clean count we had
825
826 cleantest:
827         @if cmp -s .cleancount .lastclean ; then echo ; else \
828                 $(MAKE) clean; cp -f .cleancount .lastclean;\
829                 $(MAKE) defaults.h;\
830         fi
831
832 _uninstall:
833         rm -f $(DESTDIR)$(MODULES_DIR)/*
834         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
835         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
836         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
837         rm -rf $(DESTDIR)$(ASTHEADERDIR)
838         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
839         rm -rf $(DESTDIR)$(ASTMANDIR)/man8
840         for x in $(SUBDIRS); do $(MAKE) -C $$x uninstall || exit 1 ; done
841         $(MAKE) -C sounds uninstall
842
843 uninstall: _uninstall
844         @echo " +--------- Asterisk Uninstall Complete -----+"  
845         @echo " + Asterisk binaries, sounds, man pages,     +"  
846         @echo " + headers, modules, and firmware builds,    +"  
847         @echo " + have all been uninstalled.                +"  
848         @echo " +                                           +"
849         @echo " + To remove ALL traces of Asterisk,         +"
850         @echo " + including configuration, spool            +"
851         @echo " + directories, and logs, run the following  +"
852         @echo " + command:                                  +"
853         @echo " +                                           +"
854         @echo " +            $(MAKE) uninstall-all             +"  
855         @echo " +-------------------------------------------+"  
856
857 uninstall-all: _uninstall
858         rm -rf $(DESTDIR)$(ASTLIBDIR)
859         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
860         rm -rf $(DESTDIR)$(ASTDATADIR)
861         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
862         rm -rf $(DESTDIR)$(ASTETCDIR)
863         rm -rf $(DESTDIR)$(ASTLOGDIR)
864
865 menuselect: build_tools/menuselect makeopts.xml
866         -@build_tools/menuselect ${GLOBAL_MAKEOPTS} ${USER_MAKEOPTS} menuselect.makeopts && echo "menuselect changes saved!" || echo "menuselect changes NOT saved!"
867
868 build_tools/menuselect: build_tools/menuselect.c build_tools/menuselect_curses.c build_tools/menuselect.h config.status mxml/libmxml.a $(MENUSELECT_OBJS)
869         $(MAKE) -C build_tools menuselect
870
871 mxml/libmxml.a:
872         @cd mxml && unset CFLAGS LIBS && test -f config.h || ./configure
873         $(MAKE) -C mxml libmxml.a
874
875 makeopts.xml: $(foreach dir,$(MOD_SUBDIRS),$(dir)/*.c) build_tools/cflags.xml sounds/sounds.xml
876         @echo "Generating list of available modules ..."
877         @build_tools/prep_moduledeps > $@