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