dep fix, pbx fix
[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: depend 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 include .depend
148
149 _version: 
150         if [ -d CVS ] && ! [ -f .version ]; then echo "CVS-`date +"%D-%T"`" > .version; fi 
151
152 .version: _version
153
154 .y.c:
155         bison $< --name-prefix=ast_yy -o $@
156
157 ast_expr.o: ast_expr.c
158
159 cli.o: cli.c build.h
160
161 ifneq ($(strip $(ASTERISKVERSION)),)
162 asterisk.o: asterisk.c .version
163
164 build.h: .version
165         ./make_build_h
166 else
167 build.h:
168         ./make_build_h
169 endif
170
171 asterisk: .version build.h editline/libedit.a db1-ast/libdb1.a $(OBJS)
172         gcc $(DEBUG) -o asterisk -rdynamic $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a
173
174 subdirs: 
175         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
176
177 clean:
178         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
179         rm -f *.o *.so asterisk .depend
180         rm -f build.h 
181         rm -f ast_expr.c
182         @if [ -e editline/Makefile ]; then $(MAKE) -C editline clean ; fi
183         $(MAKE) -C db1-ast clean
184
185 datafiles: all
186         mkdir -p $(ASTVARLIBDIR)/sounds/digits
187         for x in sounds/digits/*.gsm; do \
188                 if grep -q "^%`basename $$x`%" sounds.txt; then \
189                         install $$x $(ASTVARLIBDIR)/sounds/digits ; \
190                 else \
191                         echo "No description for $$x"; \
192                         exit 1; \
193                 fi; \
194         done
195         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 \
196                 if grep -q "^%`basename $$x`%" sounds.txt; then \
197                         install $$x $(ASTVARLIBDIR)/sounds ; \
198                 else \
199                         echo "No description for $$x"; \
200                         exit 1; \
201                 fi; \
202         done
203         mkdir -p $(ASTVARLIBDIR)/mohmp3
204         mkdir -p $(ASTVARLIBDIR)/images
205         for x in images/*.jpg; do \
206                 install $$x $(ASTVARLIBDIR)/images ; \
207         done
208         mkdir -p $(AGI_DIR)
209
210 update: 
211         @if [ -d CVS ]; then \
212                 echo "Updating from CVS..." ; \
213                 cvs -q update -Pd; \
214                 rm -f .version; \
215         else \
216                 echo "Not CVS";  \
217         fi
218
219 bininstall: all
220         mkdir -p $(MODULES_DIR)
221         mkdir -p $(ASTSBINDIR)
222         mkdir -p $(ASTETCDIR)
223         mkdir -p $(ASTBINDIR)
224         mkdir -p $(ASTSBINDIR)
225         mkdir -p $(ASTVARRUNDIR)
226         install -m 755 asterisk $(ASTSBINDIR)/
227         install -m 755 astgenkey $(ASTSBINDIR)/
228         install -m 755 safe_asterisk $(ASTSBINDIR)/
229         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
230         install -d $(ASTHEADERDIR)
231         install include/asterisk/*.h $(ASTHEADERDIR)
232         rm -f $(ASTVARLIBDIR)/sounds/vm
233         mkdir -p $(ASTSPOOLDIR)/vm
234         rm -f $(ASTMODULESDIR)/chan_ixj.so
235         rm -f $(ASTMODULESDIR)/chan_tor.so
236         mkdir -p $(ASTVARLIBDIR)/sounds
237         mkdir -p $(ASTLOGDIR)/cdr-csv
238         mkdir -p $(ASTVARLIBDIR)/keys
239         install -m 644 keys/iaxtel.pub $(ASTVARLIBDIR)/keys
240         ( cd $(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
241         @echo " +---- Asterisk Installation Complete -------+"  
242         @echo " +                                           +"
243         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
244         @echo " +                                           +"
245         @echo " + Asterisk has successfully been installed. +"  
246         @echo " + If you would like to install the sample   +"  
247         @echo " + configuration files (overwriting any      +"
248         @echo " + existing config files), run:              +"  
249         @echo " +                                           +"
250         @echo " +               $(MAKE) samples                +"
251         @echo " +                                           +"
252         @echo " +-----------------  or ---------------------+"
253         @echo " +                                           +"
254         @echo " + You can go ahead and install the asterisk +"
255         @echo " + program documentation now or later run:   +"
256         @echo " +                                           +"
257         @echo " +              $(MAKE) progdocs                +"
258         @echo " +                                           +"
259         @echo " + **Note** This requires that you have      +"
260         @echo " + doxygen installed on your local system    +"
261         @echo " +-------------------------------------------+"
262
263 install: all datafiles bininstall
264
265 upgrade: all bininstall
266
267 adsi: all
268         mkdir -p $(ASTETCDIR)
269         for x in configs/*.adsi; do \
270                 if ! [ -f $(ASTETCDIRX)/$$x ]; then \
271                         install -m 644 $$x $(ASTETCDIR)/`basename $$x` ; \
272                 fi ; \
273         done
274
275 samples: all datafiles adsi
276         mkdir -p $(ASTETCDIR)
277         for x in configs/*.sample; do \
278                 if [ -f $(ASTETCDIR)/`basename $$x .sample` ]; then \
279                         mv -f $(ASTETCDIR)/`basename $$x .sample` $(ASTETCDIR)/`basename $$x .sample`.old ; \
280                 fi ; \
281                 install $$x $(ASTETCDIR)/`basename $$x .sample` ;\
282         done
283         echo "[directories]" > $(ASTETCDIR)/asterisk.conf
284         echo "astetcdir => $(ASTETCDIR)" >> $(ASTETCDIR)/asterisk.conf
285         echo "astmoddir => $(MODULES_DIR)" >> $(ASTETCDIR)/asterisk.conf
286         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(ASTETCDIR)/asterisk.conf
287         echo "astagidir => $(AGI_DIR)" >> $(ASTETCDIR)/asterisk.conf
288         echo "astspooldir => $(ASTSPOOLDIR)" >> $(ASTETCDIR)/asterisk.conf
289         echo "astrundir => $(ASTVARRUNDIR)" >> $(ASTETCDIR)/asterisk.conf
290         echo "astlogdir => $(ASTLOGDIR)" >> $(ASTETCDIR)/asterisk.conf
291         for x in sounds/demo-*; do \
292                 if grep -q "^%`basename $$x`%" sounds.txt; then \
293                         install $$x $(ASTVARLIBDIR)/sounds ; \
294                 else \
295                         echo "No description for $$x"; \
296                         exit 1; \
297                 fi; \
298         done
299         for x in sounds/*.mp3; do \
300                 install $$x $(ASTVARLIBDIR)/mohmp3 ; \
301         done
302         mkdir -p $(ASTSPOOLDIR)/vm/1234/INBOX
303         :> $(ASTVARLIBDIR)/sounds/vm/1234/unavail.gsm
304         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
305                 cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/vm/1234/unavail.gsm ; \
306         done
307         :> $(ASTVARLIBDIR)/sounds/vm/1234/busy.gsm
308         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
309                 cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/vm/1234/busy.gsm ; \
310         done
311
312 webvmail:
313         @[ -d $(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
314         @[ -d $(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
315         @[ -d $(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
316         install -m 4755 -o root -g root vmail.cgi $(HTTPDIR)/cgi-bin/vmail.cgi
317         mkdir -p $(HTTPDIR)/html/_asterisk
318         for x in images/*.gif; do \
319                 install -m 644 $$x $(HTTPDIR)/html/_asterisk/; \
320         done
321         @echo " +--------- Asterisk Web Voicemail ----------+"  
322         @echo " +                                           +"
323         @echo " + Asterisk Web Voicemail is installed in    +"
324         @echo " + your cgi-bin directory.  IT USES A SETUID +"
325         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
326         @echo " + THAT, UNINSTALL IT!                       +"
327         @echo " +                                           +"
328         @echo " +-------------------------------------------+"  
329
330 mailbox:
331         ./addmailbox 
332         
333
334 rpm: __rpm
335
336 __rpm: _version
337         rm -rf /tmp/asterisk ; \
338         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
339         $(MAKE) INSTALL_PREFIX=/tmp/asterisk install ; \
340         $(MAKE) INSTALL_PREFIX=/tmp/asterisk samples ; \
341         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
342         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
343         cp -f redhat/rpmrc /tmp/asterisk/ ; \
344         cp -f redhat/rpmmacros /tmp/asterisk/ ; \
345         sed "s/Version:/Version: $(RPMVERSION)/g" redhat/asterisk.spec > /tmp/asterisk/asterisk.spec ; \
346         rpm --rcfile /usr/lib/rpm/rpmrc:/tmp/asterisk/rpmrc -bb /tmp/asterisk/asterisk.spec ; \
347         mv /tmp/asterisk/redhat/RPMS/i386/asterisk* ./ ; \
348         rm -rf /tmp/asterisk
349
350 progdocs:
351         doxygen asterisk-ng-doxygen
352
353 config:
354         if [ -d /etc/rc.d/init.d ]; then \
355                 install -m 755 init.asterisk /etc/rc.d/init.d/asterisk; \
356                 /sbin/chkconfig --add asterisk; \
357         elif [ -d /etc/init.d ]; then \
358                 install -m 755 init.asterisk /etc/init.d/asterisk; \
359         fi 
360
361         
362 dont-optimize:
363         $(MAKE) OPTIMIZE= K6OPT= install
364
365 valgrind: dont-optimize
366
367 depend: .depend
368         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
369
370 .depend:
371         ./mkdep ${CFLAGS} `ls *.c`
372