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