move the declaration of struct ast_channel ast_frame and ast_module
[asterisk/asterisk.git] / Makefile
index 24fbb96..7730cdf 100644 (file)
--- a/Makefile
+++ b/Makefile
 
 # All Makefiles use the following variables:
 #
-# LDFLAGS - linker flags (not libraries), used for all links
+# ASTCFLAGS - compiler options
+# ASTLDFLAGS - linker flags (not libraries)
 # LIBS - additional libraries, at top-level for all links,
 #      on a single object just for that object
 # SOLINK - linker flags used only for creating shared objects (.so files),
 #      used for all .so links
 #
+# Default values fo ASTCFLAGS and ASTLDFLAGS can be specified in the
+# environment when running make, as follows:
+#
+# $ ASTCFLAGS="-Werror" make
+
+export ASTTOPDIR
+export ASTERISKVERSION
+export ASTERISKVERSIONNUM
+export INSTALL_PATH
+export ASTETCDIR
+export ASTVARRUNDIR
+export MODULES_DIR
+export ASTSPOOLDIR
+export ASTVARLIBDIR
+export ASTDATADIR
+export ASTLOGDIR
+export ASTLIBDIR
+export ASTMANDIR
+export ASTHEADERDIR
+export ASTBINDIR
+export ASTSBINDIR
+export AGI_DIR
+export ASTCONFPATH
+export NOISY_BUILD
+export MENUSELECT_CFLAGS
+export AST_DEVMODE
+export CC
+export CXX
+export AR
+export RANLIB
+export HOST_CC
+export STATIC_BUILD
+export INSTALL
+export DESTDIR
+export PROC
+export SOLINK
+export STRIP
+export DOWNLOAD
+export GREP
+export ID
+export OSARCH
+
+# even though we could use '-include makeopts' here, use a wildcard
+# lookup anyway, so that make won't try to build makeopts if it doesn't
+# exist (other rules will force it to be built if needed)
+ifneq ($(wildcard makeopts),)
+  include makeopts
+endif
 
-.EXPORT_ALL_VARIABLES:
-
-include makeopts
+# Some build systems, such as the one in openwrt, like to pass custom target
+# CFLAGS and LDFLAGS in the COPTS and LDOPTS variables.
+ASTCFLAGS+=$(COPTS)
+ASTLDFLAGS+=$(LDOPTS)
 
 #Uncomment this to see all build commands instead of 'quiet' output
 #NOISY_BUILD=yes
@@ -30,7 +80,7 @@ include makeopts
 # Create OPTIONS variable
 OPTIONS=
 
-ASTTOPDIR:=$(shell pwd)
+ASTTOPDIR:=$(CURDIR)
 
 # Overwite config files on "make samples"
 OVERWRITE=y
@@ -51,6 +101,8 @@ ifeq ($(OSARCH),SunOS)
   ASTETCDIR=/var/etc/asterisk
   ASTLIBDIR=/opt/asterisk/lib
   ASTVARLIBDIR=/var/opt/asterisk
+  ASTDBDIR=$(ASTVARLIBDIR)
+  ASTKEYDIR=$(ASTVARLIBDIR)
   ASTSPOOLDIR=/var/spool/asterisk
   ASTLOGDIR=/var/log/asterisk
   ASTHEADERDIR=/opt/asterisk/include
@@ -68,13 +120,19 @@ else
   ASTLOGDIR=$(localstatedir)/log/asterisk
   ASTVARRUNDIR=$(localstatedir)/run
   ASTMANDIR=$(mandir)
-ifeq ($(OSARCH),FreeBSD)
+ifneq ($(findstring BSD,$(OSARCH)),)
   ASTVARLIBDIR=$(prefix)/share/asterisk
+  ASTVARRUNDIR=$(localstatedir)/run/asterisk
+  ASTDBDIR=$(localstatedir)/db/asterisk
 else
   ASTVARLIBDIR=$(localstatedir)/lib/asterisk
+  ASTDBDIR=$(ASTVARLIBDIR)
+endif
+  ASTKEYDIR=$(ASTVARLIBDIR)
 endif
+ifeq ($(ASTDATADIR),)
+  ASTDATADIR:=$(ASTVARLIBDIR)
 endif
-ASTDATADIR?=$(ASTVARLIBDIR)
 
 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
 # when starting Asterisk
@@ -87,8 +145,6 @@ HTTP_DOCSDIR=/var/www/html
 # Determine by a grep 'ScriptAlias' of your Apache httpd.conf file
 HTTP_CGIDIR=/var/www/cgi-bin
 
-ASTCFLAGS=
-
 # Uncomment this to use the older DSP routines
 #ASTCFLAGS+=-DOLD_DSP_ROUTINES
 
@@ -101,8 +157,8 @@ ASTCFLAGS=
 GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts)
 USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts)
 
-MOD_SUBDIR_CFLAGS=-I../include -I../main
-OTHER_SUBDIR_CFLAGS=-I../include
+MOD_SUBDIR_CFLAGS=-I$(ASTTOPDIR)/include
+OTHER_SUBDIR_CFLAGS=-I$(ASTTOPDIR)/include
 
 ifeq ($(OSARCH),linux-gnu)
   ifeq ($(PROC),x86_64)
@@ -137,21 +193,21 @@ ifeq ($(OSARCH),linux-gnu)
   endif
 endif
 
-ID=id
-
-ifeq ($(OSARCH),SunOS)
-  M4=/usr/local/bin/m4
-  ID=/usr/xpg4/bin/id
+ifeq ($(findstring -save-temps,$(ASTCFLAGS)),)
+ASTCFLAGS+=-pipe
 endif
 
-ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
+ASTCFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG)
+
+ASTCFLAGS+=-include $(ASTTOPDIR)/include/asterisk/autoconfig.h
 
 ifeq ($(AST_DEVMODE),yes)
-  ASTCFLAGS+=-Werror -Wunused
+  ASTCFLAGS+=-Werror -Wunused -Wundef $(AST_DECLARATION_AFTER_STATEMENT)
 endif
 
 ifneq ($(findstring BSD,$(OSARCH)),)
-  ASTCFLAGS+=-I/usr/local/include -L/usr/local/lib
+  ASTCFLAGS+=-I/usr/local/include
+  ASTLDFLAGS+=-L/usr/local/lib
 endif
 
 ifneq ($(PROC),ultrasparc)
@@ -163,9 +219,9 @@ ifeq ($(PROC),ppc)
 endif
 
 ifeq ($(OSARCH),FreeBSD)
-  BSDVERSION=$(shell $(MAKE) -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
+  # -V is understood by BSD Make, not by GNU make.
+  BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
   ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi)
-  AST_LIBS+=$(shell if test  $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi)
 endif
 
 ifeq ($(OSARCH),NetBSD)
@@ -183,7 +239,7 @@ endif
 ASTERISKVERSION:=$(shell build_tools/make_version .)
 
 ifneq ($(wildcard .version),)
-  ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version)
+  ASTERISKVERSIONNUM:=$(shell awk -F. '{printf "%01d%02d%02d", $$1, $$2, $$3}' .version)
   RPMVERSION:=$(shell sed 's/[-\/:]/_/g' .version)
 else
   RPMVERSION=unknown
@@ -195,15 +251,12 @@ endif
 
 ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS)
 
-MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs main
+MOD_SUBDIRS:=channels pbx apps codecs formats cdr funcs main res
 OTHER_SUBDIRS:=utils agi
 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
-SUBDIRS_CLEAN_DEPEND:=$(SUBDIRS:%=%-clean-depend)
-MOD_SUBDIRS_DEPEND:=$(MOD_SUBDIRS:%=%-depend)
-OTHER_SUBDIRS_DEPEND:=$(OTHER_SUBDIRS:%=%-depend)
-SUBDIRS_DEPEND:=$(OTHER_SUBDIRS_DEPEND) $(MOD_SUBDIRS_DEPEND)
+SUBDIRS_DIST_CLEAN:=$(SUBDIRS:%=%-dist-clean)
 SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
@@ -211,7 +264,6 @@ MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
 
 ifneq ($(findstring darwin,$(OSARCH)),)
   ASTCFLAGS+=-D__Darwin__
-  AUDIO_LIBS=-framework CoreAudio
   SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
 else
 # These are used for all but Darwin
@@ -225,6 +277,10 @@ ifeq ($(OSARCH),SunOS)
   SOLINK=-shared -fpic -L/usr/local/ssl/lib
 endif
 
+ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
+  SOLINK=-Xlinker -r
+endif
+
 # This is used when generating the doxygen documentation
 ifneq ($(DOT),:)
   HAVEDOT=yes
