Merge "CI: Add install-headers to the install make targets"
[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         "$(ASTLOGDIR)" "$(ASTLOGDIR)/cdr-csv" "$(ASTLOGDIR)/cdr-custom" \
559         "$(ASTLOGDIR)/cel-custom" "$(ASTDATADIR)" "$(ASTDATADIR)/documentation" \
560         "$(ASTDATADIR)/documentation/thirdparty" "$(ASTDATADIR)/firmware" \
561         "$(ASTDATADIR)/firmware/iax" "$(ASTDATADIR)/images" "$(ASTDATADIR)/keys" \
562         "$(ASTDATADIR)/phoneprov" "$(ASTDATADIR)/rest-api" "$(ASTDATADIR)/static-http" \
563         "$(ASTDATADIR)/sounds" "$(ASTDATADIR)/moh" "$(ASTMANDIR)/man8" "$(AGI_DIR)" "$(ASTDBDIR)" \
564         "$(ASTDATADIR)/third-party"
565
566 installdirs:
567         @for i in $(INSTALLDIRS); do \
568                 if [ ! -z "$${i}" -a ! -d "$(DESTDIR)$${i}" ]; then \
569                         $(INSTALL) -d "$(DESTDIR)$${i}"; \
570                 fi; \
571         done
572
573 main-bininstall:
574         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTLIBDIR="$(ASTLIBDIR)" $(SUBMAKE) -C main bininstall
575
576 bininstall: _all installdirs $(SUBDIRS_INSTALL) main-bininstall
577         $(INSTALL) -m 755 contrib/scripts/astversion "$(DESTDIR)$(ASTSBINDIR)/"
578         $(INSTALL) -m 755 contrib/scripts/astgenkey "$(DESTDIR)$(ASTSBINDIR)/"
579         $(INSTALL) -m 755 contrib/scripts/autosupport "$(DESTDIR)$(ASTSBINDIR)/"
580         if [ ! -f /sbin/launchd ]; then \
581                 ./build_tools/install_subst contrib/scripts/safe_asterisk "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk"; \
582         fi
583
584 ifneq ($(DISABLE_XMLDOC),yes)
585         $(INSTALL) -m 644 doc/core-*.xml "$(DESTDIR)$(ASTDATADIR)/documentation"
586         $(INSTALL) -m 644 doc/appdocsxml.xslt "$(DESTDIR)$(ASTDATADIR)/documentation"
587         $(INSTALL) -m 644 doc/appdocsxml.dtd "$(DESTDIR)$(ASTDATADIR)/documentation"
588 endif
589         $(INSTALL) -m 644 doc/asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8"
590         $(INSTALL) -m 644 doc/astdb*.8 "$(DESTDIR)$(ASTMANDIR)/man8"
591         $(INSTALL) -m 644 contrib/scripts/astgenkey.8 "$(DESTDIR)$(ASTMANDIR)/man8"
592         $(INSTALL) -m 644 contrib/scripts/autosupport.8 "$(DESTDIR)$(ASTMANDIR)/man8"
593         $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8"
594         if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
595                 $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin "$(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin"; \
596         fi
597 ifeq ($(HAVE_DAHDI),1)
598         $(INSTALL) -d $(DESTDIR)/$(DAHDI_UDEV_HOOK_DIR)
599         $(INSTALL) -m 644 contrib/scripts/dahdi_span_config_hook $(DESTDIR)$(DAHDI_UDEV_HOOK_DIR)/40-asterisk
600 endif
601
602 $(SUBDIRS_INSTALL):
603         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTDATADIR="$(ASTDATADIR)" $(SUBMAKE) -C $(@:-install=) install
604
605 NEWMODS:=$(foreach d,$(MOD_SUBDIRS),$(notdir $(wildcard $(d)/*.so)))
606 OLDMODS=$(filter-out $(NEWMODS) $(notdir $(DESTDIR)$(ASTMODDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTMODDIR)/*.so)))
607 ifneq ($(BASH),:)
608         FILMODS=$(filter-out $(shell ./build_tools/list_valid_installed_externals),$(OLDMODS))
609 else
610         FILMODS=$(OLDMODS)
611 endif
612 BADMODS=$(strip $(FILMODS))
613
614 oldmodcheck:
615         @if [ -n "$(BADMODS)" ]; then \
616                 echo " WARNING WARNING WARNING" ;\
617                 echo "" ;\
618                 echo " Your Asterisk modules directory, located at" ;\
619                 echo " $(DESTDIR)$(ASTMODDIR)" ;\
620                 echo " contains modules that were not installed by this " ;\
621                 echo " version of Asterisk. Please ensure that these" ;\
622                 echo " modules are compatible with this version before" ;\
623                 echo " attempting to run Asterisk." ;\
624                 echo "" ;\
625                 for f in $(BADMODS); do \
626                         echo "    $$f" ;\
627                 done ;\
628                 echo "" ;\
629                 echo " WARNING WARNING WARNING" ;\
630         fi
631
632 ld-cache-update:
633 ifeq ($(LDCONFIG),)
634 else ifeq ($(LDCONFIG),:)
635 else
636 ifeq ($(DESTDIR),)  # DESTDIR means binary archive creation; ldconfig should be run on postinst
637         @if [ $$(id -u) -eq 0 ] ; then \
638                 $(LDCONFIG) "$(ASTLIBDIR)/" ; \
639         else \
640                 echo " WARNING WARNING WARNING" ;\
641                 echo "" ;\
642                 echo " You cannot rebuild the system linker cache unless you are root. " ;\
643                 echo " You MUST do one of the following..." ;\
644                 echo "  * Re-run 'make install' as root. " ;\
645                 echo "  * Run 'ldconfig $(ASTLIBDIR)' as root. " ;\
646                 echo "  * Run asterisk with 'LD_LIBRARY_PATH=$(ASTLIBDIR) asterisk' " ;\
647                 echo "" ;\
648                 echo " WARNING WARNING WARNING" ;\
649         fi
650 endif
651 endif
652
653 export _oldlibdir =
654 export _oldmoddir =
655 ifeq ($(findstring 64,$(HOST_CPU)),64)
656     # Strip any trailing '/' so the dir and notdir functions work correctly
657     _current_libdir = $(patsubst %/,%,$(DESTDIR)$(ASTLIBDIR))
658
659     # Only process if the paths end in lib64 or lib.
660     # If we're installing to lib64, check lib for orphans.
661     # If we're installing to lib, check lib64 for orphans.
662     # Otherwise, leave _oldlibdir empty.
663     ifeq ($(notdir $(_current_libdir)),lib64)
664         _oldlibdir = $(dir $(_current_libdir))lib
665     else ifeq ($(notdir $(_current_libdir)),lib)
666         _oldlibdir = $(dir $(_current_libdir))lib64
667     endif
668
669     # Strip any trailing '/' so the dir and notdir functions work correctly
670     _current_moddir = $(patsubst %/,%,$(DESTDIR)$(ASTMODDIR))
671
672     # Only process if the paths contain /lib64/ or /lib/.
673     # If we're installing to lib64, check lib for orphans.
674     # If we're installing to lib, check lib64 for orphans.
675     # Otherwise, leave _oldmoddir empty.
676     ifeq ($(findstring /lib64/,$(_current_moddir)),/lib64/)
677         _oldmoddir = $(subst /lib64/,/lib/,$(_current_moddir))
678     else ifeq ($(findstring /lib/,$(_current_moddir)),/lib/)
679         _oldmoddir = $(subst /lib/,/lib64/,$(_current_moddir))
680     endif
681 endif
682
683 check-old-libdir:
684         @test -n "$(_oldlibdir)" -a -d "$(_oldlibdir)" || exit 0 ;\
685         oldfiles=`find "$(_oldlibdir)" -name libasterisk* -print -quit -o \( -path *asterisk/modules/* -a -name *.so \) -print -quit 2>/dev/null` ;\
686         if [ "x$$oldfiles" != "x" ] ; then \
687                 echo " WARNING WARNING WARNING" ;\
688                 echo "" ;\
689                 echo " Installation is to: " ;\
690                 echo "   $(DESTDIR)$(ASTLIBDIR)" ;\
691                 echo " but there are asterisk shared libraries in: " ;\
692                 echo "   $(_oldlibdir)" ;\
693                 echo " or" ;\
694                 echo "   $(_oldlibdir)/asterisk/modules" ;\
695                 echo "" ;\
696                 echo " It is unlikely that asterisk will start." ;\
697                 echo "" ;\
698                 echo " You should do one of the following..." ;\
699                 echo "  * Run 'make uninstall' to remove the incorrect libraries" ;\
700                 echo "    then run 'make install' again." ;\
701                 echo "  * Manually remove the libraries from" ;\
702                 echo "   $(_oldlibdir)" ;\
703                 echo "   and run 'ldconfig' to rebuild the linker cache." ;\
704                 echo "" ;\
705                 echo " WARNING WARNING WARNING" ;\
706         fi
707
708 badshell:
709 ifneq ($(filter ~%,$(DESTDIR)),)
710         @echo "Your shell doesn't do ~ expansion when expected (specifically, when doing \"make install DESTDIR=~/path\")."
711         @echo "Try replacing ~ with \$$HOME, as in \"make install DESTDIR=\$$HOME/path\"."
712         @exit 1
713 endif
714
715 install: badshell bininstall datafiles
716         @if [ -x /usr/sbin/asterisk-post-install ]; then \
717                 /usr/sbin/asterisk-post-install "$(DESTDIR)" . ; \
718         fi
719         @echo " +---- Asterisk Installation Complete -------+"
720         @echo " +                                           +"
721         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
722         @echo " +                                           +"
723         @echo " + Asterisk has successfully been installed. +"
724         @echo " + If you would like to install the sample   +"
725         @echo " + configuration files (overwriting any      +"
726         @echo " + existing config files), run:              +"
727         @echo " +                                           +"
728         @echo " + For generic reference documentation:      +"
729         @echo " +   $(mK) samples                           +"
730         @echo " +                                           +"
731         @echo " + For a sample basic PBX:                   +"
732         @echo " +   $(mK) basic-pbx                         +"
733         @echo " +                                           +"
734         @echo " +                                           +"
735         @echo " +-----------------  or ---------------------+"
736         @echo " +                                           +"
737         @echo " + You can go ahead and install the asterisk +"
738         @echo " + program documentation now or later run:   +"
739         @echo " +                                           +"
740         @echo " +              $(mK) progdocs               +"
741         @echo " +                                           +"
742         @echo " + **Note** This requires that you have      +"
743         @echo " + doxygen installed on your local system    +"
744         @echo " +-------------------------------------------+"
745         @$(MAKE) -s oldmodcheck
746         @$(MAKE) -s ld-cache-update
747         @$(MAKE) -s check-old-libdir
748
749 isntall: install
750
751 upgrade: bininstall
752
753
754 # Install configuration files from the specified directory
755 # Parameters:
756 #  (1) the configuration directory to install from
757 #  (2) the extension to strip off
758 define INSTALL_CONFIGS
759         @for x in $(1)/*$(2); do \
760                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x $(2)`"; \
761                 if [ -f "$${dst}" ]; then \
762                         if [ "$(OVERWRITE)" = "y" ]; then \
763                                 if cmp -s "$${dst}" "$$x" ; then \
764                                         echo "Config file $$x is unchanged"; \
765                                         continue; \
766                                 fi ; \
767                                 mv -f "$${dst}" "$${dst}.old" ; \
768                         else \
769                                 echo "Skipping config file $$x"; \
770                                 continue; \
771                         fi ;\
772                 fi ; \
773                 echo "Installing file $$x"; \
774                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
775         done ; \
776         if [ "$(OVERWRITE)" = "y" ]; then \
777                 echo "Updating asterisk.conf" ; \
778                 sed -e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
779                         -e 's|^astmoddir.*$$|astmoddir => $(ASTMODDIR)|' \
780                         -e 's|^astvarlibdir.*$$|astvarlibdir => $(ASTVARLIBDIR)|' \
781                         -e 's|^astdbdir.*$$|astdbdir => $(ASTDBDIR)|' \
782                         -e 's|^astkeydir.*$$|astkeydir => $(ASTKEYDIR)|' \
783                         -e 's|^astdatadir.*$$|astdatadir => $(ASTDATADIR)|' \
784                         -e 's|^astagidir.*$$|astagidir => $(AGI_DIR)|' \
785                         -e 's|^astspooldir.*$$|astspooldir => $(ASTSPOOLDIR)|' \
786                         -e 's|^astrundir.*$$|astrundir => $(ASTVARRUNDIR)|' \
787                         -e 's|^astlogdir.*$$|astlogdir => $(ASTLOGDIR)|' \
788                         -e 's|^astsbindir.*$$|astsbindir => $(ASTSBINDIR)|' \
789                         "$(DESTDIR)$(ASTCONFPATH)" > "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
790                 $(INSTALL) -m 644 "$(DESTDIR)$(ASTCONFPATH).tmp" "$(DESTDIR)$(ASTCONFPATH)" ; \
791                 rm -f "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
792         fi
793 endef
794
795 install-headers:
796 # Will create all components of "$(DESTDIR)$(ASTHEADERDIR)/doxygen" including "$(DESTDIR)$(includedir)"
797         $(INSTALL) -d "$(DESTDIR)$(ASTHEADERDIR)/doxygen"
798         $(INSTALL) -m 644 include/asterisk.h "$(DESTDIR)$(includedir)"
799         $(INSTALL) -m 644 include/asterisk/*.h "$(DESTDIR)$(ASTHEADERDIR)"
800         $(INSTALL) -m 644 include/asterisk/doxygen/*.h "$(DESTDIR)$(ASTHEADERDIR)/doxygen"
801         if [ -n "$(OLDHEADERS)" ]; then \
802                 for h in $(OLDHEADERS); do rm -f "$(DESTDIR)$(ASTHEADERDIR)/$$h"; done \
803         fi
804
805 install-configs:
806         @if test -z "$(CONFIG_SRC)" -o ! -d "$(CONFIG_SRC)"; then \
807                 >&2 echo "CONFIG_SRC must be set to a directory."; \
808                 exit 1; \
809         fi
810         @echo "Installing config files from $(CONFIG_SRC)/*$(CONFIG_EXTEN)"
811         $(call INSTALL_CONFIGS,$(CONFIG_SRC),$(CONFIG_EXTEN))
812
813 # XXX why *.adsi is installed first ?
814 adsi:
815         @echo Installing adsi config files...
816         $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)"
817         @for x in configs/samples/*.adsi; do \
818                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
819                 if [ -f "$${dst}" ] ; then \
820                         echo "Overwriting $$x" ; \
821                 else \
822                         echo "Installing $$x" ; \
823                 fi ; \
824                 $(INSTALL) -m 644 "$$x" "$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
825         done
826
827 samples: adsi
828         @echo Installing other config files...
829         $(call INSTALL_CONFIGS,configs/samples,.sample)
830         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX"
831         build_tools/make_sample_voicemail "$(DESTDIR)/$(ASTDATADIR)" "$(DESTDIR)/$(ASTSPOOLDIR)"
832         @for x in phoneprov/*; do \
833                 dst="$(DESTDIR)$(ASTDATADIR)/$$x" ;     \
834                 if [ -f "$${dst}" ]; then \
835                         if [ "$(OVERWRITE)" = "y" ]; then \
836                                 if cmp -s "$${dst}" "$$x" ; then \
837                                         echo "Config file $$x is unchanged"; \
838                                         continue; \
839                                 fi ; \
840                                 mv -f "$${dst}" "$${dst}.old" ; \
841                         else \
842                                 echo "Skipping config file $$x"; \
843                                 continue; \
844                         fi ;\
845                 fi ; \
846                 echo "Installing file $$x"; \
847                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
848         done
849
850 basic-pbx:
851         @echo Installing basic-pbx config files...
852         $(call INSTALL_CONFIGS,configs/basic-pbx)
853
854 webvmail:
855         @[ -d "$(DESTDIR)$(HTTP_DOCSDIR)/" ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
856         @[ -d "$(DESTDIR)$(HTTP_CGIDIR)" ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
857         $(INSTALL) -m 4755 contrib/scripts/vmail.cgi "$(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi"
858         $(INSTALL) -d "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk"
859         for x in images/*.gif; do \
860                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/"; \
861         done
862         @echo " +--------- Asterisk Web Voicemail ----------+"
863         @echo " +                                           +"
864         @echo " + Asterisk Web Voicemail is installed in    +"
865         @echo " + your cgi-bin directory:                   +"
866         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
867         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
868         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
869         @echo " +                                           +"
870         @echo " + Other static items have been stored in:   +"
871         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
872         @echo " +                                           +"
873         @echo " + If these paths do not match your httpd    +"
874         @echo " + installation, correct the definitions     +"
875         @echo " + in your Makefile of HTTP_CGIDIR and       +"
876         @echo " + HTTP_DOCSDIR                              +"
877         @echo " +                                           +"
878         @echo " +-------------------------------------------+"
879
880 progdocs:
881 # Note, Makefile conditionals must not be tabbed out. Wasted hours with that.
882         @cp doc/asterisk-ng-doxygen.in doc/asterisk-ng-doxygen
883 ifeq ($(DOXYGEN),:)
884         @echo "Doxygen is not installed.  Please install and re-run the configuration script."
885 else
886 ifeq ($(DOT),:)
887         @echo "DOT is not installed. Doxygen will not produce any diagrams. Please install and re-run the configuration script."
888 else
889         # Enable DOT
890         @echo "HAVE_DOT = YES" >> doc/asterisk-ng-doxygen
891 endif
892         # Set Doxygen PROJECT_NUMBER variable
893 ifneq ($(ASTERISKVERSION),UNKNOWN__and_probably_unsupported)
894         @echo "PROJECT_NUMBER = $(ASTERISKVERSION)" >> doc/asterisk-ng-doxygen
895 else
896         echo "Asterisk Version is unknown, not configuring Doxygen PROJECT_NUMBER."
897 endif
898         # Validate and auto-update local copy
899         @doxygen -u doc/asterisk-ng-doxygen
900         # Run Doxygen
901         @doxygen doc/asterisk-ng-doxygen
902         # Remove configuration backup file
903         @rm -f doc/asterisk-ng-doxygen.bak
904 endif
905
906 install-logrotate:
907         if [ ! -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ]; then \
908                 $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ; \
909         fi
910         sed 's#__LOGDIR__#$(ASTLOGDIR)#g' < contrib/scripts/asterisk.logrotate | sed 's#__SBINDIR__#$(ASTSBINDIR)#g' > contrib/scripts/asterisk.logrotate.tmp
911         $(INSTALL) -m 0644 contrib/scripts/asterisk.logrotate.tmp "$(DESTDIR)$(ASTETCDIR)/../logrotate.d/asterisk"
912         rm -f contrib/scripts/asterisk.logrotate.tmp
913
914 config:
915         @if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
916                 ./build_tools/install_subst contrib/init.d/rc.redhat.asterisk  "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \
917                 if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \
918                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
919                 fi ; \
920                 if [ -z "$(DESTDIR)" ] ; then \
921                         /sbin/chkconfig --add asterisk ; \
922                 fi ; \
923         elif [ -f /etc/debian_version ] ; then \
924                 ./build_tools/install_subst contrib/init.d/rc.debian.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
925                 if [ ! -f "$(DESTDIR)/etc/default/asterisk" ] ; then \
926                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/default/asterisk" ; \
927                 fi ; \
928                 if [ -z "$(DESTDIR)" ] ; then \
929                         /usr/sbin/update-rc.d asterisk defaults 50 91 ; \
930                 fi ; \
931         elif [ -f /etc/gentoo-release ] ; then \
932                 ./build_tools/install_subst contrib/init.d/rc.gentoo.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
933                 if [ -z "$(DESTDIR)" ] ; then \
934                         /sbin/rc-update add asterisk default ; \
935                 fi ; \
936         elif [ -f /etc/mandrake-release -o -f /etc/mandriva-release ] ; then \
937                 ./build_tools/install_subst contrib/init.d/rc.mandriva.asterisk  "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \
938                 if [ ! -f /etc/sysconfig/asterisk ] ; then \
939                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
940                 fi ; \
941                 if [ -z "$(DESTDIR)" ] ; then \
942                         /sbin/chkconfig --add asterisk ; \
943                 fi ; \
944         elif [ -f /etc/SuSE-release -o -f /etc/novell-release ] ; then \
945                 ./build_tools/install_subst contrib/init.d/rc.suse.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
946                 if [ ! -f /etc/sysconfig/asterisk ] ; then \
947                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
948                 fi ; \
949                 if [ -z "$(DESTDIR)" ] ; then \
950                         /sbin/chkconfig --add asterisk ; \
951                 fi ; \
952         elif [ -f /etc/os-release ] && [ "opensuse" = "$(shell . /etc/os-release 2>/dev/null && echo $$ID)" ] ; then \
953                 ./build_tools/install_subst contrib/init.d/rc.suse.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
954                 if [ ! -f /etc/sysconfig/asterisk ] ; then \
955                         $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
956                 fi ; \
957                 if [ -z "$(DESTDIR)" ] ; then \
958                         /sbin/chkconfig --add asterisk ; \
959                 fi ; \
960         elif [ -f /etc/arch-release -o -f /etc/arch-release ] ; then \
961                 ./build_tools/install_subst contrib/init.d/rc.archlinux.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
962         elif [ -f /etc/slackware-version ]; then \
963                 ./build_tools/install_subst contrib/init.d/rc.slackware.asterisk  "$(DESTDIR)/etc/rc.d/rc.asterisk"; \
964         elif [ -f /etc/os-release ] && [ "slackware" = "$(shell . /etc/os-release 2>/dev/null && echo $$ID)" ] ; then \
965                 ./build_tools/install_subst contrib/init.d/rc.slackware.asterisk  "$(DESTDIR)/etc/rc.d/rc.asterisk"; \
966         elif [ -d "$(DESTDIR)/Library/LaunchDaemons" ]; then \
967                 if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist" ]; then \
968                         ./build_tools/install_subst contrib/init.d/org.asterisk.asterisk.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist"; \
969                 fi; \
970                 if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist" ]; then \
971                         ./build_tools/install_subst contrib/init.d/org.asterisk.muted.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist"; \
972                 fi; \
973         else \
974                 echo "We could not install init scripts for your distribution." ; \
975         fi
976
977 sounds:
978         $(MAKE) -C sounds all
979
980 # If the cleancount has been changed, force a make clean.
981 # .cleancount is the global clean count, and .lastclean is the
982 # last clean count we had
983
984 .lastclean: .cleancount
985         @$(MAKE) clean
986         @[ -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")
987
988 $(SUBDIRS_UNINSTALL):
989         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTDATADIR="$(ASTDATADIR)" $(SUBMAKE) -C $(@:-uninstall=) uninstall
990
991 main-binuninstall:
992         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTLIBDIR="$(ASTLIBDIR)" $(SUBMAKE) -C main binuninstall
993
994 uninstall-headers:
995         rm -rf "$(DESTDIR)$(ASTHEADERDIR)"
996         rm -f "$(DESTDIR)$(includedir)/asterisk.h"
997
998 _uninstall: $(SUBDIRS_UNINSTALL) main-binuninstall
999         rm -f "$(DESTDIR)$(ASTMODDIR)/"*
1000         test -n "$(_oldmoddir)" -a -d "$(_oldmoddir)" && rm -f "$(_oldmoddir)/"* || :
1001         rm -f "$(DESTDIR)$(ASTSBINDIR)/astgenkey"
1002         rm -f "$(DESTDIR)$(ASTSBINDIR)/autosupport"
1003         rm -rf "$(DESTDIR)$(ASTDATADIR)/firmware"
1004         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/asterisk.8"
1005         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8"
1006         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/autosupport.8"
1007         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8"
1008 ifeq ($(HAVE_DAHDI),1)
1009         rm -f $(DESTDIR)$(DAHDI_UDEV_HOOK_DIR)/40-asterisk
1010 endif
1011         $(MAKE) -C sounds uninstall
1012 ifeq ($(LDCONFIG),)
1013 else ifeq ($(LDCONFIG),:)
1014 else
1015         $(LDCONFIG) "$(ASTLIBDIR)/" || :
1016 endif
1017
1018 uninstall: _uninstall
1019         @echo " +--------- Asterisk Uninstall Complete -----+"
1020         @echo " + Asterisk binaries, sounds, man pages,     +"
1021         @echo " + headers, modules, and firmware builds,    +"
1022         @echo " + have all been uninstalled.                +"
1023         @echo " +                                           +"
1024         @echo " + To remove ALL traces of Asterisk,         +"
1025         @echo " + including configuration, spool            +"
1026         @echo " + directories, and logs, run the following  +"
1027         @echo " + command:                                  +"
1028         @echo " +                                           +"
1029         @echo " +            $(mK) uninstall-all            +"
1030         @echo " +-------------------------------------------+"
1031
1032 uninstall-all: _uninstall uninstall-headers
1033         rm -rf "$(DESTDIR)$(ASTMODDIR)"
1034         test -n "$(_oldmoddir)" -a -d "$(_oldmoddir)" && rm -rf "$(_oldmoddir)" || :
1035         rm -rf "$(DESTDIR)$(ASTVARLIBDIR)"
1036         rm -rf "$(DESTDIR)$(ASTDATADIR)"
1037         rm -rf "$(DESTDIR)$(ASTSPOOLDIR)"
1038         rm -rf "$(DESTDIR)$(ASTETCDIR)"
1039         rm -rf "$(DESTDIR)$(ASTLOGDIR)"
1040
1041 menuconfig: menuselect
1042
1043 cmenuconfig: cmenuselect
1044
1045 gmenuconfig: gmenuselect
1046
1047 nmenuconfig: nmenuselect
1048
1049 menuselect: menuselect/cmenuselect menuselect/nmenuselect menuselect/gmenuselect
1050         @if [ -x menuselect/nmenuselect ]; then \
1051                 $(MAKE) nmenuselect; \
1052         elif [ -x menuselect/cmenuselect ]; then \
1053                 $(MAKE) cmenuselect; \
1054         elif [ -x menuselect/gmenuselect ]; then \
1055                 $(MAKE) gmenuselect; \
1056         else \
1057                 echo "No menuselect user interface found. Install ncurses,"; \
1058                 echo "newt or GTK libraries to build one and re-rerun"; \
1059                 echo "'./configure' and 'make menuselect'."; \
1060         fi
1061
1062 cmenuselect: menuselect/cmenuselect menuselect-tree menuselect.makeopts
1063         -@menuselect/cmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
1064
1065 gmenuselect: menuselect/gmenuselect menuselect-tree menuselect.makeopts
1066         -@menuselect/gmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
1067
1068 nmenuselect: menuselect/nmenuselect menuselect-tree menuselect.makeopts
1069         -@menuselect/nmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
1070
1071 # options for make in menuselect/
1072 MAKE_MENUSELECT=CC="$(BUILD_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" \
1073                 CFLAGS="$(BUILD_CFLAGS)" LDFLAGS="$(BUILD_LDFLAGS)" \
1074                 $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
1075
1076 menuselect/menuselect: menuselect/makeopts .lastclean
1077         +$(MAKE_MENUSELECT) menuselect
1078
1079 menuselect/cmenuselect: menuselect/makeopts .lastclean
1080         +$(MAKE_MENUSELECT) cmenuselect
1081
1082 menuselect/gmenuselect: menuselect/makeopts .lastclean
1083         +$(MAKE_MENUSELECT) gmenuselect
1084
1085 menuselect/nmenuselect: menuselect/makeopts .lastclean
1086         +$(MAKE_MENUSELECT) nmenuselect
1087
1088 menuselect/makeopts: makeopts .lastclean
1089         +$(MAKE_MENUSELECT) makeopts
1090
1091 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
1092         @echo "Generating input for menuselect ..."
1093         @echo "<?xml version=\"1.0\"?>" > $@
1094         @echo >> $@
1095         @echo "<menu name=\"Asterisk Module and Build Option Selection\">" >> $@
1096         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} moduleinfo >> $@; done
1097         @cat build_tools/cflags.xml >> $@
1098         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} makeopts >> $@; done
1099         @if [ "${AST_DEVMODE}" = "yes" ]; then \
1100                 cat build_tools/cflags-devmode.xml >> $@; \
1101         fi
1102         @cat utils/utils.xml >> $@
1103         @cat agi/agi.xml >> $@
1104         @cat sounds/sounds.xml >> $@
1105         @echo "</menu>" >> $@
1106
1107 # We don't want to require Python or Pystache for every build, so this is its
1108 # own target.
1109 ari-stubs:
1110 ifeq ($(PYTHON),:)
1111         @echo "--------------------------------------------------------------------------"
1112         @echo "---        Please install python to build ARI stubs            ---"
1113         @echo "--------------------------------------------------------------------------"
1114         @false
1115 else
1116         @$(INSTALL) -d doc/rest-api
1117         $(PYTHON) rest-api-templates/make_ari_stubs.py \
1118                 rest-api/resources.json .
1119 endif
1120
1121 check-alembic: makeopts
1122         @find contrib/ast-db-manage/ -name '*.pyc' -delete
1123         @ALEMBIC=$(ALEMBIC) build_tools/make_check_alembic config cdr voicemail >&2
1124
1125 .PHONY: install-configs
1126 .PHONY: install-headers
1127 .PHONY: menuselect
1128 .PHONY: main
1129 .PHONY: sounds
1130 .PHONY: clean
1131 .PHONY: dist-clean
1132 .PHONY: distclean
1133 .PHONY: all
1134 .PHONY: _all
1135 .PHONY: full
1136 .PHONY: _full
1137 .PHONY: uninstall
1138 .PHONY: _uninstall
1139 .PHONY: uninstall-all
1140 .PHONY: uninstall-headers
1141 .PHONY: badshell
1142 .PHONY: installdirs
1143 .PHONY: validate-docs
1144 .PHONY: _clean
1145 .PHONY: ari-stubs
1146 .PHONY: basic-pbx
1147 .PHONY: check-alembic
1148 .PHONY: ld-cache-update
1149 .PHONY: check-old-libdir
1150 .PHONY: $(SUBDIRS_INSTALL)
1151 .PHONY: $(SUBDIRS_DIST_CLEAN)
1152 .PHONY: $(SUBDIRS_CLEAN)
1153 .PHONY: $(SUBDIRS_UNINSTALL)
1154 .PHONY: $(SUBDIRS)
1155
1156 FORCE:
1157
1158 # This only stops targets within the root Makefile from building in parallel.
1159 .NOTPARALLEL: