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