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