bridge: Fix returning to dialplan when executing Bridge() from AMI.
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- An open source telephony toolkit.
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 dynamically loadable modules
23 #          as .so files
24 # DYLINK - linker flags used only for creating shared libaries
25 #          (.so files on Unix-type platforms, .dylib on Darwin)
26 #
27 # Values for ASTCFLAGS and ASTLDFLAGS can be specified in the
28 # environment when running make, as follows:
29 #
30 #       $ ASTCFLAGS="-Werror" make ...
31 #
32 # or as a variable value on the make command line itself:
33 #
34 #       $ make ASTCFLAGS="-Werror" ...
35
36 export ASTTOPDIR                # Top level dir, used in subdirs' Makefiles
37 export ASTERISKVERSION
38 export ASTERISKVERSIONNUM
39
40 #--- values used for default paths
41
42 # DESTDIR is the staging (or final) directory where files are copied
43 # during the install process. Define it before 'export', otherwise
44 # export will set it to the empty string making ?= fail.
45 # Trying to run asterisk from the DESTDIR is completely unsupported
46 # behavior.
47 # WARNING: do not put spaces or comments after the value.
48 DESTDIR?=$(INSTALL_PATH)
49 export DESTDIR
50
51 export INSTALL_PATH       # Additional prefix for the following paths
52 export ASTETCDIR          # Path for config files
53 export ASTVARRUNDIR
54 export ASTSPOOLDIR
55 export ASTVARLIBDIR
56 export ASTDATADIR
57 export ASTDBDIR
58 export ASTLOGDIR
59 export ASTLIBDIR
60 export ASTMODDIR
61 export ASTMANDIR
62 export ASTHEADERDIR
63 export ASTSBINDIR
64 export AGI_DIR
65 export ASTCONFPATH
66 export ASTKEYDIR
67
68 export OSARCH             # Operating system
69
70 export NOISY_BUILD        # Used in Makefile.rules
71 export MENUSELECT_CFLAGS  # Options selected in menuselect.
72 export AST_DEVMODE        # Set to "yes" for additional compiler
73                           # and runtime checks
74 export AST_DEVMODE_STRICT # Enables shadow warnings (-Wshadow)
75
76 export _SOLINK            # linker flags for all shared objects
77 export SOLINK             # linker flags for loadable modules
78 export DYLINK             # linker flags for shared libraries
79 export STATIC_BUILD       # Additional cflags, set to -static
80                           # for static builds. Probably
81                           # should go directly to ASTLDFLAGS
82
83 #--- paths to various commands
84 # The makeopts include below tries to set these if they're found during
85 # configure.
86 export CC
87 export CXX
88 export AR
89 export RANLIB
90 export HOST_CC
91 export BUILD_CC
92 export INSTALL
93 export STRIP
94 export DOWNLOAD
95 export AWK
96 export GREP
97 export MD5
98 export WGET_EXTRA_ARGS
99 export LDCONFIG
100 export LDCONFIG_FLAGS
101 export PYTHON
102 export TAR
103 export PATCH
104 export SED
105 export NM
106
107 # makeopts is required unless the goal is clean or distclean
108 ifeq ($(findstring clean,$(MAKECMDGOALS)),)
109 include makeopts
110 endif
111
112 # start the primary CFLAGS and LDFLAGS with any that were provided
113 # to the configure script
114 _ASTCFLAGS:=$(CONFIG_CFLAGS) $(CONFIG_SIGNED_CHAR)
115 _ASTLDFLAGS:=$(CONFIG_LDFLAGS)
116
117 # Some build systems, such as the one in openwrt, like to pass custom target
118 # CFLAGS and LDFLAGS in the COPTS and LDOPTS variables; these should also
119 # go before any build-system computed flags, since they are defaults, not
120 # overrides
121 _ASTCFLAGS+=$(COPTS)
122 _ASTLDFLAGS+=$(LDOPTS)
123
124 # libxml2 cflags
125 _ASTCFLAGS+=$(LIBXML2_INCLUDE)
126
127 #Uncomment this to see all build commands instead of 'quiet' output
128 #NOISY_BUILD=yes
129
130 empty:=
131 space:=$(empty) $(empty)
132 ASTTOPDIR:=$(subst $(space),\$(space),$(CURDIR))
133
134 # Overwite config files on "make samples" or other config installation targets
135 OVERWRITE=y
136
137 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
138 DEBUG=-g3
139
140 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
141 # when starting Asterisk
142 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
143 AGI_DIR=$(ASTDATADIR)/agi-bin
144
145 # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file
146 HTTP_DOCSDIR=/var/www/html
147 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
148 HTTP_CGIDIR=/var/www/cgi-bin
149
150 # If your platform's linker expects a prefix on symbols generated from compiling C
151 # source files, set LINKER_SYMBOL_PREFIX to that value. On some systems, exported symbols
152 # from C source files are prefixed with '_', for example. If this value is not set
153 # properly, the linker scripts that live in the '*.exports' files in various places
154 # in this tree will unintentionally suppress symbols that should be visible
155 # in the final binary objects.
156 LINKER_SYMBOL_PREFIX=
157
158 # Uncomment this to use the older DSP routines
159 #_ASTCFLAGS+=-DOLD_DSP_ROUTINES
160
161 # Default install directory for DAHDI hooks.
162 DAHDI_UDEV_HOOK_DIR = /usr/share/dahdi/span_config.d
163
164 # If the file .asterisk.makeopts is present in your home directory, you can
165 # include all of your favorite menuselect options so that every time you download
166 # a new version of Asterisk, you don't have to run menuselect to set them.
167 # The file /etc/asterisk.makeopts will also be included but can be overridden
168 # by the file in your home directory.
169
170 ifeq ($(wildcard menuselect.makeopts),)
171         USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
172         GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
173 else
174         USER_MAKEOPTS=
175         GLOBAL_MAKEOPTS=
176 endif
177
178
179 MOD_SUBDIR_CFLAGS="-I$(ASTTOPDIR)/include"
180 OTHER_SUBDIR_CFLAGS="-I$(ASTTOPDIR)/include"
181
182 # Create OPTIONS variable, but probably we can assign directly to ASTCFLAGS
183 OPTIONS=
184
185 ifeq ($(findstring -save-temps,$(_ASTCFLAGS) $(ASTCFLAGS)),)
186   ifeq ($(findstring -pipe,$(_ASTCFLAGS) $(ASTCFLAGS)),)
187     _ASTCFLAGS+=-pipe
188   endif
189 endif
190
191 ifeq ($(findstring -Wall,$(_ASTCFLAGS) $(ASTCFLAGS)),)
192   _ASTCFLAGS+=-Wall
193 endif
194
195 _ASTCFLAGS+=-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_NESTED_FUNCTIONS) $(AST_CLANG_BLOCKS) $(DEBUG)
196 ADDL_TARGETS=
197
198 ifeq ($(AST_DEVMODE),yes)
199   _ASTCFLAGS+=-Werror
200   _ASTCFLAGS+=-Wunused
201   _ASTCFLAGS+=$(AST_DECLARATION_AFTER_STATEMENT)
202   _ASTCFLAGS+=$(AST_TRAMPOLINES)
203   _ASTCFLAGS+=-Wundef
204   _ASTCFLAGS+=-Wmissing-format-attribute
205   _ASTCFLAGS+=-Wformat=2
206   ifeq ($(AST_DEVMODE_STRICT),yes)
207     _ASTCFLAGS+=-Wshadow
208   endif
209   ADDL_TARGETS+=validate-docs
210 endif
211
212 ifneq ($(findstring BSD,$(OSARCH)),)
213   _ASTCFLAGS+=-isystem /usr/local/include
214 endif
215
216 ifeq ($(OSARCH),FreeBSD)
217   # -V is understood by BSD Make, not by GNU make.
218   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
219   _ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
220 endif
221
222 ifeq ($(OSARCH),NetBSD)
223   _ASTCFLAGS+=-pthread -I/usr/pkg/include
224 endif
225
226 ifeq ($(OSARCH),OpenBSD)
227   _ASTCFLAGS+=-pthread -ftrampolines
228 endif
229
230 ifeq ($(OSARCH),SunOS)
231   _ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include -D_XPG4_2 -D__EXTENSIONS__
232 endif
233
234 ifneq ($(GREP),)
235   ASTERISKVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) GIT=$(GIT) build_tools/make_version .)
236 endif
237 ifneq ($(AWK),)
238   ifneq ($(wildcard .version),)
239     ASTERISKVERSIONNUM:=$(shell $(AWK) -F. '{printf "%01d%02d%02d", $$1, $$2, $$3}' .version)
240   endif
241 endif
242
243 ifneq ($(wildcard .svn),)
244   ASTERISKVERSIONNUM:=999999
245 endif
246
247 _ASTCFLAGS+=$(OPTIONS)
248
249 MOD_SUBDIRS:=third-party channels pbx apps codecs formats cdr cel bridges funcs tests main res addons $(LOCAL_MOD_SUBDIRS)
250 OTHER_SUBDIRS:=utils agi contrib
251 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
252 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
253 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
254 SUBDIRS_DIST_CLEAN:=$(SUBDIRS:%=%-dist-clean)
255 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
256 MOD_SUBDIRS_MENUSELECT_TREE:=$(MOD_SUBDIRS:%=%-menuselect-tree)
257
258 ifneq ($(findstring darwin,$(OSARCH)),)
259   _ASTCFLAGS+=-D__Darwin__ -mmacosx-version-min=10.6
260   _SOLINK=-mmacosx-version-min=10.6 -Wl,-undefined,dynamic_lookup
261   _SOLINK+=/usr/lib/bundle1.o
262   SOLINK=-bundle $(_SOLINK)
263   DYLINK=-Wl,-dylib $(_SOLINK)
264   _ASTLDFLAGS+=-L/usr/local/lib
265 else
266 # These are used for all but Darwin
267   SOLINK=-shared
268   DYLINK=$(SOLINK)
269   ifneq ($(findstring BSD,$(OSARCH)),)
270     _ASTLDFLAGS+=-L/usr/local/lib
271   endif
272 endif
273
274 # Include rpath settings
275 _ASTLDFLAGS+=$(AST_RPATH)
276
277 ifeq ($(OSARCH),SunOS)
278   SOLINK=-shared -fpic -L/usr/local/ssl/lib -lrt
279   DYLINK=$(SOLINK)
280 endif
281
282 ifeq ($(OSARCH),OpenBSD)
283   SOLINK=-shared -fpic
284   DYLINK=$(SOLINK)
285 endif
286
287 # comment to print directories during submakes
288 #PRINT_DIR=yes
289
290 ifneq ($(INSIDE_EMACS),)
291 PRINT_DIR=yes
292 endif
293
294 SILENTMAKE:=$(MAKE) --quiet --no-print-directory
295 ifneq ($(PRINT_DIR)$(NOISY_BUILD),)
296 SUBMAKE:=$(MAKE)
297 else
298 SUBMAKE:=$(MAKE) --quiet --no-print-directory
299 endif
300
301 # $(MAKE) is printed in several places, and we want it to be a
302 # fixed size string. Define a variable whose name has also the
303 # same size, so we can easily align text.
304 ifeq ($(MAKE), gmake)
305         mK="gmake"
306 else
307         mK=" make"
308 endif
309
310 all: _all
311         @echo " +--------- Asterisk Build Complete ---------+"
312         @echo " + Asterisk has successfully been built, and +"
313         @echo " + can be installed by running:              +"
314         @echo " +                                           +"
315         @echo " +               $(mK) install               +"
316         @echo " +-------------------------------------------+"
317
318 full: _full
319         @echo " +--------- Asterisk Build Complete ---------+"
320         @echo " + Asterisk has successfully been built, and +"
321         @echo " + can be installed by running:              +"
322         @echo " +                                           +"
323         @echo " +               $(mK) install               +"
324         @echo " +-------------------------------------------+"
325
326
327 _all: makeopts $(SUBDIRS) doc/core-en_US.xml $(ADDL_TARGETS)
328
329 _full: makeopts $(SUBDIRS) doc/full-en_US.xml $(ADDL_TARGETS)
330
331 makeopts: configure
332         @echo "****"
333         @echo "**** The configure script must be executed before running '$(MAKE)'."
334         @echo "****               Please run \"./configure\"."
335         @echo "****"
336         @exit 1
337
338 menuselect.makeopts: menuselect/menuselect menuselect-tree makeopts build_tools/menuselect-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS)
339 ifeq ($(filter %.menuselect,$(MAKECMDGOALS)),)
340         menuselect/menuselect --check-deps $@
341         menuselect/menuselect --check-deps $@ $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS)
342 endif
343
344 $(MOD_SUBDIRS_MENUSELECT_TREE):
345         +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) moduleinfo
346         +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) makeopts
347
348 $(SUBDIRS): makeopts .lastclean main/version.c include/asterisk/build.h include/asterisk/buildopts.h defaults.h
349
350 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
351 main: third-party
352 else
353     # Windows: we need to build main (i.e. the asterisk dll) first,
354     # followed by res, followed by the other directories, because
355     # dll symbols must be resolved during linking and not at runtime.
356 D1:= $(filter-out main,$(MOD_SUBDIRS))
357 D1:= $(filter-out res,$(D1))
358
359 $(D1): res
360 res:    main
361 endif
362
363 $(MOD_SUBDIRS): makeopts
364         +@_ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(_ASTCFLAGS)" ASTCFLAGS="$(ASTCFLAGS)" _ASTLDFLAGS="$(_ASTLDFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(SUBMAKE) --no-builtin-rules -C $@ SUBDIR=$@ all
365
366 $(OTHER_SUBDIRS): makeopts
367         +@_ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(_ASTCFLAGS)" ASTCFLAGS="$(ASTCFLAGS)" _ASTLDFLAGS="$(_ASTLDFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(SUBMAKE) --no-builtin-rules -C $@ SUBDIR=$@ all
368
369 defaults.h: makeopts .lastclean build_tools/make_defaults_h
370         @build_tools/make_defaults_h > $@.tmp
371         @cmp -s $@.tmp $@ || mv $@.tmp $@
372         @rm -f $@.tmp
373
374 main/version.c: FORCE menuselect.makeopts .lastclean
375         @build_tools/make_version_c > $@.tmp
376         @cmp -s $@.tmp $@ || mv $@.tmp $@
377         @rm -f $@.tmp
378
379 include/asterisk/buildopts.h: menuselect.makeopts .lastclean
380         @build_tools/make_buildopts_h > $@.tmp
381         @cmp -s $@.tmp $@ || mv $@.tmp $@
382         @rm -f $@.tmp
383
384 # build.h must depend on .lastclean, or parallel make may wipe it out after it's
385 # been created.
386 include/asterisk/build.h: .lastclean
387         @build_tools/make_build_h > $@
388
389 $(SUBDIRS_CLEAN):
390         +@$(SUBMAKE) -C $(@:-clean=) clean
391
392 $(SUBDIRS_DIST_CLEAN):
393         +@$(SUBMAKE) -C $(@:-dist-clean=) dist-clean
394
395 clean: $(SUBDIRS_CLEAN) _clean
396
397 _clean:
398         rm -f defaults.h
399         rm -f include/asterisk/build.h
400         rm -f main/version.c
401         rm -f doc/core-en_US.xml
402         rm -f doc/full-en_US.xml
403         rm -f doc/rest-api/*.wiki
404         rm -f doxygen.log
405         rm -rf latex
406         rm -f rest-api-templates/*.pyc
407         @$(MAKE) -C menuselect clean
408         cp -f .cleancount .lastclean
409
410 dist-clean: distclean
411
412 distclean: $(SUBDIRS_DIST_CLEAN) _clean
413         @$(MAKE) -C menuselect dist-clean
414         @$(MAKE) -C sounds dist-clean
415         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
416         rm -f config.log config.status config.cache
417         rm -rf autom4te.cache
418         rm -f include/asterisk/autoconfig.h
419         rm -f include/asterisk/buildopts.h
420         rm -rf doc/api
421         rm -f doc/asterisk-ng-doxygen
422         rm -f build_tools/menuselect-deps
423
424 datafiles: _all doc/core-en_US.xml
425         CFLAGS="$(_ASTCFLAGS) $(ASTCFLAGS)" build_tools/mkpkgconfig "$(DESTDIR)$(libdir)/pkgconfig";
426
427 #       # Recursively install contents of the static-http directory, in case
428 #       # extra content is provided there. See contrib/scripts/get_swagger_ui.sh
429         find static-http | while read x; do \
430                 if test -d $$x; then \
431                         $(INSTALL) -m 755 -d "$(DESTDIR)$(ASTDATADIR)/$$x"; \
432                 else \
433                         $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/$$x" ; \
434                 fi \
435         done
436         $(INSTALL) -m 644 doc/core-en_US.xml "$(DESTDIR)$(ASTDATADIR)/static-http";
437         $(INSTALL) -m 644 doc/appdocsxml.xslt "$(DESTDIR)$(ASTDATADIR)/static-http";
438         if [ -d doc/tex/asterisk ] ; then \
439                 $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \
440                 for n in doc/tex/asterisk/* ; do \
441                         $(INSTALL) -m 644 $$n "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \
442                 done \
443         fi
444         for x in images/*.jpg; do \
445                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/images" ; \
446         done
447         $(MAKE) -C sounds install
448         find rest-api -name "*.json" | while read x; do \
449                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/rest-api" ; \
450         done
451
452 ifneq ($(GREP),)
453   XML_core_en_US = $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
454 endif
455
456 doc/core-en_US.xml: makeopts .lastclean $(XML_core_en_US)
457         @printf "Building Documentation For: "
458         @echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $@
459         @echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@
460         @echo "<?xml-stylesheet type=\"text/xsl\" href=\"appdocsxml.xslt\"?>" >> $@
461         @echo "<docs xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> $@
462         @for x in $(MOD_SUBDIRS); do \
463                 printf "$$x " ; \
464                 for i in `find $$x -name '*.c'`; do \
465                         $(AWK) -f build_tools/get_documentation $$i >> $@ ; \
466                 done ; \
467         done
468         @echo
469         @echo "</docs>" >> $@
470
471 ifneq ($(GREP),)
472   XML_full_en_US = $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
473 endif
474
475 doc/full-en_US.xml: makeopts .lastclean $(XML_full_en_US)
476 ifeq ($(PYTHON),:)
477         @echo "--------------------------------------------------------------------------"
478         @echo "---        Please install python to build full documentation           ---"
479         @echo "--------------------------------------------------------------------------"
480 else
481         @printf "Building Documentation For: "
482         @echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $@
483         @echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@
484         @echo "<?xml-stylesheet type=\"text/xsl\" href=\"appdocsxml.xslt\"?>" >> $@
485         @echo "<docs xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> $@
486         @for x in $(MOD_SUBDIRS); do \
487                 printf "$$x " ; \
488                 for i in `find $$x -name '*.c'`; do \
489                         $(PYTHON) build_tools/get_documentation.py < $$i >> $@ ; \
490                 done ; \
491         done
492         @echo
493         @echo "</docs>" >> $@
494         @$(PYTHON) build_tools/post_process_documentation.py -i $@ -o "doc/core-en_US.xml"
495 endif
496
497 validate-docs: doc/core-en_US.xml
498 ifeq ($(XMLSTARLET)$(XMLLINT),::)
499         @echo "--------------------------------------------------------------------------"
500         @echo "--- Please install xmllint or xmlstarlet to validate the documentation ---"
501         @echo "--------------------------------------------------------------------------"
502 else
503   ifneq ($(XMLLINT),:)
504         $(XMLLINT) --dtdvalid doc/appdocsxml.dtd --noout $<
505   else
506         $(XMLSTARLET) val -d doc/appdocsxml.dtd $<
507   endif
508 endif
509
510 update:
511         @if [ -d .svn ]; then \
512                 echo "Updating from Subversion..." ; \
513                 fromrev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
514                 svn update | tee update.out; \
515                 torev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
516                 echo "`date`  Updated from revision $${fromrev} to $${torev}." >> update.log; \
517                 rm -f .version; \
518                 if [ `grep -c ^C update.out` -gt 0 ]; then \
519                         echo ; echo "The following files have conflicts:" ; \
520                         grep ^C update.out | cut -b4- ; \
521                 fi ; \
522                 rm -f update.out; \
523         else \
524                 echo "Not under version control";  \
525         fi
526
527 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
528 OLDHEADERS=$(filter-out $(NEWHEADERS) $(notdir $(DESTDIR)$(ASTHEADERDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
529 INSTALLDIRS="$(ASTLIBDIR)" "$(ASTMODDIR)" "$(ASTSBINDIR)" "$(ASTETCDIR)" "$(ASTVARRUNDIR)" \
530         "$(ASTSPOOLDIR)" "$(ASTSPOOLDIR)/dictate" "$(ASTSPOOLDIR)/meetme" \
531         "$(ASTSPOOLDIR)/monitor" "$(ASTSPOOLDIR)/system" "$(ASTSPOOLDIR)/tmp" \
532         "$(ASTSPOOLDIR)/voicemail" "$(ASTSPOOLDIR)/recording" \
533         "$(ASTHEADERDIR)" "$(ASTHEADERDIR)/doxygen" \
534         "$(ASTLOGDIR)" "$(ASTLOGDIR)/cdr-csv" "$(ASTLOGDIR)/cdr-custom" \
535         "$(ASTLOGDIR)/cel-custom" "$(ASTDATADIR)" "$(ASTDATADIR)/documentation" \
536         "$(ASTDATADIR)/documentation/thirdparty" "$(ASTDATADIR)/firmware" \
537         "$(ASTDATADIR)/firmware/iax" "$(ASTDATADIR)/images" "$(ASTDATADIR)/keys" \
538         "$(ASTDATADIR)/phoneprov" "$(ASTDATADIR)/rest-api" "$(ASTDATADIR)/static-http" \
539         "$(ASTDATADIR)/sounds" "$(ASTDATADIR)/moh" "$(ASTMANDIR)/man8" "$(AGI_DIR)" "$(ASTDBDIR)" \
540         "$(ASTDATADIR)/third-party"
541
542 installdirs:
543         @for i in $(INSTALLDIRS); do \
544                 if [ ! -z "$${i}" -a ! -d "$(DESTDIR)$${i}" ]; then \
545                         $(INSTALL) -d "$(DESTDIR)$${i}"; \
546                 fi; \
547         done
548
549 main-bininstall:
550         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTLIBDIR="$(ASTLIBDIR)" $(SUBMAKE) -C main bininstall
551
552 bininstall: _all installdirs $(SUBDIRS_INSTALL) main-bininstall
553         $(INSTALL) -m 755 contrib/scripts/astversion "$(DESTDIR)$(ASTSBINDIR)/"
554         $(INSTALL) -m 755 contrib/scripts/astgenkey "$(DESTDIR)$(ASTSBINDIR)/"
555         $(INSTALL) -m 755 contrib/scripts/autosupport "$(DESTDIR)$(ASTSBINDIR)/"
556         if [ ! -f /sbin/launchd ]; then \
557                 ./build_tools/install_subst contrib/scripts/safe_asterisk "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk"; \
558         fi
559         $(INSTALL) -m 644 include/asterisk.h "$(DESTDIR)$(includedir)"
560         $(INSTALL) -m 644 include/asterisk/*.h "$(DESTDIR)$(ASTHEADERDIR)"
561         $(INSTALL) -m 644 include/asterisk/doxygen/*.h "$(DESTDIR)$(ASTHEADERDIR)/doxygen"
562         if [ -n "$(OLDHEADERS)" ]; then \
563                 for h in $(OLDHEADERS); do rm -f "$(DESTDIR)$(ASTHEADERDIR)/$$h"; done \
564         fi
565
566         $(INSTALL) -m 644 doc/core-*.xml "$(DESTDIR)$(ASTDATADIR)/documentation"
567         $(INSTALL) -m 644 doc/appdocsxml.xslt "$(DESTDIR)$(ASTDATADIR)/documentation"
568         $(INSTALL) -m 644 doc/appdocsxml.dtd "$(DESTDIR)$(ASTDATADIR)/documentation"
569         $(INSTALL) -m 644 doc/asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8"
570         $(INSTALL) -m 644 doc/astdb*.8 "$(DESTDIR)$(ASTMANDIR)/man8"
571         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 "$(DESTDIR)$(ASTMANDIR)/man8"
572         $(INSTALL) -m 644 contrib/scripts/autosupport.8 "$(DESTDIR)$(ASTMANDIR)/man8"
573         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8"
574         if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
575                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin "$(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin"; \
576         fi
577 ifeq ($(HAVE_DAHDI),1)
578         $(INSTALL) -d $(DESTDIR)/$(DAHDI_UDEV_HOOK_DIR)
579         $(INSTALL) -m 644 contrib/scripts/dahdi_span_config_hook $(DESTDIR)$(DAHDI_UDEV_HOOK_DIR)/40-asterisk
580 endif
581
582 $(SUBDIRS_INSTALL):
583         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTDATADIR="$(ASTDATADIR)" $(SUBMAKE) -C $(@:-install=) install
584
585 NEWMODS:=$(foreach d,$(MOD_SUBDIRS),$(notdir $(wildcard $(d)/*.so)))
586 OLDMODS=$(filter-out $(NEWMODS) $(notdir $(DESTDIR)$(ASTMODDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTMODDIR)/*.so)))
587 BADMODS=$(strip $(filter-out $(shell ./build_tools/list_valid_installed_externals),$(OLDMODS)))
588
589 oldmodcheck:
590         @if [ -n "$(BADMODS)" ]; then \
591                 echo " WARNING WARNING WARNING" ;\
592                 echo "" ;\
593                 echo " Your Asterisk modules directory, located at" ;\
594                 echo " $(DESTDIR)$(ASTMODDIR)" ;\
595                 echo " contains modules that were not installed by this " ;\
596                 echo " version of Asterisk. Please ensure that these" ;\
597                 echo " modules are compatible with this version before" ;\
598                 echo " attempting to run Asterisk." ;\
599                 echo "" ;\
600                 for f in $(BADMODS); do \
601                         echo "    $$f" ;\
602                 done ;\
603                 echo "" ;\
604                 echo " WARNING WARNING WARNING" ;\
605         fi
606
607 ld-cache-update:
608 ifneq ($(LDCONFIG),)
609 ifeq ($(DESTDIR),)  # DESTDIR means binary archive creation; ldconfig should be run on postinst
610         @if [ $${EUID} -eq 0 ] ; then \
611                 $(LDCONFIG) "$(ASTLIBDIR)/" ; \
612         else \
613                 echo " WARNING WARNING WARNING" ;\
614                 echo "" ;\
615                 echo " You cannot rebuild the system linker cache unless you are root. " ;\
616                 echo " You MUST do one of the following..." ;\
617                 echo "  * Re-run 'make install' as root. " ;\
618                 echo "  * Run 'ldconfig $(ASTLIBDIR)' as root. " ;\
619                 echo "  * Run asterisk with 'LD_LIBRARY_PATH=$(ASTLIBDIR) asterisk' " ;\
620                 echo "" ;\
621                 echo " WARNING WARNING WARNING" ;\
622         fi
623 endif
624 endif
625
626 export _oldlibdir =
627 export _oldmoddir =
628 ifeq ($(findstring 64,$(HOST_CPU)),64)
629     # Strip any trailing '/' so the dir and notdir functions work correctly
630     _current_libdir = $(patsubst %/,%,$(DESTDIR)$(ASTLIBDIR))
631
632     # Only process if the paths end in lib64 or lib.
633     # If we're installing to lib64, check lib for orphans.
634     # If we're installing to lib, check lib64 for orphans.
635     # Otherwise, leave _oldlibdir empty.
636     ifeq ($(notdir $(_current_libdir)),lib64)
637         _oldlibdir = $(dir $(_current_libdir))lib
638     else ifeq ($(notdir $(_current_libdir)),lib)
639         _oldlibdir = $(dir $(_current_libdir))lib64
640     endif
641
642     # Strip any trailing '/' so the dir and notdir functions work correctly
643     _current_moddir = $(patsubst %/,%,$(DESTDIR)$(ASTMODDIR))
644
645     # Only process if the paths contain /lib64/ or /lib/.
646     # If we're installing to lib64, check lib for orphans.
647     # If we're installing to lib, check lib64 for orphans.
648     # Otherwise, leave _oldmoddir empty.
649     ifeq ($(findstring /lib64/,$(_current_moddir)),/lib64/)
650         _oldmoddir = $(subst /lib64/,/lib/,$(_current_moddir))
651     else ifeq ($(findstring /lib/,$(_current_moddir)),/lib/)
652         _oldmoddir = $(subst /lib/,/lib64/,$(_current_moddir))
653     endif
654 endif
655
656 check-old-libdir:
657         @test -n "$(_oldlibdir)" -a -d "$(_oldlibdir)" || exit 0 ;\
658         oldfiles=`find "$(_oldlibdir)" -name libasterisk* -print -quit -o \( -path *asterisk/modules/* -a -name *.so \) -print -quit 2>/dev/null` ;\
659         if [ "x$$oldfiles" != "x" ] ; then \
660                 echo " WARNING WARNING WARNING" ;\
661                 echo "" ;\
662                 echo " Installation is to: " ;\
663                 echo "   $(DESTDIR)$(ASTLIBDIR)" ;\
664                 echo " but there are asterisk shared libraries in: " ;\
665                 echo "   $(_oldlibdir)" ;\
666                 echo " or" ;\
667                 echo "   $(_oldlibdir)/asterisk/modules" ;\
668                 echo "" ;\
669                 echo " It is unlikely that asterisk will start." ;\
670                 echo "" ;\
671                 echo " You should do one of the following..." ;\
672                 echo "  * Run 'make uninstall' to remove the incorrect libraries" ;\
673                 echo "    then run 'make install' again." ;\
674                 echo "  * Manually remove the libraries from" ;\
675                 echo "   $(_oldlibdir)" ;\
676                 echo "   and run 'ldconfig' to rebuild the linker cache." ;\
677                 echo "" ;\
678                 echo " WARNING WARNING WARNING" ;\
679         fi
680
681 badshell:
682 ifneq ($(filter ~%,$(DESTDIR)),)
683         @echo "Your shell doesn't do ~ expansion when expected (specifically, when doing \"make install DESTDIR=~/path\")."
684         @echo "Try replacing ~ with \$$HOME, as in \"make install DESTDIR=\$$HOME/path\"."
685         @exit 1
686 endif
687
688 install: badshell bininstall datafiles
689         @if [ -x /usr/sbin/asterisk-post-install ]; then \
690                 /usr/sbin/asterisk-post-install "$(DESTDIR)" . ; \
691         fi
692         @echo " +---- Asterisk Installation Complete -------+"
693         @echo " +                                           +"
694         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
695         @echo " +                                           +"
696         @echo " + Asterisk has successfully been installed. +"
697         @echo " + If you would like to install the sample   +"
698         @echo " + configuration files (overwriting any      +"
699         @echo " + existing config files), run:              +"
700         @echo " +                                           +"
701         @echo " + For generic reference documentation:      +"
702         @echo " +   $(mK) samples                           +"
703         @echo " +                                           +"
704         @echo " + For a sample basic PBX:                   +"
705         @echo " +   $(mK) basic-pbx                         +"
706         @echo " +                                           +"
707         @echo " +                                           +"
708         @echo " +-----------------  or ---------------------+"
709         @echo " +                                           +"
710         @echo " + You can go ahead and install the asterisk +"
711         @echo " + program documentation now or later run:   +"
712         @echo " +                                           +"
713         @echo " +              $(mK) progdocs               +"
714         @echo " +                                           +"
715         @echo " + **Note** This requires that you have      +"
716         @echo " + doxygen installed on your local system    +"
717         @echo " +-------------------------------------------+"
718         @$(MAKE) -s oldmodcheck
719         @$(MAKE) -s ld-cache-update
720         @$(MAKE) -s check-old-libdir
721
722 isntall: install
723
724 upgrade: bininstall
725
726
727 # Install configuration files from the specified directory
728 # Parameters:
729 #  (1) the configuration directory to install from
730 #  (2) the extension to strip off
731 define INSTALL_CONFIGS
732         @for x in configs/$(1)/*$(2); do \
733                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x $(2)`"; \
734                 if [ -f "$${dst}" ]; then \
735                         if [ "$(OVERWRITE)" = "y" ]; then \
736                                 if cmp -s "$${dst}" "$$x" ; then \
737                                         echo "Config file $$x is unchanged"; \
738                                         continue; \
739                                 fi ; \
740                                 mv -f "$${dst}" "$${dst}.old" ; \
741                         else \
742                                 echo "Skipping config file $$x"; \
743                                 continue; \
744                         fi ;\
745                 fi ; \
746                 echo "Installing file $$x"; \
747                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
748         done ; \
749         if [ "$(OVERWRITE)" = "y" ]; then \
750                 echo "Updating asterisk.conf" ; \
751                 sed -e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
752                         -e 's|^astmoddir.*$$|astmoddir => $(ASTMODDIR)|' \
753                         -e 's|^astvarlibdir.*$$|astvarlibdir => $(ASTVARLIBDIR)|' \
754                         -e 's|^astdbdir.*$$|astdbdir => $(ASTDBDIR)|' \
755                         -e 's|^astkeydir.*$$|astkeydir => $(ASTKEYDIR)|' \
756                         -e 's|^astdatadir.*$$|astdatadir => $(ASTDATADIR)|' \
757                         -e 's|^astagidir.*$$|astagidir => $(AGI_DIR)|' \
758                         -e 's|^astspooldir.*$$|astspooldir => $(ASTSPOOLDIR)|' \
759                         -e 's|^astrundir.*$$|astrundir => $(ASTVARRUNDIR)|' \
760                         -e 's|^astlogdir.*$$|astlogdir => $(ASTLOGDIR)|' \
761                         -e 's|^astsbindir.*$$|astsbindir => $(ASTSBINDIR)|' \
762                         "$(DESTDIR)$(ASTCONFPATH)" > "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
763                 $(INSTALL) -m 644 "$(DESTDIR)$(ASTCONFPATH).tmp" "$(DESTDIR)$(ASTCONFPATH)" ; \
764                 rm -f "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
765         fi
766 endef
767
768 # XXX why *.adsi is installed first ?
769 adsi:
770         @echo Installing adsi config files...
771         $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)"
772         @for x in configs/samples/*.adsi; do \
773                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
774                 if [ -f "$${dst}" ] ; then \
775                         echo "Overwriting $$x" ; \
776                 else \
777                         echo "Installing $$x" ; \
778                 fi ; \
779                 $(INSTALL) -m 644 "$$x" "$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
780         done
781
782 samples: adsi
783         @echo Installing other config files...
784         $(call INSTALL_CONFIGS,samples,.sample)
785         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX"
786         build_tools/make_sample_voicemail "$(DESTDIR)/$(ASTDATADIR)" "$(DESTDIR)/$(ASTSPOOLDIR)"
787         @for x in phoneprov/*; do \
788                 dst="$(DESTDIR)$(ASTDATADIR)/$$x" ;     \
789                 if [ -f "$${dst}" ]; then \
790                         if [ "$(OVERWRITE)" = "y" ]; then \
791                                 if cmp -s "$${dst}" "$$x" ; then \
792                                         echo "Config file $$x is unchanged"; \
793                                         continue; \
794                                 fi ; \
795                                 mv -f "$${dst}" "$${dst}.old" ; \
796                         else \
797                                 echo "Skipping config file $$x"; \
798                                 continue; \
799                         fi ;\
800                 fi ; \
801                 echo "Installing file $$x"; \
802                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
803         done
804
805 basic-pbx:
806         @echo Installing basic-pbx config files...
807         $(call INSTALL_CONFIGS,basic-pbx)
808
809 webvmail:
810         @[ -d "$(DESTDIR)$(HTTP_DOCSDIR)/" ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
811         @[ -d "$(DESTDIR)$(HTTP_CGIDIR)" ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
812         $(INSTALL) -m 4755 contrib/scripts/vmail.cgi "$(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi"
813         $(INSTALL) -d "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk"
814         for x in images/*.gif; do \
815                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/"; \
816         done
817         @echo " +--------- Asterisk Web Voicemail ----------+"
818         @echo " +                                           +"
819         @echo " + Asterisk Web Voicemail is installed in    +"
820         @echo " + your cgi-bin directory:                   +"
821         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
822         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
823         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
824         @echo " +                                           +"
825         @echo " + Other static items have been stored in:   +"
826         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
827         @echo " +                                           +"
828         @echo " + If these paths do not match your httpd    +"
829         @echo " + installation, correct the definitions     +"
830         @echo " + in your Makefile of HTTP_CGIDIR and       +"
831         @echo " + HTTP_DOCSDIR                              +"
832         @echo " +                                           +"
833         @echo " +-------------------------------------------+"
834
835 progdocs:
836 # Note, Makefile conditionals must not be tabbed out. Wasted hours with that.
837         @cp doc/asterisk-ng-doxygen.in doc/asterisk-ng-doxygen
838 ifeq ($(DOXYGEN),:)
839         @echo "Doxygen is not installed.  Please install and re-run the configuration script."
840 else
841 ifeq ($(DOT),:)
842         @echo "DOT is not installed. Doxygen will not produce any diagrams. Please install and re-run the configuration script."
843 else
844         # Enable DOT
845         @echo "HAVE_DOT = YES" >> doc/asterisk-ng-doxygen
846 endif
847         # Set Doxygen PROJECT_NUMBER variable
848 ifneq ($(ASTERISKVERSION),UNKNOWN__and_probably_unsupported)
849         @echo "PROJECT_NUMBER = $(ASTERISKVERSION)" >> doc/asterisk-ng-doxygen
850 else
851         echo "Asterisk Version is unknown, not configuring Doxygen PROJECT_NUMBER."
852 endif
853         # Validate and auto-update local copy
854         @doxygen -u doc/asterisk-ng-doxygen
855         # Run Doxygen
856         @doxygen doc/asterisk-ng-doxygen
857         # Remove configuration backup file
858         @rm -f doc/asterisk-ng-doxygen.bak
859 endif
860
861 install-logrotate:
862         if [ ! -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ]; then \
863                 $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ; \
864         fi
865         sed 's#__LOGDIR__#$(ASTLOGDIR)#g' < contrib/scripts/asterisk.logrotate | sed 's#__SBINDIR__#$(ASTSBINDIR)#g' > contrib/scripts/asterisk.logrotate.tmp
866         $(INSTALL) -m 0644 contrib/scripts/asterisk.logrotate.tmp "$(DESTDIR)$(ASTETCDIR)/../logrotate.d/asterisk"
867         rm -f contrib/scripts/asterisk.logrotate.tmp
868
869 config:
870         @if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
871                 ./build_tools/install_subst contrib/init.d/rc.redhat.asterisk  "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \
872                 if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \
873                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
874                 fi ; \
875                 if [ -z "$(DESTDIR)" ] ; then \
876                         /sbin/chkconfig --add asterisk ; \
877                 fi ; \
878         elif [ -f /etc/debian_version ] ; then \
879                 ./build_tools/install_subst contrib/init.d/rc.debian.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
880                 if [ ! -f "$(DESTDIR)/etc/default/asterisk" ] ; then \
881                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/default/asterisk" ; \
882                 fi ; \
883                 if [ -z "$(DESTDIR)" ] ; then \
884                         /usr/sbin/update-rc.d asterisk defaults 50 91 ; \
885                 fi ; \
886         elif [ -f /etc/gentoo-release ] ; then \
887                 ./build_tools/install_subst contrib/init.d/rc.gentoo.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
888                 if [ -z "$(DESTDIR)" ] ; then \
889                         /sbin/rc-update add asterisk default ; \
890                 fi ; \
891         elif [ -f /etc/mandrake-release -o -f /etc/mandriva-release ] ; then \
892                 ./build_tools/install_subst contrib/init.d/rc.mandriva.asterisk  "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \
893                 if [ ! -f /etc/sysconfig/asterisk ] ; then \
894                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
895                 fi ; \
896                 if [ -z "$(DESTDIR)" ] ; then \
897                         /sbin/chkconfig --add asterisk ; \
898                 fi ; \
899         elif [ -f /etc/SuSE-release -o -f /etc/novell-release ] ; then \
900                 ./build_tools/install_subst contrib/init.d/rc.suse.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
901                 if [ ! -f /etc/sysconfig/asterisk ] ; then \
902                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
903                 fi ; \
904                 if [ -z "$(DESTDIR)" ] ; then \
905                         /sbin/chkconfig --add asterisk ; \
906                 fi ; \
907         elif [ -f /etc/arch-release -o -f /etc/arch-release ] ; then \
908                 ./build_tools/install_subst contrib/init.d/rc.archlinux.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
909         elif [ -d "$(DESTDIR)/Library/LaunchDaemons" ]; then \
910                 if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist" ]; then \
911                         ./build_tools/install_subst contrib/init.d/org.asterisk.asterisk.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist"; \
912                 fi; \
913                 if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist" ]; then \
914                         ./build_tools/install_subst contrib/init.d/org.asterisk.muted.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist"; \
915                 fi; \
916         elif [ -f /etc/slackware-version ]; then \
917                 echo "Slackware is not currently supported, although an init script does exist for it."; \
918         else \
919                 echo "We could not install init scripts for your distribution." ; \
920         fi
921
922 sounds:
923         $(MAKE) -C sounds all
924
925 # If the cleancount has been changed, force a make clean.
926 # .cleancount is the global clean count, and .lastclean is the
927 # last clean count we had
928
929 .lastclean: .cleancount
930         @$(MAKE) clean
931         @[ -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")
932
933 $(SUBDIRS_UNINSTALL):
934         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTDATADIR="$(ASTDATADIR)" $(SUBMAKE) -C $(@:-uninstall=) uninstall
935
936 main-binuninstall:
937         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTLIBDIR="$(ASTLIBDIR)" $(SUBMAKE) -C main binuninstall
938
939 _uninstall: $(SUBDIRS_UNINSTALL) main-binuninstall
940         rm -f "$(DESTDIR)$(ASTMODDIR)/"*
941         test -n "$(_oldmoddir)" -a -d "$(_oldmoddir)" && rm -f "$(_oldmoddir)/"* || :
942         rm -f "$(DESTDIR)$(ASTSBINDIR)/astgenkey"
943         rm -f "$(DESTDIR)$(ASTSBINDIR)/autosupport"
944         rm -rf "$(DESTDIR)$(ASTHEADERDIR)"
945         rm -rf "$(DESTDIR)$(ASTDATADIR)/firmware"
946         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/asterisk.8"
947         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8"
948         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/autosupport.8"
949         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8"
950 ifeq ($(HAVE_DAHDI),1)
951         rm -f $(DESTDIR)$(DAHDI_UDEV_HOOK_DIR)/40-asterisk
952 endif
953         $(MAKE) -C sounds uninstall
954 ifneq ($(LDCONFIG),)
955         $(LDCONFIG) || :
956 endif
957
958 uninstall: _uninstall
959         @echo " +--------- Asterisk Uninstall Complete -----+"
960         @echo " + Asterisk binaries, sounds, man pages,     +"
961         @echo " + headers, modules, and firmware builds,    +"
962         @echo " + have all been uninstalled.                +"
963         @echo " +                                           +"
964         @echo " + To remove ALL traces of Asterisk,         +"
965         @echo " + including configuration, spool            +"
966         @echo " + directories, and logs, run the following  +"
967         @echo " + command:                                  +"
968         @echo " +                                           +"
969         @echo " +            $(mK) uninstall-all            +"
970         @echo " +-------------------------------------------+"
971
972 uninstall-all: _uninstall
973         rm -rf "$(DESTDIR)$(ASTMODDIR)"
974         test -n "$(_oldmoddir)" -a -d "$(_oldmoddir)" && rm -rf "$(_oldmoddir)" || :
975         rm -rf "$(DESTDIR)$(ASTVARLIBDIR)"
976         rm -rf "$(DESTDIR)$(ASTDATADIR)"
977         rm -rf "$(DESTDIR)$(ASTSPOOLDIR)"
978         rm -rf "$(DESTDIR)$(ASTETCDIR)"
979         rm -rf "$(DESTDIR)$(ASTLOGDIR)"
980
981 menuconfig: menuselect
982
983 cmenuconfig: cmenuselect
984
985 gmenuconfig: gmenuselect
986
987 nmenuconfig: nmenuselect
988
989 menuselect: menuselect/cmenuselect menuselect/nmenuselect menuselect/gmenuselect
990         @if [ -x menuselect/nmenuselect ]; then \
991                 $(MAKE) nmenuselect; \
992         elif [ -x menuselect/cmenuselect ]; then \
993                 $(MAKE) cmenuselect; \
994         elif [ -x menuselect/gmenuselect ]; then \
995                 $(MAKE) gmenuselect; \
996         else \
997                 echo "No menuselect user interface found. Install ncurses,"; \
998                 echo "newt or GTK libraries to build one and re-rerun"; \
999                 echo "'./configure' and 'make menuselect'."; \
1000         fi
1001
1002 cmenuselect: menuselect/cmenuselect menuselect-tree menuselect.makeopts
1003         -@menuselect/cmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
1004
1005 gmenuselect: menuselect/gmenuselect menuselect-tree menuselect.makeopts
1006         -@menuselect/gmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
1007
1008 nmenuselect: menuselect/nmenuselect menuselect-tree menuselect.makeopts
1009         -@menuselect/nmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
1010
1011 # options for make in menuselect/
1012 MAKE_MENUSELECT=CC="$(BUILD_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" \
1013                 CFLAGS="$(BUILD_CFLAGS)" LDFLAGS="$(BUILD_LDFLAGS)" \
1014                 $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
1015
1016 menuselect/menuselect: menuselect/makeopts .lastclean
1017         +$(MAKE_MENUSELECT) menuselect
1018
1019 menuselect/cmenuselect: menuselect/makeopts .lastclean
1020         +$(MAKE_MENUSELECT) cmenuselect
1021
1022 menuselect/gmenuselect: menuselect/makeopts .lastclean
1023         +$(MAKE_MENUSELECT) gmenuselect
1024
1025 menuselect/nmenuselect: menuselect/makeopts .lastclean
1026         +$(MAKE_MENUSELECT) nmenuselect
1027
1028 menuselect/makeopts: makeopts .lastclean
1029         +$(MAKE_MENUSELECT) makeopts
1030
1031 menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc) $(wildcard $(dir)/*.xml)) build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml utils/utils.xml agi/agi.xml configure makeopts
1032         @echo "Generating input for menuselect ..."
1033         @echo "<?xml version=\"1.0\"?>" > $@
1034         @echo >> $@
1035         @echo "<menu name=\"Asterisk Module and Build Option Selection\">" >> $@
1036         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} moduleinfo >> $@; done
1037         @cat build_tools/cflags.xml >> $@
1038         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} makeopts >> $@; done
1039         @if [ "${AST_DEVMODE}" = "yes" ]; then \
1040                 cat build_tools/cflags-devmode.xml >> $@; \
1041         fi
1042         @cat utils/utils.xml >> $@
1043         @cat agi/agi.xml >> $@
1044         @cat sounds/sounds.xml >> $@
1045         @echo "</menu>" >> $@
1046
1047 # We don't want to require Python or Pystache for every build, so this is its
1048 # own target.
1049 ari-stubs:
1050 ifeq ($(PYTHON),:)
1051         @echo "--------------------------------------------------------------------------"
1052         @echo "---        Please install python to build ARI stubs            ---"
1053         @echo "--------------------------------------------------------------------------"
1054         @false
1055 else
1056         @$(INSTALL) -d doc/rest-api
1057         $(PYTHON) rest-api-templates/make_ari_stubs.py \
1058                 rest-api/resources.json .
1059 endif
1060
1061 check-alembic: makeopts
1062         @find contrib/ast-db-manage/ -name '*.pyc' -delete
1063         @ALEMBIC=$(ALEMBIC) build_tools/make_check_alembic config cdr voicemail >&2
1064
1065 .PHONY: menuselect
1066 .PHONY: main
1067 .PHONY: sounds
1068 .PHONY: clean
1069 .PHONY: dist-clean
1070 .PHONY: distclean
1071 .PHONY: all
1072 .PHONY: _all
1073 .PHONY: full
1074 .PHONY: _full
1075 .PHONY: prereqs
1076 .PHONY: uninstall
1077 .PHONY: _uninstall
1078 .PHONY: uninstall-all
1079 .PHONY: dont-optimize
1080 .PHONY: badshell
1081 .PHONY: installdirs
1082 .PHONY: validate-docs
1083 .PHONY: _clean
1084 .PHONY: ari-stubs
1085 .PHONY: basic-pbx
1086 .PHONY: check-alembic
1087 .PHONY: ld-cache-update
1088 .PHONY: check-old-libdir
1089 .PHONY: $(SUBDIRS_INSTALL)
1090 .PHONY: $(SUBDIRS_DIST_CLEAN)
1091 .PHONY: $(SUBDIRS_CLEAN)
1092 .PHONY: $(SUBDIRS_UNINSTALL)
1093 .PHONY: $(SUBDIRS)
1094
1095 FORCE:
1096