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