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