dfa1757f487ee04e77329c89151bb9a65d90b0c9
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
3
4 # Top level Makefile
5 #
6 # Copyright (C) 1999-2010, 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 # ASTCFLAGS - compiler options provided by the user (if any)
17 # _ASTCFLAGS - compiler options provided by the build system
18 # ASTLDFLAGS - linker flags (not libraries) provided by the user (if any)
19 # _ASTLDFLAGS - linker flags (not libraries) provided by the build system
20 # LIBS - additional libraries, at top-level for all links,
21 #      on a single object just for that object
22 # SOLINK - linker flags used only for creating shared objects (.so files),
23 #      used for all .so links
24 #
25 # Values for ASTCFLAGS and ASTLDFLAGS can be specified in the
26 # environment when running make, as follows:
27 #
28 #       $ ASTCFLAGS="-Werror" make ...
29 #
30 # or as a variable value on the make command line itself:
31 #
32 #       $ make ASTCFLAGS="-Werror" ...
33
34 export ASTTOPDIR                # Top level dir, used in subdirs' Makefiles
35 export ASTERISKVERSION
36 export ASTERISKVERSIONNUM
37
38 #--- values used for default paths
39
40 # DESTDIR is the staging (or final) directory where files are copied
41 # during the install process. Define it before 'export', otherwise
42 # export will set it to the empty string making ?= fail.
43 # Trying to run asterisk from the DESTDIR is completely unsupported
44 # behavior.
45 # WARNING: do not put spaces or comments after the value.
46 DESTDIR?=$(INSTALL_PATH)
47 export DESTDIR
48
49 export INSTALL_PATH     # Additional prefix for the following paths
50 export ASTETCDIR                # Path for config files
51 export ASTVARRUNDIR
52 export MODULES_DIR
53 export ASTSPOOLDIR
54 export ASTVARLIBDIR
55 export ASTDATADIR
56 export ASTDBDIR
57 export ASTLOGDIR
58 export ASTLIBDIR
59 export ASTMANDIR
60 export ASTHEADERDIR
61 export ASTSBINDIR
62 export AGI_DIR
63 export ASTCONFPATH
64 export ASTKEYDIR
65
66 export OSARCH                   # Operating system
67 export PROC                     # Processor type
68
69 export NOISY_BUILD              # Used in Makefile.rules
70 export MENUSELECT_CFLAGS        # Options selected in menuselect.
71 export AST_DEVMODE              # Set to "yes" for additional compiler
72                                 # and runtime checks
73
74 export SOLINK                   # linker flags for shared objects
75 export STATIC_BUILD             # Additional cflags, set to -static
76                                 # for static builds. Probably
77                                 # should go directly to ASTLDFLAGS
78
79 #--- paths to various commands
80 export CC
81 export CXX
82 export AR
83 export RANLIB
84 export HOST_CC
85 export BUILD_CC
86 export INSTALL
87 export STRIP
88 export DOWNLOAD
89 export AWK
90 export GREP
91 export MD5
92 export WGET_EXTRA_ARGS
93
94 # even though we could use '-include makeopts' here, use a wildcard
95 # lookup anyway, so that make won't try to build makeopts if it doesn't
96 # exist (other rules will force it to be built if needed)
97 ifneq ($(wildcard makeopts),)
98   include makeopts
99 endif
100
101 # start the primary CFLAGS and LDFLAGS with any that were provided
102 # to the configure script
103 _ASTCFLAGS:=$(CONFIG_CFLAGS)
104 _ASTLDFLAGS:=$(CONFIG_LDFLAGS)
105
106 # Some build systems, such as the one in openwrt, like to pass custom target
107 # CFLAGS and LDFLAGS in the COPTS and LDOPTS variables; these should also
108 # go before any build-system computed flags, since they are defaults, not
109 # overrides
110 _ASTCFLAGS+=$(COPTS)
111 _ASTLDFLAGS+=$(LDOPTS)
112
113 # libxml2 cflags
114 _ASTCFLAGS+=$(LIBXML2_INCLUDE)
115
116 #Uncomment this to see all build commands instead of 'quiet' output
117 #NOISY_BUILD=yes
118
119 empty:=
120 space:=$(empty) $(empty)
121 ASTTOPDIR:=$(subst $(space),\$(space),$(CURDIR))
122
123 # Overwite config files on "make samples"
124 OVERWRITE=y
125
126 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
127 DEBUG=-g3
128
129 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
130 # when starting Asterisk
131 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
132 MODULES_DIR=$(ASTLIBDIR)/modules
133 AGI_DIR=$(ASTDATADIR)/agi-bin
134
135 # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file
136 HTTP_DOCSDIR=/var/www/html
137 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
138 HTTP_CGIDIR=/var/www/cgi-bin
139
140 # If your platform's linker expects a prefix on symbols generated from compiling C
141 # source files, set LINKER_SYMBOL_PREFIX to that value. On some systems, exported symbols
142 # from C source files are prefixed with '_', for example. If this value is not set
143 # properly, the linker scripts that live in the '*.exports' files in various places
144 # in this tree will unintentionally suppress symbols that should be visible
145 # in the final binary objects.
146 LINKER_SYMBOL_PREFIX=
147
148 # Uncomment this to use the older DSP routines
149 #_ASTCFLAGS+=-DOLD_DSP_ROUTINES
150
151 # If the file .asterisk.makeopts is present in your home directory, you can
152 # include all of your favorite menuselect options so that every time you download
153 # a new version of Asterisk, you don't have to run menuselect to set them. 
154 # The file /etc/asterisk.makeopts will also be included but can be overridden
155 # by the file in your home directory.
156
157 GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
158 USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
159
160 MOD_SUBDIR_CFLAGS="-I$(ASTTOPDIR)/include"
161 OTHER_SUBDIR_CFLAGS="-I$(ASTTOPDIR)/include"
162
163 # Create OPTIONS variable, but probably we can assign directly to ASTCFLAGS
164 OPTIONS=
165
166 ifeq ($(OSARCH),linux-gnu)
167   ifeq ($(PROC),x86_64)
168     # You must have GCC 3.4 to use k8, otherwise use athlon
169     PROC=k8
170     #PROC=athlon
171   endif
172
173   ifeq ($(PROC),sparc64)
174     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
175     #This works for even old (2.96) versions of gcc and provides a small boost either way.
176     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
177     #So we go lowest common available by gcc and go a step down, still a step up from
178     #the default as we now have a better instruction set to work with. - Belgarath
179     PROC=ultrasparc
180     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
181     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
182     OPTIONS+=-fomit-frame-pointer
183   endif
184
185   ifeq ($(PROC),arm)
186     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
187     ifeq ($(SUB_PROC),maverick)
188       OPTIONS+=-fsigned-char -mcpu=ep9312
189     else
190       ifeq ($(SUB_PROC),xscale)
191         OPTIONS+=-fsigned-char -mcpu=xscale
192       else
193         OPTIONS+=-fsigned-char 
194       endif
195     endif
196   endif
197 endif
198
199 ifeq ($(findstring -save-temps,$(_ASTCFLAGS) $(ASTCFLAGS)),)
200   ifeq ($(findstring -pipe,$(_ASTCFLAGS) $(ASTCFLAGS)),)
201     _ASTCFLAGS+=-pipe
202   endif
203 endif
204
205 ifeq ($(findstring -Wall,$(_ASTCFLAGS) $(ASTCFLAGS)),)
206   _ASTCFLAGS+=-Wall
207 endif
208
209 _ASTCFLAGS+=-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
210 ADDL_TARGETS=
211
212 ifeq ($(AST_DEVMODE),yes)
213   _ASTCFLAGS+=-Werror
214   _ASTCFLAGS+=-Wunused
215   _ASTCFLAGS+=$(AST_DECLARATION_AFTER_STATEMENT)
216   _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
217   _ASTCFLAGS+=-Wundef 
218   _ASTCFLAGS+=-Wmissing-format-attribute
219   _ASTCFLAGS+=-Wformat=2
220   ADDL_TARGETS+=validate-docs
221 endif
222
223 ifneq ($(findstring BSD,$(OSARCH)),)
224   _ASTCFLAGS+=-isystem /usr/local/include
225 endif
226
227 ifeq ($(findstring -march,$(_ASTCFLAGS) $(ASTCFLAGS)),)
228   ifneq ($(AST_MARCH_NATIVE),)
229     _ASTCFLAGS+=$(AST_MARCH_NATIVE)
230   else
231     ifneq ($(PROC),ultrasparc)
232       _ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
233     endif
234   endif
235 endif
236
237 ifeq ($(PROC),ppc)
238   _ASTCFLAGS+=-fsigned-char
239 endif
240
241 ifeq ($(OSARCH),FreeBSD)
242   ifeq ($(findstring -march,$(_ASTCFLAGS) $(ASTCFLAGS)),)
243     ifeq ($(PROC),i386)
244       _ASTCFLAGS+=-march=i686
245     endif
246   endif
247   # -V is understood by BSD Make, not by GNU make.
248   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
249   _ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
250 endif
251
252 ifeq ($(OSARCH),NetBSD)
253   _ASTCFLAGS+=-pthread -I/usr/pkg/include
254 endif
255
256 ifeq ($(OSARCH),OpenBSD)
257   _ASTCFLAGS+=-pthread -ftrampolines
258 endif
259
260 ifeq ($(OSARCH),SunOS)
261   _ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include -D_XPG4_2 -D__EXTENSIONS__
262 endif
263
264 ASTERISKVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) build_tools/make_version .)
265
266 ifneq ($(wildcard .version),)
267   ASTERISKVERSIONNUM:=$(shell $(AWK) -F. '{printf "%01d%02d%02d", $$1, $$2, $$3}' .version)
268 endif
269
270 ifneq ($(wildcard .svn),)
271   ASTERISKVERSIONNUM:=999999
272 endif
273
274 _ASTCFLAGS+=$(OPTIONS)
275
276 MOD_SUBDIRS:=channels pbx apps codecs formats cdr cel bridges funcs tests main res addons $(LOCAL_MOD_SUBDIRS)
277 OTHER_SUBDIRS:=utils agi
278 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
279 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
280 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
281 SUBDIRS_DIST_CLEAN:=$(SUBDIRS:%=%-dist-clean)
282 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
283 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
284 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
285 MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
286 MOD_SUBDIRS_MENUSELECT_TREE:=$(MOD_SUBDIRS:%=%-menuselect-tree)
287
288 ifneq ($(findstring darwin,$(OSARCH)),)
289   _ASTCFLAGS+=-D__Darwin__
290   SOLINK=-bundle -Xlinker -macosx_version_min -Xlinker 10.4 -Xlinker -undefined -Xlinker dynamic_lookup -force_flat_namespace
291   ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
292     SOLINK+=/usr/lib/bundle1.o
293   endif
294   _ASTLDFLAGS+=-L/usr/local/lib
295 else
296 # These are used for all but Darwin
297   SOLINK=-shared
298   ifneq ($(findstring BSD,$(OSARCH)),)
299     _ASTLDFLAGS+=-L/usr/local/lib
300   endif
301 endif
302
303 ifeq ($(OSARCH),SunOS)
304   SOLINK=-shared -fpic -L/usr/local/ssl/lib -lrt
305 endif
306
307 ifeq ($(OSARCH),OpenBSD)
308   SOLINK=-shared -fpic
309 endif
310
311 # comment to print directories during submakes
312 #PRINT_DIR=yes
313
314 ifneq ($(INSIDE_EMACS),)
315 PRINT_DIR=yes
316 endif
317
318 SILENTMAKE:=$(MAKE) --quiet --no-print-directory
319 ifneq ($(PRINT_DIR)$(NOISY_BUILD),)
320 SUBMAKE:=$(MAKE)
321 else
322 SUBMAKE:=$(MAKE) --quiet --no-print-directory
323 endif
324
325 # This is used when generating the doxygen documentation
326 ifneq ($(DOT),:)
327   HAVEDOT=yes
328 else
329   HAVEDOT=no
330 endif
331
332 # $(MAKE) is printed in several places, and we want it to be a
333 # fixed size string. Define a variable whose name has also the
334 # same size, so we can easily align text.
335 ifeq ($(MAKE), gmake)
336         mK="gmake"
337 else
338         mK=" make"
339 endif
340
341 all: _cleantest_all
342         @echo " +--------- Asterisk Build Complete ---------+"  
343         @echo " + Asterisk has successfully been built, and +"  
344         @echo " + can be installed by running:              +"
345         @echo " +                                           +"
346         @echo " +               $(mK) install               +"  
347         @echo " +-------------------------------------------+"  
348
349 # For parallel builds, we must call cleantest *before* running the
350 # other dependencies on _all.
351 _cleantest_all: cleantest
352         @$(MAKE) _all
353
354 _all: makeopts $(SUBDIRS) doc/core-en_US.xml $(ADDL_TARGETS)
355
356 makeopts: configure
357         @echo "****"
358         @echo "**** The configure script must be executed before running '$(MAKE)'." 
359         @echo "****               Please run \"./configure\"."
360         @echo "****"
361         @exit 1
362
363 menuselect.makeopts: menuselect/menuselect menuselect-tree makeopts build_tools/menuselect-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS)
364 ifeq ($(filter %menuselect,$(MAKECMDGOALS)),)
365         menuselect/menuselect --check-deps $@
366         menuselect/menuselect --check-deps $@ $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS)
367 endif
368
369 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
370         +@echo "EMBED_LDSCRIPTS+="`$(SILENTMAKE) -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
371
372 $(MOD_SUBDIRS_EMBED_LDFLAGS):
373         +@echo "EMBED_LDFLAGS+="`$(SILENTMAKE) -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
374
375 $(MOD_SUBDIRS_EMBED_LIBS):
376         +@echo "EMBED_LIBS+="`$(SILENTMAKE) -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
377
378 $(MOD_SUBDIRS_MENUSELECT_TREE):
379         +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) moduleinfo
380         +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) makeopts
381
382 makeopts.embed_rules: menuselect.makeopts
383         @echo "Generating embedded module rules ..."
384         @rm -f $@
385         +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LDSCRIPT)
386         +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LDFLAGS)
387         +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LIBS)
388
389 $(SUBDIRS): main/version.c include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
390
391 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
392     # Non-windows:
393     # ensure that all module subdirectories are processed before 'main' during
394     # a parallel build, since if there are modules selected to be embedded the
395     # directories containing them must be completed before the main Asterisk
396     # binary can be built
397 main: $(filter-out main,$(MOD_SUBDIRS))
398 else
399     # Windows: we need to build main (i.e. the asterisk dll) first,
400     # followed by res, followed by the other directories, because
401     # dll symbols must be resolved during linking and not at runtime.
402 D1:= $(filter-out main,$(MOD_SUBDIRS))
403 D1:= $(filter-out res,$(D1))
404
405 $(D1): res
406 res:    main
407 endif
408
409 $(MOD_SUBDIRS):
410         +@_ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(_ASTCFLAGS)" ASTCFLAGS="$(ASTCFLAGS)" _ASTLDFLAGS="$(_ASTLDFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(SUBMAKE) --no-builtin-rules -C $@ SUBDIR=$@ all
411
412 $(OTHER_SUBDIRS):
413         +@_ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(_ASTCFLAGS)" ASTCFLAGS="$(ASTCFLAGS)" _ASTLDFLAGS="$(_ASTLDFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(SUBMAKE) --no-builtin-rules -C $@ SUBDIR=$@ all
414
415 defaults.h: makeopts build_tools/make_defaults_h
416         @build_tools/make_defaults_h > $@.tmp
417         @cmp -s $@.tmp $@ || mv $@.tmp $@
418         @rm -f $@.tmp
419
420 main/version.c: FORCE
421         @build_tools/make_version_c > $@.tmp
422         @cmp -s $@.tmp $@ || mv $@.tmp $@
423         @rm -f $@.tmp
424
425 include/asterisk/version.h: FORCE
426         @build_tools/make_version_h > $@.tmp
427         @cmp -s $@.tmp $@ || mv $@.tmp $@
428         @rm -f $@.tmp
429
430 include/asterisk/buildopts.h: menuselect.makeopts
431         @build_tools/make_buildopts_h > $@.tmp
432         @cmp -s $@.tmp $@ || mv $@.tmp $@
433         @rm -f $@.tmp
434
435 include/asterisk/build.h:
436         @build_tools/make_build_h > $@.tmp
437         @cmp -s $@.tmp $@ || mv $@.tmp $@
438         @rm -f $@.tmp
439
440 $(SUBDIRS_CLEAN):
441         +@$(SUBMAKE) -C $(@:-clean=) clean
442
443 $(SUBDIRS_DIST_CLEAN):
444         +@$(SUBMAKE) -C $(@:-dist-clean=) dist-clean
445
446 clean: $(SUBDIRS_CLEAN) _clean
447
448 _clean:
449         rm -f defaults.h
450         rm -f include/asterisk/build.h
451         rm -f main/version.c
452         rm -f include/asterisk/version.h
453         @$(MAKE) -C menuselect clean
454         cp -f .cleancount .lastclean
455
456 dist-clean: distclean
457
458 distclean: $(SUBDIRS_DIST_CLEAN) _clean
459         @$(MAKE) -C menuselect dist-clean
460         @$(MAKE) -C sounds dist-clean
461         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
462         rm -f makeopts.embed_rules
463         rm -f config.log config.status config.cache
464         rm -rf autom4te.cache
465         rm -f include/asterisk/autoconfig.h
466         rm -f include/asterisk/buildopts.h
467         rm -rf doc/api
468         rm -f build_tools/menuselect-deps
469
470 datafiles: _cleantest_all doc/core-en_US.xml
471         CFLAGS="$(_ASTCFLAGS) $(ASTCFLAGS)" build_tools/mkpkgconfig "$(DESTDIR)$(libdir)/pkgconfig";
472 # Should static HTTP be installed during make samples or even with its own target ala
473 # webvoicemail?  There are portions here that *could* be customized but might also be
474 # improved a lot.  I'll put it here for now.
475
476         for x in static-http/*; do \
477                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/static-http" ; \
478         done
479         $(INSTALL) -m 644 doc/core-en_US.xml "$(DESTDIR)$(ASTDATADIR)/static-http";
480         if [ -d doc/tex/asterisk ] ; then \
481                 $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \
482                 for n in doc/tex/asterisk/* ; do \
483                         $(INSTALL) -m 644 $$n "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \
484                 done \
485         fi
486         for x in images/*.jpg; do \
487                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/images" ; \
488         done
489         $(MAKE) -C sounds install
490
491 doc/core-en_US.xml: $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
492         @printf "Building Documentation For: "
493         @echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $@
494         @echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@
495         @echo "<docs xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> $@
496         @for x in $(MOD_SUBDIRS); do \
497                 printf "$$x " ; \
498                 for i in $$x/*.c; do \
499                         $(AWK) -f build_tools/get_documentation $$i >> $@ ; \
500                 done ; \
501         done
502         @echo
503         @echo "</docs>" >> $@
504
505 validate-docs: doc/core-en_US.xml
506 ifeq ($(XMLSTARLET)$(XMLLINT),::)
507         @echo "--------------------------------------------------------------------------"
508         @echo "--- Please install xmllint or xmlstarlet to validate the documentation ---"
509         @echo "--------------------------------------------------------------------------"
510 else
511   ifneq ($(XMLLINT),:)
512         $(XMLLINT) --dtdvalid doc/appdocsxml.dtd --noout $<
513   else
514         $(XMLSTARLET) val -d doc/appdocsxml.dtd $<
515   endif
516 endif
517
518 update: 
519         @if [ -d .svn ]; then \
520                 echo "Updating from Subversion..." ; \
521                 fromrev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
522                 svn update | tee update.out; \
523                 torev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
524                 echo "`date`  Updated from revision $${fromrev} to $${torev}." >> update.log; \
525                 rm -f .version; \
526                 if [ `grep -c ^C update.out` -gt 0 ]; then \
527                         echo ; echo "The following files have conflicts:" ; \
528                         grep ^C update.out | cut -b4- ; \
529                 fi ; \
530                 rm -f update.out; \
531         else \
532                 echo "Not under version control";  \
533         fi
534
535 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
536 OLDHEADERS=$(filter-out $(NEWHEADERS) $(notdir $(DESTDIR)$(ASTHEADERDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
537
538 installdirs:
539         $(INSTALL) -d "$(DESTDIR)$(MODULES_DIR)"
540         $(INSTALL) -d "$(DESTDIR)$(ASTSBINDIR)"
541         $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)"
542         $(INSTALL) -d "$(DESTDIR)$(ASTVARRUNDIR)"
543         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)"
544         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/dictate"
545         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/meetme"
546         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/monitor"
547         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/system"
548         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/tmp"
549         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/voicemail"
550         $(INSTALL) -d "$(DESTDIR)$(ASTHEADERDIR)"
551         $(INSTALL) -d "$(DESTDIR)$(ASTHEADERDIR)/doxygen"
552         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)"
553         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)/cdr-csv"
554         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)/cdr-custom"
555         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)/cel-custom"
556         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)"
557         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/documentation"
558         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/documentation/thirdparty"
559         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/firmware"
560         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/firmware/iax"
561         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/images"
562         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/keys"
563         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/phoneprov"
564         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/static-http"
565         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/sounds"
566         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/moh"
567         $(INSTALL) -d "$(DESTDIR)$(ASTMANDIR)/man8"
568         $(INSTALL) -d "$(DESTDIR)$(AGI_DIR)"
569         $(INSTALL) -d "$(DESTDIR)$(ASTDBDIR)"
570
571 bininstall: _cleantest_all installdirs $(SUBDIRS_INSTALL)
572         $(INSTALL) -m 755 main/asterisk "$(DESTDIR)$(ASTSBINDIR)/"
573         $(LN) -sf asterisk "$(DESTDIR)$(ASTSBINDIR)/rasterisk"
574         $(INSTALL) -m 755 contrib/scripts/astgenkey "$(DESTDIR)$(ASTSBINDIR)/"
575         $(INSTALL) -m 755 contrib/scripts/autosupport "$(DESTDIR)$(ASTSBINDIR)/"
576         if [ ! -f "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk" -a ! -f /sbin/launchd ]; then \
577                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;s|__ASTERISK_LOG_DIR__|$(ASTLOGDIR)|;' > contrib/scripts/safe.tmp ; \
578                 $(INSTALL) -m 755 contrib/scripts/safe.tmp "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk" ; \
579                 rm -f contrib/scripts/safe.tmp ; \
580         fi
581         $(INSTALL) -m 644 include/asterisk.h "$(DESTDIR)$(includedir)"
582         $(INSTALL) -m 644 include/asterisk/*.h "$(DESTDIR)$(ASTHEADERDIR)"
583         $(INSTALL) -m 644 include/asterisk/doxygen/*.h "$(DESTDIR)$(ASTHEADERDIR)/doxygen"
584         if [ -n "$(OLDHEADERS)" ]; then \
585                 for h in $(OLDHEADERS); do rm -f "$(DESTDIR)$(ASTHEADERDIR)/$$h"; done \
586         fi
587
588         $(INSTALL) -m 644 doc/core-*.xml "$(DESTDIR)$(ASTDATADIR)/documentation"
589         $(INSTALL) -m 644 doc/appdocsxml.dtd "$(DESTDIR)$(ASTDATADIR)/documentation"
590         $(INSTALL) -m 644 doc/asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8"
591         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 "$(DESTDIR)$(ASTMANDIR)/man8"
592         $(INSTALL) -m 644 contrib/scripts/autosupport.8 "$(DESTDIR)$(ASTMANDIR)/man8"
593         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8"
594         if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
595                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin "$(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin"; \
596         fi
597
598 $(SUBDIRS_INSTALL):
599         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" $(SUBMAKE) -C $(@:-install=) install 
600
601 NEWMODS:=$(foreach d,$(MOD_SUBDIRS),$(notdir $(wildcard $(d)/*.so)))
602 OLDMODS=$(filter-out $(NEWMODS) $(notdir $(DESTDIR)$(MODULES_DIR)),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
603
604 oldmodcheck:
605         @if [ -n "$(OLDMODS)" ]; then \
606                 echo " WARNING WARNING WARNING" ;\
607                 echo "" ;\
608                 echo " Your Asterisk modules directory, located at" ;\
609                 echo " $(DESTDIR)$(MODULES_DIR)" ;\
610                 echo " contains modules that were not installed by this " ;\
611                 echo " version of Asterisk. Please ensure that these" ;\
612                 echo " modules are compatible with this version before" ;\
613                 echo " attempting to run Asterisk." ;\
614                 echo "" ;\
615                 for f in $(OLDMODS); do \
616                         echo "    $$f" ;\
617                 done ;\
618                 echo "" ;\
619                 echo " WARNING WARNING WARNING" ;\
620         fi
621
622 badshell:
623 ifneq ($(findstring ~,$(DESTDIR)),)
624         @echo "Your shell doesn't do ~ expansion when expected (specifically, when doing \"make install DESTDIR=~/path\")."
625         @echo "Try replacing ~ with \$$HOME, as in \"make install DESTDIR=\$$HOME/path\"."
626         @exit 1
627 endif
628
629 install: badshell bininstall datafiles
630         @if [ -x /usr/sbin/asterisk-post-install ]; then \
631                 /usr/sbin/asterisk-post-install "$(DESTDIR)" . ; \
632         fi
633         @echo " +---- Asterisk Installation Complete -------+"  
634         @echo " +                                           +"
635         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
636         @echo " +                                           +"
637         @echo " + Asterisk has successfully been installed. +"  
638         @echo " + If you would like to install the sample   +"  
639         @echo " + configuration files (overwriting any      +"
640         @echo " + existing config files), run:              +"  
641         @echo " +                                           +"
642         @echo " +               $(mK) samples               +"
643         @echo " +                                           +"
644         @echo " +-----------------  or ---------------------+"
645         @echo " +                                           +"
646         @echo " + You can go ahead and install the asterisk +"
647         @echo " + program documentation now or later run:   +"
648         @echo " +                                           +"
649         @echo " +              $(mK) progdocs               +"
650         @echo " +                                           +"
651         @echo " + **Note** This requires that you have      +"
652         @echo " + doxygen installed on your local system    +"
653         @echo " +-------------------------------------------+"
654         @$(MAKE) -s oldmodcheck
655
656 isntall: install
657
658 upgrade: bininstall
659
660 # XXX why *.adsi is installed first ?
661 adsi:
662         @echo Installing adsi config files...
663         $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)"
664         @for x in configs/*.adsi; do \
665                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
666                 if [ -f "$${dst}" ] ; then \
667                         echo "Overwriting $$x" ; \
668                 else \
669                         echo "Installing $$x" ; \
670                 fi ; \
671                 $(INSTALL) -m 644 "$$x" "$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
672         done
673
674 samples: adsi
675         @echo Installing other config files...
676         @for x in configs/*.sample; do \
677                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`" ;        \
678                 if [ -f "$${dst}" ]; then \
679                         if [ "$(OVERWRITE)" = "y" ]; then \
680                                 if cmp -s "$${dst}" "$$x" ; then \
681                                         echo "Config file $$x is unchanged"; \
682                                         continue; \
683                                 fi ; \
684                                 mv -f "$${dst}" "$${dst}.old" ; \
685                         else \
686                                 echo "Skipping config file $$x"; \
687                                 continue; \
688                         fi ;\
689                 fi ; \
690                 echo "Installing file $$x"; \
691                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
692         done
693         if [ "$(OVERWRITE)" = "y" ]; then \
694                 echo "Updating asterisk.conf" ; \
695                 sed -e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
696                         -e 's|^astmoddir.*$$|astmoddir => $(MODULES_DIR)|' \
697                         -e 's|^astvarlibdir.*$$|astvarlibdir => $(ASTVARLIBDIR)|' \
698                         -e 's|^astdbdir.*$$|astdbdir => $(ASTDBDIR)|' \
699                         -e 's|^astkeydir.*$$|astkeydir => $(ASTKEYDIR)|' \
700                         -e 's|^astdatadir.*$$|astdatadir => $(ASTDATADIR)|' \
701                         -e 's|^astagidir.*$$|astagidir => $(AGI_DIR)|' \
702                         -e 's|^astspooldir.*$$|astspooldir => $(ASTSPOOLDIR)|' \
703                         -e 's|^astrundir.*$$|astrundir => $(ASTVARRUNDIR)|' \
704                         -e 's|^astlogdir.*$$|astlogdir => $(ASTLOGDIR)|' \
705                         "$(DESTDIR)$(ASTCONFPATH)" > "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
706                 $(INSTALL) -m 644 "$(DESTDIR)$(ASTCONFPATH).tmp" "$(DESTDIR)$(ASTCONFPATH)" ; \
707                 rm -f "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
708         fi ; \
709         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX"
710         build_tools/make_sample_voicemail "$(DESTDIR)/$(ASTDATADIR)" "$(DESTDIR)/$(ASTSPOOLDIR)"
711
712         @for x in phoneprov/*; do \
713                 dst="$(DESTDIR)$(ASTDATADIR)/$$x" ;     \
714                 if [ -f "$${dst}" ]; then \
715                         if [ "$(OVERWRITE)" = "y" ]; then \
716                                 if cmp -s "$${dst}" "$$x" ; then \
717                                         echo "Config file $$x is unchanged"; \
718                                         continue; \
719                                 fi ; \
720                                 mv -f "$${dst}" "$${dst}.old" ; \
721                         else \
722                                 echo "Skipping config file $$x"; \
723                                 continue; \
724                         fi ;\
725                 fi ; \
726                 echo "Installing file $$x"; \
727                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
728         done
729
730 webvmail:
731         @[ -d "$(DESTDIR)$(HTTP_DOCSDIR)/" ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
732         @[ -d "$(DESTDIR)$(HTTP_CGIDIR)" ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
733         $(INSTALL) -m 4755 contrib/scripts/vmail.cgi "$(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi"
734         $(INSTALL) -d "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk"
735         for x in images/*.gif; do \
736                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/"; \
737         done
738         @echo " +--------- Asterisk Web Voicemail ----------+"  
739         @echo " +                                           +"
740         @echo " + Asterisk Web Voicemail is installed in    +"
741         @echo " + your cgi-bin directory:                   +"
742         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
743         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
744         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
745         @echo " +                                           +"
746         @echo " + Other static items have been stored in:   +"
747         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
748         @echo " +                                           +"
749         @echo " + If these paths do not match your httpd    +"
750         @echo " + installation, correct the definitions     +"
751         @echo " + in your Makefile of HTTP_CGIDIR and       +"
752         @echo " + HTTP_DOCSDIR                              +"
753         @echo " +                                           +"
754         @echo " +-------------------------------------------+"  
755
756 progdocs:
757         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
758         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - 
759
760 install-logrotate:
761         if [ ! -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ]; then \
762                 $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ; \
763         fi
764         sed 's#__LOGDIR__#$(ASTLOGDIR)#g' < contrib/scripts/asterisk.logrotate | sed 's#__SBINDIR__#$(ASTSBINDIR)#g' > contrib/scripts/asterisk.logrotate.tmp
765         $(INSTALL) -m 0644 contrib/scripts/asterisk.logrotate.tmp "$(DESTDIR)$(ASTETCDIR)/../logrotate.d/asterisk"
766         rm -f contrib/scripts/asterisk.logrotate.tmp
767
768 config:
769         @if [ "${OSARCH}" = "linux-gnu" ]; then \
770                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
771                         cat contrib/init.d/rc.redhat.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
772                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/init.d/asterisk" ; \
773                         rm -f contrib/init.d/rc.asterisk.tmp ; \
774                         if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \
775                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
776                         fi ; \
777                         if [ -z "$(DESTDIR)" ] ; then \
778                                 /sbin/chkconfig --add asterisk ; \
779                         fi ; \
780                 elif [ -f /etc/debian_version ] ; then \
781                         cat contrib/init.d/rc.debian.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
782                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ; \
783                         rm -f contrib/init.d/rc.asterisk.tmp ; \
784                         if [ ! -f "$(DESTDIR)/etc/default/asterisk" ] ; then \
785                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/default/asterisk" ; \
786                         fi ; \
787                         if [ -z "$(DESTDIR)" ] ; then \
788                                 /usr/sbin/update-rc.d asterisk defaults 50 91 ; \
789                         fi ; \
790                 elif [ -f /etc/gentoo-release ] ; then \
791                         cat contrib/init.d/rc.gentoo.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
792                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ; \
793                         rm -f contrib/init.d/rc.asterisk.tmp ; \
794                         if [ -z "$(DESTDIR)" ] ; then \
795                                 /sbin/rc-update add asterisk default ; \
796                         fi ; \
797                 elif [ -f /etc/mandrake-release -o -f /etc/mandriva-release ] ; then \
798                         cat contrib/init.d/rc.mandriva.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
799                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/init.d/asterisk" ; \
800                         rm -f contrib/init.d/rc.asterisk.tmp ; \
801                         if [ ! -f /etc/sysconfig/asterisk ] ; then \
802                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
803                         fi ; \
804                         if [ -z "$(DESTDIR)" ] ; then \
805                                 /sbin/chkconfig --add asterisk ; \
806                         fi ; \
807                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ] ; then \
808                         cat contrib/init.d/rc.suse.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
809                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ;\
810                         rm -f contrib/init.d/rc.asterisk.tmp ; \
811                         if [ ! -f /etc/sysconfig/asterisk ] ; then \
812                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
813                         fi ; \
814                         if [ -z "$(DESTDIR)" ] ; then \
815                                 /sbin/chkconfig --add asterisk ; \
816                         fi ; \
817                 elif [ -f /etc/arch-release -o -f /etc/arch-release ] ; then \
818                         cat contrib/init.d/rc.archlinux.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
819                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/asterisk" ; \
820                         rm -f contrib/init.d/rc.asterisk.tmp ; \
821                 elif [ -d "$(DESTDIR)/Library/LaunchDaemons" ]; then \
822                         if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist" ]; then \
823                                 sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.asterisk.plist > asterisk.plist ; \
824                                 $(INSTALL) -m 644 asterisk.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist"; \
825                                 rm -f asterisk.plist; \
826                         fi; \
827                         if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist" ]; then \
828                                 sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.muted.plist > muted.plist ; \
829                                 $(INSTALL) -m 644 muted.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist"; \
830                                 rm -f muted.plist; \
831                         fi; \
832                 elif [ -f /etc/slackware-version ]; then \
833                         echo "Slackware is not currently supported, although an init script does exist for it."; \
834                 else \
835                         echo "We could not install init scripts for your distribution." ; \
836                 fi \
837         else \
838                 echo "We could not install init scripts for your operating system." ; \
839         fi
840
841 sounds:
842         $(MAKE) -C sounds all
843
844 # If the cleancount has been changed, force a make clean.
845 # .cleancount is the global clean count, and .lastclean is the 
846 # last clean count we had
847
848 cleantest:
849         @cmp -s .cleancount .lastclean || $(MAKE) clean
850         @[ -f "$(DESTDIR)$(ASTDBDIR)/astdb.sqlite3" ] || [ ! -f "$(DESTDIR)$(ASTDBDIR)/astdb" ] || [ ! -f menuselect.makeopts ] || grep -q MENUSELECT_UTILS=.*astdb2sqlite3 menuselect.makeopts || (sed -i.orig -e's/MENUSELECT_UTILS=\(.*\)/MENUSELECT_UTILS=\1 astdb2sqlite3/' menuselect.makeopts && echo "Updating menuselect.makeopts to include astdb2sqlite3" && echo "Original version backed up to menuselect.makeopts.orig")
851
852 $(SUBDIRS_UNINSTALL):
853         +@$(SUBMAKE) -C $(@:-uninstall=) uninstall
854
855 _uninstall: $(SUBDIRS_UNINSTALL)
856         rm -f "$(DESTDIR)$(MODULES_DIR)/"*
857         rm -f "$(DESTDIR)$(ASTSBINDIR)/"*asterisk*
858         rm -f "$(DESTDIR)$(ASTSBINDIR)/astgenkey"
859         rm -f "$(DESTDIR)$(ASTSBINDIR)/autosupport"
860         rm -rf "$(DESTDIR)$(ASTHEADERDIR)"
861         rm -rf "$(DESTDIR)$(ASTDATADIR)/firmware"
862         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/asterisk.8"
863         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8"
864         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/autosupport.8"
865         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8"
866         $(MAKE) -C sounds uninstall
867
868 uninstall: _uninstall
869         @echo " +--------- Asterisk Uninstall Complete -----+"  
870         @echo " + Asterisk binaries, sounds, man pages,     +"  
871         @echo " + headers, modules, and firmware builds,    +"  
872         @echo " + have all been uninstalled.                +"  
873         @echo " +                                           +"
874         @echo " + To remove ALL traces of Asterisk,         +"
875         @echo " + including configuration, spool            +"
876         @echo " + directories, and logs, run the following  +"
877         @echo " + command:                                  +"
878         @echo " +                                           +"
879         @echo " +            $(mK) uninstall-all            +"  
880         @echo " +-------------------------------------------+"  
881
882 uninstall-all: _uninstall
883         rm -rf "$(DESTDIR)$(ASTLIBDIR)"
884         rm -rf "$(DESTDIR)$(ASTVARLIBDIR)"
885         rm -rf "$(DESTDIR)$(ASTDATADIR)"
886         rm -rf "$(DESTDIR)$(ASTSPOOLDIR)"
887         rm -rf "$(DESTDIR)$(ASTETCDIR)"
888         rm -rf "$(DESTDIR)$(ASTLOGDIR)"
889
890 menuconfig: menuselect
891
892 cmenuconfig: cmenuselect
893
894 gmenuconfig: gmenuselect
895
896 nmenuconfig: nmenuselect
897
898 menuselect: menuselect/cmenuselect menuselect/nmenuselect menuselect/gmenuselect
899         @if [ -x menuselect/nmenuselect ]; then \
900                 $(MAKE) nmenuselect; \
901         elif [ -x menuselect/cmenuselect ]; then \
902                 $(MAKE) cmenuselect; \
903         elif [ -x menuselect/gmenuselect ]; then \
904                 $(MAKE) gmenuselect; \
905         else \
906                 echo "No menuselect user interface found. Install ncurses,"; \
907                 echo "newt or GTK libraries to build one and re-rerun"; \
908                 echo "'./configure' and 'make menuselect'."; \
909         fi
910
911 cmenuselect: menuselect/cmenuselect menuselect-tree menuselect.makeopts
912         -@menuselect/cmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
913
914 gmenuselect: menuselect/gmenuselect menuselect-tree menuselect.makeopts
915         -@menuselect/gmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
916
917 nmenuselect: menuselect/nmenuselect menuselect-tree menuselect.makeopts
918         -@menuselect/nmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
919
920 # options for make in menuselect/
921 MAKE_MENUSELECT=CC="$(BUILD_CC)" CXX="" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
922
923 menuselect/menuselect: menuselect/makeopts
924         +$(MAKE_MENUSELECT) menuselect
925
926 menuselect/cmenuselect: menuselect/makeopts
927         +$(MAKE_MENUSELECT) cmenuselect
928
929 menuselect/gmenuselect: menuselect/makeopts
930         +$(MAKE_MENUSELECT) gmenuselect
931
932 menuselect/nmenuselect: menuselect/makeopts
933         +$(MAKE_MENUSELECT) nmenuselect
934
935 menuselect/makeopts: makeopts
936         +$(MAKE_MENUSELECT) makeopts
937
938 menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml build_tools/embed_modules.xml utils/utils.xml agi/agi.xml configure makeopts
939         @echo "Generating input for menuselect ..."
940         @echo "<?xml version=\"1.0\"?>" > $@
941         @echo >> $@
942         @echo "<menu name=\"Asterisk Module and Build Option Selection\">" >> $@
943         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} moduleinfo >> $@; done
944         @cat build_tools/cflags.xml >> $@
945         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} makeopts >> $@; done
946         @if [ "${AST_DEVMODE}" = "yes" ]; then \
947                 cat build_tools/cflags-devmode.xml >> $@; \
948         fi
949         @cat utils/utils.xml >> $@
950         @cat agi/agi.xml >> $@
951         @cat build_tools/embed_modules.xml >> $@
952         @cat sounds/sounds.xml >> $@
953         @echo "</menu>" >> $@
954
955 .PHONY: menuselect
956 .PHONY: main
957 .PHONY: sounds
958 .PHONY: clean
959 .PHONY: dist-clean
960 .PHONY: distclean
961 .PHONY: all
962 .PHONY: _all
963 .PHONY: _cleantest_all
964 .PHONY: prereqs
965 .PHONY: cleantest
966 .PHONY: uninstall
967 .PHONY: _uninstall
968 .PHONY: uninstall-all
969 .PHONY: dont-optimize
970 .PHONY: badshell
971 .PHONY: installdirs
972 .PHONY: validate-docs
973 .PHONY: _clean
974 .PHONY: $(SUBDIRS_INSTALL)
975 .PHONY: $(SUBDIRS_DIST_CLEAN)
976 .PHONY: $(SUBDIRS_CLEAN)
977 .PHONY: $(SUBDIRS_UNINSTALL)
978 .PHONY: $(SUBDIRS)
979 .PHONY: $(MOD_SUBDIRS_EMBED_LDSCRIPT)
980 .PHONY: $(MOD_SUBDIRS_EMBED_LDFLAGS)
981 .PHONY: $(MOD_SUBDIRS_EMBED_LIBS)
982
983 FORCE:
984