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