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