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