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