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