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