fix the output of Makefile generated variables to doxygen
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999-2005, Mark Spencer
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 # If cross compiling, define these to suit
19 # CROSS_COMPILE=/opt/montavista/pro/devkit/arm/xscale_be/bin/xscale_be-
20 # CROSS_COMPILE_BIN=/opt/montavista/pro/devkit/arm/xscale_be/bin/
21 # CROSS_COMPILE_TARGET=/opt/montavista/pro/devkit/arm/xscale_be/target
22 CC=$(CROSS_COMPILE)gcc
23 HOST_CC=gcc
24 # CROSS_ARCH=Linux
25 # CROSS_PROC=arm
26 # SUB_PROC=xscale # or maverick
27
28 ifeq ($(CROSS_COMPILE),)
29   OSARCH=$(shell uname -s)
30   OSREV=$(shell uname -r)
31 else
32   OSARCH=$(CROSS_ARCH)
33   OSREV=$(CROSS_REV)
34 endif
35
36 # Remember the MAKELEVEL at the top
37 MAKETOPLEVEL?=$(MAKELEVEL)
38
39 ifneq ($(findstring dont-optimize,$(MAKECMDGOALS)),dont-optimize)
40 ######### More GSM codec optimization
41 ######### Uncomment to enable MMXTM optimizations for x86 architecture CPU's
42 ######### which support MMX instructions.  This should be newer pentiums,
43 ######### ppro's, etc, as well as the AMD K6 and K7.  
44 #K6OPT  = -DK6OPT
45
46 #Tell gcc to optimize the code
47 OPTIMIZE+=-O6
48 endif
49
50 #Overwite config files on "make samples"
51 OVERWRITE=y
52
53 #Include debug and macro symbols in the executables (-g) and profiling info (-pg)
54 DEBUG=-g3 #-pg
55
56 #Set NOCRYPTO to yes if you do not want to have crypto support or 
57 #dependencies
58 #NOCRYPTO=yes
59
60 # If you are running a radio application, define RADIO_RELAX so that the DTMF
61 # will be received more reliably
62 #OPTIONS += -DRADIO_RELAX
63
64 # If you don't have a lot of memory (e.g. embedded Asterisk), define LOW_MEMORY
65 # to reduce the size of certain static buffers
66
67 #ifneq ($(CROSS_COMPILE),)
68 #OPTIONS += -DLOW_MEMORY
69 #endif
70
71 # Optional debugging parameters
72 DEBUG_THREADS = #-DDUMP_SCHEDULER #-DDEBUG_SCHEDULER #-DDEBUG_THREADS #-DDO_CRASH #-DDETECT_DEADLOCKS
73
74 # Uncomment next one to enable ast_frame tracing (for debugging)
75 TRACE_FRAMES = #-DTRACE_FRAMES
76
77 # Uncomment next one to enable malloc debugging
78 # You can view malloc debugging with:
79 #   *CLI> show memory allocations [filename]
80 #   *CLI> show memory summary [filename]
81 #
82 MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
83
84 # Where to install asterisk after compiling
85 # Default -> leave empty
86 INSTALL_PREFIX?=
87
88 # Staging directory
89 # Files are copied here temporarily during the install process
90 # For example, make DESTDIR=/tmp/asterisk woud put things in
91 # /tmp/asterisk/etc/asterisk
92 # XXX watch out, put no spaces or comments after the value
93 DESTDIR?=
94 #DESTDIR?=/tmp/asterisk
95
96 # Original busydetect routine
97 BUSYDETECT = #-DBUSYDETECT
98
99 # Improved busydetect routine, comment the previous one if you use this one
100 BUSYDETECT+= #-DBUSYDETECT_MARTIN 
101 # Detect the busy signal looking only at tone lengths
102 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
103 BUSYDETECT+= #-DBUSYDETECT_TONEONLY
104 # Inforce the detection of busy singal (get rid of false hangups)
105 # Don't use together with -DBUSYDETECT_TONEONLY
106 BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
107
108 ifneq ($(OSARCH),SunOS)
109   ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
110   ASTVARLIBDIR=$(INSTALL_PREFIX)/var/lib/asterisk
111   ASTETCDIR=$(INSTALL_PREFIX)/etc/asterisk
112   ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
113   ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
114   ASTHEADERDIR=$(INSTALL_PREFIX)/usr/include/asterisk
115   ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
116   ASTBINDIR=$(INSTALL_PREFIX)/usr/bin
117   ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
118   ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
119   ASTMANDIR=$(INSTALL_PREFIX)/usr/share/man
120   MODULES_DIR=$(ASTLIBDIR)/modules
121   AGI_DIR=$(ASTVARLIBDIR)/agi-bin
122 else
123   ASTLIBDIR=$(INSTALL_PREFIX)/opt/asterisk/lib
124   ASTVARLIBDIR=$(INSTALL_PREFIX)/var/opt/asterisk/lib
125   ASTETCDIR=$(INSTALL_PREFIX)/etc/opt/asterisk
126   ASTSPOOLDIR=$(INSTALL_PREFIX)/var/opt/asterisk/spool
127   ASTLOGDIR=$(INSTALL_PREFIX)/var/opt/asterisk/log
128   ASTHEADERDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/include/asterisk
129   ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
130   ASTBINDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/bin
131   ASTSBINDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/sbin
132   ASTVARRUNDIR=$(INSTALL_PREFIX)/var/opt/asterisk/run
133   ASTMANDIR=$(INSTALL_PREFIX)/opt/asterisk/usr/share/man
134   MODULES_DIR=$(ASTLIBDIR)/modules
135   AGI_DIR=$(ASTVARLIBDIR)/agi-bin
136 endif
137
138 ASTCFLAGS=
139
140 # Pentium Pro Optimize
141 #PROC=i686
142
143 # Pentium & VIA processors optimize
144 #PROC=i586
145
146 #PROC=k6
147 #PROC=ppc
148
149 #Uncomment this to use the older DSP routines
150 #ASTCFLAGS+=-DOLD_DSP_ROUTINES
151
152 # Determine by a grep 'DocumentRoot' of your httpd.conf file
153 HTTP_DOCSDIR=/var/www/html
154 # Determine by a grep 'ScriptAlias' of your httpd.conf file
155 HTTP_CGIDIR=/var/www/cgi-bin
156
157 # If the file .asterisk.makeopts is present in your home directory, you can
158 # include all of your favorite Makefile options so that every time you download
159 # a new version of Asterisk, you don't have to edit the makefile to set them. 
160 # The file, /etc/asterisk.makeopts will also be included, but can be overridden
161 # by the file in your home directory.
162
163 ifneq ($(wildcard /etc/asterisk.makeopts),)
164   include /etc/asterisk.makeopts
165 endif
166
167 ifneq ($(wildcard ~/.asterisk.makeopts),)
168   include ~/.asterisk.makeopts
169 endif
170
171 ifeq ($(OSARCH),Linux)
172   ifeq ($(CROSS_COMPILE),)
173     PROC?=$(shell uname -m)
174   else
175     PROC=$(CROSS_PROC)
176   endif
177
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     OPTIONS+=-m64
183   endif
184
185   ifeq ($(PROC),sparc64)
186     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
187     #This works for even old (2.96) versions of gcc and provides a small boost either way.
188     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
189     #So we go lowest common available by gcc and go a step down, still a step up from
190     #the default as we now have a better instruction set to work with. - Belgarath
191     PROC=ultrasparc
192     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
193     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
194     OPTIONS+=-fomit-frame-pointer
195   endif
196
197   ifeq ($(PROC),arm)
198     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
199     ifeq ($(SUB_PROC),maverick)
200       OPTIONS+=-fsigned-char -mcpu=ep9312
201     else
202       ifeq ($(SUB_PROC),xscale)
203         OPTIONS+=-fsigned-char -msoft-float -mcpu=xscale
204       else
205         OPTIONS+=-fsigned-char -msoft-float 
206       endif
207     endif
208   endif
209   MPG123TARG=linux
210 endif
211
212 PWD=$(shell pwd)
213 GREP=grep
214
215 ifeq ($(OSARCH),SunOS)
216   GREP=/usr/xpg4/bin/grep
217   M4=/usr/local/bin/m4
218 endif
219
220 INCLUDE+=-Iinclude -I../include
221 ASTCFLAGS+=-pipe  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
222 ASTCFLAGS+=$(OPTIMIZE)
223 ASTOBJ=-o asterisk
224
225 ifeq ($(findstring BSD,$(OSARCH)),BSD)
226   PROC=$(shell uname -m)
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 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/osp/osp.h),)
239   ASTCFLAGS+=-DOSP_SUPPORT -I$(CROSS_COMPILE_TARGET)/usr/local/include/osp
240 else
241   ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/osp/osp.h),)
242     ASTCFLAGS+=-DOSP_SUPPORT -I$(CROSS_COMPILE_TARGET)/usr/include/osp
243   endif
244 endif
245
246 ifeq ($(OSARCH),FreeBSD)
247   BSDVERSION=$(shell make -V OSVERSION -f $(CROSS_COMPILE_TARGET)/usr/share/mk/bsd.port.subdir.mk)
248   ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
249   LIBS+=$(shell if test  $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
250   ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/spandsp),)
251     ASTCFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/spandsp
252   endif
253   MPG123TARG=freebsd
254
255   # XXX FreeBSD paths
256   PREFIX?=/usr/local
257   ASTLIBDIR=$(INSTALL_PREFIX)$(PREFIX)/lib/asterisk
258   ASTVARLIBDIR=$(INSTALL_PREFIX)$(PREFIX)/share/asterisk
259   ASTETCDIR=$(INSTALL_PREFIX)$(PREFIX)/etc/asterisk
260   ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
261   ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
262   ASTHEADERDIR=$(INSTALL_PREFIX)$(PREFIX)/include/asterisk
263   ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
264   ASTBINDIR=$(INSTALL_PREFIX)$(PREFIX)/bin
265   ASTSBINDIR=$(INSTALL_PREFIX)$(PREFIX)/sbin
266   ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
267   ASTMANDIR=$(INSTALL_PREFIX)$(PREFIX)/man
268   # XXX end FreeBSD paths
269
270 endif # FreeBSD
271
272 ifeq ($(OSARCH),NetBSD)
273   ASTCFLAGS+=-pthread
274   INCLUDE+=-I$(CROSS_COMPILE_TARGET)/usr/pkg/include
275   MPG123TARG=netbsd
276 endif
277
278 ifeq ($(OSARCH),OpenBSD)
279   ASTCFLAGS+=-pthread
280 endif
281
282 ifeq ($(OSARCH),SunOS)
283   ASTCFLAGS+=-Wcast-align -DSOLARIS
284   INCLUDE+=-Iinclude/solaris-compat -I$(CROSS_COMPILE_TARGET)/usr/local/ssl/include
285 endif
286
287 ifeq ($(findstring CYGWIN,$(OSARCH)),CYGWIN)
288   CYGLOADER=cygwin_a
289   OSARCH=CYGWIN
290   ASTOBJ=-shared -o asterisk.dll -Wl,--out-implib=libasterisk.dll.a -Wl,--export-all-symbols
291   ASTLINK=
292   LIBS+=-lpthread -lncurses -lm -lresolv
293   ASTSBINDIR=$(MODULES_DIR)
294   PROC=$(shell uname -m)
295 endif
296
297 ifndef WITHOUT_ZAPTEL
298
299 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/pkg/include/zaptel.h),)
300   ASTCFLAGS+=-DZAPTEL_OPTIMIZATIONS
301 endif
302
303 endif # WITHOUT_ZAPTEL
304
305 LIBEDIT=editline/libedit.a
306
307 ifneq ($(wildcard .version),)
308   ASTERISKVERSION=$(shell cat .version)
309   ASTERISKVERSIONNUM=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
310   RPMVERSION=$(shell sed 's/[-\/:]/_/g' .version)
311 else
312   RPMVERSION=unknown
313 endif
314
315 ifneq ($(wildcard CVS),)
316   ASTERISKVERSIONNUM=999999
317   ifneq ($(wildcard CVS/Tag),)
318     ASTERISKVERSION=$(shell echo "CVS-`sed 's/^T//g' CVS/Tag`-`date +"%D-%T"`")
319   else
320     ASTERISKVERSION=CVS HEAD
321   endif
322 else
323   ASTERISKVERSIONNUM=000000
324 endif
325
326 ASTCFLAGS+= $(DEBUG_THREADS)
327 ASTCFLAGS+= $(TRACE_FRAMES)
328 ASTCFLAGS+= $(MALLOC_DEBUG)
329 ASTCFLAGS+= $(BUSYDETECT)
330 ASTCFLAGS+= $(OPTIONS)
331 ASTCFLAGS+= -fomit-frame-pointer 
332 SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
333
334 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
335         translate.o file.o say.o pbx.o cli.o md5.o term.o \
336         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
337         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o \
338         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
339         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
340         utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
341         netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
342         cryptostub.o
343
344 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sys/poll.h),)
345   OBJS+= poll.o
346   ASTCFLAGS+=-DPOLLCOMPAT
347 endif
348
349 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/dlfcn.h),)
350   OBJS+= dlfcn.o
351   ASTCFLAGS+=-DDLFCNCOMPAT
352 endif
353
354 ifeq ($(OSARCH),Linux)
355   LIBS+=-ldl -lpthread -lncurses -lm -lresolv  #-lnjamd
356 else
357   LIBS+=-lncurses -lm
358 endif
359
360 ifeq ($(OSARCH),Darwin)
361   LIBS+=-lresolv
362   ASTCFLAGS+=-D__Darwin__
363   AUDIO_LIBS=-framework CoreAudio
364   ASTLINK=-Wl,-dynamic
365   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
366   OBJS+=poll.o
367   ASTCFLAGS+=-DPOLLCOMPAT
368 else
369 #These are used for all but Darwin
370   ASTLINK=-Wl,-E 
371   SOLINK=-shared -Xlinker -x
372 endif
373
374 ifeq ($(OSARCH),FreeBSD)
375   LIBS+=-lcrypto
376 endif
377
378 ifeq ($(OSARCH),NetBSD)
379   LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
380 endif
381
382 ifeq ($(OSARCH),OpenBSD)
383   LIBS+=-lcrypto -lpthread -lm -lncurses
384 endif
385
386 ifeq ($(OSARCH),SunOS)
387   LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
388   OBJS+=strcompat.o
389   ASTLINK=
390   SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
391 endif
392
393 ifeq ($(MAKETOPLEVEL),$(MAKELEVEL))
394   CFLAGS+=$(ASTCFLAGS)
395 endif
396
397 # This is used when generating the doxygen documentation
398 ifneq ($(wildcard /usr/local/bin/dot)$(wildcard /usr/bin/dot),)
399   HAVEDOT=yes
400 else
401   HAVEDOT=no
402 endif
403
404 LIBS+=-lssl
405
406 INSTALL=install
407
408 _all: all
409         @echo " +--------- Asterisk Build Complete ---------+"  
410         @echo " + Asterisk has successfully been built, but +"  
411         @echo " + cannot be run before being installed by   +"  
412         @echo " + running:                                  +"  
413         @echo " +                                           +"
414         @echo " +               $(MAKE) install                +"  
415         @echo " +-------------------------------------------+"  
416
417 all: cleantest depend asterisk subdirs 
418
419 #ifneq ($(wildcard tags),)
420 ctags: tags
421 #endif
422
423 ifneq ($(wildcard TAGS),)
424 all: TAGS
425 endif
426
427 noclean: depend asterisk subdirs
428
429 editline/config.h:
430         cd editline && unset CFLAGS LIBS && ./configure ; \
431
432 editline/libedit.a: FORCE
433         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
434         $(MAKE) -C editline libedit.a
435
436 db1-ast/libdb1.a: FORCE
437         @if [ -d db1-ast ]; then \
438                 $(MAKE) -C db1-ast libdb1.a ; \
439         else \
440                 echo "You need to do a cvs update -d not just cvs update"; \
441                 exit 1; \
442         fi
443
444 ifneq ($(wildcard .depend),)
445   include .depend
446 endif
447
448 ifneq ($(wildcard .tags-depend),)
449   include .tags-depend
450 endif
451
452 ast_expr2.c:
453         bison -d --name-prefix=ast_yy ast_expr2.y -o ast_expr2.c
454
455 ast_expr2f.c:
456         flex --full ast_expr2.fl
457
458 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
459         gcc -g -c -DSTANDALONE ast_expr2f.c
460         gcc -g -c -DSTANDALONE ast_expr2.c
461         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
462         rm ast_expr2.o ast_expr2f.o 
463
464 manpage: asterisk.8
465
466 asterisk.8: asterisk.sgml
467         rm -f asterisk.8
468         docbook2man asterisk.sgml
469         mv ./*.8 asterisk.8
470
471 asterisk.pdf: asterisk.sgml
472         docbook2pdf asterisk.sgml
473
474 asterisk.ps: asterisk.sgml
475         docbook2ps asterisk.sgml
476
477 asterisk.html: asterisk.sgml
478         docbook2html asterisk.sgml
479         mv r1.html asterisk.html
480
481 asterisk.txt: asterisk.sgml
482         docbook2txt asterisk.sgml
483
484 defaults.h: FORCE
485         build_tools/make_defaults_h > $@.tmp
486         if cmp -s $@.tmp $@ ; then echo ; else \
487                 mv $@.tmp $@ ; \
488         fi
489         rm -f $@.tmp
490
491 include/asterisk/version.h: FORCE
492         build_tools/make_version_h > $@.tmp
493         if cmp -s $@.tmp $@ ; then echo; else \
494                 mv $@.tmp $@ ; \
495         fi
496         rm -f $@.tmp
497
498 stdtime/libtime.a: FORCE
499         @if [ -d stdtime ]; then \
500                 $(MAKE) -C stdtime libtime.a ; \
501         else \
502                 echo "You need to do a cvs update -d not just cvs update"; \
503                 exit 1; \
504         fi
505
506 cygwin_a:
507         $(MAKE) -C cygwin all
508
509 asterisk: $(CYGLOADER) editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
510         build_tools/make_build_h > include/asterisk/build.h.tmp
511         if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \
512                 mv include/asterisk/build.h.tmp include/asterisk/build.h ; \
513         fi
514         rm -f include/asterisk/build.h.tmp
515         $(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
516         $(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
517
518 muted: muted.o
519         $(CC) $(AUDIO_LIBS) -o muted muted.o
520
521 subdirs: 
522         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
523
524 clean:
525         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
526         rm -f *.o *.so asterisk .depend
527         rm -f defaults.h
528         rm -f include/asterisk/build.h
529         rm -f include/asterisk/version.h
530         rm -f .tags-depend .tags-sources tags TAGS
531         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
532         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
533         $(MAKE) -C db1-ast clean
534         $(MAKE) -C stdtime clean
535
536 datafiles: all
537         if test $$(id -u) = 0; then sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
538         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
539         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/priv-callerintros
540         for x in sounds/digits/*.gsm; do \
541                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
542                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
543                 else \
544                         echo "No description for $$x"; \
545                         exit 1; \
546                 fi; \
547         done
548         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
549         for x in sounds/dictate/*.gsm; do \
550                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
551                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
552                 else \
553                         echo "No description for $$x"; \
554                         exit 1; \
555                 fi; \
556         done
557         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
558         for x in sounds/letters/*.gsm; do \
559                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
560                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
561                 else \
562                         echo "No description for $$x"; \
563                         exit 1; \
564                 fi; \
565         done
566         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
567         for x in sounds/phonetic/*.gsm; do \
568                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
569                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
570                 else \
571                         echo "No description for $$x"; \
572                         exit 1; \
573                 fi; \
574         done
575         for x in sounds/demo-* sounds/vm-* sounds/transfer* sounds/pbx-* sounds/ss-* sounds/beep* sounds/dir-* sounds/conf-* sounds/agent-* sounds/invalid* sounds/tt-* sounds/auth-* sounds/privacy-* sounds/queue-* sounds/spy-* sounds/priv-* sounds/screen-* sounds/hello-*; do \
576                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
577                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
578                 else \
579                         echo "No description for $$x"; \
580                         exit 1; \
581                 fi; \
582         done
583         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
584         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
585         for x in images/*.jpg; do \
586                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
587         done
588         mkdir -p $(DESTDIR)$(AGI_DIR)
589
590 update: 
591         @if [ -d CVS ]; then \
592                 if [ -f patches/.applied ]; then \
593                         patches=`cat patches/.applied`; \
594                 fi; \
595                 if [ ! -z "$$patches" ]; then \
596                         for x in $$patches; do \
597                                 echo "Unapplying $$x..."; \
598                                 patch -R -p0 < patches/$$x; \
599                         done; \
600                         rm -f patches/.applied; \
601                 fi ; \
602                 echo "Updating from CVS..." ; \
603                 cvs -q -z3 update -Pd | tee update.out; \
604                 rm -f .version; \
605                 if [ `grep -c ^C update.out` -gt 0 ]; then \
606                         echo ; echo "The following files have conflicts:" ; \
607                         grep ^C update.out | cut -d' ' -f2- ; \
608                 fi ; \
609                 rm -f update.out; \
610                 if [ ! -z "$$patches" ]; then \
611                         for x in $$patches; do \
612                                 if [ -f patches/$$x ]; then \
613                                         echo "Applying patch $$x..."; \
614                                         patch -p0 < patches/$$x; \
615                                         echo $$x >> patches/.applied; \
616                                 else \
617                                         echo "Patch $$x no longer relevant"; \
618                                 fi; \
619                         done; \
620                 fi; \
621         else \
622                 echo "Not CVS";  \
623         fi
624
625 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
626 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
627
628 bininstall: all
629         mkdir -p $(DESTDIR)$(MODULES_DIR)
630         mkdir -p $(DESTDIR)$(ASTSBINDIR)
631         mkdir -p $(DESTDIR)$(ASTETCDIR)
632         mkdir -p $(DESTDIR)$(ASTBINDIR)
633         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
634         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
635         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
636         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
637         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
638         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
639         if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
640         if [ -f cygwin/asterisk.exe ]; then $(INSTALL) -m 755 cygwin/asterisk.exe $(DESTDIR)$(ASTSBINDIR)/; fi
641         if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
642         ln -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
643         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
644         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/  
645         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
646                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
647                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
648         fi
649         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
650         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
651         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
652         if [ -n "$(OLDHEADERS)" ]; then \
653                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
654         fi
655         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
656         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
657         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
658         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
659         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
660         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
661         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
662         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
663         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
664         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
665         $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
666         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
667         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
668         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
669         if [ -d contrib/firmware/iax ]; then \
670                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
671         else \
672                 echo "You need to do cvs update -d not just cvs update" ; \
673         fi 
674         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
675         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
676         @echo " +---- Asterisk Installation Complete -------+"  
677         @echo " +                                           +"
678         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
679         @echo " +                                           +"
680         @echo " + Asterisk has successfully been installed. +"  
681         @echo " + If you would like to install the sample   +"  
682         @echo " + configuration files (overwriting any      +"
683         @echo " + existing config files), run:              +"  
684         @echo " +                                           +"
685         @echo " +               $(MAKE) samples                +"
686         @echo " +                                           +"
687         @echo " +-----------------  or ---------------------+"
688         @echo " +                                           +"
689         @echo " + You can go ahead and install the asterisk +"
690         @echo " + program documentation now or later run:   +"
691         @echo " +                                           +"
692         @echo " +              $(MAKE) progdocs                +"
693         @echo " +                                           +"
694         @echo " + **Note** This requires that you have      +"
695         @echo " + doxygen installed on your local system    +"
696         @echo " +-------------------------------------------+"
697         @$(MAKE) -s oldmodcheck
698
699 NEWMODS=$(notdir $(wildcard */*.so))
700 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
701
702 oldmodcheck:
703         @if [ -n "$(OLDMODS)" ]; then \
704                 echo " WARNING WARNING WARNING" ;\
705                 echo "" ;\
706                 echo " Your Asterisk modules directory, located at" ;\
707                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
708                 echo " contains modules that were not installed by this " ;\
709                 echo " version of Asterisk. Please ensure that these" ;\
710                 echo " modules are compatible with this version before" ;\
711                 echo " attempting to run Asterisk." ;\
712                 echo "" ;\
713                 for f in $(OLDMODS); do \
714                         echo "    $$f" ;\
715                 done ;\
716                 echo "" ;\
717                 echo " WARNING WARNING WARNING" ;\
718         fi
719
720 install: all datafiles bininstall
721         @if [ -x /usr/sbin/asterisk-post-install ]; then \
722                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
723         fi
724
725 upgrade: all bininstall
726
727 adsi:
728         mkdir -p $(DESTDIR)$(ASTETCDIR)
729         for x in configs/*.adsi; do \
730                 if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
731                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
732                 fi ; \
733         done
734
735 samples: adsi
736         mkdir -p $(DESTDIR)$(ASTETCDIR)
737         for x in configs/*.sample; do \
738                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
739                         if [ "$(OVERWRITE)" = "y" ]; then \
740                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
741                                         echo "Config file $$x is unchanged"; \
742                                         continue; \
743                                 fi ; \
744                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
745                         else \
746                                 echo "Skipping config file $$x"; \
747                                 continue; \
748                         fi ;\
749                 fi ; \
750                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
751         done
752         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
753                 ( \
754                 echo "[directories]" ; \
755                 echo "astetcdir => $(ASTETCDIR)" ; \
756                 echo "astmoddir => $(MODULES_DIR)" ; \
757                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
758                 echo "astagidir => $(AGI_DIR)" ; \
759                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
760                 echo "astrundir => $(ASTVARRUNDIR)" ; \
761                 echo "astlogdir => $(ASTLOGDIR)" ; \
762                 echo "" ; \
763                 echo "; Changing the following lines may compromise your security." ; \
764                 echo ";[files]" ; \
765                 echo ";astctlpermissions = 0660" ; \
766                 echo ";astctlowner = root" ; \
767                 echo ";astctlgroup = apache" ; \
768                 echo ";astctl = asterisk.ctl" ; \
769                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
770         else \
771                 echo "Skipping asterisk.conf creation"; \
772         fi
773         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
774         for x in sounds/demo-*; do \
775                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
776                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
777                 else \
778                         echo "No description for $$x"; \
779                         exit 1; \
780                 fi; \
781         done
782         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
783         for x in sounds/*.mp3; do \
784                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
785         done
786         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
787         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
788         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
789         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
790                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
791         done
792         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
793         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
794                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
795         done
796
797 webvmail:
798         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
799         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
800         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
801         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
802         for x in images/*.gif; do \
803                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
804         done
805         @echo " +--------- Asterisk Web Voicemail ----------+"  
806         @echo " +                                           +"
807         @echo " + Asterisk Web Voicemail is installed in    +"
808         @echo " + your cgi-bin directory:                   +"
809         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
810         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
811         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
812         @echo " +                                           +"
813         @echo " + Other static items have been stored in:   +"
814         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
815         @echo " +                                           +"
816         @echo " + If these paths do not match your httpd    +"
817         @echo " + installation, correct the definitions     +"
818         @echo " + in your Makefile of HTTP_CGIDIR and       +"
819         @echo " + HTTP_DOCSDIR                              +"
820         @echo " +                                           +"
821         @echo " +-------------------------------------------+"  
822
823 spec: 
824         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
825
826 rpm: __rpm
827
828 __rpm: include/asterisk/version.h spec
829         rm -rf /tmp/asterisk ; \
830         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
831         $(MAKE) DESTDIR=/tmp/asterisk install ; \
832         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
833         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
834         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
835         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
836
837 progdocs:
838         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
839         echo "PROJECT_NUMBER=$(ASTERISKVERSION)  -  $(ASTERISKVERSIONNUM)") | doxygen - 
840
841 mpg123:
842         @wget -V >/dev/null || (echo "You need wget" ; false )
843         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
844         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
845         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
846
847 config:
848         if [ -d /etc/rc.d/init.d ]; then \
849                 $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
850                 /sbin/chkconfig --add asterisk; \
851         elif [ -d /etc/init.d ]; then \
852                 $(INSTALL) -m 755 init.asterisk /etc/init.d/asterisk; \
853         fi 
854
855 dont-optimize: install
856
857 valgrind: dont-optimize
858
859 depend: include/asterisk/version.h .depend defaults.h 
860         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
861
862 .depend: include/asterisk/version.h
863         build_tools/mkdep $(CFLAGS) $(wildcard *.c)
864
865 .tags-depend:
866         @echo -n ".tags-depend: " > $@
867         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
868         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
869         @find $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@
870         @find $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@
871         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
872         @echo >> $@
873
874 .tags-sources:
875         @rm -f $@
876         @find . -maxdepth 1 -name \*.c -print >> $@
877         @find . -maxdepth 1 -name \*.h -print >> $@
878         @find $(SUBDIRS) -name \*.c -print >> $@
879         @find $(SUBDIRS) -name \*.h -print >> $@
880         @find include -name \*.h -print >> $@
881
882 tags: .tags-depend .tags-sources
883         ctags -L .tags-sources -o $@
884
885 ctags: tags
886
887 TAGS: .tags-depend .tags-sources
888         etags -o $@ `cat .tags-sources`
889
890 etags: TAGS
891
892 FORCE:
893
894 %_env:
895         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
896
897 env:
898         env
899
900 # If the cleancount has been changed, force a make clean.
901 # .cleancount is the global clean count, and .lastclean is the 
902 # last clean count we had
903 # We can avoid this by making noclean
904
905 cleantest:
906         if cmp -s .cleancount .lastclean ; then echo ; else \
907                 $(MAKE) clean; cp -f .cleancount .lastclean;\
908         fi
909
910 patchlist:
911         @echo "Experimental Patches:"
912         @for x in patches/*; do \
913                 patch=`basename $$x`; \
914                 if [ "$$patch" = "CVS" ]; then \
915                         continue; \
916                 fi; \
917                 if grep -q ^$$patch$$ patches/.applied; then \
918                         echo "$$patch (applied)"; \
919                 else \
920                         echo "$$patch (available)"; \
921                 fi; \
922         done
923
924 apply: 
925         @if [ -z "$(PATCH)" ]; then \
926                 echo "Usage: make PATCH=<patchname> apply"; \
927         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
928                 echo "Patch $(PATCH) is already applied"; \
929         elif [ -f "patches/$(PATCH)" ]; then \
930                 echo "Applying patch $(PATCH)"; \
931                 patch -p0 < patches/$(PATCH); \
932                 echo "$(PATCH)" >> patches/.applied; \
933         else \
934                 echo "No such patch $(PATCH) in patches directory"; \
935         fi
936
937 unapply: 
938         @if [ -z "$(PATCH)" ]; then \
939                 echo "Usage: make PATCH=<patchname> unapply"; \
940         elif grep -v -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
941                 echo "Patch $(PATCH) is not applied"; \
942         elif [ -f "patches/$(PATCH)" ]; then \
943                 echo "Un-applying patch $(PATCH)"; \
944                 patch -p0 -R < patches/$(PATCH); \
945                 rm -f patches/.tmpapplied || :; \
946                 mv patches/.applied patches/.tmpapplied; \
947                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
948                 rm -f patches/.tmpapplied; \
949         else \
950                 echo "No such patch $(PATCH) in patches directory"; \
951         fi
952