get rid of another annoying stray space in the gcc commands
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999-2006, Digium, Inc.
7 #
8 # Mark Spencer <markster@digium.com>
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 .PHONY: sounds clean clean-depend dist-clean all
17
18 # Create OPTIONS variable
19 OPTIONS=
20
21 # If cross compiling, define these to suit
22 #CROSS_COMPILE=/opt/montavista/pro/devkit/arm/xscale_be/bin/xscale_be-
23 #CROSS_COMPILE_BIN=/opt/montavista/pro/devkit/arm/xscale_be/bin/
24 #CROSS_COMPILE_TARGET=/opt/montavista/pro/devkit/arm/xscale_be/target
25 #CROSS_ARCH=Linux
26 #CROSS_PROC=arm
27 #SUB_PROC=xscale # or maverick
28
29 ifeq ($(CROSS_COMPILE),)
30   OSARCH=$(shell uname -s)
31   PROC?=$(shell uname -m)
32 else
33   OSARCH=$(CROSS_ARCH)
34   PROC=$(CROSS_PROC)
35 endif
36
37 PWD=$(shell pwd)
38
39 # Remember the MAKELEVEL at the top
40 MAKETOPLEVEL?=$(MAKELEVEL)
41
42 # Overwite config files on "make samples"
43 OVERWRITE=y
44
45 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
46 DEBUG=-g3
47
48 # Staging directory
49 # Files are copied here temporarily during the install process
50 # For example, make DESTDIR=/tmp/asterisk woud put things in
51 # /tmp/asterisk/etc/asterisk
52 # !!! Watch out, put no spaces or comments after the value !!!
53 DESTDIR?=
54 #DESTDIR?=/tmp/asterisk
55
56 # Original busydetect routine
57 #BUSYDETECT = -DBUSYDETECT
58
59 # Improved busydetect routine, comment the previous one if you use this one
60 #BUSYDETECT+= -DBUSYDETECT_MARTIN 
61 # Detect the busy signal looking only at tone lengths
62 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
63 #BUSYDETECT+= -DBUSYDETECT_TONEONLY
64 # Enforce the detection of busy signal (get rid of false hangups)
65 # Don't use together with -DBUSYDETECT_TONEONLY
66 #BUSYDETECT+= -DBUSYDETECT_COMPARE_TONE_AND_SILENCE
67
68 # Define standard directories for various platforms
69 # These apply if they are not redefined in asterisk.conf 
70 ifeq ($(OSARCH),SunOS)
71   ASTETCDIR=/etc/opt/asterisk
72   ASTLIBDIR=/opt/asterisk/lib
73   ASTVARLIBDIR=/var/opt/asterisk/lib
74   ASTSPOOLDIR=/var/opt/asterisk/spool
75   ASTLOGDIR=/var/opt/asterisk/log
76   ASTHEADERDIR=/opt/asterisk/usr/include/asterisk
77   ASTBINDIR=/opt/asterisk/usr/bin
78   ASTSBINDIR=/opt/asterisk/usr/sbin
79   ASTVARRUNDIR=/var/opt/asterisk/run
80   ASTMANDIR=/opt/asterisk/usr/share/man
81 else
82   ASTETCDIR=$(sysconfdir)/asterisk
83   ASTLIBDIR=$(libdir)/asterisk
84   ASTHEADERDIR=$(includedir)/asterisk
85   ASTBINDIR=$(bindir)
86   ASTSBINDIR=$(sbindir)
87   ASTSPOOLDIR=$(localstatedir)/spool/asterisk
88   ASTLOGDIR=$(localstatedir)/log/asterisk
89   ASTVARRUNDIR=$(localstatedir)/run
90   ASTMANDIR=$(mandir)
91 ifeq ($(OSARCH),FreeBSD)
92   ASTVARLIBDIR=$(prefix)/share/asterisk
93 else
94   ASTVARLIBDIR=$(localstatedir)/lib/asterisk
95 endif
96 endif
97 ASTDATADIR?=$(ASTVARLIBDIR)
98
99 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
100 # when starting Asterisk
101 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
102 MODULES_DIR=$(ASTLIBDIR)/modules
103 AGI_DIR=$(ASTDATADIR)/agi-bin
104
105 # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file
106 HTTP_DOCSDIR=/var/www/html
107 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
108 HTTP_CGIDIR=/var/www/cgi-bin
109
110 ASTCFLAGS=
111
112 # Uncomment this to use the older DSP routines
113 #ASTCFLAGS+=-DOLD_DSP_ROUTINES
114
115 # If the file .asterisk.makeopts is present in your home directory, you can
116 # include all of your favorite menuselect options so that every time you download
117 # a new version of Asterisk, you don't have to run menuselect to set them. 
118 # The file /etc/asterisk.makeopts will also be included but can be overridden
119 # by the file in your home directory.
120
121 GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
122 USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
123
124 ifneq ($(wildcard menuselect.makeopts),)
125   include menuselect.makeopts
126 endif
127
128 ifneq ($(wildcard makeopts),)
129   include makeopts
130 endif
131
132 TOPDIR_CFLAGS=-Iinclude
133 MOD_SUBDIR_CFLAGS=-I../include -I..
134 OTHER_SUBDIR_CFLAGS=-I../include -I..
135
136 ifeq ($(or $(findstring dont-optimize,$(MAKECMDGOALS)),$(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))),)
137 # More GSM codec optimization
138 # Uncomment to enable MMXTM optimizations for x86 architecture CPU's
139 # which support MMX instructions.  This should be newer pentiums,
140 # ppro's, etc, as well as the AMD K6 and K7.  
141 #K6OPT  = -DK6OPT
142
143 # Tell gcc to optimize the code
144 OPTIMIZE+=-O6
145 else
146   # Stack backtraces, while useful for debugging, are incompatible with optimizations
147   ifeq ($(OSARCH),Linux)
148     CFLAGS+=-DSTACK_BACKTRACES
149   endif
150 endif
151
152 #   *CLI> show memory allocations [filename]
153 #   *CLI> show memory summary [filename]
154 ifneq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),)
155   TOPDIR_CFLAGS+=-include include/asterisk/astmm.h
156   MOD_SUBDIR_CFLAGS+=-include ../include/asterisk/astmm.h
157 endif
158
159 MOD_SUBDIR_CFLAGS+=-fPIC
160
161 ifeq ($(OSARCH),Linux)
162   ifeq ($(PROC),x86_64)
163     # You must have GCC 3.4 to use k8, otherwise use athlon
164     PROC=k8
165     #PROC=athlon
166   endif
167
168   ifeq ($(PROC),sparc64)
169     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
170     #This works for even old (2.96) versions of gcc and provides a small boost either way.
171     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
172     #So we go lowest common available by gcc and go a step down, still a step up from
173     #the default as we now have a better instruction set to work with. - Belgarath
174     PROC=ultrasparc
175     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
176     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
177     OPTIONS+=-fomit-frame-pointer
178   endif
179
180   ifeq ($(PROC),arm)
181     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
182     ifeq ($(SUB_PROC),maverick)
183       OPTIONS+=-fsigned-char -mcpu=ep9312
184     else
185       ifeq ($(SUB_PROC),xscale)
186         OPTIONS+=-fsigned-char -mcpu=xscale
187       else
188         OPTIONS+=-fsigned-char 
189       endif
190     endif
191   endif
192 endif
193
194 GREP=grep
195 ID=id
196
197 ifeq ($(OSARCH),SunOS)
198   GREP=/usr/xpg4/bin/grep
199   M4=/usr/local/bin/m4
200   ID=/usr/xpg4/bin/id
201 endif
202
203 ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
204 ifneq ($(OPTIMIZE),)
205 ASTCFLAGS+=$(OPTIMIZE)
206 endif
207
208 ifeq ($(AST_DEVMODE),yes)
209   ASTCFLAGS+=-Werror -Wunused
210 endif
211
212 ifeq ($(shell gcc -v 2>&1 | grep 'gcc version' | cut -f3 -d' ' | cut -f1 -d.),4)
213 ASTCFLAGS+=-Wno-pointer-sign
214 endif
215 ASTOBJ=-o asterisk
216
217 ifeq ($(findstring BSD,$(OSARCH)),BSD)
218   ASTCFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
219 endif
220
221 ifneq ($(PROC),ultrasparc)
222   ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
223 endif
224
225 ifeq ($(PROC),ppc)
226   ASTCFLAGS+=-fsigned-char
227 endif
228
229 ifeq ($(OSARCH),FreeBSD)
230   BSDVERSION=$(shell make -V OSVERSION -f $(CROSS_COMPILE_TARGET)/usr/share/mk/bsd.port.subdir.mk)
231   ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
232   LIBS+=$(shell if test  $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
233   ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/spandsp),)
234     ASTCFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include/spandsp
235   endif
236 endif # FreeBSD
237
238 ifeq ($(OSARCH),NetBSD)
239   AST_CFLAGS+=-pthread -I$(CROSS_COMPILE_TARGET)/usr/pkg/include
240 endif
241
242 ifeq ($(OSARCH),OpenBSD)
243   ASTCFLAGS+=-pthread
244 endif
245
246 ifeq ($(OSARCH),SunOS)
247   ASTCFLAGS+=-Wcast-align -DSOLARIS -Iinclude/solaris-compat -I$(CROSS_COMPILE_TARGET)/usr/local/ssl/include
248 endif
249
250 LIBEDIT=editline/libedit.a
251
252 ASTERISKVERSION:=$(shell build_tools/make_version .)
253
254 ifneq ($(wildcard .version),)
255   ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
256   RPMVERSION:=$(shell sed 's/[-\/:]/_/g' .version)
257 else
258   RPMVERSION=unknown
259 endif
260
261 ifneq ($(wildcard .svn),)
262   ASTERISKVERSIONNUM=999999
263 endif
264
265 ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS)
266
267 MOD_SUBDIRS=res channels pbx apps codecs formats cdr funcs
268 OTHER_SUBDIRS=utils agi
269 SUBDIRS:=$(MOD_SUBDIRS) $(OTHER_SUBDIRS)
270 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
271
272 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
273         translate.o file.o pbx.o cli.o md5.o term.o \
274         ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
275         cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
276         dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
277         astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
278         utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
279         netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
280         cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o
281
282 # we need to link in the objects statically, not as a library, because
283 # otherwise modules will not have them available if none of the static
284 # objects use it.
285 OBJS+=stdtime/localtime.o
286
287 # At the moment say.o is an optional component which can be overridden
288 # by a module.
289 OBJS+=say.o
290
291 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sys/poll.h),)
292   OBJS+= poll.o
293   ASTCFLAGS+=-DPOLLCOMPAT
294 endif
295
296 ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/dlfcn.h),)
297   OBJS+= dlfcn.o
298   ASTCFLAGS+=-DDLFCNCOMPAT
299 endif
300
301 ifeq ($(OSARCH),Linux)
302   LIBS+=-ldl -lpthread $(EDITLINE_LIBS) -lm -lresolv  #-lnjamd
303 else
304   LIBS+=$(EDITLINE_LIBS) -lm
305 endif
306
307 ifeq ($(OSARCH),Darwin)
308   LIBS+=-lresolv
309   ASTCFLAGS+=-D__Darwin__
310   AUDIO_LIBS=-framework CoreAudio
311   ASTLINK=-Wl,-dynamic
312   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
313   # Mac on Intel CoreDuo does not need poll compatibility layer
314   ifneq ($(PROC),i386)
315     OBJS+=poll.o
316     ASTCFLAGS+=-DPOLLCOMPAT
317   endif
318 else
319 # These are used for all but Darwin
320   ASTLINK=-Wl,-E 
321   SOLINK=-shared -Xlinker -x
322   ifeq ($(findstring BSD,$(OSARCH)),BSD)
323     SOLINK+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib
324   endif
325 endif
326
327 ifeq ($(OSARCH),FreeBSD)
328   LIBS+=-lcrypto
329 endif
330
331 ifeq ($(OSARCH),NetBSD)
332   LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib $(EDITLINE_LIBS)
333 endif
334
335 ifeq ($(OSARCH),OpenBSD)
336   LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIBS)
337 endif
338
339 ifeq ($(OSARCH),SunOS)
340   LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
341   OBJS+=strcompat.o
342   MENUSELECT_OBJS+=strcompat.o
343   ASTLINK=
344   SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
345 endif
346
347 ifeq ($(MAKETOPLEVEL),$(MAKELEVEL))
348   CFLAGS+=$(TOPDIR_CFLAGS)$(ASTCFLAGS)
349 endif
350
351 # This is used when generating the doxygen documentation
352 ifneq ($(DOT),:)
353   HAVEDOT=yes
354 else
355   HAVEDOT=no
356 endif
357
358 _all: all
359         @echo " +--------- Asterisk Build Complete ---------+"  
360         @echo " + Asterisk has successfully been built, but +"  
361         @echo " + cannot be run before being installed by   +"  
362         @echo " + running:                                  +"  
363         @echo " +                                           +"
364         @echo " +               make install                +"  
365         @echo " +-------------------------------------------+"  
366
367 all: cleantest config.status menuselect.makeopts depend asterisk $(SUBDIRS)
368
369 config.status: configure
370         @CFLAGS="" ./configure
371         @echo "****"
372         @echo "**** The configure script was just executed, so 'make' needs to be"
373         @echo "**** restarted."
374         @echo "****"
375         @exit 1
376
377 makeopts: configure
378         @CFLAGS="" ./configure
379         @echo "****"
380         @echo "**** The configure script was just executed, so 'make' needs to be"
381         @echo "**** restarted."
382         @echo "****"
383         @exit 1
384
385 menuselect.makeopts: build_tools/menuselect makeopts.xml
386         @build_tools/menuselect --check-deps ${GLOBAL_MAKEOPTS} ${USER_MAKEOPTS} $@
387
388 #ifneq ($(wildcard tags),)
389 ctags: tags
390 #endif
391
392 ifneq ($(wildcard TAGS),)
393 all: TAGS
394 endif
395
396 editline/config.h:
397         cd editline && unset CFLAGS LIBS && CFLAGS="$(OPTIMIZE)" ./configure ; \
398
399 editline/libedit.a:
400         cd editline && unset CFLAGS LIBS && test -f config.h || CFLAGS="$(OPTIMIZE)" ./configure
401         $(MAKE) -C editline libedit.a
402
403 db1-ast/libdb1.a:
404         $(MAKE) -C db1-ast libdb1.a
405
406 ifneq ($(wildcard .depend),)
407   include .depend
408 endif
409
410 ifneq ($(wildcard .tags-depend),)
411   include .tags-depend
412 endif
413
414 ast_expr2.c ast_expr2.h:
415         bison -o $@ -d --name-prefix=ast_yy ast_expr2.y
416
417 ast_expr2f.c:
418         flex -o $@ --full ast_expr2.fl
419
420 testexpr2: config.status include/asterisk/buildopts.h ast_expr2f.c ast_expr2.c ast_expr2.h
421         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c
422         $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c
423         $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o
424         rm ast_expr2.o ast_expr2f.o 
425
426 manpage: asterisk.8
427
428 asterisk.8: asterisk.sgml
429         rm -f asterisk.8
430         docbook2man asterisk.sgml
431         mv ./*.8 asterisk.8
432
433 asterisk.pdf: asterisk.sgml
434         docbook2pdf asterisk.sgml
435
436 asterisk.ps: asterisk.sgml
437         docbook2ps asterisk.sgml
438
439 asterisk.html: asterisk.sgml
440         docbook2html asterisk.sgml
441         mv r1.html asterisk.html
442
443 asterisk.txt: asterisk.sgml
444         docbook2txt asterisk.sgml
445
446 defaults.h: makeopts
447         @build_tools/make_defaults_h > $@.tmp
448         @if cmp -s $@.tmp $@ ; then : ; else \
449                 mv $@.tmp $@ ; \
450         fi
451         @rm -f $@.tmp
452
453 include/asterisk/version.h:
454         @build_tools/make_version_h > $@.tmp
455         @if cmp -s $@.tmp $@ ; then : ; else \
456                 mv $@.tmp $@ ; \
457         fi
458         @rm -f $@.tmp
459
460 include/asterisk/buildopts.h: menuselect.makeopts
461         @build_tools/make_buildopts_h > $@.tmp
462         @if cmp -s $@.tmp $@ ; then : ; else \
463                 mv $@.tmp $@ ; \
464         fi
465         @rm -f $@.tmp
466
467 asterisk: include/asterisk/buildopts.h editline/libedit.a db1-ast/libdb1.a $(OBJS)
468         build_tools/make_build_h > include/asterisk/build.h.tmp
469         if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \
470                 mv include/asterisk/build.h.tmp include/asterisk/build.h ; \
471         fi
472         rm -f include/asterisk/build.h.tmp
473         $(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
474         $(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a $(LIBS)
475
476 muted: muted.o
477         $(CC) $(AUDIO_LIBS) -o muted muted.o
478
479 $(MOD_SUBDIRS): FORCE
480         @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $@
481
482 $(OTHER_SUBDIRS): FORCE 
483         @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $@
484
485 clean-depend:
486         @for x in $(SUBDIRS); do $(MAKE) -C $$x clean-depend || exit 1 ; done
487         rm -f .depend .tags-depend
488
489 clean: clean-depend
490         @for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done
491         rm -f *.o *.so asterisk
492         rm -f defaults.h
493         rm -f include/asterisk/build.h
494         rm -f include/asterisk/version.h
495         rm -f .tags-sources tags TAGS
496         @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi
497         $(MAKE) -C db1-ast clean
498         $(MAKE) -C stdtime clean
499
500 distclean: dist-clean
501
502 dist-clean: clean
503         $(MAKE) -C mxml clean
504         $(MAKE) -C build_tools dist-clean
505         $(MAKE) -C sounds dist-clean
506         rm -f menuselect.makeopts makeopts makeopts.xml
507         rm -f config.log config.status
508         rm -f include/autoconfig.h
509         rm -f include/asterisk/buildopts.h
510
511 datafiles: all
512         if [ x`$(ID) -un` = xroot ]; then sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
513 # Should static HTTP be installed during make samples or even with its own target ala
514 # webvoicemail?  There are portions here that *could* be customized but might also be
515 # improved a lot.  I'll put it here for now.
516         mkdir -p $(DESTDIR)$(ASTDATADIR)/static-http
517         for x in static-http/*; do \
518                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/static-http ; \
519         done
520         mkdir -p $(DESTDIR)$(ASTDATADIR)/images
521         for x in images/*.jpg; do \
522                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTDATADIR)/images ; \
523         done
524         mkdir -p $(DESTDIR)$(AGI_DIR)
525         $(MAKE) -C sounds install
526
527 update: 
528         @if [ -d .svn ]; then \
529                 echo "Updating from Subversion..." ; \
530                 svn update | tee update.out; \
531                 rm -f .version; \
532                 if [ `grep -c ^C update.out` -gt 0 ]; then \
533                         echo ; echo "The following files have conflicts:" ; \
534                         grep ^C update.out | cut -b4- ; \
535                 fi ; \
536                 rm -f update.out; \
537                 $(MAKE) clean-depend; \
538         else \
539                 echo "Not under version control";  \
540         fi
541
542 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
543 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
544
545 bininstall: all
546         mkdir -p $(DESTDIR)$(MODULES_DIR)
547         mkdir -p $(DESTDIR)$(ASTSBINDIR)
548         mkdir -p $(DESTDIR)$(ASTETCDIR)
549         mkdir -p $(DESTDIR)$(ASTBINDIR)
550         mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
551         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
552         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/dictate
553         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
554         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
555         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
556         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor
557         if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
558         if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
559         $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
560         $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
561         $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
562         if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
563                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
564                 chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
565         fi
566         $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
567         $(INSTALL) -m 644 include/asterisk.h $(DESTDIR)$(includedir)
568         $(INSTALL) -m 644 include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
569         if [ -n "$(OLDHEADERS)" ]; then \
570                 rm -f $(addprefix $(DESTDIR)$(ASTHEADERDIR)/,$(OLDHEADERS)) ;\
571         fi
572         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
573         mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-custom
574         mkdir -p $(DESTDIR)$(ASTDATADIR)/keys
575         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
576         mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
577         mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
578         $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
579         $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
580         $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
581         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
582         $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
583         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
584         $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
585
586 $(SUBDIRS_INSTALL):
587         @$(MAKE) -C $(@:-install=) install
588
589 NEWMODS=$(notdir $(wildcard */*.so))
590 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
591
592 oldmodcheck:
593         @if [ -n "$(OLDMODS)" ]; then \
594                 echo " WARNING WARNING WARNING" ;\
595                 echo "" ;\
596                 echo " Your Asterisk modules directory, located at" ;\
597                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
598                 echo " contains modules that were not installed by this " ;\
599                 echo " version of Asterisk. Please ensure that these" ;\
600                 echo " modules are compatible with this version before" ;\
601                 echo " attempting to run Asterisk." ;\
602                 echo "" ;\
603                 for f in $(OLDMODS); do \
604                         echo "    $$f" ;\
605                 done ;\
606                 echo "" ;\
607                 echo " WARNING WARNING WARNING" ;\
608         fi
609
610 install: all datafiles bininstall $(SUBDIRS_INSTALL)
611         @if [ -x /usr/sbin/asterisk-post-install ]; then \
612                 /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
613         fi
614         @echo " +---- Asterisk Installation Complete -------+"  
615         @echo " +                                           +"
616         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
617         @echo " +                                           +"
618         @echo " + Asterisk has successfully been installed. +"  
619         @echo " + If you would like to install the sample   +"  
620         @echo " + configuration files (overwriting any      +"
621         @echo " + existing config files), run:              +"  
622         @echo " +                                           +"
623         @echo " +               $(MAKE) samples                +"
624         @echo " +                                           +"
625         @echo " +-----------------  or ---------------------+"
626         @echo " +                                           +"
627         @echo " + You can go ahead and install the asterisk +"
628         @echo " + program documentation now or later run:   +"
629         @echo " +                                           +"
630         @echo " +              $(MAKE) progdocs                +"
631         @echo " +                                           +"
632         @echo " + **Note** This requires that you have      +"
633         @echo " + doxygen installed on your local system    +"
634         @echo " +-------------------------------------------+"
635         @$(MAKE) -s oldmodcheck
636
637 upgrade: all bininstall
638
639 adsi:
640         mkdir -p $(DESTDIR)$(ASTETCDIR)
641         for x in configs/*.adsi; do \
642                 if [ ! -f $(DESTDIR)$(ASTETCDIR)/$$x ]; then \
643                         $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
644                 fi ; \
645         done
646
647 samples: adsi
648         mkdir -p $(DESTDIR)$(ASTETCDIR)
649         for x in configs/*.sample; do \
650                 if [ -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ]; then \
651                         if [ "$(OVERWRITE)" = "y" ]; then \
652                                 if cmp -s $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $$x ; then \
653                                         echo "Config file $$x is unchanged"; \
654                                         continue; \
655                                 fi ; \
656                                 mv -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`.old ; \
657                         else \
658                                 echo "Skipping config file $$x"; \
659                                 continue; \
660                         fi ;\
661                 fi ; \
662                 $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ;\
663         done
664         if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
665                 ( \
666                 echo "[directories]" ; \
667                 echo "astetcdir => $(ASTETCDIR)" ; \
668                 echo "astmoddir => $(MODULES_DIR)" ; \
669                 echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
670                 echo "astdatadir => $(ASTDATADIR)" ; \
671                 echo "astagidir => $(AGI_DIR)" ; \
672                 echo "astspooldir => $(ASTSPOOLDIR)" ; \
673                 echo "astrundir => $(ASTVARRUNDIR)" ; \
674                 echo "astlogdir => $(ASTLOGDIR)" ; \
675                 echo "" ; \
676                 echo "; Changing the following lines may compromise your security." ; \
677                 echo ";[files]" ; \
678                 echo ";astctlpermissions = 0660" ; \
679                 echo ";astctlowner = root" ; \
680                 echo ";astctlgroup = apache" ; \
681                 echo ";astctl = asterisk.ctl" ; \
682                 echo ";[options]" ; \
683                 echo ";internal_timing = yes" ; \
684                 ) > $(DESTDIR)$(ASTCONFPATH) ; \
685         else \
686                 echo "Skipping asterisk.conf creation"; \
687         fi
688         mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
689         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
690         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
691                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
692         done
693         :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
694         for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
695                 cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
696         done
697
698 webvmail:
699         @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
700         @[ -d $(DESTDIR)$(HTTP_CGIDIR) ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
701         $(INSTALL) -m 4755 -o root -g root contrib/scripts/vmail.cgi $(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi
702         mkdir -p $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk
703         for x in images/*.gif; do \
704                 $(INSTALL) -m 644 $$x $(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/; \
705         done
706         @echo " +--------- Asterisk Web Voicemail ----------+"  
707         @echo " +                                           +"
708         @echo " + Asterisk Web Voicemail is installed in    +"
709         @echo " + your cgi-bin directory:                   +"
710         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
711         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
712         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
713         @echo " +                                           +"
714         @echo " + Other static items have been stored in:   +"
715         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
716         @echo " +                                           +"
717         @echo " + If these paths do not match your httpd    +"
718         @echo " + installation, correct the definitions     +"
719         @echo " + in your Makefile of HTTP_CGIDIR and       +"
720         @echo " + HTTP_DOCSDIR                              +"
721         @echo " +                                           +"
722         @echo " +-------------------------------------------+"  
723
724 spec: 
725         sed "s/^Version:.*/Version: $(RPMVERSION)/g" redhat/asterisk.spec > asterisk.spec ; \
726
727 rpm: __rpm
728
729 __rpm: include/asterisk/version.h include/asterisk/buildopts.h spec
730         rm -rf /tmp/asterisk ; \
731         mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
732         $(MAKE) DESTDIR=/tmp/asterisk install ; \
733         $(MAKE) DESTDIR=/tmp/asterisk samples ; \
734         mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
735         cp -f contrib/init.d/rc.redhat.asterisk /tmp/asterisk/etc/rc.d/init.d/asterisk ; \
736         rpmbuild --rcfile /usr/lib/rpm/rpmrc:redhat/rpmrc -bb asterisk.spec
737
738 progdocs:
739         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
740         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
741
742 config:
743         @if [ "${OSARCH}" = "Linux" ]; then \
744                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
745                         $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
746                         /sbin/chkconfig --add asterisk; \
747                 elif [ -f /etc/debian_version ]; then \
748                         $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk; \
749                         /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; \
750                 elif [ -f /etc/gentoo-release ]; then \
751                         $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk /etc/init.d/asterisk; \
752                         /sbin/rc-update add asterisk default; \
753                 elif [ -f /etc/mandrake-release ]; then \
754                         $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk /etc/rc.d/init.d/asterisk; \
755                         /sbin/chkconfig --add asterisk; \
756                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
757                         $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk /etc/init.d/asterisk; \
758                         /sbin/chkconfig --add asterisk; \
759                 elif [ -f /etc/slackware-version ]; then \
760                         echo "Slackware is not currently supported, although an init script does exist for it." \
761                 else \
762                         echo "We could not install init scripts for your distribution."; \
763                 fi \
764         else \
765                 echo "We could not install init scripts for your operating system."; \
766         fi
767
768 dont-optimize: _all
769
770 valgrind: dont-optimize
771
772 depend: include/asterisk/version.h include/asterisk/buildopts.h .depend defaults.h 
773         @for x in $(MOD_SUBDIRS); do CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $$x depend || exit 1 ; done
774         @for x in $(OTHER_SUBDIRS); do CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $$x depend || exit 1 ; done
775
776 .depend: include/asterisk/version.h include/asterisk/buildopts.h defaults.h
777         build_tools/mkdep $(CFLAGS) $(wildcard *.c)
778
779 .tags-depend:
780         @echo -n ".tags-depend: " > $@
781         @$(FIND) . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@
782         @$(FIND) . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@
783         @$(FIND) $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@
784         @$(FIND) $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@
785         @$(FIND) include -name \*.h -printf "\t%p \\\\\n" >> $@
786         @echo >> $@
787
788 .tags-sources:
789         @rm -f $@
790         @$(FIND) . -maxdepth 1 -name \*.c -print >> $@
791         @$(FIND) . -maxdepth 1 -name \*.h -print >> $@
792         @$(FIND) $(SUBDIRS) -name \*.c -print >> $@
793         @$(FIND) $(SUBDIRS) -name \*.h -print >> $@
794         @$(FIND) include -name \*.h -print >> $@
795
796 tags: .tags-depend .tags-sources
797         ctags -L .tags-sources -o $@
798
799 ctags: tags
800
801 TAGS: .tags-depend .tags-sources
802         etags -o $@ `cat .tags-sources`
803
804 etags: TAGS
805
806 FORCE:
807
808 %_env:
809         $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env
810
811 sounds:
812         $(MAKE) -C sounds all
813
814 env:
815         env
816
817 # If the cleancount has been changed, force a make clean.
818 # .cleancount is the global clean count, and .lastclean is the 
819 # last clean count we had
820
821 cleantest:
822         @if cmp -s .cleancount .lastclean ; then echo ; else \
823                 $(MAKE) clean; cp -f .cleancount .lastclean;\
824                 $(MAKE) defaults.h;\
825         fi
826
827 _uninstall:
828         rm -f $(DESTDIR)$(MODULES_DIR)/*
829         rm -f $(DESTDIR)$(ASTSBINDIR)/*asterisk*
830         rm -f $(DESTDIR)$(ASTSBINDIR)/astgenkey
831         rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
832         rm -rf $(DESTDIR)$(ASTHEADERDIR)
833         rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
834         rm -rf $(DESTDIR)$(ASTMANDIR)/man8
835         for x in $(SUBDIRS); do $(MAKE) -C $$x uninstall || exit 1 ; done
836         $(MAKE) -C sounds uninstall
837
838 uninstall: _uninstall
839         @echo " +--------- Asterisk Uninstall Complete -----+"  
840         @echo " + Asterisk binaries, sounds, man pages,     +"  
841         @echo " + headers, modules, and firmware builds,    +"  
842         @echo " + have all been uninstalled.                +"  
843         @echo " +                                           +"
844         @echo " + To remove ALL traces of Asterisk,         +"
845         @echo " + including configuration, spool            +"
846         @echo " + directories, and logs, run the following  +"
847         @echo " + command:                                  +"
848         @echo " +                                           +"
849         @echo " +            $(MAKE) uninstall-all             +"  
850         @echo " +-------------------------------------------+"  
851
852 uninstall-all: _uninstall
853         rm -rf $(DESTDIR)$(ASTLIBDIR)
854         rm -rf $(DESTDIR)$(ASTVARLIBDIR)
855         rm -rf $(DESTDIR)$(ASTDATADIR)
856         rm -rf $(DESTDIR)$(ASTSPOOLDIR)
857         rm -rf $(DESTDIR)$(ASTETCDIR)
858         rm -rf $(DESTDIR)$(ASTLOGDIR)
859
860 menuselect: build_tools/menuselect makeopts.xml
861         -@build_tools/menuselect ${GLOBAL_MAKEOPTS} ${USER_MAKEOPTS} menuselect.makeopts && echo "menuselect changes saved!" || echo "menuselect changes NOT saved!"
862
863 build_tools/menuselect: build_tools/menuselect.c build_tools/menuselect_curses.c build_tools/menuselect.h config.status mxml/libmxml.a $(MENUSELECT_OBJS)
864         $(MAKE) -C build_tools menuselect
865
866 mxml/libmxml.a:
867         @cd mxml && unset CFLAGS LIBS && test -f config.h || ./configure
868         $(MAKE) -C mxml libmxml.a
869
870 makeopts.xml: $(foreach dir,$(MOD_SUBDIRS),$(dir)/*.c) build_tools/cflags.xml sounds/sounds.xml
871         @echo "Generating list of available modules ..."
872         @build_tools/prep_moduledeps > $@