56b1dcc7b86ad262ec402a53b21d1fc1403799e8
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999, Mark Spencer
7 #
8 # Mark Spencer <markster@linux-support.net>
9 #
10 # This program is free software, distributed under the terms of
11 # the GNU General Public License
12 #
13
14 .EXPORT_ALL_VARIABLES:
15
16 # Create OPTIONS variable
17 OPTIONS=
18
19 OSARCH=$(shell uname -s)
20
21 ifeq (${OSARCH},Linux)
22 PROC=$(shell uname -m)
23 ifeq ($(PROC),x86_64)
24 # You must have GCC 3.4 to use k8, otherwise use athlon
25 PROC=k8
26 #PROC=athlon
27 OPTIONS+=-m64
28 endif
29 ifeq ($(PROC),sparc64)
30 #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
31 #This works for even old (2.96) versions of gcc and provides a small boost either way.
32 #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
33 #So we go lowest common available by gcc and go a step down, still a step up from
34 #the default as we now have a better instruction set to work with. - Belgarath
35 PROC=ultrasparc
36 OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
37 OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
38 OPTIONS+=-fomit-frame-pointer
39 endif
40
41 MPG123TARG=linux
42 endif
43
44 ifeq ($(findstring BSD,${OSARCH}),BSD)
45 PROC=$(shell uname -m)
46 endif
47
48 # Pentium Pro Optimize
49 #PROC=i686
50
51 # Pentium & VIA processors optimize
52 #PROC=i586
53
54 #PROC=k6
55 #PROC=ppc
56
57 PWD=$(shell pwd)
58
59 GREP=grep
60 ifeq (${OSARCH},SunOS)
61 GREP=/usr/xpg4/bin/grep
62 M4=/usr/local/bin/m4
63 endif
64
65 ######### More GSM codec optimization
66 ######### Uncomment to enable MMXTM optimizations for x86 architecture CPU's
67 ######### which support MMX instructions.  This should be newer pentiums,
68 ######### ppro's, etc, as well as the AMD K6 and K7.  
69 #K6OPT  = -DK6OPT
70
71 #Overwite config files on "make samples"
72 OVERWRITE=y
73
74 #Tell gcc to optimize the asterisk's code
75 OPTIMIZE+=-O6
76
77 #Include debug symbols in the executables (-g) and profiling info (-pg)
78 DEBUG=-g #-pg
79
80 # If you are running a radio application, define RADIO_RELAX so that the DTMF
81 # will be received more reliably
82 #OPTIONS += -DRADIO_RELAX
83
84 # If you don't have a lot of memory (e.g. embedded Asterisk), uncomment the
85 # following to reduce the size of certain static buffers
86 #OPTIONS += -DLOW_MEMORY
87
88 # Optional debugging parameters
89 DEBUG_THREADS = #-DDEBUG_THREADS #-DDO_CRASH #-DDETECT_DEADLOCKS
90
91 # Uncomment next one to enable ast_frame tracing (for debugging)
92 TRACE_FRAMES = #-DTRACE_FRAMES
93
94 # Uncomment next one to enable malloc debugging
95 # You can view malloc debugging with:
96 #   *CLI> show memory allocations [filename]
97 #   *CLI> show memory summary [filename]
98 #
99 MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
100
101 # Where to install asterisk after compiling
102 # Default -> leave empty
103 INSTALL_PREFIX=
104
105 # Staging directory
106 # Files are copied here temporarily during the install process
107 # For example, make DESTDIR=/tmp/asterisk woud put things in
108 # /tmp/asterisk/etc/asterisk
109 DESTDIR=
110
111 # Original busydetect routine
112 BUSYDETECT = #-DBUSYDETECT
113
114 # Improved busydetect routine, comment the previous one if you use this one
115 BUSYDETECT+= -DBUSYDETECT_MARTIN 
116 # Detect the busy signal looking only at tone lengths
117 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
118 BUSYDETECT+= #-DBUSYDETECT_TONEONLY
119 # Inforce the detection of busy singal (get rid of false hangups)
120 # Don't use together with -DBUSYDETECT_TONEONLY
121 BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
122
123 ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
124 ASTVARLIBDIR=$(INSTALL_PREFIX)/var/lib/asterisk
125 ASTETCDIR=$(INSTALL_PREFIX)/etc/asterisk
126 ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
127 ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
128 ASTHEADERDIR=$(INSTALL_PREFIX)/usr/include/asterisk
129 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
130 ASTBINDIR=$(INSTALL_PREFIX)/usr/bin
131 ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
132 ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
133 ASTMANDIR=$(INSTALL_PREFIX)/usr/share/man
134
135 MODULES_DIR=$(ASTLIBDIR)/modules
136 AGI_DIR=$(ASTVARLIBDIR)/agi-bin
137
138 INCLUDE=-Iinclude -I../include
139 CFLAGS=-pipe  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
140 CFLAGS+=$(OPTIMIZE)
141
142 ifneq ($(PROC),ultrasparc)
143 CFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
144 endif
145
146 CFLAGS+=$(shell if uname -m | $(GREP) -q ppc; then echo "-fsigned-char"; fi)
147 CFLAGS+=$(shell if [ -f /usr/include/osp/osp.h ]; then echo "-DOSP_SUPPORT -I/usr/include/osp" ; fi)
148
149 ifeq (${OSARCH},FreeBSD)
150 OSVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
151 CFLAGS+=$(shell if test ${OSVERSION} -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
152 LIBS+=$(shell if test  ${OSVERSION} -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
153 INCLUDE+=-I/usr/local/include
154 CFLAGS+=$(shell if [ -d /usr/local/include/spandsp ]; then echo "-I/usr/local/include/spandsp"; fi)
155 MPG123TARG=freebsd
156 endif # FreeBSD
157
158 ifeq (${OSARCH},NetBSD)
159 CFLAGS+=-pthread
160 INCLUDE+=-I/usr/local/include -I/usr/pkg/include
161 MPG123TARG=netbsd
162 endif
163
164 ifeq (${OSARCH},OpenBSD)
165 CFLAGS+=-pthread
166 endif
167 ifeq (${OSARCH},SunOS)
168 CFLAGS+=-Wcast-align -DSOLARIS
169 INCLUDE+=-Iinclude/solaris-compat -I/usr/local/ssl/include
170 endif
171
172 #Uncomment this to use the older DSP routines
173 #CFLAGS+=-DOLD_DSP_ROUTINES
174
175 CFLAGS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
176 CFLAGS+=$(shell if [ -f /usr/local/include/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
177
178 LIBEDIT=editline/libedit.a
179
180 ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; else if [ -d CVS ]; then if [ -f CVS/Tag ] ; then echo "CVS-`sed 's/^T//g' CVS/Tag`-`date +"%D-%T"`"; else echo "CVS-HEAD-`date +"%D-%T"`"; fi; fi; fi)
181 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)
182 HTTPDIR=$(shell if [ -d /var/www ]; then echo "/var/www"; else echo "/home/httpd"; fi)
183 RPMVERSION=$(shell if [ -f .version ]; then sed 's/[-\/:]/_/g' .version; else echo "unknown" ; fi)
184 CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\"
185 CFLAGS+=-DASTERISK_VERSION_NUM=$(ASTERISKVERSIONNUM)
186 CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
187 CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\"
188 CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\"
189 CFLAGS+=-DASTVARLIBDIR=\"$(ASTVARLIBDIR)\"
190 CFLAGS+=-DASTVARRUNDIR=\"$(ASTVARRUNDIR)\"
191 CFLAGS+=-DASTSPOOLDIR=\"$(ASTSPOOLDIR)\"
192 CFLAGS+=-DASTLOGDIR=\"$(ASTLOGDIR)\"
193 CFLAGS+=-DASTCONFPATH=\"$(ASTCONFPATH)\"
194 CFLAGS+=-DASTMODDIR=\"$(MODULES_DIR)\"
195 CFLAGS+=-DASTAGIDIR=\"$(AGI_DIR)\"
196
197 CFLAGS+= $(DEBUG_THREADS)
198 CFLAGS+= $(TRACE_FRAMES)
199 CFLAGS+= $(MALLOC_DEBUG)
200 CFLAGS+= $(BUSYDETECT)
201 CFLAGS+= $(OPTIONS)
202 CFLAGS+= -fomit-frame-pointer 
203 SUBDIRS=res channels pbx apps codecs formats agi cdr utils stdtime
204 ifeq (${OSARCH},Linux)
205 LIBS=-ldl -lpthread
206 endif
207 LIBS+=-lncurses -lm
208 ifeq (${OSARCH},Linux)
209 LIBS+=-lresolv  #-lnjamd
210 endif
211 ifeq (${OSARCH},Darwin)
212 LIBS+=-lresolv
213 CFLAGS+=-D__OSX__
214 endif
215 ifeq (${OSARCH},FreeBSD)
216 LIBS+=-lcrypto
217 endif
218 ifeq (${OSARCH},NetBSD)
219 LIBS+=-lpthread -lcrypto -lm -L/usr/local/lib -L/usr/pkg/lib -lncurses
220 endif
221 ifeq (${OSARCH},OpenBSD)
222 LIBS=-lcrypto -lpthread -lm -lncurses
223 endif
224 ifeq (${OSARCH},SunOS)
225 LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L/usr/local/ssl/lib
226 endif
227 LIBS+=-lssl
228 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
229         translate.o file.o say.o pbx.o cli.o md5.o term.o \
230         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
231         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
232         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
233         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
234         utils.o config_old.o
235 ifeq (${OSARCH},Darwin)
236 OBJS+=poll.o dlfcn.o
237 ASTLINK=-Wl,-dynamic
238 SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
239 else
240 ASTLINK=-Wl,-E 
241 SOLINK=-shared -Xlinker -x
242 endif
243 ifeq (${OSARCH},SunOS)
244 OBJS+=strcompat.o
245 ASTLINK=
246 SOLINK=-shared -fpic -L/usr/local/ssl/lib
247 endif
248
249 CC=gcc
250 INSTALL=install
251
252 _all: all
253         @echo " +--------- Asterisk Build Complete ---------+"  
254         @echo " + Asterisk has successfully been built, but +"  
255         @echo " + cannot be run before being installed by   +"  
256         @echo " + running:                                  +"  
257         @echo " +                                           +"
258         @echo " +               $(MAKE) install                +"  
259         @echo " +-------------------------------------------+"  
260
261 all: cleantest depend asterisk subdirs 
262
263 noclean: depend asterisk subdirs
264
265 editline/config.h:
266         cd editline && unset CFLAGS LIBS && ./configure ; \
267
268 editline/libedit.a: FORCE
269         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
270         $(MAKE) -C editline libedit.a
271
272 db1-ast/libdb1.a: FORCE
273         @if [ -d db1-ast ]; then \
274                 $(MAKE) -C db1-ast libdb1.a ; \
275         else \
276                 echo "You need to do a cvs update -d not just cvs update"; \
277                 exit 1; \
278         fi
279
280 ifneq ($(wildcard .depend),)
281 include .depend
282 endif
283
284 .PHONY: _version
285
286 _version: 
287         if [ -d CVS ] && [ ! -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
288
289 .version: _version
290
291 .y.c:
292         bison $< --name-prefix=ast_yy -o $@
293
294 ast_expr.o: ast_expr.c
295
296 cli.o: cli.c build.h
297
298 asterisk.o: asterisk.c build.h
299
300 manpage: asterisk.8.gz
301
302 asterisk.8.gz: asterisk.sgml
303         rm -f asterisk.8
304         docbook2man asterisk.sgml
305         mv ./*.8 asterisk.8
306         gzip asterisk.8
307
308 ifneq ($(strip $(ASTERISKVERSION)),)
309 build.h: .version
310         ./make_build_h
311 else
312 build.h:
313         ./make_build_h
314 endif
315
316 stdtime/libtime.a: FORCE
317         @if [ -d stdtime ]; then \
318                 $(MAKE) -C stdtime libtime.a ; \
319         else \
320                 echo "You need to do a cvs update -d not just cvs update"; \
321                 exit 1; \
322         fi
323
324 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
325         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
326
327 muted: muted.o
328         $(CC) -o muted muted.o
329
330 subdirs: 
331         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
332
333 clean:
334         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
335         rm -f *.o *.so asterisk .depend
336         rm -f build.h 
337         rm -f ast_expr.c
338         rm -f .version
339         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
340         @if [ -d mpg123-0.59r ]; then $(MAKE) -C mpg123-0.59r clean; fi
341         $(MAKE) -C db1-ast clean
342         $(MAKE) -C stdtime clean
343
344 datafiles: all
345         sh mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig
346         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
347         for x in sounds/digits/*.gsm; do \
348                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
349                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
350                 else \
351                         echo "No description for $$x"; \
352                         exit 1; \
353                 fi; \
354         done
355         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters
356         for x in sounds/letters/*.gsm; do \
357                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
358                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/letters ; \
359                 else \
360                         echo "No description for $$x"; \
361                         exit 1; \
362                 fi; \
363         done
364         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic
365         for x in sounds/phonetic/*.gsm; do \
366                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
367                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/phonetic ; \
368                 else \
369                         echo "No description for $$x"; \
370                         exit 1; \
371                 fi; \
372         done
373         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 \
374                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
375                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
376                 else \
377                         echo "No description for $$x"; \
378                         exit 1; \
379                 fi; \
380         done
381         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
382         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
383         for x in images/*.jpg; do \
384                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
385         done
386         mkdir -p $(DESTDIR)$(AGI_DIR)
387
388 update: 
389         @if [ -d CVS ]; then \
390                 if [ -f patches/.applied ]; then \
391                         patches=`cat patches/.applied`; \
392                 fi; \
393                 if ! [ -z "$$patches" ]; then \
394                         for x in $$patches; do \
395                                 echo "Unapplying $$x..."; \
396                                 patch -R -p0 < patches/$$x; \
397                         done; \
398                         rm -f patches/.applied; \
399                 fi ; \
400                 echo "Updating from CVS..." ; \
401                 cvs -q -z3 update -Pd | tee update.out; \
402                 rm -f .version; \
403                 if [ `grep -c ^C update.out` -gt 0 ]; then \
404                         echo ; echo "The following files have conflicts:" ; \
405                         grep ^C update.out | cut -d' ' -f2- ; \
406                 fi ; \
407                 rm -f update.out; \
408                 if ! [ -z "$$patches" ]; then \
409                         for x in $$patches; do \
410                                 if [ -f patches/$$x ]; then \
411                                         echo "Applying patch $$x..."; \
412                                         patch -p0 < patches/$$x; \
413                                         echo $$x >> patches/.applied; \
414                                 else \
415                                         echo "Patch $$x no longer relevant"; \
416                                 fi; \
417                         done; \
418                 fi; \
419         else \
420                 echo "Not CVS";  \
421         fi
422
423 bininstall: all
424         mkdir -p $(DESTDIR)$(MODULES_DIR)
425         mkdir -p $(DESTDIR)$(ASTSBINDIR)
426         mkdir -p $(DESTDIR)$(ASTETCDIR)
427         mkdir -p $(DESTDIR)$(ASTBINDIR)
428         mkdir -p $(DESTDIR)$(ASTSBINDIR)
429         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
430         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
431         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
432         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
433         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
434         install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
435         install -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/     
436         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
437                 install -m 755 contrib/scripts/safe_asterisk $(DESTDIR)$(ASTSBINDIR)/ ;\
438         fi
439         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
440         install -d $(DESTDIR)$(ASTHEADERDIR)
441         install -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
442         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
443         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
444         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
445         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
446         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware
447         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax
448         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
449         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
450         install -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
451         install -m 644 asterisk.8.gz $(DESTDIR)$(ASTMANDIR)/man8
452         if [ -d contrib/firmware/iax ]; then \
453                 install -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTVARLIBDIR)/firmware/iax/iaxy.bin; \
454         else \
455                 echo "You need to do cvs update -d not just cvs update" ; \
456         fi 
457         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
458         if [ -f mpg123-0.59r/mpg123 ]; then $(MAKE) -C mpg123-0.59r install; fi
459         @echo " +---- Asterisk Installation Complete -------+"  
460         @echo " +                                           +"
461         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
462         @echo " +                                           +"
463         @echo " + Asterisk has successfully been installed. +"  
464         @echo " + If you would like to install the sample   +"  
465         @echo " + configuration files (overwriting any      +"
466         @echo " + existing config files), run:              +"  
467         @echo " +                                           +"
468         @echo " +               $(MAKE) samples                +"
469         @echo " +                                           +"
470         @echo " +-----------------  or ---------------------+"
471         @echo " +                                           +"
472         @echo " + You can go ahead and install the asterisk +"
473         @echo " + program documentation now or later run:   +"
474         @echo " +                                           +"
475         @echo " +              $(MAKE) progdocs                +"
476         @echo " +                                           +"
477         @echo " + **Note** This requires that you have      +"
478         @echo " + doxygen installed on your local system    +"
479         @echo " +-------------------------------------------+"
480
481 install: all datafiles bininstall
482
483 upgrade: all bininstall
484
485 adsi: all
486         mkdir -p $(DESTDIR)$(ASTETCDIR)
487         for x in configs/*.adsi; do \
488                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
489                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
490                 fi ; \
491         done
492
493 samples: all datafiles adsi
494         mkdir -p $(DESTDIR)$(ASTETCDIR)
495         for x in configs/*.sample; do \
496                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
497                         if [ "$(OVERWRITE)" = "y" ]; then \
498                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $$x ; then \
499                                         echo "Config file $$x is unchanged"; \
500                                         continue; \
501                                 fi ; \
502                                 mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
503                         else \
504                                 echo "Skipping config file $$x"; \
505                                 continue; \
506                         fi ;\
507                 fi ; \
508                 install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
509         done
510         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTETCDIR)/asterisk.conf ]; then \
511                 echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
512                 echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
513                 echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
514                 echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
515                 echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
516                 echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
517                 echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
518                 echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
519                 echo "" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
520                 echo "; Changing the following lines may compromise your security." >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
521                 echo ";[files]" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
522                 echo ";astctlpermissions = 0660" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
523                 echo ";astctlowner = root" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
524                 echo ";astctlgroup = apache" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
525                 echo ";astctl = asterisk.ctl" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf ; \
526         else \
527                 echo "Skipping asterisk.conf creation"; \
528         fi
529         for x in sounds/demo-*; do \
530                 if $(GREP) -q "^%`basename $$x`%" sounds.txt; then \
531                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
532                 else \
533                         echo "No description for $$x"; \
534                         exit 1; \
535                 fi; \
536         done
537         for x in sounds/*.mp3; do \
538                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
539         done
540         rm -f $(DESTDIR)$(ASTVARLIBDIR)/mohmp3/sample-hold.mp3
541         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
542         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
543         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
544                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
545         done
546         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
547         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
548                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
549         done
550
551 webvmail:
552         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
553         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
554         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
555         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
556         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
557         for x in images/*.gif; do \
558                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
559         done
560         @echo " +--------- Asterisk Web Voicemail ----------+"  
561         @echo " +                                           +"
562         @echo " + Asterisk Web Voicemail is installed in    +"
563         @echo " + your cgi-bin directory.  IT USES A SETUID +"
564         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
565         @echo " + THAT, UNINSTALL IT!                       +"
566         @echo " +                                           +"
567         @echo " +-------------------------------------------+"  
568
569 mailbox:
570         ./contrib/scripts/addmailbox 
571
572 spec: 
573         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
574
575 rpm: __rpm
576
577 __rpm: _version spec
578         rm -rf /tmp/asterisk ; \
579         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
580         $(MAKE) DESTDIR=/tmp/asterisk install ; \
581         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
582         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
583         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
584         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
585
586 progdocs:
587         doxygen contrib/asterisk-ng-doxygen
588
589 mpg123:
590         @wget -V >/dev/null || (echo "You need wget" ; false )
591         [ -f mpg123-0.59r.tar.gz ] || wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
592         [ -d mpg123-0.59r ] || tar xfz mpg123-0.59r.tar.gz
593         $(MAKE) -C mpg123-0.59r $(MPG123TARG)
594
595 config:
596         if [ -d /etc/rc.d/init.d ]; then \
597                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
598                 /sbin/chkconfig --add asterisk; \
599         elif [ -d /etc/init.d ]; then \
600                 install -m 755 init.asterisk /etc/init.d/asterisk; \
601         fi 
602
603 dont-optimize:
604         $(MAKE) OPTIMIZE= K6OPT= install
605
606 valgrind: dont-optimize
607
608 depend: .depend
609         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
610
611 .depend:
612         ./mkdep ${CFLAGS} `ls *.c`
613
614 FORCE:
615
616 %_env:
617         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
618
619 env:
620         env
621
622 # If the cleancount has been changed, force a make clean.
623 # .cleancount is the global clean count, and .lastclean is the 
624 #       last clean count # we had
625 # We can avoid this by making noclean
626
627 cleantest:
628         if ! cmp -s .cleancount .lastclean ; then \
629                 $(MAKE) clean; cp -f .cleancount .lastclean;\
630         fi
631
632 patchlist:
633         @echo "Experimental Patches:"
634         @for x in patches/*; do \
635                 patch=`basename $$x`; \
636                 if [ "$$patch" = "CVS" ]; then \
637                         continue; \
638                 fi; \
639                 if grep -q ^$$patch$$ patches/.applied; then \
640                         echo "$$patch (applied)"; \
641                 else \
642                         echo "$$patch (available)"; \
643                 fi; \
644         done
645                 
646         
647 apply: 
648         @if [ -z "$(PATCH)" ]; then \
649                 echo "Usage: make PATCH=<patchname> apply"; \
650         elif grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
651                 echo "Patch $(PATCH) is already applied"; \
652         elif [ -f "patches/$(PATCH)" ]; then \
653                 echo "Applying patch $(PATCH)"; \
654                 patch -p0 < patches/$(PATCH); \
655                 echo "$(PATCH)" >> patches/.applied; \
656         else \
657                 echo "No such patch $(PATCH) in patches directory"; \
658         fi
659         
660 unapply: 
661         @if [ -z "$(PATCH)" ]; then \
662                 echo "Usage: make PATCH=<patchname> unapply"; \
663         elif ! grep -q ^$(PATCH)$$ patches/.applied 2>/dev/null; then \
664                 echo "Patch $(PATCH) is not applied"; \
665         elif [ -f "patches/$(PATCH)" ]; then \
666                 echo "Un-applying patch $(PATCH)"; \
667                 patch -p0 -R < patches/$(PATCH); \
668                 rm -f patches/.tmpapplied || :; \
669                 mv patches/.applied patches/.tmpapplied; \
670                 cat patches/.tmpapplied | grep -v ^$(PATCH)$$ > patches/.applied; \
671                 rm -f patches/.tmpapplied; \
672         else \
673                 echo "No such patch $(PATCH) in patches directory"; \
674         fi
675
676