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