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