Ditch format_mp3 too
[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 endif
24 # Pentium Pro Optimize
25 #PROC=i686
26
27 # Pentium & VIA processors optimize
28 #PROC=i586
29
30 #PROC=k6
31 #PROC=ppc
32
33 PWD=$(shell pwd)
34
35 ######### More GSM codec optimization
36 ######### Uncomment to enable MMXTM optimizations for x86 architecture CPU's
37 ######### which support MMX instructions.  This should be newer pentiums,
38 ######### ppro's, etc, as well as the AMD K6 and K7.  
39 #K6OPT  = -DK6OPT
40
41 #Tell gcc to optimize the asterisk's code
42 OPTIMIZE=-O6
43
44 #Include debug symbols in the executables (-g) and profiling info (-pg)
45 DEBUG=-g #-pg
46
47 # New hangup routines for chan_zap.c
48 # If this flag is uncommented then you need to have new libpri code in your system
49 # You can still use the old libpri if you do "cvs update -D "08/03/03" in libpri source code
50 OPTIONS += -DNEW_PRI_HANGUP
51
52 # Optional debugging parameters
53 DEBUG_THREADS = #-DDEBUG_THREADS #-DDO_CRASH 
54
55 # Uncomment next one to enable ast_frame tracing (for debugging)
56 TRACE_FRAMES = #-DTRACE_FRAMES
57
58 # Uncomment next one to enable malloc debugging
59 # You can view malloc debugging with:
60 #   *CLI> show memory allocations [filename]
61 #   *CLI> show memory summary [filename]
62 #
63 MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
64
65 # Where to install asterisk after compiling
66 # Default -> leave empty
67 INSTALL_PREFIX=
68
69 # Staging directory
70 # Files are copied here temporarily during the install process
71 # For example, make DESTDIR=/tmp/asterisk woud put things in
72 # /tmp/asterisk/etc/asterisk
73 DESTDIR=
74
75 # Original busydetect routine
76 BUSYDETECT = #-DBUSYDETECT
77
78 # Improved busydetect routine, comment the previous one if you use this one
79 BUSYDETECT+= -DBUSYDETECT_MARTIN 
80 # Detect the busy signal looking only at tone lengths
81 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
82 BUSYDETECT+= #-DBUSYDETECT_TONEONLY
83 # Inforce the detection of busy singal (get rid of false hangups)
84 # Don't use together with -DBUSYDETECT_TONEONLY
85 BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
86
87 ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
88 ASTVARLIBDIR=$(INSTALL_PREFIX)/var/lib/asterisk
89 ASTETCDIR=$(INSTALL_PREFIX)/etc/asterisk
90 ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
91 ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
92 ASTHEADERDIR=$(INSTALL_PREFIX)/usr/include/asterisk
93 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
94 ASTBINDIR=$(INSTALL_PREFIX)/usr/bin
95 ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
96 ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
97
98 MODULES_DIR=$(ASTLIBDIR)/modules
99 AGI_DIR=$(ASTVARLIBDIR)/agi-bin
100
101 INCLUDE=-Iinclude -I../include
102 CFLAGS=-pipe  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
103 CFLAGS+=$(OPTIMIZE)
104 CFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
105 CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
106 ifeq (${OSARCH},FreeBSD)
107 CFLAGS+=-pthread
108 endif
109 ifeq (${OSARCH},OpenBSD)
110 CFLAGS+=-pthread
111 endif
112
113 CFLAGS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
114
115 LIBEDIT=editline/libedit.a
116
117 ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; else if [ -d CVS ]; then echo "CVS-`date +"%D-%T"`"; fi; fi)
118 HTTPDIR=$(shell if [ -d /var/www ]; then echo "/var/www"; else echo "/home/httpd"; fi)
119 RPMVERSION=$(shell if [ -f .version ]; then sed 's/[-\/:]/_/g' .version; else echo "unknown" ; fi)
120 CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\"
121 CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
122 CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\"
123 CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\"
124 CFLAGS+=-DASTVARLIBDIR=\"$(ASTVARLIBDIR)\"
125 CFLAGS+=-DASTVARRUNDIR=\"$(ASTVARRUNDIR)\"
126 CFLAGS+=-DASTSPOOLDIR=\"$(ASTSPOOLDIR)\"
127 CFLAGS+=-DASTLOGDIR=\"$(ASTLOGDIR)\"
128 CFLAGS+=-DASTCONFPATH=\"$(ASTCONFPATH)\"
129 CFLAGS+=-DASTMODDIR=\"$(MODULES_DIR)\"
130 CFLAGS+=-DASTAGIDIR=\"$(AGI_DIR)\"
131
132 CFLAGS+= $(DEBUG_THREADS)
133 CFLAGS+= $(TRACE_FRAMES)
134 CFLAGS+= $(MALLOC_DEBUG)
135 CFLAGS+= $(BUSYDETECT)
136 CFLAGS+= $(OPTIONS)
137 CFLAGS+=# -fomit-frame-pointer 
138 SUBDIRS=res channels pbx apps codecs formats agi cdr astman stdtime
139 ifeq (${OSARCH},Linux)
140 LIBS=-ldl -lpthread
141 endif
142 ifeq (${OSARCH},OpenBSD)
143 LIBS=-pthread
144 else
145 ifeq (${OSARCH},FreeBSD)
146 LIBS=-pthread
147 else
148 endif
149 endif
150 LIBS+=-lncurses -lm
151 ifeq (${OSARCH},Linux)
152 LIBS+=-lresolv  #-lnjamd
153 endif
154 ifeq (${OSARCH},Darwin)
155 ifeq ($(shell uname -r),7.0.0)
156 LIBS+=-lresolv
157 endif
158 endif
159 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
160         translate.o file.o say.o pbx.o cli.o md5.o term.o \
161         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
162         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
163         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
164         astmm.o enum.o srv.o dns.o
165 ifeq (${OSARCH},Darwin)
166 OBJS+=poll.o dlfcn.o
167 ASTLINK=-Wl,-dynamic
168 SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
169 else
170 ASTLINK=-Wl,-E 
171 SOLINK=-shared -Xlinker -x
172 endif
173
174 CC=gcc
175 INSTALL=install
176
177 _all: all
178         @echo " +--------- Asterisk Build Complete ---------+"  
179         @echo " + Asterisk has successfully been built, but +"  
180         @echo " + cannot be run before being installed by   +"  
181         @echo " + running:                                  +"  
182         @echo " +                                           +"
183         @echo " +               $(MAKE) install                +"  
184         @echo " +-------------------------------------------+"  
185
186 all: depend asterisk subdirs
187
188 editline/config.h:
189         cd editline && unset CFLAGS LIBS && ./configure ; \
190
191 editline/libedit.a: FORCE
192         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
193         $(MAKE) -C editline libedit.a
194
195 db1-ast/libdb1.a: FORCE
196         @if [ -d db1-ast ]; then \
197                 $(MAKE) -C db1-ast libdb1.a ; \
198         else \
199                 echo "You need to do a cvs update -d not just cvs update"; \
200                 exit 1; \
201         fi
202
203 ifneq ($(wildcard .depend),)
204 include .depend
205 endif
206
207 .PHONY: _version
208
209 _version: 
210         if [ -d CVS ] && ! [ -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
211
212 .version: _version
213
214 .y.c:
215         bison $< --name-prefix=ast_yy -o $@
216
217 ast_expr.o: ast_expr.c
218
219 cli.o: cli.c build.h
220
221 asterisk.o: asterisk.c build.h
222
223 ifneq ($(strip $(ASTERISKVERSION)),)
224 build.h: .version
225         ./make_build_h
226 else
227 build.h:
228         ./make_build_h
229 endif
230
231 stdtime/libtime.a: FORCE
232         @if [ -d stdtime ]; then \
233                 $(MAKE) -C stdtime libtime.a ; \
234         else \
235                 echo "You need to do a cvs update -d not just cvs update"; \
236                 exit 1; \
237         fi
238
239 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
240         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a
241
242 subdirs: 
243         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
244
245 clean:
246         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
247         rm -f *.o *.so asterisk .depend
248         rm -f build.h 
249         rm -f ast_expr.c
250         @if [ -e editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
251         $(MAKE) -C db1-ast clean
252         $(MAKE) -C stdtime clean
253
254 datafiles: all
255         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
256         for x in sounds/digits/*.gsm; do \
257                 if grep -q "^%`basename $$x`%" sounds.txt; then \
258                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
259                 else \
260                         echo "No description for $$x"; \
261                         exit 1; \
262                 fi; \
263         done
264         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-*; do \
265                 if grep -q "^%`basename $$x`%" sounds.txt; then \
266                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
267                 else \
268                         echo "No description for $$x"; \
269                         exit 1; \
270                 fi; \
271         done
272         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
273         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
274         for x in images/*.jpg; do \
275                 install $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
276         done
277         mkdir -p $(DESTDIR)$(AGI_DIR)
278
279 update: 
280         @if [ -d CVS ]; then \
281                 echo "Updating from CVS..." ; \
282                 cvs -q update -Pd; \
283                 rm -f .version; \
284         else \
285                 echo "Not CVS";  \
286         fi
287
288 bininstall: all
289         mkdir -p $(DESTDIR)$(MODULES_DIR)
290         mkdir -p $(DESTDIR)$(ASTSBINDIR)
291         mkdir -p $(DESTDIR)$(ASTETCDIR)
292         mkdir -p $(DESTDIR)$(ASTBINDIR)
293         mkdir -p $(DESTDIR)$(ASTSBINDIR)
294         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
295         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
296         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
297         install -m 755 astgenkey $(DESTDIR)$(ASTSBINDIR)/
298         install -m 755 safe_asterisk $(DESTDIR)$(ASTSBINDIR)/
299         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
300         install -d $(DESTDIR)$(ASTHEADERDIR)
301         install include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
302         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/vm
303         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
304         if [ ! -h $(DESTDIR)$(ASTSPOOLDIR)/vm ] && [ -d $(DESTDIR)$(ASTSPOOLDIR)/vm ]; then \
305                 mv $(DESTDIR)$(ASTSPOOLDIR)/vm $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
306         else \
307                 mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
308                 rm -f $(DESTDIR)$(ASTSPOOLDIR)/vm; \
309         fi
310         ln -s $(ASTSPOOLDIR)/voicemail/default $(DESTDIR)$(ASTSPOOLDIR)/vm
311         rm -f $(DESTDIR)$(MODULES_DIR)/chan_ixj.so
312         rm -f $(DESTDIR)$(MODULES_DIR)/chan_tor.so
313         rm -f $(DESTDIR)$(MODULES_DIR)/cdr_mysql.so
314         rm -f $(DESTDIR)$(MODULES_DIR)/codec_mp3_d.so
315         rm -f $(DESTDIR)$(MODULES_DIR)/format_mp3.so
316         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
317         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
318         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
319         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
320         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
321         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
322         @echo " +---- Asterisk Installation Complete -------+"  
323         @echo " +                                           +"
324         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
325         @echo " +                                           +"
326         @echo " + Asterisk has successfully been installed. +"  
327         @echo " + If you would like to install the sample   +"  
328         @echo " + configuration files (overwriting any      +"
329         @echo " + existing config files), run:              +"  
330         @echo " +                                           +"
331         @echo " +               $(MAKE) samples                +"
332         @echo " +                                           +"
333         @echo " +-----------------  or ---------------------+"
334         @echo " +                                           +"
335         @echo " + You can go ahead and install the asterisk +"
336         @echo " + program documentation now or later run:   +"
337         @echo " +                                           +"
338         @echo " +              $(MAKE) progdocs                +"
339         @echo " +                                           +"
340         @echo " + **Note** This requires that you have      +"
341         @echo " + doxygen installed on your local system    +"
342         @echo " +-------------------------------------------+"
343
344 install: all datafiles bininstall
345
346 upgrade: all bininstall
347
348 adsi: all
349         mkdir -p $(DESTDIR)$(ASTETCDIR)
350         for x in configs/*.adsi; do \
351                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
352                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
353                 fi ; \
354         done
355
356 samples: all datafiles adsi
357         mkdir -p $(DESTDIR)$(ASTETCDIR)
358         for x in configs/*.sample; do \
359                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
360                         mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
361                 fi ; \
362                 install $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
363         done
364         echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf
365         echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
366         echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
367         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
368         echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
369         echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
370         echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
371         echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
372         for x in sounds/demo-*; do \
373                 if grep -q "^%`basename $$x`%" sounds.txt; then \
374                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
375                 else \
376                         echo "No description for $$x"; \
377                         exit 1; \
378                 fi; \
379         done
380         for x in sounds/*.mp3; do \
381                 install $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
382         done
383         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
384         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm
385         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
386                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm ; \
387         done
388         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
389         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
390                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm ; \
391         done
392
393 webvmail:
394         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
395         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
396         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
397         install -m 4755 -o root -g root vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
398         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
399         for x in images/*.gif; do \
400                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
401         done
402         @echo " +--------- Asterisk Web Voicemail ----------+"  
403         @echo " +                                           +"
404         @echo " + Asterisk Web Voicemail is installed in    +"
405         @echo " + your cgi-bin directory.  IT USES A SETUID +"
406         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
407         @echo " + THAT, UNINSTALL IT!                       +"
408         @echo " +                                           +"
409         @echo " +-------------------------------------------+"  
410
411 mailbox:
412         ./addmailbox 
413         
414
415 rpm: __rpm
416
417 __rpm: _version
418         rm -rf /tmp/asterisk ; \
419         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
420         $(MAKE) DESTDIR=/tmp/asterisk install ; \
421         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
422         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
423         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
424         cp -f redhat/rpmrc /tmp/asterisk/ ; \
425         cp -f redhat/rpmmacros /tmp/asterisk/ ; \
426         sed "s/Version:/Version: $(RPMVERSION)/g" redhat/asterisk.spec > /tmp/asterisk/asterisk.spec ; \
427         rpm --rcfile /usr/lib/rpm/rpmrc:/tmp/asterisk/rpmrc -bb /tmp/asterisk/asterisk.spec ; \
428         mv /tmp/asterisk/redhat/RPMS/i386/asterisk* ./ ; \
429         rm -rf /tmp/asterisk
430
431 progdocs:
432         doxygen asterisk-ng-doxygen
433
434 config:
435         if [ -d /etc/rc.d/init.d ]; then \
436                 install -m 755 init.asterisk /etc/rc.d/init.d/asterisk; \
437                 /sbin/chkconfig --add asterisk; \
438         elif [ -d /etc/init.d ]; then \
439                 install -m 755 init.asterisk /etc/init.d/asterisk; \
440         fi 
441
442         
443 dont-optimize:
444         $(MAKE) OPTIMIZE= K6OPT= install
445
446 valgrind: dont-optimize
447
448 depend: .depend
449         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
450
451 .depend:
452         ./mkdep ${CFLAGS} `ls *.c`
453
454 FORCE: