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