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