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