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