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