Adding INCLUDE statement per Bug #672
[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 # Create OPTIONS variable
17 OPTIONS=
18
19 OSARCH=$(shell uname -s)
20
21 ifeq (${OSARCH},Linux)
22 PROC=$(shell uname -m)
23 else
24 ifeq (${OSARCH},FreeBSD)
25 PROC=$(shell uname -m)
26 endif
27 endif
28 # Pentium Pro Optimize
29 #PROC=i686
30
31 # Pentium & VIA processors optimize
32 #PROC=i586
33
34 #PROC=k6
35 #PROC=ppc
36
37 PWD=$(shell pwd)
38
39 ######### More GSM codec optimization
40 ######### Uncomment to enable MMXTM optimizations for x86 architecture CPU's
41 ######### which support MMX instructions.  This should be newer pentiums,
42 ######### ppro's, etc, as well as the AMD K6 and K7.  
43 #K6OPT  = -DK6OPT
44
45 #Tell gcc to optimize the asterisk's code
46 OPTIMIZE=-O6
47
48 #Include debug symbols in the executables (-g) and profiling info (-pg)
49 DEBUG=-g #-pg
50
51 # New hangup routines for chan_zap.c
52 # If this flag is uncommented then you need to have new libpri code in your system
53 # You can still use the old libpri if you do "cvs update -D "08/03/03" in libpri source code
54 OPTIONS += -DNEW_PRI_HANGUP
55
56 # Optional debugging parameters
57 DEBUG_THREADS = #-DDEBUG_THREADS #-DDO_CRASH 
58
59 # Uncomment next one to enable ast_frame tracing (for debugging)
60 TRACE_FRAMES = #-DTRACE_FRAMES
61
62 # Uncomment next one to enable malloc debugging
63 # You can view malloc debugging with:
64 #   *CLI> show memory allocations [filename]
65 #   *CLI> show memory summary [filename]
66 #
67 MALLOC_DEBUG = #-include $(PWD)/include/asterisk/astmm.h
68
69 # Where to install asterisk after compiling
70 # Default -> leave empty
71 INSTALL_PREFIX=
72
73 # Staging directory
74 # Files are copied here temporarily during the install process
75 # For example, make DESTDIR=/tmp/asterisk woud put things in
76 # /tmp/asterisk/etc/asterisk
77 DESTDIR=
78
79 # Original busydetect routine
80 BUSYDETECT = #-DBUSYDETECT
81
82 # Improved busydetect routine, comment the previous one if you use this one
83 BUSYDETECT+= -DBUSYDETECT_MARTIN 
84 # Detect the busy signal looking only at tone lengths
85 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
86 BUSYDETECT+= #-DBUSYDETECT_TONEONLY
87 # Inforce the detection of busy singal (get rid of false hangups)
88 # Don't use together with -DBUSYDETECT_TONEONLY
89 BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
90
91 ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
92 ASTVARLIBDIR=$(INSTALL_PREFIX)/var/lib/asterisk
93 ASTETCDIR=$(INSTALL_PREFIX)/etc/asterisk
94 ASTSPOOLDIR=$(INSTALL_PREFIX)/var/spool/asterisk
95 ASTLOGDIR=$(INSTALL_PREFIX)/var/log/asterisk
96 ASTHEADERDIR=$(INSTALL_PREFIX)/usr/include/asterisk
97 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
98 ASTBINDIR=$(INSTALL_PREFIX)/usr/bin
99 ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
100 ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
101
102 MODULES_DIR=$(ASTLIBDIR)/modules
103 AGI_DIR=$(ASTVARLIBDIR)/agi-bin
104
105 INCLUDE=-Iinclude -I../include
106 CFLAGS=-pipe  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
107 CFLAGS+=$(OPTIMIZE)
108 CFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
109 CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
110 ifeq (${OSARCH},FreeBSD)
111 CFLAGS+=-pthread
112 INCLUDE+=-I/usr/local/include
113 endif
114 ifeq (${OSARCH},OpenBSD)
115 CFLAGS+=-pthread
116 endif
117
118 CFLAGS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "-DZAPTEL_OPTIMIZATIONS"; fi)
119
120 LIBEDIT=editline/libedit.a
121
122 ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; else if [ -d CVS ]; then echo "CVS-`date +"%D-%T"`"; fi; fi)
123 HTTPDIR=$(shell if [ -d /var/www ]; then echo "/var/www"; else echo "/home/httpd"; fi)
124 RPMVERSION=$(shell if [ -f .version ]; then sed 's/[-\/:]/_/g' .version; else echo "unknown" ; fi)
125 CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\"
126 CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\"
127 CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\"
128 CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\"
129 CFLAGS+=-DASTVARLIBDIR=\"$(ASTVARLIBDIR)\"
130 CFLAGS+=-DASTVARRUNDIR=\"$(ASTVARRUNDIR)\"
131 CFLAGS+=-DASTSPOOLDIR=\"$(ASTSPOOLDIR)\"
132 CFLAGS+=-DASTLOGDIR=\"$(ASTLOGDIR)\"
133 CFLAGS+=-DASTCONFPATH=\"$(ASTCONFPATH)\"
134 CFLAGS+=-DASTMODDIR=\"$(MODULES_DIR)\"
135 CFLAGS+=-DASTAGIDIR=\"$(AGI_DIR)\"
136
137 CFLAGS+= $(DEBUG_THREADS)
138 CFLAGS+= $(TRACE_FRAMES)
139 CFLAGS+= $(MALLOC_DEBUG)
140 CFLAGS+= $(BUSYDETECT)
141 CFLAGS+= $(OPTIONS)
142 CFLAGS+=# -fomit-frame-pointer 
143 SUBDIRS=res channels pbx apps codecs formats agi cdr astman stdtime
144 ifeq (${OSARCH},Linux)
145 LIBS=-ldl -lpthread
146 endif
147 ifeq (${OSARCH},OpenBSD)
148 LIBS=-pthread
149 else
150 ifeq (${OSARCH},FreeBSD)
151 LIBS=-pthread
152 else
153 endif
154 endif
155 LIBS+=-lncurses -lm
156 ifeq (${OSARCH},Linux)
157 LIBS+=-lresolv  #-lnjamd
158 endif
159 ifeq (${OSARCH},Darwin)
160 ifeq ($(shell uname -r),7.0.0)
161 LIBS+=-lresolv
162 endif
163 endif
164 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
165         translate.o file.o say.o pbx.o cli.o md5.o term.o \
166         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
167         cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
168         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
169         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o
170 ifeq (${OSARCH},Darwin)
171 OBJS+=poll.o dlfcn.o
172 ASTLINK=-Wl,-dynamic
173 SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
174 else
175 ASTLINK=-Wl,-E 
176 SOLINK=-shared -Xlinker -x
177 endif
178
179 CC=gcc
180 INSTALL=install
181
182 _all: all
183         @echo " +--------- Asterisk Build Complete ---------+"  
184         @echo " + Asterisk has successfully been built, but +"  
185         @echo " + cannot be run before being installed by   +"  
186         @echo " + running:                                  +"  
187         @echo " +                                           +"
188         @echo " +               $(MAKE) install                +"  
189         @echo " +-------------------------------------------+"  
190
191 all: depend asterisk subdirs
192
193 editline/config.h:
194         cd editline && unset CFLAGS LIBS && ./configure ; \
195
196 editline/libedit.a: FORCE
197         cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
198         $(MAKE) -C editline libedit.a
199
200 db1-ast/libdb1.a: FORCE
201         @if [ -d db1-ast ]; then \
202                 $(MAKE) -C db1-ast libdb1.a ; \
203         else \
204                 echo "You need to do a cvs update -d not just cvs update"; \
205                 exit 1; \
206         fi
207
208 ifneq ($(wildcard .depend),)
209 include .depend
210 endif
211
212 .PHONY: _version
213
214 _version: 
215         if [ -d CVS ] && ! [ -f .version ]; then echo $(ASTERISKVERSION) > .version; fi 
216
217 .version: _version
218
219 .y.c:
220         bison $< --name-prefix=ast_yy -o $@
221
222 ast_expr.o: ast_expr.c
223
224 cli.o: cli.c build.h
225
226 asterisk.o: asterisk.c build.h
227
228 ifneq ($(strip $(ASTERISKVERSION)),)
229 build.h: .version
230         ./make_build_h
231 else
232 build.h:
233         ./make_build_h
234 endif
235
236 stdtime/libtime.a: FORCE
237         @if [ -d stdtime ]; then \
238                 $(MAKE) -C stdtime libtime.a ; \
239         else \
240                 echo "You need to do a cvs update -d not just cvs update"; \
241                 exit 1; \
242         fi
243
244 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
245         $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a
246
247 subdirs: 
248         for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
249
250 clean:
251         for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
252         rm -f *.o *.so asterisk .depend
253         rm -f build.h 
254         rm -f ast_expr.c
255         @if [ -e editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
256         $(MAKE) -C db1-ast clean
257         $(MAKE) -C stdtime clean
258
259 datafiles: all
260         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
261         for x in sounds/digits/*.gsm; do \
262                 if grep -q "^%`basename $$x`%" sounds.txt; then \
263                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
264                 else \
265                         echo "No description for $$x"; \
266                         exit 1; \
267                 fi; \
268         done
269         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 \
270                 if grep -q "^%`basename $$x`%" sounds.txt; then \
271                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
272                 else \
273                         echo "No description for $$x"; \
274                         exit 1; \
275                 fi; \
276         done
277         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
278         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
279         for x in images/*.jpg; do \
280                 install $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
281         done
282         mkdir -p $(DESTDIR)$(AGI_DIR)
283
284 update: 
285         @if [ -d CVS ]; then \
286                 echo "Updating from CVS..." ; \
287                 cvs -q update -Pd; \
288                 rm -f .version; \
289         else \
290                 echo "Not CVS";  \
291         fi
292
293 bininstall: all
294         mkdir -p $(DESTDIR)$(MODULES_DIR)
295         mkdir -p $(DESTDIR)$(ASTSBINDIR)
296         mkdir -p $(DESTDIR)$(ASTETCDIR)
297         mkdir -p $(DESTDIR)$(ASTBINDIR)
298         mkdir -p $(DESTDIR)$(ASTSBINDIR)
299         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
300         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
301         install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
302         install -m 755 astgenkey $(DESTDIR)$(ASTSBINDIR)/
303         install -m 755 safe_asterisk $(DESTDIR)$(ASTSBINDIR)/
304         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
305         install -d $(DESTDIR)$(ASTHEADERDIR)
306         install include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
307         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/vm
308         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
309         if [ ! -h $(DESTDIR)$(ASTSPOOLDIR)/vm ] && [ -d $(DESTDIR)$(ASTSPOOLDIR)/vm ]; then \
310                 mv $(DESTDIR)$(ASTSPOOLDIR)/vm $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
311         else \
312                 mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
313                 rm -f $(DESTDIR)$(ASTSPOOLDIR)/vm; \
314         fi
315         ln -s $(ASTSPOOLDIR)/voicemail/default $(DESTDIR)$(ASTSPOOLDIR)/vm
316         rm -f $(DESTDIR)$(MODULES_DIR)/chan_ixj.so
317         rm -f $(DESTDIR)$(MODULES_DIR)/chan_tor.so
318         rm -f $(DESTDIR)$(MODULES_DIR)/cdr_mysql.so
319         rm -f $(DESTDIR)$(MODULES_DIR)/cdr_unixodbc.so
320         rm -f $(DESTDIR)$(MODULES_DIR)/codec_mp3_d.so
321         rm -f $(DESTDIR)$(MODULES_DIR)/format_mp3.so
322         rm -f $(DESTDIR)$(MODULES_DIR)/app_voicemail2.so
323         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
324         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
325         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
326         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
327         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
328         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
329         @echo " +---- Asterisk Installation Complete -------+"  
330         @echo " +                                           +"
331         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
332         @echo " +                                           +"
333         @echo " + Asterisk has successfully been installed. +"  
334         @echo " + If you would like to install the sample   +"  
335         @echo " + configuration files (overwriting any      +"
336         @echo " + existing config files), run:              +"  
337         @echo " +                                           +"
338         @echo " +               $(MAKE) samples                +"
339         @echo " +                                           +"
340         @echo " +-----------------  or ---------------------+"
341         @echo " +                                           +"
342         @echo " + You can go ahead and install the asterisk +"
343         @echo " + program documentation now or later run:   +"
344         @echo " +                                           +"
345         @echo " +              $(MAKE) progdocs                +"
346         @echo " +                                           +"
347         @echo " + **Note** This requires that you have      +"
348         @echo " + doxygen installed on your local system    +"
349         @echo " +-------------------------------------------+"
350
351 install: all datafiles bininstall
352
353 upgrade: all bininstall
354
355 adsi: all
356         mkdir -p $(DESTDIR)$(ASTETCDIR)
357         for x in configs/*.adsi; do \
358                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
359                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
360                 fi ; \
361         done
362
363 samples: all datafiles adsi
364         mkdir -p $(DESTDIR)$(ASTETCDIR)
365         for x in configs/*.sample; do \
366                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
367                         mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
368                 fi ; \
369                 install $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
370         done
371         echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf
372         echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
373         echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
374         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
375         echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
376         echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
377         echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
378         echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
379         for x in sounds/demo-*; do \
380                 if grep -q "^%`basename $$x`%" sounds.txt; then \
381                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
382                 else \
383                         echo "No description for $$x"; \
384                         exit 1; \
385                 fi; \
386         done
387         for x in sounds/*.mp3; do \
388                 install $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
389         done
390         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
391         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm
392         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
393                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm ; \
394         done
395         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
396         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
397                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm ; \
398         done
399
400 webvmail:
401         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
402         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
403         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
404         install -m 4755 -o root -g root vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
405         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
406         for x in images/*.gif; do \
407                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
408         done
409         @echo " +--------- Asterisk Web Voicemail ----------+"  
410         @echo " +                                           +"
411         @echo " + Asterisk Web Voicemail is installed in    +"
412         @echo " + your cgi-bin directory.  IT USES A SETUID +"
413         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
414         @echo " + THAT, UNINSTALL IT!                       +"
415         @echo " +                                           +"
416         @echo " +-------------------------------------------+"  
417
418 mailbox:
419         ./addmailbox 
420         
421
422 rpm: __rpm
423
424 __rpm: _version
425         rm -rf /tmp/asterisk ; \
426         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
427         $(MAKE) DESTDIR=/tmp/asterisk install ; \
428         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
429         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
430         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
431         cp -f redhat/rpmrc /tmp/asterisk/ ; \
432         cp -f redhat/rpmmacros /tmp/asterisk/ ; \
433         sed "s/Version:/Version: $(RPMVERSION)/g" redhat/asterisk.spec > /tmp/asterisk/asterisk.spec ; \
434         rpm --rcfile /usr/lib/rpm/rpmrc:/tmp/asterisk/rpmrc -bb /tmp/asterisk/asterisk.spec ; \
435         mv /tmp/asterisk/redhat/RPMS/i386/asterisk* ./ ; \
436         rm -rf /tmp/asterisk
437
438 progdocs:
439         doxygen asterisk-ng-doxygen
440
441 config:
442         if [ -d /etc/rc.d/init.d ]; then \
443                 install -m 755 init.asterisk /etc/rc.d/init.d/asterisk; \
444                 /sbin/chkconfig --add asterisk; \
445         elif [ -d /etc/init.d ]; then \
446                 install -m 755 init.asterisk /etc/init.d/asterisk; \
447         fi 
448
449         
450 dont-optimize:
451         $(MAKE) OPTIMIZE= K6OPT= install
452
453 valgrind: dont-optimize
454
455 depend: .depend
456         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
457
458 .depend:
459         ./mkdep ${CFLAGS} `ls *.c`
460
461 FORCE: