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