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