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