5777b59917d0732ffcc5e393e79987f7d1e4a4b5
[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 # 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-`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 funcs 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
263 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
264         translate.o file.o say.o pbx.o cli.o md5.o term.o \
265         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
266         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o \
267         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
268         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
269         utils.o config_old.o plc.o jitterbuf.o dnsmgr.o
270 ifeq (${OSARCH},Darwin)
271 OBJS+=poll.o dlfcn.o
272 ASTLINK=-Wl,-dynamic
273 SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
274 else
275 ASTLINK=-Wl,-E 
276 SOLINK=-shared -Xlinker -x
277 endif
278 ifeq (${OSARCH},SunOS)
279 OBJS+=strcompat.o
280 ASTLINK=
281 SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
282 endif
283
284 INSTALL=install
285
286 _all: all
287         @echo " +--------- Asterisk Build Complete ---------+"  
288         @echo " + Asterisk has successfully been built, but +"  
289         @echo " + cannot be run before being installed by   +"  
290         @echo " + running:                                  +"  
291         @echo " +                                           +"
292         @echo " +               $(MAKE) install                +"  
293         @echo " +-------------------------------------------+"  
294
295 all: cleantest depend asterisk subdirs 
296
297 ifneq ($(wildcard tags),)
298 all: tags
299 endif
300
301 ifneq ($(wildcard TAGS),)
302 all: TAGS
303 endif
304
305 noclean: depend asterisk subdirs
306
307 editline/config.h:
308         cd editline && unset CFLAGS LIBS && ./configure ; \
309
310 editline/libedit.a: FORCE
311         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
312         $(MAKE) -C editline libedit.a
313
314 db1-ast/libdb1.a: FORCE
315         @if [ -d db1-ast ]; then \
316                 $(MAKE) -C db1-ast libdb1.a ; \
317         else \
318                 echo "You need to do a cvs update -d not just cvs update"; \
319                 exit 1; \
320         fi
321
322 ifneq ($(wildcard .depend),)
323 include .depend
324 endif
325
326 ifneq ($(wildcard .tags-depend),)
327 include .tags-depend
328 endif
329
330 .PHONY: _version ast_expr
331
332 _version: 
333         if [ -d CVS ] && [ ! -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
334
335 .version: _version
336
337 vercomp: vercomp.c
338         $(HOST_CC) -o $@ $<
339
340 ast_expr: vercomp
341         $(MAKE) ast_expr.a
342
343 ifeq ($(MAKECMDGOALS),ast_expr.a)
344 FLEXVER_GT_2_5_31=$(shell ./vercomp flex \>= 2.5.31)
345 BISONVER=$(shell bison --version | grep \^bison | sed 's/.* \([0-9]\+\.[-0-9.]\+[a-z]\?\)/\1/' )
346 BISONVER_GE_1_85=$(shell ./vercomp bison \>= 1.85 )
347 endif
348
349 ifeq ($(FLEXVER_GT_2_5_31),true)
350 FLEXOBJS=ast_expr2.o ast_expr2f.o
351 else
352 FLEXOBJS=ast_expr.o
353 endif
354
355 ast_expr.a: $(FLEXOBJS)
356         @rm -f $@
357         ar r $@ $(FLEXOBJS)
358         ranlib $@
359
360 ifeq ($(BISONVER_GE_1_85),false)
361 .y.c:
362         @echo "=================================================================================" ;\
363         echo "NOTE: You may have trouble if you do not have bison-1.85 or higher installed!" ;\
364         echo "NOTE: You can pick up a copy at: http://ftp.gnu.org/ or its mirrors" ;\
365         echo "NOTE: You have: $(BISONVER)" ;\
366         echo "================================================================================" ;\
367         bison -v -d --name-prefix=ast_yy $< -o $@
368 else
369 .y.c:
370         bison -v -d --name-prefix=ast_yy $< -o $@
371 endif
372
373 ast_expr.o:: ast_expr.c
374         @echo "=================================================================================" ;\
375         echo "NOTE: Using older version of expression parser. To use the newer version," ;\
376         echo "NOTE: upgrade to flex 2.5.31 or higher, which can be found at" ;\
377         echo "NOTE: http://sourceforge.net/project/showfiles.php?group_id=72099" ;\
378         echo "=================================================================================" ;\
379
380 ast_expr.o:: ast_expr.c
381
382 ast_expr2f.c: ast_expr2.fl
383         flex ast_expr2.fl
384
385 cli.o: cli.c build.h
386
387 asterisk.o: asterisk.c build.h
388
389 testexpr2 :
390         flex ast_expr2.fl
391         bison -v -d --name-prefix=ast_yy -o ast_expr2.c ast_expr2.y
392         gcc -g -c -DSTANDALONE ast_expr2f.c
393         gcc -g -c -DSTANDALONE ast_expr2.c
394         gcc -g -o testexpr2 ast_expr2f.o ast_expr2.o
395         rm ast_expr2.c ast_expr2.o ast_expr2f.o ast_expr2f.c
396
397 manpage: asterisk.8.gz
398
399 asterisk.8.gz: asterisk.sgml
400         rm -f asterisk.8
401         docbook2man asterisk.sgml
402         mv ./*.8 asterisk.8
403         gzip asterisk.8
404
405 asterisk.pdf: asterisk.sgml
406         docbook2pdf asterisk.sgml
407
408 asterisk.ps: asterisk.sgml
409         docbook2ps asterisk.sgml
410
411 asterisk.html: asterisk.sgml
412         docbook2html asterisk.sgml
413         mv r1.html asterisk.html
414
415 asterisk.txt: asterisk.sgml
416         docbook2txt asterisk.sgml
417
418 ifneq ($(strip $(ASTERISKVERSION)),)
419 build.h: .version
420         ./make_build_h
421 else
422 build.h:
423         ./make_build_h
424 endif
425
426 stdtime/libtime.a: FORCE
427         @if [ -d stdtime ]; then \
428                 $(MAKE) -C stdtime libtime.a ; \
429         else \
430                 echo "You need to do a cvs update -d not just cvs update"; \
431                 exit 1; \
432         fi
433
434 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS) ast_expr
435         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) ast_expr.a $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
436
437 muted: muted.o
438         $(CC) -o muted muted.o
439
440 subdirs: 
441         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
442
443 clean:
444         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
445         rm -f *.o *.so asterisk .depend
446         rm -f build.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 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: _version 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
762         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
763
764 .depend:
765         ./mkdep ${CFLAGS} `ls *.c`
766
767 .tags-depend:
768         @echo -n ".tags-depend: " > $@
769         @find . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
770         @find . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
771         @find ${SUBDIRS} -name \*.c -printf "\t%p \\\\\n" >> $@
772         @find ${SUBDIRS} -name \*.h -printf "\t%p \\\\\n" >> $@
773         @find include -name \*.h -printf "\t%p \\\\\n" >> $@
774         @echo >> $@
775
776 .tags-sources:
777         @rm -f $@
778         @find . -maxdepth 1 -name \*.c -print >> $@
779         @find . -maxdepth 1 -name \*.h -print >> $@
780         @find ${SUBDIRS} -name \*.c -print >> $@
781         @find ${SUBDIRS} -name \*.h -print >> $@
782         @find include -name \*.h -print >> $@
783
784 tags: .tags-depend .tags-sources
785         ctags -L .tags-sources -o $@
786
787 ctags: tags
788
789 TAGS: .tags-depend .tags-sources
790         etags -o $@ `cat .tags-sources`
791
792 etags: TAGS
793
794 FORCE:
795
796 %_env:
797         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
798
799 env:
800         env
801
802 # If the cleancount has been changed, force a make clean.
803 # .cleancount is the global clean count, and .lastclean is the 
804 # last clean count we had
805 # We can avoid this by making noclean
806
807 cleantest:
808         if ! cmp -s .cleancount .lastclean ; then \
809                 $(MAKE) clean; cp -f .cleancount .lastclean;\
810         fi
811
812 patchlist:
813         @echo "Experimental Patches:"
814         @for x in patches/*; do \
815                 patch=`basename $$x`; \
816                 if [ "$$patch" = "CVS" ]; then \
817                         continue; \
818                 fi; \
819                 if grep -q ^$$patch$$ patches/.applied; then \
820                         echo "$$patch (applied)"; \
821                 else \
822                         echo "$$patch (available)"; \
823                 fi; \
824         done
825
826 apply: 
827         @if [ -z "$(PATCH)" ]; then \
828                 echo "Usage: make PATCH=<patchname> apply"; \
829         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
830                 echo "Patch $(PATCH) is already applied"; \
831         elif [ -f "patches/$(PATCH)" ]; then \
832                 echo "Applying patch $(PATCH)"; \
833                 patch -p0 < patches/$(PATCH); \
834                 echo "$(PATCH)" >> patches/.applied; \
835         else \
836                 echo "No such patch $(PATCH) in patches directory"; \
837         fi
838
839 unapply: 
840         @if [ -z "$(PATCH)" ]; then \
841                 echo "Usage: make PATCH=<patchname> unapply"; \
842         elif ! grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
843                 echo "Patch $(PATCH) is not applied"; \
844         elif [ -f "patches/$(PATCH)" ]; then \
845                 echo "Un-applying patch $(PATCH)"; \
846                 patch -p0 -R < patches/$(PATCH); \
847                 rm -f patches/.tmpapplied || :; \
848                 mv patches/.applied patches/.tmpapplied; \
849                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
850                 rm -f patches/.tmpapplied; \
851         else \
852                 echo "No such patch $(PATCH) in patches directory"; \
853         fi