b678b15fb7327ca6857c812627cce5cc4c99fab6
[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 INCLUDE+=-I/usr/local/include
113 endif
114 ifeq (${OSARCH},OpenBSD)
115 CFLAGS+=-pthread
116 endif
117
118 #Uncomment this to use the older DSP routines
119 #CFLAGS+=-DOLD_DSP_ROUTINES
120
121 CFLAGS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
122
123 LIBEDIT=editline/libedit.a
124
125 ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; else if [ -d CVS ]; then echo "CVS-`date +"%D-%T"`"; fi; fi)
126 HTTPDIR=$(shell if [ -d /var/www ]; then echo "/var/www"; else echo "/home/httpd"; fi)
127 RPMVERSION=$(shell if [ -f .version ]; then sed 's/[-\/:]/_/g' .version; else echo "unknown" ; fi)
128 CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\"
129 CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
130 CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\"
131 CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\"
132 CFLAGS+=-DASTVARLIBDIR=\"$(ASTVARLIBDIR)\"
133 CFLAGS+=-DASTVARRUNDIR=\"$(ASTVARRUNDIR)\"
134 CFLAGS+=-DASTSPOOLDIR=\"$(ASTSPOOLDIR)\"
135 CFLAGS+=-DASTLOGDIR=\"$(ASTLOGDIR)\"
136 CFLAGS+=-DASTCONFPATH=\"$(ASTCONFPATH)\"
137 CFLAGS+=-DASTMODDIR=\"$(MODULES_DIR)\"
138 CFLAGS+=-DASTAGIDIR=\"$(AGI_DIR)\"
139
140 CFLAGS+= $(DEBUG_THREADS)
141 CFLAGS+= $(TRACE_FRAMES)
142 CFLAGS+= $(MALLOC_DEBUG)
143 CFLAGS+= $(BUSYDETECT)
144 CFLAGS+= $(OPTIONS)
145 CFLAGS+=# -fomit-frame-pointer 
146 SUBDIRS=res channels pbx apps codecs formats agi cdr astman stdtime
147 ifeq (${OSARCH},Linux)
148 LIBS=-ldl -lpthread
149 endif
150 ifeq (${OSARCH},OpenBSD)
151 LIBS=-pthread
152 else
153 ifeq (${OSARCH},FreeBSD)
154 LIBS=-pthread
155 else
156 endif
157 endif
158 LIBS+=-lncurses -lm
159 ifeq (${OSARCH},Linux)
160 LIBS+=-lresolv  #-lnjamd
161 endif
162 ifeq (${OSARCH},Darwin)
163 ifeq ($(shell uname -r),7.0.0)
164 LIBS+=-lresolv
165 endif
166 endif
167 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
168         translate.o file.o say.o pbx.o cli.o md5.o term.o \
169         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
170         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
171         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
172         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o
173 ifeq (${OSARCH},Darwin)
174 OBJS+=poll.o dlfcn.o
175 ASTLINK=-Wl,-dynamic
176 SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
177 else
178 ASTLINK=-Wl,-E 
179 SOLINK=-shared -Xlinker -x
180 endif
181
182 CC=gcc
183 INSTALL=install
184
185 _all: all
186         @echo " +--------- Asterisk Build Complete ---------+"  
187         @echo " + Asterisk has successfully been built, but +"  
188         @echo " + cannot be run before being installed by   +"  
189         @echo " + running:                                  +"  
190         @echo " +                                           +"
191         @echo " +               $(MAKE) install                +"  
192         @echo " +-------------------------------------------+"  
193
194 all: depend asterisk subdirs
195
196 editline/config.h:
197         cd editline && unset CFLAGS LIBS && ./configure ; \
198
199 editline/libedit.a: FORCE
200         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
201         $(MAKE) -C editline libedit.a
202
203 db1-ast/libdb1.a: FORCE
204         @if [ -d db1-ast ]; then \
205                 $(MAKE) -C db1-ast libdb1.a ; \
206         else \
207                 echo "You need to do a cvs update -d not just cvs update"; \
208                 exit 1; \
209         fi
210
211 ifneq ($(wildcard .depend),)
212 include .depend
213 endif
214
215 .PHONY: _version
216
217 _version: 
218         if [ -d CVS ] && ! [ -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
219
220 .version: _version
221
222 .y.c:
223         bison $< --name-prefix=ast_yy -o $@
224
225 ast_expr.o: ast_expr.c
226
227 cli.o: cli.c build.h
228
229 asterisk.o: asterisk.c build.h
230
231 ifneq ($(strip $(ASTERISKVERSION)),)
232 build.h: .version
233         ./make_build_h
234 else
235 build.h:
236         ./make_build_h
237 endif
238
239 stdtime/libtime.a: FORCE
240         @if [ -d stdtime ]; then \
241                 $(MAKE) -C stdtime libtime.a ; \
242         else \
243                 echo "You need to do a cvs update -d not just cvs update"; \
244                 exit 1; \
245         fi
246
247 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
248         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a
249
250 subdirs: 
251         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
252
253 clean:
254         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
255         rm -f *.o *.so asterisk .depend
256         rm -f build.h 
257         rm -f ast_expr.c
258         @if [ -e editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
259         $(MAKE) -C db1-ast clean
260         $(MAKE) -C stdtime clean
261
262 datafiles: all
263         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
264         for x in sounds/digits/*.gsm; do \
265                 if grep -q "^%`basename $$x`%" sounds.txt; then \
266                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
267                 else \
268                         echo "No description for $$x"; \
269                         exit 1; \
270                 fi; \
271         done
272         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 \
273                 if grep -q "^%`basename $$x`%" sounds.txt; then \
274                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
275                 else \
276                         echo "No description for $$x"; \
277                         exit 1; \
278                 fi; \
279         done
280         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
281         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
282         for x in images/*.jpg; do \
283                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
284         done
285         mkdir -p $(DESTDIR)$(AGI_DIR)
286
287 update: 
288         @if [ -d CVS ]; then \
289                 echo "Updating from CVS..." ; \
290                 cvs -q update -Pd; \
291                 rm -f .version; \
292         else \
293                 echo "Not CVS";  \
294         fi
295
296 bininstall: all
297         mkdir -p $(DESTDIR)$(MODULES_DIR)
298         mkdir -p $(DESTDIR)$(ASTSBINDIR)
299         mkdir -p $(DESTDIR)$(ASTETCDIR)
300         mkdir -p $(DESTDIR)$(ASTBINDIR)
301         mkdir -p $(DESTDIR)$(ASTSBINDIR)
302         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
303         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
304         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
305         install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
306         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
307                 install -m 755 contrib/scripts/safe_asterisk $(DESTDIR)$(ASTSBINDIR)/ ;\
308         fi
309         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
310         install -d $(DESTDIR)$(ASTHEADERDIR)
311         install -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
312         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/vm
313         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
314         if [ ! -h $(DESTDIR)$(ASTSPOOLDIR)/vm ] && [ -d $(DESTDIR)$(ASTSPOOLDIR)/vm ]; then \
315                 mv $(DESTDIR)$(ASTSPOOLDIR)/vm $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
316         else \
317                 mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
318                 rm -f $(DESTDIR)$(ASTSPOOLDIR)/vm; \
319         fi
320         ln -s $(ASTSPOOLDIR)/voicemail/default $(DESTDIR)$(ASTSPOOLDIR)/vm
321         rm -f $(DESTDIR)$(MODULES_DIR)/chan_ixj.so
322         rm -f $(DESTDIR)$(MODULES_DIR)/chan_tor.so
323         rm -f $(DESTDIR)$(MODULES_DIR)/cdr_mysql.so
324         rm -f $(DESTDIR)$(MODULES_DIR)/cdr_unixodbc.so
325         rm -f $(DESTDIR)$(MODULES_DIR)/codec_mp3_d.so
326         rm -f $(DESTDIR)$(MODULES_DIR)/format_mp3.so
327         rm -f $(DESTDIR)$(MODULES_DIR)/app_voicemail2.so
328         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
329         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
330         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
331         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
332         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
333         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
334         @echo " +---- Asterisk Installation Complete -------+"  
335         @echo " +                                           +"
336         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
337         @echo " +                                           +"
338         @echo " + Asterisk has successfully been installed. +"  
339         @echo " + If you would like to install the sample   +"  
340         @echo " + configuration files (overwriting any      +"
341         @echo " + existing config files), run:              +"  
342         @echo " +                                           +"
343         @echo " +               $(MAKE) samples                +"
344         @echo " +                                           +"
345         @echo " +-----------------  or ---------------------+"
346         @echo " +                                           +"
347         @echo " + You can go ahead and install the asterisk +"
348         @echo " + program documentation now or later run:   +"
349         @echo " +                                           +"
350         @echo " +              $(MAKE) progdocs                +"
351         @echo " +                                           +"
352         @echo " + **Note** This requires that you have      +"
353         @echo " + doxygen installed on your local system    +"
354         @echo " +-------------------------------------------+"
355
356 install: all datafiles bininstall
357
358 upgrade: all bininstall
359
360 adsi: all
361         mkdir -p $(DESTDIR)$(ASTETCDIR)
362         for x in configs/*.adsi; do \
363                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
364                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
365                 fi ; \
366         done
367
368 samples: all datafiles adsi
369         mkdir -p $(DESTDIR)$(ASTETCDIR)
370         for x in configs/*.sample; do \
371                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
372                         mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
373                 fi ; \
374                 install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
375         done
376         echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf
377         echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
378         echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
379         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
380         echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
381         echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
382         echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
383         echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
384         for x in sounds/demo-*; do \
385                 if grep -q "^%`basename $$x`%" sounds.txt; then \
386                         install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
387                 else \
388                         echo "No description for $$x"; \
389                         exit 1; \
390                 fi; \
391         done
392         for x in sounds/*.mp3; do \
393                 install -m 644 $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
394         done
395         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
396         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
397         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
398                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
399         done
400         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
401         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
402                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
403         done
404
405 webvmail:
406         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
407         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
408         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
409         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
410         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
411         for x in images/*.gif; do \
412                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
413         done
414         @echo " +--------- Asterisk Web Voicemail ----------+"  
415         @echo " +                                           +"
416         @echo " + Asterisk Web Voicemail is installed in    +"
417         @echo " + your cgi-bin directory.  IT USES A SETUID +"
418         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
419         @echo " + THAT, UNINSTALL IT!                       +"
420         @echo " +                                           +"
421         @echo " +-------------------------------------------+"  
422
423 mailbox:
424         ./contrib/scripts/addmailbox 
425         
426
427 rpm: __rpm
428
429 __rpm: _version
430         rm -rf /tmp/asterisk ; \
431         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
432         $(MAKE) DESTDIR=/tmp/asterisk install ; \
433         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
434         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
435         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
436         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
437         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
438         
439 progdocs:
440         doxygen contrib/asterisk-ng-doxygen
441
442 config:
443         if [ -d /etc/rc.d/init.d ]; then \
444                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
445                 /sbin/chkconfig --add asterisk; \
446         elif [ -d /etc/init.d ]; then \
447                 install -m 755 init.asterisk /etc/init.d/asterisk; \
448         fi 
449
450         
451 dont-optimize:
452         $(MAKE) OPTIMIZE= K6OPT= install
453
454 valgrind: dont-optimize
455
456 depend: .depend
457         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
458
459 .depend:
460         ./mkdep ${CFLAGS} `ls *.c`
461
462 FORCE: