5c18fca0f7d3aa6aabf9c3099c77622dada9ddc9
[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 # CVS mirrors of SVN have .svnrevision files showing
316 # which SVN revision they are based on, and .svnbranch
317 # showing the branch they are made from
318 ifneq ($(wildcard .svnrevision),)
319   ASTERISKVERSIONNUM=999999
320   ASTERISKVERSION:=SVN-$(shell cat .svnbranch)-r$(shell cat .svnrevision)
321 else
322   ifneq ($(wildcard .svn),)
323     ASTERISKVERSIONNUM=999999
324     ASTERISKVERSION=SVN-$(shell build_tools/make_svn_branch_name)
325   else
326     ASTERISKVERSIONNUM=000000
327   endif
328 endif
329
330 ASTCFLAGS+= $(DEBUG_THREADS)
331 ASTCFLAGS+= $(TRACE_FRAMES)
332 ASTCFLAGS+= $(MALLOC_DEBUG)
333 ASTCFLAGS+= $(BUSYDETECT)
334 ASTCFLAGS+= $(OPTIONS)
335 ASTCFLAGS+= -fomit-frame-pointer 
336 SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
337
338 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
339         translate.o file.o say.o pbx.o cli.o md5.o term.o \
340         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
341         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o \
342         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
343         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
344         utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
345         netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
346         cryptostub.o
347
348 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sys/poll.h),)
349   OBJS+= poll.o
350   ASTCFLAGS+=-DPOLLCOMPAT
351 endif
352
353 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/dlfcn.h),)
354   OBJS+= dlfcn.o
355   ASTCFLAGS+=-DDLFCNCOMPAT
356 endif
357
358 ifeq ($(OSARCH),Linux)
359   LIBS+=-ldl -lpthread -lncurses -lm -lresolv  #-lnjamd
360 else
361   LIBS+=-lncurses -lm
362 endif
363
364 ifeq ($(OSARCH),Darwin)
365   LIBS+=-lresolv
366   ASTCFLAGS+=-D__Darwin__
367   AUDIO_LIBS=-framework CoreAudio
368   ASTLINK=-Wl,-dynamic
369   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
370   OBJS+=poll.o
371   ASTCFLAGS+=-DPOLLCOMPAT
372 else
373 #These are used for all but Darwin
374   ASTLINK=-Wl,-E 
375   SOLINK=-shared -Xlinker -x
376 endif
377
378 ifeq ($(OSARCH),FreeBSD)
379   LIBS+=-lcrypto
380 endif
381
382 ifeq ($(OSARCH),NetBSD)
383   LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
384 endif
385
386 ifeq ($(OSARCH),OpenBSD)
387   LIBS+=-lcrypto -lpthread -lm -lncurses
388 endif
389
390 ifeq ($(OSARCH),SunOS)
391   LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
392   OBJS+=strcompat.o
393   ASTLINK=
394   SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
395 endif
396
397 ifeq ($(MAKETOPLEVEL),$(MAKELEVEL))
398   CFLAGS+=$(ASTCFLAGS)
399 endif
400
401 # This is used when generating the doxygen documentation
402 ifneq ($(wildcard /usr/local/bin/dot)$(wildcard /usr/bin/dot),)
403   HAVEDOT=yes
404 else
405   HAVEDOT=no
406 endif
407
408 LIBS+=-lssl
409
410 INSTALL=install
411
412 _all: all
413         @echo " +--------- Asterisk Build Complete ---------+"  
414         @echo " + Asterisk has successfully been built, but +"  
415         @echo " + cannot be run before being installed by   +"  
416         @echo " + running:                                  +"  
417         @echo " +                                           +"
418         @echo " +               $(MAKE) install                +"  
419         @echo " +-------------------------------------------+"  
420
421 all: cleantest depend asterisk subdirs 
422
423 #ifneq ($(wildcard tags),)
424 ctags: tags
425 #endif
426
427 ifneq ($(wildcard TAGS),)
428 all: TAGS
429 endif
430
431 noclean: depend asterisk subdirs
432
433 editline/config.h:
434         cd editline && unset CFLAGS LIBS && ./configure ; \
435
436 editline/libedit.a: FORCE
437         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
438         $(MAKE) -C editline libedit.a
439
440 db1-ast/libdb1.a: FORCE
441         @if [ -d db1-ast ]; then \
442                 $(MAKE) -C db1-ast libdb1.a ; \
443         else \
444                 echo "You need to do a cvs update -d not just cvs update"; \
445                 exit 1; \
446         fi
447
448 ifneq ($(wildcard .depend),)
449   include .depend
450 endif
451
452 ifneq ($(wildcard .tags-depend),)
453   include .tags-depend
454 endif
455
456 ast_expr2.c:
457         bison -d --name-prefix=ast_yy ast_expr2.y -o ast_expr2.c
458
459 ast_expr2f.c:
460         flex --full ast_expr2.fl
461
462 testexpr2: ast_expr2f.c ast_expr2.c ast_expr2.h
463         gcc -g -c -DSTANDALONE ast_expr2f.c
464         gcc -g -c -DSTANDALONE ast_expr2.c
465         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
466         rm ast_expr2.o ast_expr2f.o 
467
468 manpage: asterisk.8
469
470 asterisk.8: asterisk.sgml
471         rm -f asterisk.8
472         docbook2man asterisk.sgml
473         mv ./*.8 asterisk.8
474
475 asterisk.pdf: asterisk.sgml
476         docbook2pdf asterisk.sgml
477
478 asterisk.ps: asterisk.sgml
479         docbook2ps asterisk.sgml
480
481 asterisk.html: asterisk.sgml
482         docbook2html asterisk.sgml
483         mv r1.html asterisk.html
484
485 asterisk.txt: asterisk.sgml
486         docbook2txt asterisk.sgml
487
488 defaults.h: FORCE
489         build_tools/make_defaults_h > $@.tmp
490         if cmp -s $@.tmp $@ ; then echo ; else \
491                 mv $@.tmp $@ ; \
492         fi
493         rm -f $@.tmp
494
495 include/asterisk/version.h: FORCE
496         build_tools/make_version_h > $@.tmp
497         if cmp -s $@.tmp $@ ; then echo; else \
498                 mv $@.tmp $@ ; \
499         fi
500         rm -f $@.tmp
501
502 stdtime/libtime.a: FORCE
503         @if [ -d stdtime ]; then \
504                 $(MAKE) -C stdtime libtime.a ; \
505         else \
506                 echo "You need to do a cvs update -d not just cvs update"; \
507                 exit 1; \
508         fi
509
510 cygwin_a:
511         $(MAKE) -C cygwin all
512
513 asterisk: $(CYGLOADER) editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
514         build_tools/make_build_h > include/asterisk/build.h.tmp
515         if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \
516                 mv include/asterisk/build.h.tmp include/asterisk/build.h ; \
517         fi
518         rm -f include/asterisk/build.h.tmp
519         $(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
520         $(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
521
522 muted: muted.o
523         $(CC) $(AUDIO_LIBS) -o muted muted.o
524
525 subdirs: 
526         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
527
528 clean:
529         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
530         rm -f *.o *.so asterisk .depend
531         rm -f defaults.h
532         rm -f include/asterisk/build.h
533         rm -f include/asterisk/version.h
534         rm -f .tags-depend .tags-sources tags TAGS
535         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
536         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
537         $(MAKE) -C db1-ast clean
538         $(MAKE) -C stdtime clean
539
540 datafiles: all
541         if [ x`whoami` = xroot ]; then sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
542         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
543         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/priv-callerintros
544         for x in sounds/digits/*.gsm; do \
545                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
546                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
547                 else \
548                         echo "No description for $$x"; \
549                         exit 1; \
550                 fi; \
551         done
552         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate
553         for x in sounds/dictate/*.gsm; do \
554                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
555                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/dictate ; \
556                 else \
557                         echo "No description for $$x"; \
558                         exit 1; \
559                 fi; \
560         done
561         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
562         for x in sounds/letters/*.gsm; do \
563                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
564                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
565                 else \
566                         echo "No description for $$x"; \
567                         exit 1; \
568                 fi; \
569         done
570         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
571         for x in sounds/phonetic/*.gsm; do \
572                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
573                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
574                 else \
575                         echo "No description for $$x"; \
576                         exit 1; \
577                 fi; \
578         done
579         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 \
580                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
581                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
582                 else \
583                         echo "No description for $$x"; \
584                         exit 1; \
585                 fi; \
586         done
587         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
588         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
589         for x in images/*.jpg; do \
590                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
591         done
592         mkdir -p $(DESTDIR)$(AGI_DIR)
593
594 update: 
595         @if [ -d CVS ]; then \
596                 if [ -f patches/.applied ]; then \
597                         patches=`cat patches/.applied`; \
598                 fi; \
599                 if [ ! -z "$$patches" ]; then \
600                         for x in $$patches; do \
601                                 echo "Unapplying $$x..."; \
602                                 patch -R -p0 < patches/$$x; \
603                         done; \
604                         rm -f patches/.applied; \
605                 fi ; \
606                 echo "Updating from CVS..." ; \
607                 cvs -q -z3 update -Pd | tee update.out; \
608                 rm -f .version; \
609                 if [ `grep -c ^C update.out` -gt 0 ]; then \
610                         echo ; echo "The following files have conflicts:" ; \
611                         grep ^C update.out | cut -d' ' -f2- ; \
612                 fi ; \
613                 rm -f update.out; \
614                 if [ ! -z "$$patches" ]; then \
615                         for x in $$patches; do \
616                                 if [ -f patches/$$x ]; then \
617                                         echo "Applying patch $$x..."; \
618                                         patch -p0 < patches/$$x; \
619                                         echo $$x >> patches/.applied; \
620                                 else \
621                                         echo "Patch $$x no longer relevant"; \
622                                 fi; \
623                         done; \
624                 fi; \
625         else \
626                 echo "Not CVS";  \
627         fi
628
629 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
630 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
631
632 bininstall: all
633         mkdir -p $(DESTDIR)$(MODULES_DIR)
634         mkdir -p $(DESTDIR)$(ASTSBINDIR)
635         mkdir -p $(DESTDIR)$(ASTETCDIR)
636         mkdir -p $(DESTDIR)$(ASTBINDIR)
637         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
638         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
639         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
640         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
641         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
642         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
643         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
644         if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
645         if [ -f cygwin/asterisk.exe ]; then $(INSTALL) -m 755 cygwin/asterisk.exe $(DESTDIR)$(ASTSBINDIR)/; fi
646         if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
647         ln -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
648         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
649         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/  
650         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
651                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
652                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
653         fi
654         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
655         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
656         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
657         if [ -n "$(OLDHEADERS)" ]; then \
658                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
659         fi
660         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
661         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
662         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
663         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
664         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
665         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
666         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
667         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
668         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
669         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
670         $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
671         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
672         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
673         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
674         if [ -d contrib/firmware/iax ]; then \
675                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
676         else \
677                 echo "You need to do cvs update -d not just cvs update" ; \
678         fi 
679         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
680         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
681         @echo " +---- Asterisk Installation Complete -------+"  
682         @echo " +                                           +"
683         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
684         @echo " +                                           +"
685         @echo " + Asterisk has successfully been installed. +"  
686         @echo " + If you would like to install the sample   +"  
687         @echo " + configuration files (overwriting any      +"
688         @echo " + existing config files), run:              +"  
689         @echo " +                                           +"
690         @echo " +               $(MAKE) samples                +"
691         @echo " +                                           +"
692         @echo " +-----------------  or ---------------------+"
693         @echo " +                                           +"
694         @echo " + You can go ahead and install the asterisk +"
695         @echo " + program documentation now or later run:   +"
696         @echo " +                                           +"
697         @echo " +              $(MAKE) progdocs                +"
698         @echo " +                                           +"
699         @echo " + **Note** This requires that you have      +"
700         @echo " + doxygen installed on your local system    +"
701         @echo " +-------------------------------------------+"
702         @$(MAKE) -s oldmodcheck
703
704 NEWMODS=$(notdir $(wildcard */*.so))
705 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
706
707 oldmodcheck:
708         @if [ -n "$(OLDMODS)" ]; then \
709                 echo " WARNING WARNING WARNING" ;\
710                 echo "" ;\
711                 echo " Your Asterisk modules directory, located at" ;\
712                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
713                 echo " contains modules that were not installed by this " ;\
714                 echo " version of Asterisk. Please ensure that these" ;\
715                 echo " modules are compatible with this version before" ;\
716                 echo " attempting to run Asterisk." ;\
717                 echo "" ;\
718                 for f in $(OLDMODS); do \
719                         echo "    $$f" ;\
720                 done ;\
721                 echo "" ;\
722                 echo " WARNING WARNING WARNING" ;\
723         fi
724
725 install: all datafiles bininstall
726         @if [ -x /usr/sbin/asterisk-post-install ]; then \
727                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
728         fi
729
730 upgrade: all bininstall
731
732 adsi:
733         mkdir -p $(DESTDIR)$(ASTETCDIR)
734         for x in configs/*.adsi; do \
735                 if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
736                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
737                 fi ; \
738         done
739
740 samples: adsi
741         mkdir -p $(DESTDIR)$(ASTETCDIR)
742         for x in configs/*.sample; do \
743                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
744                         if [ "$(OVERWRITE)" = "y" ]; then \
745                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
746                                         echo "Config file $$x is unchanged"; \
747                                         continue; \
748                                 fi ; \
749                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
750                         else \
751                                 echo "Skipping config file $$x"; \
752                                 continue; \
753                         fi ;\
754                 fi ; \
755                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
756         done
757         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
758                 ( \
759                 echo "[directories]" ; \
760                 echo "astetcdir => $(ASTETCDIR)" ; \
761                 echo "astmoddir => $(MODULES_DIR)" ; \
762                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
763                 echo "astagidir => $(AGI_DIR)" ; \
764                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
765                 echo "astrundir => $(ASTVARRUNDIR)" ; \
766                 echo "astlogdir => $(ASTLOGDIR)" ; \
767                 echo "" ; \
768                 echo "; Changing the following lines may compromise your security." ; \
769                 echo ";[files]" ; \
770                 echo ";astctlpermissions = 0660" ; \
771                 echo ";astctlowner = root" ; \
772                 echo ";astctlgroup = apache" ; \
773                 echo ";astctl = asterisk.ctl" ; \
774                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
775         else \
776                 echo "Skipping asterisk.conf creation"; \
777         fi
778         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
779         for x in sounds/demo-*; do \
780                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
781                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
782                 else \
783                         echo "No description for $$x"; \
784                         exit 1; \
785                 fi; \
786         done
787         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
788         for x in sounds/*.mp3; do \
789                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
790         done
791         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
792         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
793         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
794         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
795                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
796         done
797         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
798         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
799                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
800         done
801
802 webvmail:
803         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
804         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
805         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
806         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
807         for x in images/*.gif; do \
808                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
809         done
810         @echo " +--------- Asterisk Web Voicemail ----------+"  
811         @echo " +                                           +"
812         @echo " + Asterisk Web Voicemail is installed in    +"
813         @echo " + your cgi-bin directory:                   +"
814         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
815         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
816         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
817         @echo " +                                           +"
818         @echo " + Other static items have been stored in:   +"
819         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
820         @echo " +                                           +"
821         @echo " + If these paths do not match your httpd    +"
822         @echo " + installation, correct the definitions     +"
823         @echo " + in your Makefile of HTTP_CGIDIR and       +"
824         @echo " + HTTP_DOCSDIR                              +"
825         @echo " +                                           +"
826         @echo " +-------------------------------------------+"  
827
828 spec: 
829         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
830
831 rpm: __rpm
832
833 __rpm: include/asterisk/version.h spec
834         rm -rf /tmp/asterisk ; \
835         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
836         $(MAKE) DESTDIR=/tmp/asterisk install ; \
837         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
838         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
839         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
840         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
841
842 progdocs:
843         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
844         echo "PROJECT_NUMBER=$(ASTERISKVERSION)  -  $(ASTERISKVERSIONNUM)") | doxygen - 
845
846 mpg123:
847         @wget -V >/dev/null || (echo "You need wget" ; false )
848         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
849         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
850         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
851
852 config:
853         if [ -d /etc/rc.d/init.d ]; then \
854                 $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
855                 /sbin/chkconfig --add asterisk; \
856         elif [ -d /etc/init.d ]; then \
857                 $(INSTALL) -m 755 init.asterisk /etc/init.d/asterisk; \
858         fi 
859
860 dont-optimize: install
861
862 valgrind: dont-optimize
863
864 depend: include/asterisk/version.h .depend defaults.h 
865         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
866
867 .depend: include/asterisk/version.h
868         build_tools/mkdep $(CFLAGS) $(wildcard *.c)
869
870 .tags-depend:
871         @echo -n ".tags-depend: " > $@
872         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
873         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
874         @find $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@
875         @find $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@
876         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
877         @echo >> $@
878
879 .tags-sources:
880         @rm -f $@
881         @find . -maxdepth 1 -name \*.c -print >> $@
882         @find . -maxdepth 1 -name \*.h -print >> $@
883         @find $(SUBDIRS) -name \*.c -print >> $@
884         @find $(SUBDIRS) -name \*.h -print >> $@
885         @find include -name \*.h -print >> $@
886
887 tags: .tags-depend .tags-sources
888         ctags -L .tags-sources -o $@
889
890 ctags: tags
891
892 TAGS: .tags-depend .tags-sources
893         etags -o $@ `cat .tags-sources`
894
895 etags: TAGS
896
897 FORCE:
898
899 %_env:
900         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
901
902 env:
903         env
904
905 # If the cleancount has been changed, force a make clean.
906 # .cleancount is the global clean count, and .lastclean is the 
907 # last clean count we had
908 # We can avoid this by making noclean
909
910 cleantest:
911         if cmp -s .cleancount .lastclean ; then echo ; else \
912                 $(MAKE) clean; cp -f .cleancount .lastclean;\
913         fi
914
915 patchlist:
916         @echo "Experimental Patches:"
917         @for x in patches/*; do \
918                 patch=`basename $$x`; \
919                 if [ "$$patch" = "CVS" ]; then \
920                         continue; \
921                 fi; \
922                 if grep -q ^$$patch$$ patches/.applied; then \
923                         echo "$$patch (applied)"; \
924                 else \
925                         echo "$$patch (available)"; \
926                 fi; \
927         done
928
929 apply: 
930         @if [ -z "$(PATCH)" ]; then \
931                 echo "Usage: make PATCH=<patchname> apply"; \
932         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
933                 echo "Patch $(PATCH) is already applied"; \
934         elif [ -f "patches/$(PATCH)" ]; then \
935                 echo "Applying patch $(PATCH)"; \
936                 patch -p0 < patches/$(PATCH); \
937                 echo "$(PATCH)" >> patches/.applied; \
938         else \
939                 echo "No such patch $(PATCH) in patches directory"; \
940         fi
941
942 unapply: 
943         @if [ -z "$(PATCH)" ]; then \
944                 echo "Usage: make PATCH=<patchname> unapply"; \
945         elif grep -v -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
946                 echo "Patch $(PATCH) is not applied"; \
947         elif [ -f "patches/$(PATCH)" ]; then \
948                 echo "Un-applying patch $(PATCH)"; \
949                 patch -p0 -R < patches/$(PATCH); \
950                 rm -f patches/.tmpapplied || :; \
951                 mv patches/.applied patches/.tmpapplied; \
952                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
953                 rm -f patches/.tmpapplied; \
954         else \
955                 echo "No such patch $(PATCH) in patches directory"; \
956         fi
957