Add a new API call for creating detached threads. Then, go replace all of the
[asterisk/asterisk.git] / Makefile
index 7ebf890..aa7de5a 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)
+# AST_LIBS - libraries to build binaries XXX
 # 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
 #
-
-.EXPORT_ALL_VARIABLES:
-
-include makeopts
+# 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 OSARCH
+export CURSES_DIR
+export NCURSES_DIR
+export TERMCAP_DIR
+export TINFO_DIR
+export GTK2_LIB
+export GTK2_INCLUDE
+
+# 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
 
 #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
@@ -74,7 +124,9 @@ else
   ASTVARLIBDIR=$(localstatedir)/lib/asterisk
 endif
 endif
-ASTDATADIR?=$(ASTVARLIBDIR)
+ifeq ($(ASTDATADIR),)
+  ASTDATADIR:=$(ASTVARLIBDIR)
+endif
 
 # Asterisk.conf is located in ASTETCDIR or by using the -C flag
 # when starting Asterisk
@@ -87,8 +139,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 +151,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 +187,17 @@ ifeq ($(OSARCH),linux-gnu)
   endif
 endif
 
-ID=id
-
-ifeq ($(OSARCH),SunOS)
-  M4=/usr/local/bin/m4
-  ID=/usr/xpg4/bin/id
-endif
-
 ASTCFLAGS+=-pipe -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
 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,7 +209,8 @@ 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
@@ -183,7 +230,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
@@ -200,10 +247,6 @@ 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_UNINSTALL:=$(SUBDIRS:%=%-uninstall)
 MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript)
 MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags)
@@ -232,18 +275,20 @@ else
   HAVEDOT=no
 endif
 
-all: cleantest $(SUBDIRS)
+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 " +               $(MAKE) 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
 
@@ -266,7 +311,7 @@ makeopts.embed_rules: menuselect.makeopts
        @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS)
        @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS)
 
-$(SUBDIRS): depend makeopts.embed_rules
+$(SUBDIRS): include/asterisk/version.h include/asterisk/build.h include/asterisk/buildopts.h defaults.h 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
@@ -275,10 +320,10 @@ $(SUBDIRS): depend makeopts.embed_rules
 main: $(filter-out main,$(MOD_SUBDIRS))
 
 $(MOD_SUBDIRS):
-       @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all
+       @ASTCFLAGS="$(MOD_SUBDIR_CFLAGS) $(ASTCFLAGS)" ASTLDFLAGS="$(ASTLDFLAGS)" AST_LIBS="$(AST_LIBS)" $(MAKE) --no-print-directory --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)" AUDIO_LIBS="$(AUDIO_LIBS)" $(MAKE) --no-print-directory --no-builtin-rules -C $@ SUBDIR=$@ all
 
 defaults.h: makeopts
        @build_tools/make_defaults_h > $@.tmp
@@ -301,20 +346,22 @@ 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
 
-clean-depend: $(SUBDIRS_CLEAN_DEPEND)
-
-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
 
@@ -330,7 +377,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 +403,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 +410,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 +427,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 +448,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 +476,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
@@ -455,7 +503,7 @@ install: all datafiles bininstall $(SUBDIRS_INSTALL)
        @echo " +-------------------------------------------+"
        @$(MAKE) -s oldmodcheck
 
-upgrade: all bininstall
+upgrade: bininstall
 
 adsi:
        mkdir -p $(DESTDIR)$(ASTETCDIR)
@@ -494,27 +542,22 @@ samples: adsi
                echo "astrundir => $(ASTVARRUNDIR)" ; \
                echo "astlogdir => $(ASTLOGDIR)" ; \
                echo "" ; \
+               echo ";[options]" ; \
+               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 "; 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 )
@@ -586,14 +629,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
 
@@ -603,8 +638,7 @@ sounds:
 
 cleantest:
        @if ! cmp -s .cleancount .lastclean ; then \
-               $(MAKE) clean; cp -f .cleancount .lastclean;\
-               $(MAKE) defaults.h;\
+               $(MAKE) clean;\
        fi
 
 $(SUBDIRS_UNINSTALL):
@@ -642,14 +676,44 @@ 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: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
-       @CFLAGS="-include $(ASTTOPDIR)/include/asterisk/autoconfig.h -I$(ASTTOPDIR)/include" PARENTSRC="$(ASTTOPDIR)" $(MAKE) -C menuselect CC="$(HOST_CC)"
+       @CC="$(HOST_CC)" LD="" AR="" RANLIB="" $(MAKE) -C menuselect CONFIGURE_SILENT="--silent"
+
+menuselect/gmenuselect: makeopts menuselect/menuselect.c menuselect/menuselect_gtk.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts
+       @CC="$(HOST_CC)" CXX="$(CXX)" LD="" AR="" RANLIB="" $(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
        @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: doc/asterisk.pdf
+
+doc/asterisk.pdf: $(wildcard doc/*.tex)
+ifeq ($(findstring rubber,$(RUBBER)),)
+       @echo "**********************************************"
+       @echo "** You must install the \"rubber\" tool      ***"
+       @echo "** to generate the Asterisk reference PDF. ***"
+       @echo "**********************************************"
+else
+       @echo "**********************************************"
+       @echo "** The Asterisk reference PDF will now be  ***"
+       @echo "** generated.  When complete, it will be   ***"
+       @echo "** located at doc/asterisk.pdf.            ***"  
+       @echo "**********************************************"
+       @cp doc/asterisk.tex doc/asterisk.tex.orig
+       @sed -i -e 's/ASTERISKVERSION/$(ASTERISKVERSION)/' doc/asterisk.tex
+       @cd doc && $(RUBBER) --pdf asterisk.tex
+       @mv doc/asterisk.tex.orig doc/asterisk.tex
+endif
+
+.PHONY: menuselect main sounds clean dist-clean distclean all prereqs cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS) menuselect.makeopts