84603fdaa91e82def662c9326de9db4c86fe6d4e
[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 #CFLAGS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
83
84 LIBEDIT=editline/libedit.a
85
86 ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; fi)
87 HTTPDIR=$(shell if [ -d /var/www ]; then echo "/var/www"; else echo "/home/httpd"; fi)
88 RPMVERSION=$(shell if [ -f .version ]; then sed 's/[-\/:]/_/g' .version; else echo "unknown" ; fi)
89 CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\"
90 CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
91 CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\"
92 CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\"
93 CFLAGS+=-DASTVARLIBDIR=\"$(ASTVARLIBDIR)\"
94 CFLAGS+=-DASTVARRUNDIR=\"$(ASTVARRUNDIR)\"
95 CFLAGS+=-DASTSPOOLDIR=\"$(ASTSPOOLDIR)\"
96 CFLAGS+=-DASTLOGDIR=\"$(ASTLOGDIR)\"
97 CFLAGS+=-DASTCONFPATH=\"$(ASTCONFPATH)\"
98 CFLAGS+=-DASTMODDIR=\"$(MODULES_DIR)\"
99 CFLAGS+=-DASTAGIDIR=\"$(AGI_DIR)\"
100
101 CFLAGS+= $(DEBUG_THREADS)
102 CFLAGS+= $(TRACE_FRAMES)
103 CFLAGS+= $(MALLOC_DEBUG)
104 CFLAGS+=# -fomit-frame-pointer 
105 SUBDIRS=res channels pbx apps codecs formats agi cdr astman
106 ifeq (${OSARCH},Linux)
107 LIBS=-ldl
108 endif
109 LIBS+=-lpthread -lncurses -lm -lresolv  #-lnjamd
110 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
111         translate.o file.o say.o pbx.o cli.o md5.o term.o \
112         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
113         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
114         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
115         astmm.o enum.o
116 CC=gcc
117 INSTALL=install
118
119 _all: all
120         @echo " +--------- Asterisk Build Complete ---------+"  
121         @echo " + Asterisk has successfully been built, but +"  
122         @echo " + cannot be run before being installed by   +"  
123         @echo " + running:                                  +"  
124         @echo " +                                           +"
125         @echo " +               $(MAKE) install                +"  
126         @echo " +-------------------------------------------+"  
127
128 all: depend asterisk subdirs
129
130 editline/config.h:
131         @if [ -d editline ]; then \
132                 cd editline && unset CFLAGS LIBS && ./configure ; \
133         else \
134                 echo "You need to do a cvs update -d not just cvs update"; \
135                 exit 1; \
136         fi
137
138 editline/libedit.a: editline/config.h
139         $(MAKE) -C editline libedit.a
140
141 db1-ast/libdb1.a: 
142         @if [ -d db1-ast ]; then \
143                 $(MAKE) -C db1-ast libdb1.a ; \
144         else \
145                 echo "You need to do a cvs update -d not just cvs update"; \
146                 exit 1; \
147         fi
148
149 include .depend
150
151 _version: 
152         if [ -d CVS ] && ! [ -f .version ]; then echo "CVS-`date +"%D-%T"`" > .version; fi 
153
154 .version: _version
155
156 .y.c:
157         bison $< --name-prefix=ast_yy -o $@
158
159 ast_expr.o: ast_expr.c
160
161 cli.o: cli.c build.h
162
163 ifneq ($(strip $(ASTERISKVERSION)),)
164 asterisk.o: asterisk.c .version
165
166 build.h: .version
167         ./make_build_h
168 else
169 build.h:
170         ./make_build_h
171 endif
172
173 asterisk: .version build.h editline/libedit.a db1-ast/libdb1.a $(OBJS)
174         gcc $(DEBUG) -o asterisk -rdynamic $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a
175
176 subdirs: 
177         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
178
179 clean:
180         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
181         rm -f *.o *.so asterisk .depend
182         rm -f build.h 
183         rm -f ast_expr.c
184         @if [ -e editline/Makefile ]; then $(MAKE) -C editline clean ; fi
185         $(MAKE) -C db1-ast clean
186
187 datafiles: all
188         mkdir -p $(ASTVARLIBDIR)/sounds/digits
189         for x in sounds/digits/*.gsm; do \
190                 if grep -q "^%`basename $$x`%" sounds.txt; then \
191                         install $$x $(ASTVARLIBDIR)/sounds/digits ; \
192                 else \
193                         echo "No description for $$x"; \
194                         exit 1; \
195                 fi; \
196         done
197         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 \
198                 if grep -q "^%`basename $$x`%" sounds.txt; then \
199                         install $$x $(ASTVARLIBDIR)/sounds ; \
200                 else \
201                         echo "No description for $$x"; \
202                         exit 1; \
203                 fi; \
204         done
205         mkdir -p $(ASTVARLIBDIR)/mohmp3
206         mkdir -p $(ASTVARLIBDIR)/images
207         for x in images/*.jpg; do \
208                 install $$x $(ASTVARLIBDIR)/images ; \
209         done
210         mkdir -p $(AGI_DIR)
211
212 update: 
213         @if [ -d CVS ]; then \
214                 echo "Updating from CVS..." ; \
215                 cvs -q update -Pd; \
216                 rm -f .version; \
217         else \
218                 echo "Not CVS";  \
219         fi
220
221 bininstall: all
222         mkdir -p $(MODULES_DIR)
223         mkdir -p $(ASTSBINDIR)
224         mkdir -p $(ASTETCDIR)
225         mkdir -p $(ASTBINDIR)
226         mkdir -p $(ASTSBINDIR)
227         mkdir -p $(ASTVARRUNDIR)
228         mkdir -p $(ASTSPOOLDIR)/voicemail
229         install -m 755 asterisk $(ASTSBINDIR)/
230         install -m 755 astgenkey $(ASTSBINDIR)/
231         install -m 755 safe_asterisk $(ASTSBINDIR)/
232         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
233         install -d $(ASTHEADERDIR)
234         install include/asterisk/*.h $(ASTHEADERDIR)
235         rm -f $(ASTVARLIBDIR)/sounds/vm
236         rm -f $(ASTVARLIBDIR)/sounds/voicemail
237         if [ ! -h $(ASTSPOOLDIR)/vm ] && [ -d $(ASTSPOOLDIR)/vm ]; then \
238                 mv $(ASTSPOOLDIR)/vm $(ASTSPOOLDIR)/voicemail/default; \
239         else \
240                 mkdir -p $(ASTSPOOLDIR)/voicemail/default; \
241                 rm -f $(ASTSPOOLDIR)/vm; \
242         fi
243         ln -s $(ASTSPOOLDIR)/voicemail/default $(ASTSPOOLDIR)/vm
244         rm -f $(ASTMODULESDIR)/chan_ixj.so
245         rm -f $(ASTMODULESDIR)/chan_tor.so
246         mkdir -p $(ASTVARLIBDIR)/sounds
247         mkdir -p $(ASTLOGDIR)/cdr-csv
248         mkdir -p $(ASTVARLIBDIR)/keys
249         install -m 644 keys/iaxtel.pub $(ASTVARLIBDIR)/keys
250         ( cd $(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
251         ( cd $(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
252         @echo " +---- Asterisk Installation Complete -------+"  
253         @echo " +                                           +"
254         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
255         @echo " +                                           +"
256         @echo " + Asterisk has successfully been installed. +"  
257         @echo " + If you would like to install the sample   +"  
258         @echo " + configuration files (overwriting any      +"
259         @echo " + existing config files), run:              +"  
260         @echo " +                                           +"
261         @echo " +               $(MAKE) samples                +"
262         @echo " +                                           +"
263         @echo " +-----------------  or ---------------------+"
264         @echo " +                                           +"
265         @echo " + You can go ahead and install the asterisk +"
266         @echo " + program documentation now or later run:   +"
267         @echo " +                                           +"
268         @echo " +              $(MAKE) progdocs                +"
269         @echo " +                                           +"
270         @echo " + **Note** This requires that you have      +"
271         @echo " + doxygen installed on your local system    +"
272         @echo " +-------------------------------------------+"
273
274 install: all datafiles bininstall
275
276 upgrade: all bininstall
277
278 adsi: all
279         mkdir -p $(ASTETCDIR)
280         for x in configs/*.adsi; do \
281                 if ! [ -f $(ASTETCDIRX)/$$x ]; then \
282                         install -m 644 $$x $(ASTETCDIR)/`basename $$x` ; \
283                 fi ; \
284         done
285
286 samples: all datafiles adsi
287         mkdir -p $(ASTETCDIR)
288         for x in configs/*.sample; do \
289                 if [ -f $(ASTETCDIR)/`basename $$x .sample` ]; then \
290                         mv -f $(ASTETCDIR)/`basename $$x .sample` $(ASTETCDIR)/`basename $$x .sample`.old ; \
291                 fi ; \
292                 install $$x $(ASTETCDIR)/`basename $$x .sample` ;\
293         done
294         echo "[directories]" > $(ASTETCDIR)/asterisk.conf
295         echo "astetcdir => $(ASTETCDIR)" >> $(ASTETCDIR)/asterisk.conf
296         echo "astmoddir => $(MODULES_DIR)" >> $(ASTETCDIR)/asterisk.conf
297         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(ASTETCDIR)/asterisk.conf
298         echo "astagidir => $(AGI_DIR)" >> $(ASTETCDIR)/asterisk.conf
299         echo "astspooldir => $(ASTSPOOLDIR)" >> $(ASTETCDIR)/asterisk.conf
300         echo "astrundir => $(ASTVARRUNDIR)" >> $(ASTETCDIR)/asterisk.conf
301         echo "astlogdir => $(ASTLOGDIR)" >> $(ASTETCDIR)/asterisk.conf
302         for x in sounds/demo-*; do \
303                 if grep -q "^%`basename $$x`%" sounds.txt; then \
304                         install $$x $(ASTVARLIBDIR)/sounds ; \
305                 else \
306                         echo "No description for $$x"; \
307                         exit 1; \
308                 fi; \
309         done
310         for x in sounds/*.mp3; do \
311                 install $$x $(ASTVARLIBDIR)/mohmp3 ; \
312         done
313         mkdir -p $(ASTSPOOLDIR)/voicemail/default/1234/INBOX
314         :> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm
315         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
316                 cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm ; \
317         done
318         :> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
319         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
320                 cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm ; \
321         done
322
323 webvmail:
324         @[ -d $(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
325         @[ -d $(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
326         @[ -d $(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
327         install -m 4755 -o root -g root vmail.cgi $(HTTPDIR)/cgi-bin/vmail.cgi
328         mkdir -p $(HTTPDIR)/html/_asterisk
329         for x in images/*.gif; do \
330                 install -m 644 $$x $(HTTPDIR)/html/_asterisk/; \
331         done
332         @echo " +--------- Asterisk Web Voicemail ----------+"  
333         @echo " +                                           +"
334         @echo " + Asterisk Web Voicemail is installed in    +"
335         @echo " + your cgi-bin directory.  IT USES A SETUID +"
336         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
337         @echo " + THAT, UNINSTALL IT!                       +"
338         @echo " +                                           +"
339         @echo " +-------------------------------------------+"  
340
341 mailbox:
342         ./addmailbox 
343         
344
345 rpm: __rpm
346
347 __rpm: _version
348         rm -rf /tmp/asterisk ; \
349         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
350         $(MAKE) INSTALL_PREFIX=/tmp/asterisk install ; \
351         $(MAKE) INSTALL_PREFIX=/tmp/asterisk samples ; \
352         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
353         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
354         cp -f redhat/rpmrc /tmp/asterisk/ ; \
355         cp -f redhat/rpmmacros /tmp/asterisk/ ; \
356         sed "s/Version:/Version: $(RPMVERSION)/g" redhat/asterisk.spec > /tmp/asterisk/asterisk.spec ; \
357         rpm --rcfile /usr/lib/rpm/rpmrc:/tmp/asterisk/rpmrc -bb /tmp/asterisk/asterisk.spec ; \
358         mv /tmp/asterisk/redhat/RPMS/i386/asterisk* ./ ; \
359         rm -rf /tmp/asterisk
360
361 progdocs:
362         doxygen asterisk-ng-doxygen
363
364 config:
365         if [ -d /etc/rc.d/init.d ]; then \
366                 install -m 755 init.asterisk /etc/rc.d/init.d/asterisk; \
367                 /sbin/chkconfig --add asterisk; \
368         elif [ -d /etc/init.d ]; then \
369                 install -m 755 init.asterisk /etc/init.d/asterisk; \
370         fi 
371
372         
373 dont-optimize:
374         $(MAKE) OPTIMIZE= K6OPT= install
375
376 valgrind: dont-optimize
377
378 depend: .depend
379         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
380
381 .depend:
382         ./mkdep ${CFLAGS} `ls *.c`
383