@@ -232,18 +288,32 @@ else
   HAVEDOT=no
 endif
 
-all: cleantest $(SUBDIRS)
+# $(MAKE) is printed in several places, and we want it to be a
+# fixed size string. Define a variable whose name has also the
+# same size, so we can easily align text.
+ifeq ($(MAKE), gmake)
+       mK="gmake"
+else
+       mK=" make"
+endif
+
+# comment to print directories during submakes
+PRINT_DIR:= --no-print-directory
+
+all: _all
        @echo " +--------- Asterisk Build Complete ---------+"  
-       @echo " + Asterisk has successfully been built, but +"  
-       @echo " + cannot be run before being installed by   +"  
-       @echo " + running:                                  +"  
+       @echo " + Asterisk has successfully been built, and +"  
+       @echo " + can be installed by running:              +"
        @echo " +                                           +"
-       @echo " +               make install                +"  
+       @echo " +               $(mK) install               +"  
        @echo " +-------------------------------------------+"  
 
+_all: cleantest $(SUBDIRS)
+
 makeopts: configure
        @echo "****"
-       @echo "**** The configure script must be executed before running 'make'."
+       @echo "**** The configure script must be executed before running '$(MAKE)'." 
+       @echo "****               Please run \"./configure\"."
        @echo "****"
        @exit 1
 
@@ -251,34 +321,46 @@ menuselect.makeopts: menuselect/menuselect menuselect-tree
        menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts
 
 $(MOD_SUBDIRS_EMBED_LDSCRIPT):
-       @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
+       @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet $(PRINT_DIR) -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
 
 $(MOD_SUBDIRS_EMBED_LDFLAGS):
-       @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
+       @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet $(PRINT_DIR) -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
 
 $(MOD_SUBDIRS_EMBED_LIBS):
-       @echo "EMBED_LIBS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
+       @echo "EMBED_LIBS+="`$(MAKE) --quiet $(PRINT_DIR) -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
 
 makeopts.embed_rules: menuselect.makeopts
        @echo "Generating embedded module rules ..."
        @rm -f $@
-       @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDSCRIPT)
-       @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
-       @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
-
-$(SUBDIRS): depend makeopts.embed_rules
-
-# ensure that all module subdirectories are processed before 'main' during
-# a parallel build, since if there are modules selected to be embedded the
-# directories containing them must be completed before the main Asterisk
-# binary can be built
+       @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LDSCRIPT)
+       @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LDFLAGS)
+       @$(MAKE) $(PRINT_DIR) $(MOD_SUBDIRS_EMBED_LIBS)
+
+$(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
+
+ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
+    # Non-windows:
+    # ensure that all module subdirectories are processed before 'main' during
+    # a parallel build, since if there are modules selected to be embedded the
+    # directories containing them must be completed before the main Asterisk
+    # binary can be built
 main: $(filter-out main,$(MOD_SUBDIRS))
+else
+    # Windows: we need to build main (i.e. the asterisk dll) first,
+    # followed by res, followed by the other directories, because
+    # dll symbols must be resolved during linking and not at runtime.
+D1:= $(filter-out main,$(MOD_SUBDIRS))
+D1:= $(filter-out res,$(D1))
+
+$(D1): res
+res:   main
+endif
 
 $(MOD_SUBDIRS):
-       @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
+       @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(MAKE) $(PRINT_DIR) --no-builtin-rules -C $@ SUBDIR=$@ all
 
 $(OTHER_SUBDIRS):
-       @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
+       @ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" $(MAKE) $(PRINT_DIR) --no-builtin-rules -C $@ SUBDIR=$@ all
 
 defaults.h: makeopts
        @build_tools/make_defaults_h > $@.tmp
@@ -301,24 +383,29 @@ include/asterisk/buildopts.h: menuselect.makeopts
        fi
        @rm -f $@.tmp
 
-$(SUBDIRS_CLEAN_DEPEND):
-       @$(MAKE) --no-print-directory -C $(@:-clean-depend=) clean-depend
+include/asterisk/build.h:
+       @build_tools/make_build_h > $@.tmp
+       @if cmp -s $@.tmp $@ ; then : ; else \
+               mv $@.tmp $@ ; \
+       fi
+       @rm -f $@.tmp
 
 $(SUBDIRS_CLEAN):
-       @$(MAKE) --no-print-directory -C $(@:-clean=) clean
+       @$(MAKE) $(PRINT_DIR) -C $(@:-clean=) clean
 
-clean-depend: $(SUBDIRS_CLEAN_DEPEND)
+$(SUBDIRS_DIST_CLEAN):
+       @$(MAKE) $(PRINT_DIR) -C $(@:-dist-clean=) dist-clean
 
-clean: $(SUBDIRS_CLEAN) clean-depend
+clean: $(SUBDIRS_CLEAN)
        rm -f defaults.h
        rm -f include/asterisk/build.h
        rm -f include/asterisk/version.h
-       rm -f .depend
        @$(MAKE) -C menuselect clean
+       cp -f .cleancount .lastclean
 
 dist-clean: distclean
 
-distclean: clean
+distclean: $(SUBDIRS_DIST_CLEAN) clean
        @$(MAKE) -C menuselect dist-clean
        @$(MAKE) -C sounds dist-clean
        rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
@@ -330,7 +417,7 @@ distclean: clean
        rm -rf doc/api
        rm -f build_tools/menuselect-deps
 
-datafiles: all
+datafiles: _all
        if [ x`$(ID) -un` = xroot ]; then CFLAGS="$(ASTCFLAGS)" sh build_tools/mkpkgconfig $(DESTDIR)/usr/lib/pkgconfig; fi
 # Should static HTTP be installed during make samples or even with its own target ala
 # webvoicemail?  There are portions here that *could* be customized but might also be
@@ -356,7 +443,6 @@ update:
                        grep ^C update.out | cut -b4- ; \
                fi ; \
                rm -f update.out; \
-               $(MAKE) clean-depend; \
        else \
                echo "Not under version control";  \
        fi
@@ -364,7 +450,7 @@ update:
 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
 OLDHEADERS=$(filter-out $(NEWHEADERS),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
 
-bininstall: all
+bininstall: _all
        mkdir -p $(DESTDIR)$(MODULES_DIR)
        mkdir -p $(DESTDIR)$(ASTSBINDIR)
        mkdir -p $(DESTDIR)$(ASTETCDIR)
@@ -381,7 +467,7 @@ bininstall: all
        $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
        $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/
        if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \
-               cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
+               cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ;\
                chmod 755 $(DESTDIR)$(ASTSBINDIR)/safe_asterisk;\
        fi
        $(INSTALL) -d $(DESTDIR)$(ASTHEADERDIR)
@@ -402,10 +488,12 @@ bininstall: all
        $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8
        $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8
        $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
-       $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
+       if [ -f contrib/firmware/iax/iaxy.bin ] ; then \
+               $(INSTALL) -m 644 contrib/firmware/iax/iaxy.bin $(DESTDIR)$(ASTDATADIR)/firmware/iax/iaxy.bin; \
+       fi
 
 $(SUBDIRS_INSTALL):
-       @$(MAKE) -C $(@:-install=) install
+       @DESTDIR="$(DESTDIR)" ASTSBINDIR="$(ASTSBINDIR)" $(MAKE) -C $(@:-install=) install
 
 NEWMODS=$(notdir $(wildcard */*.so))
 OLDMODS=$(filter-out $(NEWMODS),$(notdir $(wildcard $(DESTDIR)$(MODULES_DIR)/*.so)))
@@ -428,7 +516,7 @@ oldmodcheck:
                echo " WARNING WARNING WARNING" ;\
        fi
 
-install: all datafiles bininstall $(SUBDIRS_INSTALL)
+install: datafiles bininstall $(SUBDIRS_INSTALL)
        @if [ -x /usr/sbin/asterisk-post-install ]; then \
                /usr/sbin/asterisk-post-install $(DESTDIR) . ; \
        fi
@@ -441,80 +529,112 @@ install: all datafiles bininstall $(SUBDIRS_INSTALL)
        @echo " + configuration files (overwriting any      +"
        @echo " + existing config files), run:              +"  
        @echo " +                                           +"
-       @echo " +               $(MAKE) samples                +"
+       @echo " +               $(mK) samples               +"
        @echo " +                                           +"
        @echo " +-----------------  or ---------------------+"
        @echo " +                                           +"
        @echo " + You can go ahead and install the asterisk +"
        @echo " + program documentation now or later run:   +"
        @echo " +                                           +"
-       @echo " +              $(MAKE) progdocs                +"
+       @echo " +              $(mK) progdocs               +"
        @echo " +                                           +"
        @echo " + **Note** This requires that you have      +"
        @echo " + doxygen installed on your local system    +"
        @echo " +-------------------------------------------+"
        @$(MAKE) -s oldmodcheck
 
-upgrade: all bininstall
+upgrade: bininstall
 
+# XXX why *.adsi is installed first ?
 adsi:
-       mkdir -p $(DESTDIR)$(ASTETCDIR)
-       for x in configs/*.adsi; do \
-               if [ ! -f $(DESTDIR)$(ASTETCDIR)/$$x ]; then \
-                       $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
+       @echo Installing adsi config files...
+       @mkdir -p $(DESTDIR)$(ASTETCDIR)
+       @for x in configs/*.adsi; do \
+               dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x`" ; \
+               if [ -f $${dst} ] ; then \
+                       echo "Overwriting $$x" ; \
+               else \
+                       echo "Installing $$x" ; \
                fi ; \
+               $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x` ; \
        done
 
 samples: adsi
-       mkdir -p $(DESTDIR)$(ASTETCDIR)
-       for x in configs/*.sample; do \
-               if [ -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ]; then \
+       @echo Installing other config files...
+       @mkdir -p $(DESTDIR)$(ASTETCDIR)
+       @for x in configs/*.sample; do \
+               dst="$(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`" ;        \
+               if [ -f $${dst} ]; then \
                        if [ "$(OVERWRITE)" = "y" ]; then \
-                               if cmp -s $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $$x ; then \
+                               if cmp -s $${dst} $$x ; then \
                                        echo "Config file $$x is unchanged"; \
                                        continue; \
                                fi ; \
-                               mv -f $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample`.old ; \
+                               mv -f $${dst} $${dst}.old ; \
                        else \
                                echo "Skipping config file $$x"; \
                                continue; \
                        fi ;\
                fi ; \
-               $(INSTALL) -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`$(BASENAME) $$x .sample` ;\
+               echo "Installing file $$x"; \
+               $(INSTALL) -m 644 $$x $${dst} ;\
        done
-       if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
+       @if [ "$(OVERWRITE)" = "y" ] || [ ! -f $(DESTDIR)$(ASTCONFPATH) ]; then \
+               echo "Creating asterisk.conf"; \
                ( \
                echo "[directories]" ; \
                echo "astetcdir => $(ASTETCDIR)" ; \
                echo "astmoddir => $(MODULES_DIR)" ; \
                echo "astvarlibdir => $(ASTVARLIBDIR)" ; \
+               echo "astdbdir => $(ASTDBDIR)" ; \
+               echo "astkeydir => $(ASTKEYDIR)" ; \
                echo "astdatadir => $(ASTDATADIR)" ; \
                echo "astagidir => $(AGI_DIR)" ; \
                echo "astspooldir => $(ASTSPOOLDIR)" ; \
                echo "astrundir => $(ASTVARRUNDIR)" ; \
                echo "astlogdir => $(ASTLOGDIR)" ; \
                echo "" ; \
+               echo ";[options]" ; \
+               echo ";verbose = 3" ; \
+               echo ";debug = 3" ; \
+               echo ";alwaysfork = yes ; same as -F at startup" ; \
+               echo ";nofork = yes ; same as -f at startup" ; \
+               echo ";quiet = yes ; same as -q at startup" ; \
+               echo ";timestamp = yes ; same as -T at startup" ; \
+               echo ";execincludes = yes ; support #exec in config files" ; \
+               echo ";console = yes ; Run as console (same as -c at startup)" ; \
+               echo ";highpriority = yes ; Run realtime priority (same as -p at startup)" ; \
+               echo ";initcrypto = yes ; Initialize crypto keys (same as -i at startup)" ; \
+               echo ";nocolor = yes ; Disable console colors" ; \
+               echo ";dontwarn = yes ; Disable some warnings" ; \
+               echo ";dumpcore = yes ; Dump core on crash (same as -g at startup)" ; \
+               echo ";languageprefix = yes ; Use the new sound prefix path syntax" ; \
+               echo ";internal_timing = yes" ; \
+               echo ";systemname = my_system_name ; prefix uniqueid with a system name for global uniqueness issues" ; \
+               echo ";autosystemname = yes ; automatically set systemname to hostname - uses 'localhost' on failure, or systemname if set" ; \
+               echo ";maxcalls = 10 ; Maximum amount of calls allowed" ; \
+               echo ";maxload = 0.9 ; Asterisk stops accepting new calls if the load average exceed this limit" ; \
+               echo ";maxfiles = 1000 ; Maximum amount of openfiles" ; \
+               echo ";minmemfree = 1 ; in MBs, Asterisk stops accepting new calls if the amount of free memory falls below this watermark" ; \
+               echo ";cache_record_files = yes ; Cache recorded sound files to another directory during recording" ; \
+               echo ";record_cache_dir = /tmp ; Specify cache directory (used in cnjunction with cache_record_files)" ; \
+               echo ";transmit_silence_during_record = yes ; Transmit SLINEAR silence while a channel is being recorded" ; \
+               echo ";transcode_via_sln = yes ; Build transcode paths via SLINEAR, instead of directly" ; \
+               echo ";runuser = asterisk ; The user to run as" ; \
+               echo ";rungroup = asterisk ; The group to run as" ; \
+               echo "" ; \
                echo "; Changing the following lines may compromise your security." ; \
                echo ";[files]" ; \
                echo ";astctlpermissions = 0660" ; \
                echo ";astctlowner = root" ; \
                echo ";astctlgroup = apache" ; \
                echo ";astctl = asterisk.ctl" ; \
-               echo ";[options]" ; \
-               echo ";internal_timing = yes" ; \
                ) > $(DESTDIR)$(ASTCONFPATH) ; \
        else \
                echo "Skipping asterisk.conf creation"; \
        fi
        mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
-       :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm
-       for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
-               cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/unavail.gsm ; \
-       done
-       :> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm
-       for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
-               cat $(DESTDIR)$(ASTDATADIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/busy.gsm ; \
-       done
+       build_tools/make_sample_voicemail $(DESTDIR)/$(ASTDATADIR) $(DESTDIR)/$(ASTSPOOLDIR)
 
 webvmail:
        @[ -d $(DESTDIR)$(HTTP_DOCSDIR)/ ] || ( printf "http docs directory not found.\nUpdate assignment of variable HTTP_DOCSDIR in Makefile!\n" && exit 1 )
@@ -563,20 +683,20 @@ progdocs:
 config:
        @if [ "${OSARCH}" = "linux-gnu" ]; then \
                if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
-                       $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \
-                       /sbin/chkconfig --add asterisk; \
+                       $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk $(DESTDIR)/etc/rc.d/init.d/asterisk; \
+                       if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
                elif [ -f /etc/debian_version ]; then \
-                       $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk; \
-                       /usr/sbin/update-rc.d asterisk start 10 2 3 4 5 . stop 91 2 3 4 5 .; \
+                       $(INSTALL) -m 755 contrib/init.d/rc.debian.asterisk $(DESTDIR)/etc/init.d/asterisk; \
+                       if [ -z "$(DESTDIR)" ]; then /usr/sbin/update-rc.d asterisk start 50 2 3 4 5 . stop 91 2 3 4 5 .; fi; \
                elif [ -f /etc/gentoo-release ]; then \
-                       $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk /etc/init.d/asterisk; \
-                       /sbin/rc-update add asterisk default; \
-               elif [ -f /etc/mandrake-release ]; then \
-                       $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk /etc/rc.d/init.d/asterisk; \
-                       /sbin/chkconfig --add asterisk; \
+                       $(INSTALL) -m 755 contrib/init.d/rc.gentoo.asterisk $(DESTDIR)/etc/init.d/asterisk; \
+                       if [ -z "$(DESTDIR)" ]; then /sbin/rc-update add asterisk default; fi; \
+               elif [ -f /etc/mandrake-release -o -f /etc/mandriva-release ]; then \
+                       $(INSTALL) -m 755 contrib/init.d/rc.mandrake.asterisk $(DESTDIR)/etc/rc.d/init.d/asterisk; \
+                       if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
                elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
-                       $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk /etc/init.d/asterisk; \
-                       /sbin/chkconfig --add asterisk; \
+                       $(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk $(DESTDIR)/etc/init.d/asterisk; \
+                       if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
                elif [ -f /etc/slackware-version ]; then \
                        echo "Slackware is not currently supported, although an init script does exist for it." \
                else \
@@ -586,14 +706,6 @@ config:
                echo "We could not install init scripts for your operating system."; \
        fi
 
-$(MOD_SUBDIRS_DEPEND):
-       @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
-
-$(OTHER_SUBDIRS_DEPEND):
-       @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
-
-depend: include/asterisk/version.h include/asterisk/buildopts.h defaults.h $(SUBDIRS_DEPEND)
-
 sounds:
        $(MAKE) -C sounds all
 
@@ -602,13 +714,10 @@ sounds:
 # last clean count we had
 
 cleantest:
-       @if ! cmp -s .cleancount .lastclean ; then \
-               $(MAKE) clean; cp -f .cleancount .lastclean;\
-               $(MAKE) defaults.h;\
-       fi
+       @cmp -s .cleancount .lastclean || $(MAKE) clean
 
 $(SUBDIRS_UNINSTALL):
-       @$(MAKE) --no-print-directory -C $(@:-uninstall=) uninstall
+       @$(MAKE) $(PRINT_DIR) -C $(@:-uninstall=) uninstall
 
 _uninstall: $(SUBDIRS_UNINSTALL)
        rm -f $(DESTDIR)$(MODULES_DIR)/*
@@ -617,7 +726,10 @@ _uninstall: $(SUBDIRS_UNINSTALL)
        rm -f $(DESTDIR)$(ASTSBINDIR)/autosupport
        rm -rf $(DESTDIR)$(ASTHEADERDIR)
        rm -rf $(DESTDIR)$(ASTDATADIR)/firmware
-       rm -rf $(DESTDIR)$(ASTMANDIR)/man8
+       rm -f $(DESTDIR)$(ASTMANDIR)/man8/asterisk.8
+       rm -f $(DESTDIR)$(ASTMANDIR)/man8/astgenkey.8
+       rm -f $(DESTDIR)$(ASTMANDIR)/man8/autosupport.8
+       rm -f $(DESTDIR)$(ASTMANDIR)/man8/safe_asterisk.8
        $(MAKE) -C sounds uninstall
 
 uninstall: _uninstall
@@ -631,7 +743,7 @@ uninstall: _uninstall
        @echo " + directories, and logs, run the following  +"
        @echo " + command:                                  +"
        @echo " +                                           +"
-       @echo " +            $(MAKE) uninstall-all             +"  
+       @echo " +            $(mK) uninstall-all            +"  
        @echo " +-------------------------------------------+"  
 
 uninstall-all: _uninstall
@@ -642,14 +754,31 @@ uninstall-all: _uninstall
        rm -rf $(DESTDIR)$(ASTETCDIR)
        rm -rf $(DESTDIR)$(ASTLOGDIR)
 
+menuconfig: menuselect
+
+gmenuconfig: gmenuselect
+
 menuselect: menuselect/menuselect menuselect-tree
-       -@menuselect/menuselect $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts && echo "menuselect changes saved!" || echo "menuselect changes NOT saved!"
+       -@menuselect/menuselect $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
+
+gmenuselect: menuselect/gmenuselect menuselect-tree
+       -@menuselect/gmenuselect $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts && (echo "menuselect changes saved!"; rm -f channels/h323/Makefile.ast main/asterisk) || echo "menuselect changes NOT saved!"
+
+menuselect/menuselect: menuselect/makeopts
+       echo "doing menuselect with $(HOST_CC)"
+       @CC="$(HOST_CC)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
 
-menuselect/menuselect: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
-       @PARENTSRC="$(ASTTOPDIR)" $(MAKE) -C menuselect CC="$(HOST_CC)"
+menuselect/gmenuselect: menuselect/makeopts
+       @CC="$(HOST_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect gmenuselect CONFIGURE_SILENT="--silent"
 
-menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml sounds/sounds.xml build_tools/embed_modules.xml
+menuselect/makeopts:
+       @CC="$(HOST_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" CFLAGS="" $(MAKE) -C menuselect makeopts CONFIGURE_SILENT="--silent"
+
+menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml sounds/sounds.xml build_tools/embed_modules.xml configure
        @echo "Generating input for menuselect ..."
        @build_tools/prep_moduledeps > $@
 
-.PHONY: menuselect main sounds clean clean-depend dist-clean distclean all prereqs depend cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEAN_DEPEND) $(SUBDIRS_DEPEND) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS)
+asterisk.pdf:
+       $(MAKE) -C doc/tex asterisk.pdf
+
+.PHONY: menuselect main sounds clean dist-clean distclean all prereqs cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_DIST_CLEAN) $(SUBDIRS_CLEAN) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS) menuselect.makeopts