56a50679cf298c3ae23811653e3fdd4024a01179
[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 dnsmgr.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 ifneq ($(wildcard tags),)
297 all: tags
298 endif
299
300 ifneq ($(wildcard TAGS),)
301 all: TAGS
302 endif
303
304 noclean: depend asterisk subdirs
305
306 editline/config.h:
307         cd editline && unset CFLAGS LIBS && ./configure ; \
308
309 editline/libedit.a: FORCE
310         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
311         $(MAKE) -C editline libedit.a
312
313 db1-ast/libdb1.a: FORCE
314         @if [ -d db1-ast ]; then \
315                 $(MAKE) -C db1-ast libdb1.a ; \
316         else \
317                 echo "You need to do a cvs update -d not just cvs update"; \
318                 exit 1; \
319         fi
320
321 ifneq ($(wildcard .depend),)
322 include .depend
323 endif
324
325 ifneq ($(wildcard .tags-depend),)
326 include .tags-depend
327 endif
328
329 .PHONY: _version
330
331 _version: 
332         if [ -d CVS ] && [ ! -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
333
334 .version: _version
335
336 .y.c:
337         bison $< --name-prefix=ast_yy -o $@
338
339 ast_expr.o: ast_expr.c
340
341 cli.o: cli.c build.h
342
343 asterisk.o: asterisk.c build.h
344
345 manpage: asterisk.8.gz
346
347 asterisk.8.gz: asterisk.sgml
348         rm -f asterisk.8
349         docbook2man asterisk.sgml
350         mv ./*.8 asterisk.8
351         gzip asterisk.8
352
353 asterisk.pdf: asterisk.sgml
354         docbook2pdf asterisk.sgml
355
356 asterisk.ps: asterisk.sgml
357         docbook2ps asterisk.sgml
358
359 asterisk.html: asterisk.sgml
360         docbook2html asterisk.sgml
361         mv r1.html asterisk.html
362
363 asterisk.txt: asterisk.sgml
364         docbook2txt asterisk.sgml
365
366 ifneq ($(strip $(ASTERISKVERSION)),)
367 build.h: .version
368         ./make_build_h
369 else
370 build.h:
371         ./make_build_h
372 endif
373
374 stdtime/libtime.a: FORCE
375         @if [ -d stdtime ]; then \
376                 $(MAKE) -C stdtime libtime.a ; \
377         else \
378                 echo "You need to do a cvs update -d not just cvs update"; \
379                 exit 1; \
380         fi
381
382 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
383         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
384
385 muted: muted.o
386         $(CC) -o muted muted.o
387
388 subdirs: 
389         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
390
391 clean:
392         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
393         rm -f *.o *.so asterisk .depend
394         rm -f build.h 
395         rm -f ast_expr.c
396         rm -f .version
397         rm -f .tags-depend .tags-sources tags TAGS
398         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
399         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
400         $(MAKE) -C db1-ast clean
401         $(MAKE) -C stdtime clean
402
403 datafiles: all
404         sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig
405         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
406         for x in sounds/digits/*.gsm; do \
407                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
408                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
409                 else \
410                         echo "No description for $$x"; \
411                         exit 1; \
412                 fi; \
413         done
414         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
415         for x in sounds/letters/*.gsm; do \
416                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
417                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
418                 else \
419                         echo "No description for $$x"; \
420                         exit 1; \
421                 fi; \
422         done
423         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
424         for x in sounds/phonetic/*.gsm; do \
425                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
426                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
427                 else \
428                         echo "No description for $$x"; \
429                         exit 1; \
430                 fi; \
431         done
432         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 \
433                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
434                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
435                 else \
436                         echo "No description for $$x"; \
437                         exit 1; \
438                 fi; \
439         done
440         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
441         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
442         for x in images/*.jpg; do \
443                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
444         done
445         mkdir -p $(DESTDIR)$(AGI_DIR)
446
447 update: 
448         @if [ -d CVS ]; then \
449                 if [ -f patches/.applied ]; then \
450                         patches=`cat patches/.applied`; \
451                 fi; \
452                 if ! [ -z "$$patches" ]; then \
453                         for x in $$patches; do \
454                                 echo "Unapplying $$x..."; \
455                                 patch -R -p0 < patches/$$x; \
456                         done; \
457                         rm -f patches/.applied; \
458                 fi ; \
459                 echo "Updating from CVS..." ; \
460                 cvs -q -z3 update -Pd | tee update.out; \
461                 rm -f .version; \
462                 if [ `grep -c ^C update.out` -gt 0 ]; then \
463                         echo ; echo "The following files have conflicts:" ; \
464                         grep ^C update.out | cut -d' ' -f2- ; \
465                 fi ; \
466                 rm -f update.out; \
467                 if ! [ -z "$$patches" ]; then \
468                         for x in $$patches; do \
469                                 if [ -f patches/$$x ]; then \
470                                         echo "Applying patch $$x..."; \
471                                         patch -p0 < patches/$$x; \
472                                         echo $$x >> patches/.applied; \
473                                 else \
474                                         echo "Patch $$x no longer relevant"; \
475                                 fi; \
476                         done; \
477                 fi; \
478         else \
479                 echo "Not CVS";  \
480         fi
481
482 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
483 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
484
485 bininstall: all
486         mkdir -p $(DESTDIR)$(MODULES_DIR)
487         mkdir -p $(DESTDIR)$(ASTSBINDIR)
488         mkdir -p $(DESTDIR)$(ASTETCDIR)
489         mkdir -p $(DESTDIR)$(ASTBINDIR)
490         mkdir -p $(DESTDIR)$(ASTSBINDIR)
491         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
492         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
493         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
494         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
495         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
496         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
497         install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
498         install -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/     
499         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
500                 install -m 755 contrib/scripts/safe_asterisk $(DESTDIR)$(ASTSBINDIR)/ ;\
501         fi
502         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
503         install -d $(DESTDIR)$(ASTHEADERDIR)
504         install -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
505         if [ -n "$(OLDHEADERS)" ]; then \
506                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
507         fi
508         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
509         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
510         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
511         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
512         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
513         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
514         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
515         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
516         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
517         install -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
518         install -m 644 asterisk.8.gz $(DESTDIR)$(ASTMANDIR)/man8
519         if [ -d contrib/firmware/iax ]; then \
520                 install -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
521         else \
522                 echo "You need to do cvs update -d not just cvs update" ; \
523         fi 
524         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
525         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
526         @echo " +---- Asterisk Installation Complete -------+"  
527         @echo " +                                           +"
528         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
529         @echo " +                                           +"
530         @echo " + Asterisk has successfully been installed. +"  
531         @echo " + If you would like to install the sample   +"  
532         @echo " + configuration files (overwriting any      +"
533         @echo " + existing config files), run:              +"  
534         @echo " +                                           +"
535         @echo " +               $(MAKE) samples                +"
536         @echo " +                                           +"
537         @echo " +-----------------  or ---------------------+"
538         @echo " +                                           +"
539         @echo " + You can go ahead and install the asterisk +"
540         @echo " + program documentation now or later run:   +"
541         @echo " +                                           +"
542         @echo " +              $(MAKE) progdocs                +"
543         @echo " +                                           +"
544         @echo " + **Note** This requires that you have      +"
545         @echo " + doxygen installed on your local system    +"
546         @echo " +-------------------------------------------+"
547         @$(MAKE) -s oldmodcheck
548
549 NEWMODS=$(notdir $(wildcard */*.so))
550 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
551
552 oldmodcheck:
553         @if [ -n "$(OLDMODS)" ]; then \
554                 echo " WARNING WARNING WARNING" ;\
555                 echo "" ;\
556                 echo " Your Asterisk modules directory, located at" ;\
557                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
558                 echo " contains modules that were not installed by this " ;\
559                 echo " version of Asterisk. Please ensure that these" ;\
560                 echo " modules are compatible with this version before" ;\
561                 echo " attempting to run Asterisk." ;\
562                 echo "" ;\
563                 for f in $(OLDMODS); do \
564                         echo "    $$f" ;\
565                 done ;\
566                 echo "" ;\
567                 echo " WARNING WARNING WARNING" ;\
568         fi
569
570 install: all datafiles bininstall
571
572 upgrade: all bininstall
573
574 adsi: all
575         mkdir -p $(DESTDIR)$(ASTETCDIR)
576         for x in configs/*.adsi; do \
577                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
578                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
579                 fi ; \
580         done
581
582 samples: all datafiles adsi
583         mkdir -p $(DESTDIR)$(ASTETCDIR)
584         for x in configs/*.sample; do \
585                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
586                         if [ "$(OVERWRITE)" = "y" ]; then \
587                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
588                                         echo "Config file $$x is unchanged"; \
589                                         continue; \
590                                 fi ; \
591                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
592                         else \
593                                 echo "Skipping config file $$x"; \
594                                 continue; \
595                         fi ;\
596                 fi ; \
597                 install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
598         done
599         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTETCDIR)/asterisk.conf ]; then \
600                 echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
601                 echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
602                 echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
603                 echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
604                 echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
605                 echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
606                 echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
607                 echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
608                 echo "" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
609                 echo "; Changing the following lines may compromise your security." >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
610                 echo ";[files]" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
611                 echo ";astctlpermissions = 0660" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
612                 echo ";astctlowner = root" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
613                 echo ";astctlgroup = apache" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
614                 echo ";astctl = asterisk.ctl" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
615         else \
616                 echo "Skipping asterisk.conf creation"; \
617         fi
618         for x in sounds/demo-*; do \
619                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
620                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
621                 else \
622                         echo "No description for $$x"; \
623                         exit 1; \
624                 fi; \
625         done
626         for x in sounds/*.mp3; do \
627                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
628         done
629         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
630         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
631         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
632         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
633                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
634         done
635         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
636         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
637                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
638         done
639
640 webvmail:
641         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
642         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
643         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
644         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
645         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
646         for x in images/*.gif; do \
647                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
648         done
649         @echo " +--------- Asterisk Web Voicemail ----------+"  
650         @echo " +                                           +"
651         @echo " + Asterisk Web Voicemail is installed in    +"
652         @echo " + your cgi-bin directory.  IT USES A SETUID +"
653         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
654         @echo " + THAT, UNINSTALL IT!                       +"
655         @echo " +                                           +"
656         @echo " +-------------------------------------------+"  
657
658 mailbox:
659         ./contrib/scripts/addmailbox 
660
661 spec: 
662         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
663
664 rpm: __rpm
665
666 __rpm: _version spec
667         rm -rf /tmp/asterisk ; \
668         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
669         $(MAKE) DESTDIR=/tmp/asterisk install ; \
670         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
671         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
672         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
673         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
674
675 progdocs:
676         doxygen contrib/asterisk-ng-doxygen
677
678 mpg123:
679         @wget -V >/dev/null || (echo "You need wget" ; false )
680         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
681         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
682         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
683
684 config:
685         if [ -d /etc/rc.d/init.d ]; then \
686                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
687                 /sbin/chkconfig --add asterisk; \
688         elif [ -d /etc/init.d ]; then \
689                 install -m 755 init.asterisk /etc/init.d/asterisk; \
690         fi 
691
692 dont-optimize:
693         $(MAKE) OPTIMIZE= K6OPT= install
694
695 valgrind: dont-optimize
696
697 depend: .depend
698         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
699
700 .depend:
701         ./mkdep ${CFLAGS} `ls *.c`
702
703 .tags-depend:
704         @echo -n ".tags-depend: " > $@
705         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
706         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
707         @find ${SUBDIRS} -name \*.c -printf "\t%p \\\\\n" >> $@
708         @find ${SUBDIRS} -name \*.h -printf "\t%p \\\\\n" >> $@
709         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
710         @echo >> $@
711
712 .tags-sources:
713         @rm -f $@
714         @find . -maxdepth 1 -name \*.c -print >> $@
715         @find . -maxdepth 1 -name \*.h -print >> $@
716         @find ${SUBDIRS} -name \*.c -print >> $@
717         @find ${SUBDIRS} -name \*.h -print >> $@
718         @find include -name \*.h -print >> $@
719
720 tags: .tags-depend .tags-sources
721         ctags -L .tags-sources -o $@
722
723 ctags: tags
724
725 TAGS: .tags-depend .tags-sources
726         etags -o $@ `cat .tags-sources`
727
728 etags: TAGS
729
730 FORCE:
731
732 %_env:
733         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
734
735 env:
736         env
737
738 # If the cleancount has been changed, force a make clean.
739 # .cleancount is the global clean count, and .lastclean is the 
740 # last clean count we had
741 # We can avoid this by making noclean
742
743 cleantest:
744         if ! cmp -s .cleancount .lastclean ; then \
745                 $(MAKE) clean; cp -f .cleancount .lastclean;\
746         fi
747
748 patchlist:
749         @echo "Experimental Patches:"
750         @for x in patches/*; do \
751                 patch=`basename $$x`; \
752                 if [ "$$patch" = "CVS" ]; then \
753                         continue; \
754                 fi; \
755                 if grep -q ^$$patch$$ patches/.applied; then \
756                         echo "$$patch (applied)"; \
757                 else \
758                         echo "$$patch (available)"; \
759                 fi; \
760         done
761
762 apply: 
763         @if [ -z "$(PATCH)" ]; then \
764                 echo "Usage: make PATCH=<patchname> apply"; \
765         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
766                 echo "Patch $(PATCH) is already applied"; \
767         elif [ -f "patches/$(PATCH)" ]; then \
768                 echo "Applying patch $(PATCH)"; \
769                 patch -p0 < patches/$(PATCH); \
770                 echo "$(PATCH)" >> patches/.applied; \
771         else \
772                 echo "No such patch $(PATCH) in patches directory"; \
773         fi
774
775 unapply: 
776         @if [ -z "$(PATCH)" ]; then \
777                 echo "Usage: make PATCH=<patchname> unapply"; \
778         elif ! grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
779                 echo "Patch $(PATCH) is not applied"; \
780         elif [ -f "patches/$(PATCH)" ]; then \
781                 echo "Un-applying patch $(PATCH)"; \
782                 patch -p0 -R < patches/$(PATCH); \
783                 rm -f patches/.tmpapplied || :; \
784                 mv patches/.applied patches/.tmpapplied; \
785                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
786                 rm -f patches/.tmpapplied; \
787         else \
788                 echo "No such patch $(PATCH) in patches directory"; \
789         fi