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