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