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