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