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