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