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