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