caacc70f3ab67572c78fa81e280a0234e43c6711
[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         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
316         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
317         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
318         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
319         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
320         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
321         @echo " +---- Asterisk Installation Complete -------+"  
322         @echo " +                                           +"
323         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
324         @echo " +                                           +"
325         @echo " + Asterisk has successfully been installed. +"  
326         @echo " + If you would like to install the sample   +"  
327         @echo " + configuration files (overwriting any      +"
328         @echo " + existing config files), run:              +"  
329         @echo " +                                           +"
330         @echo " +               $(MAKE) samples                +"
331         @echo " +                                           +"
332         @echo " +-----------------  or ---------------------+"
333         @echo " +                                           +"
334         @echo " + You can go ahead and install the asterisk +"
335         @echo " + program documentation now or later run:   +"
336         @echo " +                                           +"
337         @echo " +              $(MAKE) progdocs                +"
338         @echo " +                                           +"
339         @echo " + **Note** This requires that you have      +"
340         @echo " + doxygen installed on your local system    +"
341         @echo " +-------------------------------------------+"
342
343 install: all datafiles bininstall
344
345 upgrade: all bininstall
346
347 adsi: all
348         mkdir -p $(DESTDIR)$(ASTETCDIR)
349         for x in configs/*.adsi; do \
350                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
351                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
352                 fi ; \
353         done
354
355 samples: all datafiles adsi
356         mkdir -p $(DESTDIR)$(ASTETCDIR)
357         for x in configs/*.sample; do \
358                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
359                         mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
360                 fi ; \
361                 install $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
362         done
363         echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf
364         echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
365         echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
366         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
367         echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
368         echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
369         echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
370         echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
371         for x in sounds/demo-*; do \
372                 if grep -q "^%`basename $$x`%" sounds.txt; then \
373                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
374                 else \
375                         echo "No description for $$x"; \
376                         exit 1; \
377                 fi; \
378         done
379         for x in sounds/*.mp3; do \
380                 install $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
381         done
382         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
383         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm
384         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
385                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm ; \
386         done
387         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
388         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
389                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm ; \
390         done
391
392 webvmail:
393         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
394         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
395         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
396         install -m 4755 -o root -g root vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
397         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
398         for x in images/*.gif; do \
399                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
400         done
401         @echo " +--------- Asterisk Web Voicemail ----------+"  
402         @echo " +                                           +"
403         @echo " + Asterisk Web Voicemail is installed in    +"
404         @echo " + your cgi-bin directory.  IT USES A SETUID +"
405         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
406         @echo " + THAT, UNINSTALL IT!                       +"
407         @echo " +                                           +"
408         @echo " +-------------------------------------------+"  
409
410 mailbox:
411         ./addmailbox 
412         
413
414 rpm: __rpm
415
416 __rpm: _version
417         rm -rf /tmp/asterisk ; \
418         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
419         $(MAKE) DESTDIR=/tmp/asterisk install ; \
420         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
421         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
422         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
423         cp -f redhat/rpmrc /tmp/asterisk/ ; \
424         cp -f redhat/rpmmacros /tmp/asterisk/ ; \
425         sed "s/Version:/Version: $(RPMVERSION)/g" redhat/asterisk.spec > /tmp/asterisk/asterisk.spec ; \
426         rpm --rcfile /usr/lib/rpm/rpmrc:/tmp/asterisk/rpmrc -bb /tmp/asterisk/asterisk.spec ; \
427         mv /tmp/asterisk/redhat/RPMS/i386/asterisk* ./ ; \
428         rm -rf /tmp/asterisk
429
430 progdocs:
431         doxygen asterisk-ng-doxygen
432
433 config:
434         if [ -d /etc/rc.d/init.d ]; then \
435                 install -m 755 init.asterisk /etc/rc.d/init.d/asterisk; \
436                 /sbin/chkconfig --add asterisk; \
437         elif [ -d /etc/init.d ]; then \
438                 install -m 755 init.asterisk /etc/init.d/asterisk; \
439         fi 
440
441         
442 dont-optimize:
443         $(MAKE) OPTIMIZE= K6OPT= install
444
445 valgrind: dont-optimize
446
447 depend: .depend
448         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
449
450 .depend:
451         ./mkdep ${CFLAGS} `ls *.c`
452
453 FORCE: