9ca498ca1f796a870a80cefcc2b21077b2b6ded4
[asterisk/asterisk.git] / Makefile
1 #
2 # Asterisk -- A telephony toolkit for Linux.
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 export PROC                     # Processor type
70
71 export NOISY_BUILD              # Used in Makefile.rules
72 export MENUSELECT_CFLAGS        # Options selected in menuselect.
73 export AST_DEVMODE              # Set to "yes" for additional compiler
74                                 # and runtime checks
75
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 export CC
85 export CXX
86 export AR
87 export RANLIB
88 export HOST_CC
89 export BUILD_CC
90 export INSTALL
91 export STRIP
92 export DOWNLOAD
93 export AWK
94 export GREP
95 export MD5
96 export WGET_EXTRA_ARGS
97 export LDCONFIG
98 export LDCONFIG_FLAGS
99
100 # even though we could use '-include makeopts' here, use a wildcard
101 # lookup anyway, so that make won't try to build makeopts if it doesn't
102 # exist (other rules will force it to be built if needed)
103 ifneq ($(wildcard makeopts),)
104   include makeopts
105 endif
106
107 # start the primary CFLAGS and LDFLAGS with any that were provided
108 # to the configure script
109 _ASTCFLAGS:=$(CONFIG_CFLAGS)
110 _ASTLDFLAGS:=$(CONFIG_LDFLAGS)
111
112 # Some build systems, such as the one in openwrt, like to pass custom target
113 # CFLAGS and LDFLAGS in the COPTS and LDOPTS variables; these should also
114 # go before any build-system computed flags, since they are defaults, not
115 # overrides
116 _ASTCFLAGS+=$(COPTS)
117 _ASTLDFLAGS+=$(LDOPTS)
118
119 # libxml2 cflags
120 _ASTCFLAGS+=$(LIBXML2_INCLUDE)
121
122 #Uncomment this to see all build commands instead of 'quiet' output
123 #NOISY_BUILD=yes
124
125 empty:=
126 space:=$(empty) $(empty)
127 ASTTOPDIR:=$(subst $(space),\$(space),$(CURDIR))
128
129 # Overwite config files on "make samples"
130 OVERWRITE=y
131
132 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
133 DEBUG=-g3
134
135 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
136 # when starting Asterisk
137 ASTCONFPATH=$(ASTETCDIR)/asterisk.conf
138 AGI_DIR=$(ASTDATADIR)/agi-bin
139
140 # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file
141 HTTP_DOCSDIR=/var/www/html
142 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
143 HTTP_CGIDIR=/var/www/cgi-bin
144
145 # If your platform's linker expects a prefix on symbols generated from compiling C
146 # source files, set LINKER_SYMBOL_PREFIX to that value. On some systems, exported symbols
147 # from C source files are prefixed with '_', for example. If this value is not set
148 # properly, the linker scripts that live in the '*.exports' files in various places
149 # in this tree will unintentionally suppress symbols that should be visible
150 # in the final binary objects.
151 LINKER_SYMBOL_PREFIX=
152
153 # Uncomment this to use the older DSP routines
154 #_ASTCFLAGS+=-DOLD_DSP_ROUTINES
155
156 # If the file .asterisk.makeopts is present in your home directory, you can
157 # include all of your favorite menuselect options so that every time you download
158 # a new version of Asterisk, you don't have to run menuselect to set them.
159 # The file /etc/asterisk.makeopts will also be included but can be overridden
160 # by the file in your home directory.
161
162 GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
163 USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
164
165 MOD_SUBDIR_CFLAGS="-I$(ASTTOPDIR)/include"
166 OTHER_SUBDIR_CFLAGS="-I$(ASTTOPDIR)/include"
167
168 # Create OPTIONS variable, but probably we can assign directly to ASTCFLAGS
169 OPTIONS=
170
171 ifeq ($(OSARCH),linux-gnu)
172   ifeq ($(PROC),x86_64)
173     # You must have GCC 3.4 to use k8, otherwise use athlon
174     PROC=k8
175     #PROC=athlon
176   endif
177
178   ifeq ($(PROC),sparc64)
179     #The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
180     #This works for even old (2.96) versions of gcc and provides a small boost either way.
181     #A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
182     #So we go lowest common available by gcc and go a step down, still a step up from
183     #the default as we now have a better instruction set to work with. - Belgarath
184     PROC=ultrasparc
185     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
186     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
187     OPTIONS+=-fomit-frame-pointer
188   endif
189
190   ifeq ($(PROC),arm)
191     # The Cirrus logic is the only heavily shipping arm processor with a real floating point unit
192     ifeq ($(SUB_PROC),maverick)
193       OPTIONS+=-fsigned-char -mcpu=ep9312
194     else
195       ifeq ($(SUB_PROC),xscale)
196         OPTIONS+=-fsigned-char -mcpu=xscale
197       else
198         OPTIONS+=-fsigned-char
199       endif
200     endif
201   endif
202   # flag to tell 'ldconfig' to only process specified directories
203   LDCONFIG_FLAGS=-n
204 endif
205
206 ifeq ($(findstring -save-temps,$(_ASTCFLAGS) $(ASTCFLAGS)),)
207   ifeq ($(findstring -pipe,$(_ASTCFLAGS) $(ASTCFLAGS)),)
208     _ASTCFLAGS+=-pipe
209   endif
210 endif
211
212 ifeq ($(findstring -Wall,$(_ASTCFLAGS) $(ASTCFLAGS)),)
213   _ASTCFLAGS+=-Wall
214 endif
215
216 _ASTCFLAGS+=-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
217 ADDL_TARGETS=
218
219 ifeq ($(AST_DEVMODE),yes)
220   _ASTCFLAGS+=-Werror
221   _ASTCFLAGS+=-Wunused
222   _ASTCFLAGS+=$(AST_DECLARATION_AFTER_STATEMENT)
223   _ASTCFLAGS+=$(AST_FORTIFY_SOURCE)
224   _ASTCFLAGS+=-Wundef
225   _ASTCFLAGS+=-Wmissing-format-attribute
226   _ASTCFLAGS+=-Wformat=2
227   ADDL_TARGETS+=validate-docs
228 endif
229
230 ifneq ($(findstring BSD,$(OSARCH)),)
231   _ASTCFLAGS+=-isystem /usr/local/include
232 endif
233
234 ifeq ($(findstring -march,$(_ASTCFLAGS) $(ASTCFLAGS)),)
235   ifneq ($(AST_MARCH_NATIVE),)
236     _ASTCFLAGS+=$(AST_MARCH_NATIVE)
237   else
238     ifneq ($(PROC),ultrasparc)
239       _ASTCFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
240     endif
241   endif
242 endif
243
244 ifeq ($(PROC),ppc)
245   _ASTCFLAGS+=-fsigned-char
246 endif
247
248 ifeq ($(OSARCH),FreeBSD)
249   ifeq ($(findstring -march,$(_ASTCFLAGS) $(ASTCFLAGS)),)
250     ifeq ($(PROC),i386)
251       _ASTCFLAGS+=-march=i686
252     endif
253   endif
254   # -V is understood by BSD Make, not by GNU make.
255   BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
256   _ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
257   # flag to tell 'ldconfig' to only process specified directories
258   LDCONFIG_FLAGS=-m
259 endif
260
261 ifeq ($(OSARCH),NetBSD)
262   _ASTCFLAGS+=-pthread -I/usr/pkg/include
263 endif
264
265 ifeq ($(OSARCH),OpenBSD)
266   _ASTCFLAGS+=-pthread -ftrampolines
267 endif
268
269 ifeq ($(OSARCH),SunOS)
270   _ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include -D_XPG4_2 -D__EXTENSIONS__
271 endif
272
273 ASTERISKVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) build_tools/make_version .)
274
275 ifneq ($(wildcard .version),)
276   ASTERISKVERSIONNUM:=$(shell $(AWK) -F. '{printf "%01d%02d%02d", $$1, $$2, $$3}' .version)
277 endif
278
279 ifneq ($(wildcard .svn),)
280   ASTERISKVERSIONNUM:=999999
281 endif
282
283 _ASTCFLAGS+=$(OPTIONS)
284
285 MOD_SUBDIRS:=channels pbx apps codecs formats cdr cel bridges funcs tests main res addons $(LOCAL_MOD_SUBDIRS)
286 OTHER_SUBDIRS:=utils agi
287 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
288 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
289 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
290 SUBDIRS_DIST_CLEAN:=$(SUBDIRS:%=%-dist-clean)
291 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
292 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
293 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
294 MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
295 MOD_SUBDIRS_MENUSELECT_TREE:=$(MOD_SUBDIRS:%=%-menuselect-tree)
296
297 ifneq ($(findstring darwin,$(OSARCH)),)
298   _ASTCFLAGS+=-D__Darwin__
299   _SOLINK=-Xlinker -macosx_version_min -Xlinker 10.4 -Xlinker -undefined -Xlinker dynamic_lookup -force_flat_namespace
300   ifeq ($(shell if test `/usr/bin/sw_vers -productVersion | cut -c4` -gt 5; then echo 6; else echo 0; fi),6)
301     _SOLINK+=/usr/lib/bundle1.o
302   endif
303   SOLINK=-bundle $(_SOLINK)
304   DYLINK=-Xlinker -dylib $(_SOLINK)
305   _ASTLDFLAGS+=-L/usr/local/lib
306 else
307 # These are used for all but Darwin
308   SOLINK=-shared
309   DYLINK=$(SOLINK)
310   ifneq ($(findstring BSD,$(OSARCH)),)
311     _ASTLDFLAGS+=-L/usr/local/lib
312   endif
313 endif
314
315 ifeq ($(OSARCH),SunOS)
316   SOLINK=-shared -fpic -L/usr/local/ssl/lib -lrt
317   DYLINK=$(SOLINK)
318 endif
319
320 ifeq ($(OSARCH),OpenBSD)
321   SOLINK=-shared -fpic
322   DYLINK=$(SOLINK)
323 endif
324
325 # comment to print directories during submakes
326 #PRINT_DIR=yes
327
328 ifneq ($(INSIDE_EMACS),)
329 PRINT_DIR=yes
330 endif
331
332 SILENTMAKE:=$(MAKE) --quiet --no-print-directory
333 ifneq ($(PRINT_DIR)$(NOISY_BUILD),)
334 SUBMAKE:=$(MAKE)
335 else
336 SUBMAKE:=$(MAKE) --quiet --no-print-directory
337 endif
338
339 # This is used when generating the doxygen documentation
340 ifneq ($(DOT),:)
341   HAVEDOT=yes
342 else
343   HAVEDOT=no
344 endif
345
346 # $(MAKE) is printed in several places, and we want it to be a
347 # fixed size string. Define a variable whose name has also the
348 # same size, so we can easily align text.
349 ifeq ($(MAKE), gmake)
350         mK="gmake"
351 else
352         mK=" make"
353 endif
354
355 all: _cleantest_all
356         @echo " +--------- Asterisk Build Complete ---------+"
357         @echo " + Asterisk has successfully been built, and +"
358         @echo " + can be installed by running:              +"
359         @echo " +                                           +"
360         @echo " +               $(mK) install               +"
361         @echo " +-------------------------------------------+"
362
363 # For parallel builds, we must call cleantest *before* running the
364 # other dependencies on _all.
365 _cleantest_all: cleantest
366         @$(MAKE) _all
367
368 _all: makeopts $(SUBDIRS) doc/core-en_US.xml $(ADDL_TARGETS)
369
370 makeopts: configure
371         @echo "****"
372         @echo "**** The configure script must be executed before running '$(MAKE)'."
373         @echo "****               Please run \"./configure\"."
374         @echo "****"
375         @exit 1
376
377 menuselect.makeopts: menuselect/menuselect menuselect-tree makeopts build_tools/menuselect-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS)
378 ifeq ($(filter %menuselect,$(MAKECMDGOALS)),)
379         menuselect/menuselect --check-deps $@
380         menuselect/menuselect --check-deps $@ $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS)
381 endif
382
383 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
384         +@echo "EMBED_LDSCRIPTS+="`$(SILENTMAKE) -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
385
386 $(MOD_SUBDIRS_EMBED_LDFLAGS):
387         +@echo "EMBED_LDFLAGS+="`$(SILENTMAKE) -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
388
389 $(MOD_SUBDIRS_EMBED_LIBS):
390         +@echo "EMBED_LIBS+="`$(SILENTMAKE) -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
391
392 $(MOD_SUBDIRS_MENUSELECT_TREE):
393         +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) moduleinfo
394         +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) makeopts
395
396 makeopts.embed_rules: menuselect.makeopts
397         @echo "Generating embedded module rules ..."
398         @rm -f $@
399         +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LDSCRIPT)
400         +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LDFLAGS)
401         +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LIBS)
402
403 $(SUBDIRS): main/version.c include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
404
405 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
406     # Non-windows:
407     # ensure that all module subdirectories are processed before 'main' during
408     # a parallel build, since if there are modules selected to be embedded the
409     # directories containing them must be completed before the main Asterisk
410     # binary can be built
411 main: $(filter-out main,$(MOD_SUBDIRS))
412 else
413     # Windows: we need to build main (i.e. the asterisk dll) first,
414     # followed by res, followed by the other directories, because
415     # dll symbols must be resolved during linking and not at runtime.
416 D1:= $(filter-out main,$(MOD_SUBDIRS))
417 D1:= $(filter-out res,$(D1))
418
419 $(D1): res
420 res:    main
421 endif
422
423 $(MOD_SUBDIRS):
424         +@_ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(_ASTCFLAGS)" ASTCFLAGS="$(ASTCFLAGS)" _ASTLDFLAGS="$(_ASTLDFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(SUBMAKE) --no-builtin-rules -C $@ SUBDIR=$@ all
425
426 $(OTHER_SUBDIRS):
427         +@_ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(_ASTCFLAGS)" ASTCFLAGS="$(ASTCFLAGS)" _ASTLDFLAGS="$(_ASTLDFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(SUBMAKE) --no-builtin-rules -C $@ SUBDIR=$@ all
428
429 defaults.h: makeopts build_tools/make_defaults_h
430         @build_tools/make_defaults_h > $@.tmp
431         @cmp -s $@.tmp $@ || mv $@.tmp $@
432         @rm -f $@.tmp
433
434 main/version.c: FORCE
435         @build_tools/make_version_c > $@.tmp
436         @cmp -s $@.tmp $@ || mv $@.tmp $@
437         @rm -f $@.tmp
438
439 include/asterisk/buildopts.h: menuselect.makeopts
440         @build_tools/make_buildopts_h > $@.tmp
441         @cmp -s $@.tmp $@ || mv $@.tmp $@
442         @rm -f $@.tmp
443
444 include/asterisk/build.h:
445         @build_tools/make_build_h > $@.tmp
446         @cmp -s $@.tmp $@ || mv $@.tmp $@
447         @rm -f $@.tmp
448
449 $(SUBDIRS_CLEAN):
450         +@$(SUBMAKE) -C $(@:-clean=) clean
451
452 $(SUBDIRS_DIST_CLEAN):
453         +@$(SUBMAKE) -C $(@:-dist-clean=) dist-clean
454
455 clean: $(SUBDIRS_CLEAN) _clean
456
457 _clean:
458         rm -f defaults.h
459         rm -f include/asterisk/build.h
460         rm -f main/version.c
461         @$(MAKE) -C menuselect clean
462         cp -f .cleancount .lastclean
463
464 dist-clean: distclean
465
466 distclean: $(SUBDIRS_DIST_CLEAN) _clean
467         @$(MAKE) -C menuselect dist-clean
468         @$(MAKE) -C sounds dist-clean
469         rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
470         rm -f makeopts.embed_rules
471         rm -f config.log config.status config.cache
472         rm -rf autom4te.cache
473         rm -f include/asterisk/autoconfig.h
474         rm -f include/asterisk/buildopts.h
475         rm -rf doc/api
476         rm -f build_tools/menuselect-deps
477
478 datafiles: _cleantest_all doc/core-en_US.xml
479         CFLAGS="$(_ASTCFLAGS) $(ASTCFLAGS)" build_tools/mkpkgconfig "$(DESTDIR)$(libdir)/pkgconfig";
480 # Should static HTTP be installed during make samples or even with its own target ala
481 # webvoicemail?  There are portions here that *could* be customized but might also be
482 # improved a lot.  I'll put it here for now.
483
484         for x in static-http/*; do \
485                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/static-http" ; \
486         done
487         $(INSTALL) -m 644 doc/core-en_US.xml "$(DESTDIR)$(ASTDATADIR)/static-http";
488         if [ -d doc/tex/asterisk ] ; then \
489                 $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \
490                 for n in doc/tex/asterisk/* ; do \
491                         $(INSTALL) -m 644 $$n "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \
492                 done \
493         fi
494         for x in images/*.jpg; do \
495                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/images" ; \
496         done
497         $(MAKE) -C sounds install
498
499 doc/core-en_US.xml: $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
500         @printf "Building Documentation For: "
501         @echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $@
502         @echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@
503         @echo "<docs xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> $@
504         @for x in $(MOD_SUBDIRS); do \
505                 printf "$$x " ; \
506                 for i in $$x/*.c; do \
507                         $(AWK) -f build_tools/get_documentation $$i >> $@ ; \
508                 done ; \
509         done
510         @echo
511         @echo "</docs>" >> $@
512
513 validate-docs: doc/core-en_US.xml
514 ifeq ($(XMLSTARLET)$(XMLLINT),::)
515         @echo "--------------------------------------------------------------------------"
516         @echo "--- Please install xmllint or xmlstarlet to validate the documentation ---"
517         @echo "--------------------------------------------------------------------------"
518 else
519   ifneq ($(XMLLINT),:)
520         $(XMLLINT) --dtdvalid doc/appdocsxml.dtd --noout $<
521   else
522         $(XMLSTARLET) val -d doc/appdocsxml.dtd $<
523   endif
524 endif
525
526 update:
527         @if [ -d .svn ]; then \
528                 echo "Updating from Subversion..." ; \
529                 fromrev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
530                 svn update | tee update.out; \
531                 torev="`svn info | $(AWK) '/Revision: / {print $$2}'`"; \
532                 echo "`date`  Updated from revision $${fromrev} to $${torev}." >> update.log; \
533                 rm -f .version; \
534                 if [ `grep -c ^C update.out` -gt 0 ]; then \
535                         echo ; echo "The following files have conflicts:" ; \
536                         grep ^C update.out | cut -b4- ; \
537                 fi ; \
538                 rm -f update.out; \
539         else \
540                 echo "Not under version control";  \
541         fi
542
543 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
544 OLDHEADERS=$(filter-out $(NEWHEADERS) $(notdir $(DESTDIR)$(ASTHEADERDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
545
546 installdirs:
547         $(INSTALL) -d "$(DESTDIR)$(ASTLIBDIR)"
548         $(INSTALL) -d "$(DESTDIR)$(ASTMODDIR)"
549         $(INSTALL) -d "$(DESTDIR)$(ASTSBINDIR)"
550         $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)"
551         $(INSTALL) -d "$(DESTDIR)$(ASTVARRUNDIR)"
552         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)"
553         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/dictate"
554         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/meetme"
555         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/monitor"
556         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/system"
557         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/tmp"
558         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/voicemail"
559         $(INSTALL) -d "$(DESTDIR)$(ASTHEADERDIR)"
560         $(INSTALL) -d "$(DESTDIR)$(ASTHEADERDIR)/doxygen"
561         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)"
562         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)/cdr-csv"
563         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)/cdr-custom"
564         $(INSTALL) -d "$(DESTDIR)$(ASTLOGDIR)/cel-custom"
565         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)"
566         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/documentation"
567         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/documentation/thirdparty"
568         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/firmware"
569         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/firmware/iax"
570         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/images"
571         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/keys"
572         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/phoneprov"
573         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/static-http"
574         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/sounds"
575         $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/moh"
576         $(INSTALL) -d "$(DESTDIR)$(ASTMANDIR)/man8"
577         $(INSTALL) -d "$(DESTDIR)$(AGI_DIR)"
578         $(INSTALL) -d "$(DESTDIR)$(ASTDBDIR)"
579
580 main-bininstall:
581         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTLIBDIR="$(ASTLIBDIR)" $(SUBMAKE) -C main bininstall
582
583 bininstall: _cleantest_all installdirs $(SUBDIRS_INSTALL) main-bininstall
584         $(INSTALL) -m 755 contrib/scripts/astgenkey "$(DESTDIR)$(ASTSBINDIR)/"
585         $(INSTALL) -m 755 contrib/scripts/autosupport "$(DESTDIR)$(ASTSBINDIR)/"
586         if [ ! -f "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk" -a ! -f /sbin/launchd ]; then \
587                 cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;s|__ASTERISK_LOG_DIR__|$(ASTLOGDIR)|;' > contrib/scripts/safe.tmp ; \
588                 $(INSTALL) -m 755 contrib/scripts/safe.tmp "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk" ; \
589                 rm -f contrib/scripts/safe.tmp ; \
590         fi
591         $(INSTALL) -m 644 include/asterisk.h "$(DESTDIR)$(includedir)"
592         $(INSTALL) -m 644 include/asterisk/*.h "$(DESTDIR)$(ASTHEADERDIR)"
593         $(INSTALL) -m 644 include/asterisk/doxygen/*.h "$(DESTDIR)$(ASTHEADERDIR)/doxygen"
594         if [ -n "$(OLDHEADERS)" ]; then \
595                 for h in $(OLDHEADERS); do rm -f "$(DESTDIR)$(ASTHEADERDIR)/$$h"; done \
596         fi
597
598         $(INSTALL) -m 644 doc/core-*.xml "$(DESTDIR)$(ASTDATADIR)/documentation"
599         $(INSTALL) -m 644 doc/appdocsxml.dtd "$(DESTDIR)$(ASTDATADIR)/documentation"
600         $(INSTALL) -m 644 doc/asterisk.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
608 $(SUBDIRS_INSTALL):
609         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" $(SUBMAKE) -C $(@:-install=) install
610
611 NEWMODS:=$(foreach d,$(MOD_SUBDIRS),$(notdir $(wildcard $(d)/*.so)))
612 OLDMODS=$(filter-out $(NEWMODS) $(notdir $(DESTDIR)$(ASTMODDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTMODDIR)/*.so)))
613
614 oldmodcheck:
615         @if [ -n "$(OLDMODS)" ]; then \
616                 echo " WARNING WARNING WARNING" ;\
617                 echo "" ;\
618                 echo " Your Asterisk modules directory, located at" ;\
619                 echo " $(DESTDIR)$(ASTMODDIR)" ;\
620                 echo " contains modules that were not installed by this " ;\
621                 echo " version of Asterisk. Please ensure that these" ;\
622                 echo " modules are compatible with this version before" ;\
623                 echo " attempting to run Asterisk." ;\
624                 echo "" ;\
625                 for f in $(OLDMODS); do \
626                         echo "    $$f" ;\
627                 done ;\
628                 echo "" ;\
629                 echo " WARNING WARNING WARNING" ;\
630         fi
631
632 badshell:
633 ifneq ($(findstring ~,$(DESTDIR)),)
634         @echo "Your shell doesn't do ~ expansion when expected (specifically, when doing \"make install DESTDIR=~/path\")."
635         @echo "Try replacing ~ with \$$HOME, as in \"make install DESTDIR=\$$HOME/path\"."
636         @exit 1
637 endif
638
639 install: badshell bininstall datafiles
640         @if [ -x /usr/sbin/asterisk-post-install ]; then \
641                 /usr/sbin/asterisk-post-install "$(DESTDIR)" . ; \
642         fi
643         @echo " +---- Asterisk Installation Complete -------+"
644         @echo " +                                           +"
645         @echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
646         @echo " +                                           +"
647         @echo " + Asterisk has successfully been installed. +"
648         @echo " + If you would like to install the sample   +"
649         @echo " + configuration files (overwriting any      +"
650         @echo " + existing config files), run:              +"
651         @echo " +                                           +"
652         @echo " +               $(mK) samples               +"
653         @echo " +                                           +"
654         @echo " +-----------------  or ---------------------+"
655         @echo " +                                           +"
656         @echo " + You can go ahead and install the asterisk +"
657         @echo " + program documentation now or later run:   +"
658         @echo " +                                           +"
659         @echo " +              $(mK) progdocs               +"
660         @echo " +                                           +"
661         @echo " + **Note** This requires that you have      +"
662         @echo " + doxygen installed on your local system    +"
663         @echo " +-------------------------------------------+"
664         @$(MAKE) -s oldmodcheck
665
666 isntall: install
667
668 upgrade: bininstall
669
670 # XXX why *.adsi is installed first ?
671 adsi:
672         @echo Installing adsi config files...
673         $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)"
674         @for x in configs/*.adsi; do \
675                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
676                 if [ -f "$${dst}" ] ; then \
677                         echo "Overwriting $$x" ; \
678                 else \
679                         echo "Installing $$x" ; \
680                 fi ; \
681                 $(INSTALL) -m 644 "$$x" "$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
682         done
683
684 samples: adsi
685         @echo Installing other config files...
686         @for x in configs/*.sample; do \
687                 dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`" ;        \
688                 if [ -f "$${dst}" ]; then \
689                         if [ "$(OVERWRITE)" = "y" ]; then \
690                                 if cmp -s "$${dst}" "$$x" ; then \
691                                         echo "Config file $$x is unchanged"; \
692                                         continue; \
693                                 fi ; \
694                                 mv -f "$${dst}" "$${dst}.old" ; \
695                         else \
696                                 echo "Skipping config file $$x"; \
697                                 continue; \
698                         fi ;\
699                 fi ; \
700                 echo "Installing file $$x"; \
701                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
702         done
703         if [ "$(OVERWRITE)" = "y" ]; then \
704                 echo "Updating asterisk.conf" ; \
705                 sed -e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
706                         -e 's|^astmoddir.*$$|astmoddir => $(ASTMODDIR)|' \
707                         -e 's|^astvarlibdir.*$$|astvarlibdir => $(ASTVARLIBDIR)|' \
708                         -e 's|^astdbdir.*$$|astdbdir => $(ASTDBDIR)|' \
709                         -e 's|^astkeydir.*$$|astkeydir => $(ASTKEYDIR)|' \
710                         -e 's|^astdatadir.*$$|astdatadir => $(ASTDATADIR)|' \
711                         -e 's|^astagidir.*$$|astagidir => $(AGI_DIR)|' \
712                         -e 's|^astspooldir.*$$|astspooldir => $(ASTSPOOLDIR)|' \
713                         -e 's|^astrundir.*$$|astrundir => $(ASTVARRUNDIR)|' \
714                         -e 's|^astlogdir.*$$|astlogdir => $(ASTLOGDIR)|' \
715                         "$(DESTDIR)$(ASTCONFPATH)" > "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
716                 $(INSTALL) -m 644 "$(DESTDIR)$(ASTCONFPATH).tmp" "$(DESTDIR)$(ASTCONFPATH)" ; \
717                 rm -f "$(DESTDIR)$(ASTCONFPATH).tmp" ; \
718         fi ; \
719         $(INSTALL) -d "$(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX"
720         build_tools/make_sample_voicemail "$(DESTDIR)/$(ASTDATADIR)" "$(DESTDIR)/$(ASTSPOOLDIR)"
721
722         @for x in phoneprov/*; do \
723                 dst="$(DESTDIR)$(ASTDATADIR)/$$x" ;     \
724                 if [ -f "$${dst}" ]; then \
725                         if [ "$(OVERWRITE)" = "y" ]; then \
726                                 if cmp -s "$${dst}" "$$x" ; then \
727                                         echo "Config file $$x is unchanged"; \
728                                         continue; \
729                                 fi ; \
730                                 mv -f "$${dst}" "$${dst}.old" ; \
731                         else \
732                                 echo "Skipping config file $$x"; \
733                                 continue; \
734                         fi ;\
735                 fi ; \
736                 echo "Installing file $$x"; \
737                 $(INSTALL) -m 644 "$$x" "$${dst}" ;\
738         done
739
740 webvmail:
741         @[ -d "$(DESTDIR)$(HTTP_DOCSDIR)/" ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
742         @[ -d "$(DESTDIR)$(HTTP_CGIDIR)" ] || ( printf "cgi-bin directory not found.\nUpdate assignment of variable HTTP_CGIDIR in Makefile!\n" && exit 1 )
743         $(INSTALL) -m 4755 contrib/scripts/vmail.cgi "$(DESTDIR)$(HTTP_CGIDIR)/vmail.cgi"
744         $(INSTALL) -d "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk"
745         for x in images/*.gif; do \
746                 $(INSTALL) -m 644 $$x "$(DESTDIR)$(HTTP_DOCSDIR)/_asterisk/"; \
747         done
748         @echo " +--------- Asterisk Web Voicemail ----------+"
749         @echo " +                                           +"
750         @echo " + Asterisk Web Voicemail is installed in    +"
751         @echo " + your cgi-bin directory:                   +"
752         @echo " + $(DESTDIR)$(HTTP_CGIDIR)"
753         @echo " + IT USES A SETUID ROOT PERL SCRIPT, SO     +"
754         @echo " + IF YOU DON'T LIKE THAT, UNINSTALL IT!     +"
755         @echo " +                                           +"
756         @echo " + Other static items have been stored in:   +"
757         @echo " + $(DESTDIR)$(HTTP_DOCSDIR)"
758         @echo " +                                           +"
759         @echo " + If these paths do not match your httpd    +"
760         @echo " + installation, correct the definitions     +"
761         @echo " + in your Makefile of HTTP_CGIDIR and       +"
762         @echo " + HTTP_DOCSDIR                              +"
763         @echo " +                                           +"
764         @echo " +-------------------------------------------+"
765
766 progdocs:
767         (cat contrib/asterisk-ng-doxygen; echo "HAVE_DOT=$(HAVEDOT)"; \
768         echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen -
769
770 install-logrotate:
771         if [ ! -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ]; then \
772                 $(INSTALL) -d "$(DESTDIR)$(ASTETCDIR)/../logrotate.d" ; \
773         fi
774         sed 's#__LOGDIR__#$(ASTLOGDIR)#g' < contrib/scripts/asterisk.logrotate | sed 's#__SBINDIR__#$(ASTSBINDIR)#g' > contrib/scripts/asterisk.logrotate.tmp
775         $(INSTALL) -m 0644 contrib/scripts/asterisk.logrotate.tmp "$(DESTDIR)$(ASTETCDIR)/../logrotate.d/asterisk"
776         rm -f contrib/scripts/asterisk.logrotate.tmp
777
778 config:
779         @if [ "${OSARCH}" = "linux-gnu" ]; then \
780                 if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
781                         cat contrib/init.d/rc.redhat.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
782                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/init.d/asterisk" ; \
783                         rm -f contrib/init.d/rc.asterisk.tmp ; \
784                         if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \
785                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
786                         fi ; \
787                         if [ -z "$(DESTDIR)" ] ; then \
788                                 /sbin/chkconfig --add asterisk ; \
789                         fi ; \
790                 elif [ -f /etc/debian_version ] ; then \
791                         cat contrib/init.d/rc.debian.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
792                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ; \
793                         rm -f contrib/init.d/rc.asterisk.tmp ; \
794                         if [ ! -f "$(DESTDIR)/etc/default/asterisk" ] ; then \
795                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/default/asterisk" ; \
796                         fi ; \
797                         if [ -z "$(DESTDIR)" ] ; then \
798                                 /usr/sbin/update-rc.d asterisk defaults 50 91 ; \
799                         fi ; \
800                 elif [ -f /etc/gentoo-release ] ; then \
801                         cat contrib/init.d/rc.gentoo.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
802                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ; \
803                         rm -f contrib/init.d/rc.asterisk.tmp ; \
804                         if [ -z "$(DESTDIR)" ] ; then \
805                                 /sbin/rc-update add asterisk default ; \
806                         fi ; \
807                 elif [ -f /etc/mandrake-release -o -f /etc/mandriva-release ] ; then \
808                         cat contrib/init.d/rc.mandriva.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
809                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/init.d/asterisk" ; \
810                         rm -f contrib/init.d/rc.asterisk.tmp ; \
811                         if [ ! -f /etc/sysconfig/asterisk ] ; then \
812                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
813                         fi ; \
814                         if [ -z "$(DESTDIR)" ] ; then \
815                                 /sbin/chkconfig --add asterisk ; \
816                         fi ; \
817                 elif [ -f /etc/SuSE-release -o -f /etc/novell-release ] ; then \
818                         cat contrib/init.d/rc.suse.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
819                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ;\
820                         rm -f contrib/init.d/rc.asterisk.tmp ; \
821                         if [ ! -f /etc/sysconfig/asterisk ] ; then \
822                                 $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
823                         fi ; \
824                         if [ -z "$(DESTDIR)" ] ; then \
825                                 /sbin/chkconfig --add asterisk ; \
826                         fi ; \
827                 elif [ -f /etc/arch-release -o -f /etc/arch-release ] ; then \
828                         cat contrib/init.d/rc.archlinux.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
829                         $(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/asterisk" ; \
830                         rm -f contrib/init.d/rc.asterisk.tmp ; \
831                 elif [ -d "$(DESTDIR)/Library/LaunchDaemons" ]; then \
832                         if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist" ]; then \
833                                 sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.asterisk.plist > asterisk.plist ; \
834                                 $(INSTALL) -m 644 asterisk.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist"; \
835                                 rm -f asterisk.plist; \
836                         fi; \
837                         if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist" ]; then \
838                                 sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.muted.plist > muted.plist ; \
839                                 $(INSTALL) -m 644 muted.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist"; \
840                                 rm -f muted.plist; \
841                         fi; \
842                 elif [ -f /etc/slackware-version ]; then \
843                         echo "Slackware is not currently supported, although an init script does exist for it."; \
844                 else \
845                         echo "We could not install init scripts for your distribution." ; \
846                 fi \
847         else \
848                 echo "We could not install init scripts for your operating system." ; \
849         fi
850
851 sounds:
852         $(MAKE) -C sounds all
853
854 # If the cleancount has been changed, force a make clean.
855 # .cleancount is the global clean count, and .lastclean is the
856 # last clean count we had
857
858 cleantest:
859         @cmp -s .cleancount .lastclean || $(MAKE) clean
860         @[ -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")
861
862 $(SUBDIRS_UNINSTALL):
863         +@$(SUBMAKE) -C $(@:-uninstall=) uninstall
864
865 main-binuninstall:
866         +@DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" ASTLIBDIR="$(ASTLIBDIR)" $(SUBMAKE) -C main binuninstall
867
868 _uninstall: $(SUBDIRS_UNINSTALL) main-binuninstall
869         rm -f "$(DESTDIR)$(ASTMODDIR)/"*
870         rm -f "$(DESTDIR)$(ASTSBINDIR)/astgenkey"
871         rm -f "$(DESTDIR)$(ASTSBINDIR)/autosupport"
872         rm -rf "$(DESTDIR)$(ASTHEADERDIR)"
873         rm -rf "$(DESTDIR)$(ASTDATADIR)/firmware"
874         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/asterisk.8"
875         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8"
876         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/autosupport.8"
877         rm -f "$(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8"
878         $(MAKE) -C sounds uninstall
879
880 uninstall: _uninstall
881         @echo " +--------- Asterisk Uninstall Complete -----+"
882         @echo " + Asterisk binaries, sounds, man pages,     +"
883         @echo " + headers, modules, and firmware builds,    +"
884         @echo " + have all been uninstalled.                +"
885         @echo " +                                           +"
886         @echo " + To remove ALL traces of Asterisk,         +"
887         @echo " + including configuration, spool            +"
888         @echo " + directories, and logs, run the following  +"
889         @echo " + command:                                  +"
890         @echo " +                                           +"
891         @echo " +            $(mK) uninstall-all            +"
892         @echo " +-------------------------------------------+"
893
894 uninstall-all: _uninstall
895         rm -rf "$(DESTDIR)$(ASTMODDIR)"
896         rm -rf "$(DESTDIR)$(ASTVARLIBDIR)"
897         rm -rf "$(DESTDIR)$(ASTDATADIR)"
898         rm -rf "$(DESTDIR)$(ASTSPOOLDIR)"
899         rm -rf "$(DESTDIR)$(ASTETCDIR)"
900         rm -rf "$(DESTDIR)$(ASTLOGDIR)"
901
902 menuconfig: menuselect
903
904 cmenuconfig: cmenuselect
905
906 gmenuconfig: gmenuselect
907
908 nmenuconfig: nmenuselect
909
910 menuselect: menuselect/cmenuselect menuselect/nmenuselect menuselect/gmenuselect
911         @if [ -x menuselect/nmenuselect ]; then \
912                 $(MAKE) nmenuselect; \
913         elif [ -x menuselect/cmenuselect ]; then \
914                 $(MAKE) cmenuselect; \
915         elif [ -x menuselect/gmenuselect ]; then \
916                 $(MAKE) gmenuselect; \
917         else \
918                 echo "No menuselect user interface found. Install ncurses,"; \
919                 echo "newt or GTK libraries to build one and re-rerun"; \
920                 echo "'./configure' and 'make menuselect'."; \
921         fi
922
923 cmenuselect: menuselect/cmenuselect menuselect-tree menuselect.makeopts
924         -@menuselect/cmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
925
926 gmenuselect: menuselect/gmenuselect menuselect-tree menuselect.makeopts
927         -@menuselect/gmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
928
929 nmenuselect: menuselect/nmenuselect menuselect-tree menuselect.makeopts
930         -@menuselect/nmenuselect menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
931
932 # options for make in menuselect/
933 MAKE_MENUSELECT=CC="$(BUILD_CC)" CXX="" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
934
935 menuselect/menuselect: menuselect/makeopts
936         +$(MAKE_MENUSELECT) menuselect
937
938 menuselect/cmenuselect: menuselect/makeopts
939         +$(MAKE_MENUSELECT) cmenuselect
940
941 menuselect/gmenuselect: menuselect/makeopts
942         +$(MAKE_MENUSELECT) gmenuselect
943
944 menuselect/nmenuselect: menuselect/makeopts
945         +$(MAKE_MENUSELECT) nmenuselect
946
947 menuselect/makeopts: makeopts
948         +$(MAKE_MENUSELECT) makeopts
949
950 menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml build_tools/embed_modules.xml utils/utils.xml agi/agi.xml configure makeopts
951         @echo "Generating input for menuselect ..."
952         @echo "<?xml version=\"1.0\"?>" > $@
953         @echo >> $@
954         @echo "<menu name=\"Asterisk Module and Build Option Selection\">" >> $@
955         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} moduleinfo >> $@; done
956         @cat build_tools/cflags.xml >> $@
957         +@for dir in $(sort $(filter-out main,$(MOD_SUBDIRS))); do $(SILENTMAKE) -C $${dir} SUBDIR=$${dir} makeopts >> $@; done
958         @if [ "${AST_DEVMODE}" = "yes" ]; then \
959                 cat build_tools/cflags-devmode.xml >> $@; \
960         fi
961         @cat utils/utils.xml >> $@
962         @cat agi/agi.xml >> $@
963         @cat build_tools/embed_modules.xml >> $@
964         @cat sounds/sounds.xml >> $@
965         @echo "</menu>" >> $@
966
967 .PHONY: menuselect
968 .PHONY: main
969 .PHONY: sounds
970 .PHONY: clean
971 .PHONY: dist-clean
972 .PHONY: distclean
973 .PHONY: all
974 .PHONY: _all
975 .PHONY: _cleantest_all
976 .PHONY: prereqs
977 .PHONY: cleantest
978 .PHONY: uninstall
979 .PHONY: _uninstall
980 .PHONY: uninstall-all
981 .PHONY: dont-optimize
982 .PHONY: badshell
983 .PHONY: installdirs
984 .PHONY: validate-docs
985 .PHONY: _clean
986 .PHONY: $(SUBDIRS_INSTALL)
987 .PHONY: $(SUBDIRS_DIST_CLEAN)
988 .PHONY: $(SUBDIRS_CLEAN)
989 .PHONY: $(SUBDIRS_UNINSTALL)
990 .PHONY: $(SUBDIRS)
991 .PHONY: $(MOD_SUBDIRS_EMBED_LDSCRIPT)
992 .PHONY: $(MOD_SUBDIRS_EMBED_LDFLAGS)
993 .PHONY: $(MOD_SUBDIRS_EMBED_LIBS)
994
995 FORCE:
996