Small Makefile fix for safe_asterisk
[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 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
303         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
304                 install -m 755 contrib/scripts/safe_asterisk $(DESTDIR)$(ASTSBINDIR)/ ;\
305         fi
306         for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
307         install -d $(DESTDIR)$(ASTHEADERDIR)
308         install include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
309         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/vm
310         rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
311         if [ ! -h $(DESTDIR)$(ASTSPOOLDIR)/vm ] && [ -d $(DESTDIR)$(ASTSPOOLDIR)/vm ]; then \
312                 mv $(DESTDIR)$(ASTSPOOLDIR)/vm $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
313         else \
314                 mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
315                 rm -f $(DESTDIR)$(ASTSPOOLDIR)/vm; \
316         fi
317         ln -s $(ASTSPOOLDIR)/voicemail/default $(DESTDIR)$(ASTSPOOLDIR)/vm
318         rm -f $(DESTDIR)$(MODULES_DIR)/chan_ixj.so
319         rm -f $(DESTDIR)$(MODULES_DIR)/chan_tor.so
320         rm -f $(DESTDIR)$(MODULES_DIR)/cdr_mysql.so
321         rm -f $(DESTDIR)$(MODULES_DIR)/cdr_unixodbc.so
322         rm -f $(DESTDIR)$(MODULES_DIR)/codec_mp3_d.so
323         rm -f $(DESTDIR)$(MODULES_DIR)/format_mp3.so
324         rm -f $(DESTDIR)$(MODULES_DIR)/app_voicemail2.so
325         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
326         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
327         mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
328         install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
329         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
330         ( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
331         @echo " +---- Asterisk Installation Complete -------+"  
332         @echo " +                                           +"
333         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
334         @echo " +                                           +"
335         @echo " + Asterisk has successfully been installed. +"  
336         @echo " + If you would like to install the sample   +"  
337         @echo " + configuration files (overwriting any      +"
338         @echo " + existing config files), run:              +"  
339         @echo " +                                           +"
340         @echo " +               $(MAKE) samples                +"
341         @echo " +                                           +"
342         @echo " +-----------------  or ---------------------+"
343         @echo " +                                           +"
344         @echo " + You can go ahead and install the asterisk +"
345         @echo " + program documentation now or later run:   +"
346         @echo " +                                           +"
347         @echo " +              $(MAKE) progdocs                +"
348         @echo " +                                           +"
349         @echo " + **Note** This requires that you have      +"
350         @echo " + doxygen installed on your local system    +"
351         @echo " +-------------------------------------------+"
352
353 install: all datafiles bininstall
354
355 upgrade: all bininstall
356
357 adsi: all
358         mkdir -p $(DESTDIR)$(ASTETCDIR)
359         for x in configs/*.adsi; do \
360                 if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
361                         install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
362                 fi ; \
363         done
364
365 samples: all datafiles adsi
366         mkdir -p $(DESTDIR)$(ASTETCDIR)
367         for x in configs/*.sample; do \
368                 if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
369                         mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
370                 fi ; \
371                 install $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
372         done
373         echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf
374         echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
375         echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
376         echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
377         echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
378         echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
379         echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
380         echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
381         for x in sounds/demo-*; do \
382                 if grep -q "^%`basename $$x`%" sounds.txt; then \
383                         install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
384                 else \
385                         echo "No description for $$x"; \
386                         exit 1; \
387                 fi; \
388         done
389         for x in sounds/*.mp3; do \
390                 install $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
391         done
392         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
393         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
394         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
395                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
396         done
397         :> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
398         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
399                 cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
400         done
401
402 webvmail:
403         @[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
404         @[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
405         @[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
406         install -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
407         mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
408         for x in images/*.gif; do \
409                 install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
410         done
411         @echo " +--------- Asterisk Web Voicemail ----------+"  
412         @echo " +                                           +"
413         @echo " + Asterisk Web Voicemail is installed in    +"
414         @echo " + your cgi-bin directory.  IT USES A SETUID +"
415         @echo " + ROOT PERL SCRIPT, SO IF YOU DON'T LIKE    +"
416         @echo " + THAT, UNINSTALL IT!                       +"
417         @echo " +                                           +"
418         @echo " +-------------------------------------------+"  
419
420 mailbox:
421         ./contrib/scripts/addmailbox 
422         
423
424 rpm: __rpm
425
426 __rpm: _version
427         rm -rf /tmp/asterisk ; \
428         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
429         $(MAKE) DESTDIR=/tmp/asterisk install ; \
430         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
431         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
432         cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
433         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
434         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
435         
436 progdocs:
437         doxygen contrib/asterisk-ng-doxygen
438
439 config:
440         if [ -d /etc/rc.d/init.d ]; then \
441                 install -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
442                 /sbin/chkconfig --add asterisk; \
443         elif [ -d /etc/init.d ]; then \
444                 install -m 755 init.asterisk /etc/init.d/asterisk; \
445         fi 
446
447         
448 dont-optimize:
449         $(MAKE) OPTIMIZE= K6OPT= install
450
451 valgrind: dont-optimize
452
453 depend: .depend
454         for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done
455
456 .depend:
457         ./mkdep ${CFLAGS} `ls *.c`
458
459 FORCE: