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