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