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