20d1bbb2ade58ac11743bf761192121c43c1298c
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999, Mark Spencer
7 #
8 # Mark Spencer <markster@linux-support.net>
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
19 # If cross compiling, define these to suit
20 # CROSS_COMPILE=/opt/montavista/pro/devkit/arm/xscale_be/bin/xscale_be-
21 # CROSS_COMPILE_BIN=/opt/montavista/pro/devkit/arm/xscale_be/bin/
22 # CROSS_COMPILE_TARGET=/opt/montavista/pro/devkit/arm/xscale_be/target
23 # CC=$(CROSS_COMPILE)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-`date +"%D-%T"`"; 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 CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\"
219 CFLAGS+=-DASTERISK_VERSION_NUM=$(ASTERISKVERSIONNUM)
220 CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
221 CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\"
222 CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\"
223 CFLAGS+=-DASTVARLIBDIR=\"$(ASTVARLIBDIR)\"
224 CFLAGS+=-DASTVARRUNDIR=\"$(ASTVARRUNDIR)\"
225 CFLAGS+=-DASTSPOOLDIR=\"$(ASTSPOOLDIR)\"
226 CFLAGS+=-DASTLOGDIR=\"$(ASTLOGDIR)\"
227 CFLAGS+=-DASTCONFPATH=\"$(ASTCONFPATH)\"
228 CFLAGS+=-DASTMODDIR=\"$(MODULES_DIR)\"
229 CFLAGS+=-DASTAGIDIR=\"$(AGI_DIR)\"
230
231 CFLAGS+= $(DEBUG_THREADS)
232 CFLAGS+= $(TRACE_FRAMES)
233 CFLAGS+= $(MALLOC_DEBUG)
234 CFLAGS+= $(BUSYDETECT)
235 CFLAGS+= $(OPTIONS)
236 CFLAGS+= -fomit-frame-pointer 
237 SUBDIRS=res channels pbx apps codecs formats agi cdr utils stdtime
238 ifeq (${OSARCH},Linux)
239 LIBS=-ldl -lpthread
240 endif
241 LIBS+=-lncurses -lm
242 ifeq (${OSARCH},Linux)
243 LIBS+=-lresolv  #-lnjamd
244 endif
245 ifeq (${OSARCH},Darwin)
246 LIBS+=-lresolv
247 CFLAGS+=-D__OSX__
248 endif
249 ifeq (${OSARCH},FreeBSD)
250 LIBS+=-lcrypto
251 endif
252 ifeq (${OSARCH},NetBSD)
253 LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/local/lib -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib -lncurses
254 endif
255 ifeq (${OSARCH},OpenBSD)
256 LIBS=-lcrypto -lpthread -lm -lncurses
257 endif
258 ifeq (${OSARCH},SunOS)
259 LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
260 endif
261 LIBS+=-lssl
262 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
263         translate.o file.o say.o pbx.o cli.o md5.o term.o \
264         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
265         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
266         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
267         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
268         utils.o config_old.o plc.o jitterbuf.o
269 ifeq (${OSARCH},Darwin)
270 OBJS+=poll.o dlfcn.o
271 ASTLINK=-Wl,-dynamic
272 SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
273 else
274 ASTLINK=-Wl,-E 
275 SOLINK=-shared -Xlinker -x
276 endif
277 ifeq (${OSARCH},SunOS)
278 OBJS+=strcompat.o
279 ASTLINK=
280 SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
281 endif
282
283 INSTALL=install
284
285 _all: all
286         @echo " +--------- Asterisk Build Complete ---------+"  
287         @echo " + Asterisk has successfully been built, but +"  
288         @echo " + cannot be run before being installed by   +"  
289         @echo " + running:                                  +"  
290         @echo " +                                           +"
291         @echo " +               $(MAKE) install                +"  
292         @echo " +-------------------------------------------+"  
293
294 all: cleantest depend asterisk subdirs 
295
296 noclean: depend asterisk subdirs
297
298 editline/config.h:
299         cd editline && unset CFLAGS LIBS && ./configure ; \
300
301 editline/libedit.a: FORCE
302         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
303         $(MAKE) -C editline libedit.a
304
305 db1-ast/libdb1.a: FORCE
306         @if [ -d db1-ast ]; then \
307                 $(MAKE) -C db1-ast libdb1.a ; \
308         else \
309                 echo "You need to do a cvs update -d not just cvs update"; \
310                 exit 1; \
311         fi
312
313 ifneq ($(wildcard .depend),)
314 include .depend
315 endif
316
317 .PHONY: _version
318
319 _version: 
320         if [ -d CVS ] && [ ! -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
321
322 .version: _version
323
324 .y.c:
325         bison $< --name-prefix=ast_yy -o $@
326
327 ast_expr.o: ast_expr.c
328
329 cli.o: cli.c build.h
330
331 asterisk.o: asterisk.c build.h
332
333 manpage: asterisk.8.gz
334
335 asterisk.8.gz: asterisk.sgml
336         rm -f asterisk.8
337         docbook2man asterisk.sgml
338         mv ./*.8 asterisk.8
339         gzip asterisk.8
340
341 ifneq ($(strip $(ASTERISKVERSION)),)
342 build.h: .version
343         ./make_build_h
344 else
345 build.h:
346         ./make_build_h
347 endif
348
349 stdtime/libtime.a: FORCE
350         @if [ -d stdtime ]; then \
351                 $(MAKE) -C stdtime libtime.a ; \
352         else \
353                 echo "You need to do a cvs update -d not just cvs update"; \
354                 exit 1; \
355         fi
356
357 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
358         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
359
360 muted: muted.o
361         $(CC) -o muted muted.o
362
363 subdirs: 
364         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
365
366 clean:
367         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
368         rm -f *.o *.so asterisk .depend
369         rm -f build.h 
370         rm -f ast_expr.c
371         rm -f .version
372         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
373         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
374         $(MAKE) -C db1-ast clean
375         $(MAKE) -C stdtime clean
376
377 datafiles: all
378         sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig
379         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
380         for x in sounds/digits/*.gsm; do \
381                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
382                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
383                 else \
384                         echo "No description for $$x"; \
385                         exit 1; \
386                 fi; \
387         done
388         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
389         for x in sounds/letters/*.gsm; do \
390                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
391                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
392                 else \
393                         echo "No description for $$x"; \
394                         exit 1; \
395                 fi; \
396         done
397         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
398         for x in sounds/phonetic/*.gsm; do \
399                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
400                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
401                 else \
402                         echo "No description for $$x"; \
403                         exit 1; \
404                 fi; \
405         done
406         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 \
407                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
408                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
409                 else \
410                         echo "No description for $$x"; \
411                         exit 1; \
412                 fi; \
413         done
414         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
415         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
416         for x in images/*.jpg; do \
417                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
418         done
419         mkdir -p $(DESTDIR)$(AGI_DIR)
420
421 update: 
422         @if [ -d CVS ]; then \
423                 if [ -f patches/.applied ]; then \
424                         patches=`cat patches/.applied`; \
425                 fi; \
426                 if ! [ -z "$$patches" ]; then \
427                         for x in $$patches; do \
428                                 echo "Unapplying $$x..."; \
429                                 patch -R -p0 < patches/$$x; \
430                         done; \
431                         rm -f patches/.applied; \
432                 fi ; \
433                 echo "Updating from CVS..." ; \
434                 cvs -q -z3 update -Pd | tee update.out; \
435                 rm -f .version; \
436                 if [ `grep -c ^C update.out` -gt 0 ]; then \
437                         echo ; echo "The following files have conflicts:" ; \
438                         grep ^C update.out | cut -d' ' -f2- ; \
439                 fi ; \
440                 rm -f update.out; \
441                 if ! [ -z "$$patches" ]; then \
442                         for x in $$patches; do \
443                                 if [ -f patches/$$x ]; then \
444                                         echo "Applying patch $$x..."; \
445                                         patch -p0 < patches/$$x; \
446                                         echo $$x >> patches/.applied; \
447                                 else \
448                                         echo "Patch $$x no longer relevant"; \
449                                 fi; \
450                         done; \
451                 fi; \
452         else \
453                 echo "Not CVS";  \
454         fi
455
456 bininstall: all
457         mkdir -p $(DESTDIR)$(MODULES_DIR)
458         mkdir -p $(DESTDIR)$(ASTSBINDIR)
459         mkdir -p $(DESTDIR)$(ASTETCDIR)
460         mkdir -p $(DESTDIR)$(ASTBINDIR)
461         mkdir -p $(DESTDIR)$(ASTSBINDIR)
462         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
463         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
464         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
465         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
466         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
467         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
468         install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
469         install -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/     
470         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
471                 install -m 755 contrib/scripts/safe_asterisk $(DESTDIR)$(ASTSBINDIR)/ ;\
472         fi
473         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
474         install -d $(DESTDIR)$(ASTHEADERDIR)
475         install -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
476         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
477         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
478         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
479         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
480         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
481         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
482         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
483         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
484         install -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
485         install -m 644 asterisk.8.gz $(DESTDIR)$(ASTMANDIR)/man8
486         if [ -d contrib/firmware/iax ]; then \
487                 install -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
488         else \
489                 echo "You need to do cvs update -d not just cvs update" ; \
490         fi 
491         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
492         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
493         @echo " +---- Asterisk Installation Complete -------+"  
494         @echo " +                                           +"
495         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
496         @echo " +                                           +"
497         @echo " + Asterisk has successfully been installed. +"  
498         @echo " + If you would like to install the sample   +"  
499         @echo " + configuration files (overwriting any      +"
500         @echo " + existing config files), run:              +"  
501         @echo " +                                           +"
502         @echo " +               $(MAKE) samples                +"
503         @echo " +                                           +"
504         @echo " +-----------------  or ---------------------+"
505         @echo " +                                           +"
506         @echo " + You can go ahead and install the asterisk +"
507         @echo " + program documentation now or later run:   +"
508         @echo " +                                           +"
509         @echo " +              $(MAKE) progdocs                +"
510         @echo " +                                           +"
511         @echo " + **Note** This requires that you have      +"
512         @echo " + doxygen installed on your local system    +"
513         @echo " +-------------------------------------------+"
514
515 install: all datafiles bininstall
516
517 upgrade: all bininstall
518
519 adsi: all
520         mkdir -p $(DESTDIR)$(ASTETCDIR)
521         for x in configs/*.adsi; do \
522                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
523                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
524                 fi ; \
525         done
526
527 samples: all datafiles adsi
528         mkdir -p $(DESTDIR)$(ASTETCDIR)
529         for x in configs/*.sample; do \
530                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
531                         if [ "$(OVERWRITE)" = "y" ]; then \
532                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
533                                         echo "Config file $$x is unchanged"; \
534                                         continue; \
535                                 fi ; \
536                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
537                         else \
538                                 echo "Skipping config file $$x"; \
539                                 continue; \
540                         fi ;\
541                 fi ; \
542                 install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
543         done
544         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTETCDIR)/asterisk.conf ]; then \
545                 echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
546                 echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
547                 echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
548                 echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
549                 echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
550                 echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
551                 echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
552                 echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
553                 echo "" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
554                 echo "; Changing the following lines may compromise your security." >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
555                 echo ";[files]" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
556                 echo ";astctlpermissions = 0660" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
557                 echo ";astctlowner = root" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
558                 echo ";astctlgroup = apache" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
559                 echo ";astctl = asterisk.ctl" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
560         else \
561                 echo "Skipping asterisk.conf creation"; \
562         fi
563         for x in sounds/demo-*; do \
564                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
565                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
566                 else \
567                         echo "No description for $$x"; \
568                         exit 1; \
569                 fi; \
570         done
571         for x in sounds/*.mp3; do \
572                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
573         done
574         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
575         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
576         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
577         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
578                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
579         done
580         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
581         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
582                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
583         done
584
585 webvmail:
586         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
587         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
588         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
589         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
590         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
591         for x in images/*.gif; do \
592                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
593         done
594         @echo " +--------- Asterisk Web Voicemail ----------+"  
595         @echo " +                                           +"
596         @echo " + Asterisk Web Voicemail is installed in    +"
597         @echo " + your cgi-bin directory.  IT USES A SETUID +"
598         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
599         @echo " + THAT, UNINSTALL IT!                       +"
600         @echo " +                                           +"
601         @echo " +-------------------------------------------+"  
602
603 mailbox:
604         ./contrib/scripts/addmailbox 
605
606 spec: 
607         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
608
609 rpm: __rpm
610
611 __rpm: _version spec
612         rm -rf /tmp/asterisk ; \
613         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
614         $(MAKE) DESTDIR=/tmp/asterisk install ; \
615         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
616         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
617         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
618         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
619
620 progdocs:
621         doxygen contrib/asterisk-ng-doxygen
622
623 mpg123:
624         @wget -V >/dev/null || (echo "You need wget" ; false )
625         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
626         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
627         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
628
629 config:
630         if [ -d /etc/rc.d/init.d ]; then \
631                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
632                 /sbin/chkconfig --add asterisk; \
633         elif [ -d /etc/init.d ]; then \
634                 install -m 755 init.asterisk /etc/init.d/asterisk; \
635         fi 
636
637 dont-optimize:
638         $(MAKE) OPTIMIZE= K6OPT= install
639
640 valgrind: dont-optimize
641
642 depend: .depend
643         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
644
645 .depend:
646         ./mkdep ${CFLAGS} `ls *.c`
647
648 FORCE:
649
650 %_env:
651         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
652
653 env:
654         env
655
656 # If the cleancount has been changed, force a make clean.
657 # .cleancount is the global clean count, and .lastclean is the 
658 #       last clean count # we had
659 # We can avoid this by making noclean
660
661 cleantest:
662         if ! cmp -s .cleancount .lastclean ; then \
663                 $(MAKE) clean; cp -f .cleancount .lastclean;\
664         fi
665
666 patchlist:
667         @echo "Experimental Patches:"
668         @for x in patches/*; do \
669                 patch=`basename $$x`; \
670                 if [ "$$patch" = "CVS" ]; then \
671                         continue; \
672                 fi; \
673                 if grep -q ^$$patch$$ patches/.applied; then \
674                         echo "$$patch (applied)"; \
675                 else \
676                         echo "$$patch (available)"; \
677                 fi; \
678         done
679                 
680         
681 apply: 
682         @if [ -z "$(PATCH)" ]; then \
683                 echo "Usage: make PATCH=<patchname> apply"; \
684         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
685                 echo "Patch $(PATCH) is already applied"; \
686         elif [ -f "patches/$(PATCH)" ]; then \
687                 echo "Applying patch $(PATCH)"; \
688                 patch -p0 < patches/$(PATCH); \
689                 echo "$(PATCH)" >> patches/.applied; \
690         else \
691                 echo "No such patch $(PATCH) in patches directory"; \
692         fi
693         
694 unapply: 
695         @if [ -z "$(PATCH)" ]; then \
696                 echo "Usage: make PATCH=<patchname> unapply"; \
697         elif ! grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
698                 echo "Patch $(PATCH) is not applied"; \
699         elif [ -f "patches/$(PATCH)" ]; then \
700                 echo "Un-applying patch $(PATCH)"; \
701                 patch -p0 -R < patches/$(PATCH); \
702                 rm -f patches/.tmpapplied || :; \
703                 mv patches/.applied patches/.tmpapplied; \
704                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
705                 rm -f patches/.tmpapplied; \
706         else \
707                 echo "No such patch $(PATCH) in patches directory"; \
708         fi
709
710