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