ff3d2abccb4a28f8ddc4bddaa1ad7db26f047bce
[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 build_tools/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 .svn ]; then \
596                 echo "Updating from Subversion..." ; \
597                 svn update | tee update.out; \
598                 rm -f .version; \
599                 if [ `grep -c ^C update.out` -gt 0 ]; then \
600                         echo ; echo "The following files have conflicts:" ; \
601                         grep ^C update.out | cut -b4- ; \
602                 fi ; \
603                 rm -f update.out; \
604         elif [ -d CVS ]; then \
605                 echo "Updating from CVS..." ; \
606                 cvs -q -z3 update -Pd | tee update.out; \
607                 rm -f .version; \
608                 if [ `grep -c ^C update.out` -gt 0 ]; then \
609                         echo ; echo "The following files have conflicts:" ; \
610                         grep ^C update.out | cut -d' ' -f2- ; \
611                 fi ; \
612                 rm -f update.out; \
613         else \
614                 echo "Not under version control";  \
615         fi
616
617 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
618 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
619
620 bininstall: all
621         mkdir -p $(DESTDIR)$(MODULES_DIR)
622         mkdir -p $(DESTDIR)$(ASTSBINDIR)
623         mkdir -p $(DESTDIR)$(ASTETCDIR)
624         mkdir -p $(DESTDIR)$(ASTBINDIR)
625         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
626         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
627         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
628         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
629         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
630         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
631         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
632         if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
633         if [ -f cygwin/asterisk.exe ]; then $(INSTALL) -m 755 cygwin/asterisk.exe $(DESTDIR)$(ASTSBINDIR)/; fi
634         if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
635         ln -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
636         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
637         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/  
638         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
639                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
640                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
641         fi
642         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
643         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
644         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
645         if [ -n "$(OLDHEADERS)" ]; then \
646                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
647         fi
648         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
649         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
650         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
651         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
652         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
653         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
654         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
655         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
656         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
657         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
658         $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
659         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
660         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
661         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
662         if [ -d contrib/firmware/iax ]; then \
663                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
664         else \
665                 echo "You need to do cvs update -d not just cvs update" ; \
666         fi 
667         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
668         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
669         @echo " +---- Asterisk Installation Complete -------+"  
670         @echo " +                                           +"
671         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
672         @echo " +                                           +"
673         @echo " + Asterisk has successfully been installed. +"  
674         @echo " + If you would like to install the sample   +"  
675         @echo " + configuration files (overwriting any      +"
676         @echo " + existing config files), run:              +"  
677         @echo " +                                           +"
678         @echo " +               $(MAKE) samples                +"
679         @echo " +                                           +"
680         @echo " +-----------------  or ---------------------+"
681         @echo " +                                           +"
682         @echo " + You can go ahead and install the asterisk +"
683         @echo " + program documentation now or later run:   +"
684         @echo " +                                           +"
685         @echo " +              $(MAKE) progdocs                +"
686         @echo " +                                           +"
687         @echo " + **Note** This requires that you have      +"
688         @echo " + doxygen installed on your local system    +"
689         @echo " +-------------------------------------------+"
690         @$(MAKE) -s oldmodcheck
691
692 NEWMODS=$(notdir $(wildcard */*.so))
693 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
694
695 oldmodcheck:
696         @if [ -n "$(OLDMODS)" ]; then \
697                 echo " WARNING WARNING WARNING" ;\
698                 echo "" ;\
699                 echo " Your Asterisk modules directory, located at" ;\
700                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
701                 echo " contains modules that were not installed by this " ;\
702                 echo " version of Asterisk. Please ensure that these" ;\
703                 echo " modules are compatible with this version before" ;\
704                 echo " attempting to run Asterisk." ;\
705                 echo "" ;\
706                 for f in $(OLDMODS); do \
707                         echo "    $$f" ;\
708                 done ;\
709                 echo "" ;\
710                 echo " WARNING WARNING WARNING" ;\
711         fi
712
713 install: all datafiles bininstall
714         @if [ -x /usr/sbin/asterisk-post-install ]; then \
715                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
716         fi
717
718 upgrade: all bininstall
719
720 adsi:
721         mkdir -p $(DESTDIR)$(ASTETCDIR)
722         for x in configs/*.adsi; do \
723                 if [ ! -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
724                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
725                 fi ; \
726         done
727
728 samples: adsi
729         mkdir -p $(DESTDIR)$(ASTETCDIR)
730         for x in configs/*.sample; do \
731                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
732                         if [ "$(OVERWRITE)" = "y" ]; then \
733                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
734                                         echo "Config file $$x is unchanged"; \
735                                         continue; \
736                                 fi ; \
737                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
738                         else \
739                                 echo "Skipping config file $$x"; \
740                                 continue; \
741                         fi ;\
742                 fi ; \
743                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
744         done
745         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
746                 ( \
747                 echo "[directories]" ; \
748                 echo "astetcdir => $(ASTETCDIR)" ; \
749                 echo "astmoddir => $(MODULES_DIR)" ; \
750                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
751                 echo "astagidir => $(AGI_DIR)" ; \
752                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
753                 echo "astrundir => $(ASTVARRUNDIR)" ; \
754                 echo "astlogdir => $(ASTLOGDIR)" ; \
755                 echo "" ; \
756                 echo "; Changing the following lines may compromise your security." ; \
757                 echo ";[files]" ; \
758                 echo ";astctlpermissions = 0660" ; \
759                 echo ";astctlowner = root" ; \
760                 echo ";astctlgroup = apache" ; \
761                 echo ";astctl = asterisk.ctl" ; \
762                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
763         else \
764                 echo "Skipping asterisk.conf creation"; \
765         fi
766         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
767         for x in sounds/demo-*; do \
768                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
769                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
770                 else \
771                         echo "No description for $$x"; \
772                         exit 1; \
773                 fi; \
774         done
775         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
776         for x in sounds/*.mp3; do \
777                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
778         done
779         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
780         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
781         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
782         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
783                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
784         done
785         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
786         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
787                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
788         done
789
790 webvmail:
791         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
792         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
793         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
794         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
795         for x in images/*.gif; do \
796                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
797         done
798         @echo " +--------- Asterisk Web Voicemail ----------+"  
799         @echo " +                                           +"
800         @echo " + Asterisk Web Voicemail is installed in    +"
801         @echo " + your cgi-bin directory:                   +"
802         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
803         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
804         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
805         @echo " +                                           +"
806         @echo " + Other static items have been stored in:   +"
807         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
808         @echo " +                                           +"
809         @echo " + If these paths do not match your httpd    +"
810         @echo " + installation, correct the definitions     +"
811         @echo " + in your Makefile of HTTP_CGIDIR and       +"
812         @echo " + HTTP_DOCSDIR                              +"
813         @echo " +                                           +"
814         @echo " +-------------------------------------------+"  
815
816 spec: 
817         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
818
819 rpm: __rpm
820
821 __rpm: include/asterisk/version.h spec
822         rm -rf /tmp/asterisk ; \
823         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
824         $(MAKE) DESTDIR=/tmp/asterisk install ; \
825         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
826         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
827         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
828         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
829
830 progdocs:
831         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
832         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
833
834 mpg123:
835         @wget -V >/dev/null || (echo "You need wget" ; false )
836         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
837         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
838         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
839
840 config:
841         if [ -d /etc/rc.d/init.d ]; then \
842                 $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
843                 /sbin/chkconfig --add asterisk; \
844         elif [ -d /etc/init.d ]; then \
845                 $(INSTALL) -m 755 init.asterisk /etc/init.d/asterisk; \
846         fi 
847
848 dont-optimize: install
849
850 valgrind: dont-optimize
851
852 depend: include/asterisk/version.h .depend defaults.h 
853         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
854
855 .depend: include/asterisk/version.h
856         build_tools/mkdep $(CFLAGS) $(wildcard *.c)
857
858 .tags-depend:
859         @echo -n ".tags-depend: " > $@
860         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
861         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
862         @find $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@
863         @find $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@
864         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
865         @echo >> $@
866
867 .tags-sources:
868         @rm -f $@
869         @find . -maxdepth 1 -name \*.c -print >> $@
870         @find . -maxdepth 1 -name \*.h -print >> $@
871         @find $(SUBDIRS) -name \*.c -print >> $@
872         @find $(SUBDIRS) -name \*.h -print >> $@
873         @find include -name \*.h -print >> $@
874
875 tags: .tags-depend .tags-sources
876         ctags -L .tags-sources -o $@
877
878 ctags: tags
879
880 TAGS: .tags-depend .tags-sources
881         etags -o $@ `cat .tags-sources`
882
883 etags: TAGS
884
885 FORCE:
886
887 %_env:
888         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
889
890 env:
891         env
892
893 # If the cleancount has been changed, force a make clean.
894 # .cleancount is the global clean count, and .lastclean is the 
895 # last clean count we had
896 # We can avoid this by making noclean
897
898 cleantest:
899         if cmp -s .cleancount .lastclean ; then echo ; else \
900                 $(MAKE) clean; cp -f .cleancount .lastclean;\
901         fi