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