install_prereq: Add SUSE.
[asterisk/asterisk.git] / Makefile
index 80845d5..54368f7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -104,8 +104,11 @@ export PATCH
 export SED
 export NM
 
-# makeopts is required unless the goal is clean or distclean
-ifeq ($(findstring clean,$(MAKECMDGOALS)),)
+# makeopts is required unless the goal is just {dist{-}}clean
+ifeq ($(MAKECMDGOALS),clean)
+else ifeq ($(MAKECMDGOALS),distclean)
+else ifeq ($(MAKECMDGOALS),dist-clean)
+else
 include makeopts
 endif
 
@@ -124,6 +127,9 @@ _ASTLDFLAGS+=$(LDOPTS)
 # libxml2 cflags
 _ASTCFLAGS+=$(LIBXML2_INCLUDE)
 
+# BIND_8_COMPAT
+_ASTCFLAGS+=$(BIND8_CFLAGS)
+
 #Uncomment this to see all build commands instead of 'quiet' output
 #NOISY_BUILD=yes
 
@@ -206,10 +212,14 @@ ifeq ($(AST_DEVMODE),yes)
   ifeq ($(AST_DEVMODE_STRICT),yes)
     _ASTCFLAGS+=-Wshadow
   endif
-  ADDL_TARGETS+=validate-docs
+  ifneq ($(DISABLE_XMLDOC),yes)
+    ADDL_TARGETS+=validate-docs
+  endif
 endif
 
-ifneq ($(findstring BSD,$(OSARCH)),)
+ifeq ($(OSARCH),NetBSD)
+  _ASTCFLAGS+=-isystem /usr/pkg/include
+else ifneq ($(findstring BSD,$(OSARCH)),)
   _ASTCFLAGS+=-isystem /usr/local/include
 endif
 
@@ -220,7 +230,7 @@ ifeq ($(OSARCH),FreeBSD)
 endif
 
 ifeq ($(OSARCH),NetBSD)
-  _ASTCFLAGS+=-pthread -I/usr/pkg/include
+  _ASTCFLAGS+=-pthread -D__LIBPTHREAD_SOURCE__ -I/usr/pkg/include
 endif
 
 ifeq ($(OSARCH),OpenBSD)
@@ -231,7 +241,9 @@ ifeq ($(OSARCH),SunOS)
   _ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include -D_XPG4_2 -D__EXTENSIONS__
 endif
 
-ifneq ($(GREP),)
+ifeq ($(GREP),)
+else ifeq ($(GREP),:)
+else
   ASTERISKVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) GIT=$(GIT) build_tools/make_version .)
 endif
 ifneq ($(AWK),)
@@ -244,6 +256,14 @@ ifneq ($(wildcard .svn),)
   ASTERISKVERSIONNUM:=999999
 endif
 
+ifneq ($(DISABLE_XMLDOC),yes)
+  CORE_XMLDOC=doc/core-en_US.xml
+  FULL_XMLDOC=doc/full-en_US.xml
+else
+  CORE_XMLDOC=
+  FULL_XMLDOC=
+endif
+
 _ASTCFLAGS+=$(OPTIONS)
 
 MOD_SUBDIRS:=third-party channels pbx apps codecs formats cdr cel bridges funcs tests main res addons $(LOCAL_MOD_SUBDIRS)
@@ -253,9 +273,6 @@ SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)
 SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean)
 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)
-MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs)
 MOD_SUBDIRS_MENUSELECT_TREE:=$(MOD_SUBDIRS:%=%-menuselect-tree)
 
 ifneq ($(findstring darwin,$(OSARCH)),)
@@ -269,7 +286,9 @@ else
 # These are used for all but Darwin
   SOLINK=-shared
   DYLINK=$(SOLINK)
-  ifneq ($(findstring BSD,$(OSARCH)),)
+  ifeq ($(OSARCH),NetBSD)
+    _ASTLDFLAGS+=-L/usr/pkg/lib
+  else ifneq ($(findstring BSD,$(OSARCH)),)
     _ASTLDFLAGS+=-L/usr/local/lib
   endif
 endif
@@ -327,9 +346,9 @@ full: _full
        @echo " +-------------------------------------------+"
 
 
-_all: makeopts $(SUBDIRS) doc/core-en_US.xml $(ADDL_TARGETS)
+_all: makeopts $(SUBDIRS) $(CORE_XMLDOC) $(ADDL_TARGETS)
 
-_full: makeopts $(SUBDIRS) doc/full-en_US.xml $(ADDL_TARGETS)
+_full: makeopts $(SUBDIRS) $(FULL_XMLDOC) $(ADDL_TARGETS)
 
 makeopts: configure
        @echo "****"
@@ -344,41 +363,14 @@ ifeq ($(filter %.menuselect,$(MAKECMDGOALS)),)
        menuselect/menuselect --check-deps $@ $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS)
 endif
 
-$(MOD_SUBDIRS_EMBED_LDSCRIPT):
-       +@echo "EMBED_LDSCRIPTS+="`$(SILENTMAKE) -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules
-
-$(MOD_SUBDIRS_EMBED_LDFLAGS):
-       +@echo "EMBED_LDFLAGS+="`$(SILENTMAKE) -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules
-
-$(MOD_SUBDIRS_EMBED_LIBS):
-       +@echo "EMBED_LIBS+="`$(SILENTMAKE) -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules
-
 $(MOD_SUBDIRS_MENUSELECT_TREE):
        +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) moduleinfo
        +@$(SUBMAKE) -C $(@:-menuselect-tree=) SUBDIR=$(@:-menuselect-tree=) makeopts
 
-makeopts.embed_rules: menuselect.makeopts
-       @echo "Generating embedded module rules ..."
-       @rm -f $@
-       +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LDSCRIPT)
-       +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LDFLAGS)
-       +@$(SUBMAKE) $(MOD_SUBDIRS_EMBED_LIBS)
-
-$(SUBDIRS): makeopts .lastclean main/version.c include/asterisk/build.h include/asterisk/buildopts.h defaults.h makeopts.embed_rules
+$(SUBDIRS): makeopts .lastclean main/version.c include/asterisk/build.h include/asterisk/buildopts.h defaults.h
 
 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
-  ifeq ($(shell grep ^MENUSELECT_EMBED=$$ menuselect.makeopts 2>/dev/null),)
-    # 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.
-    # If MENUSELECT_EMBED is empty, we don't need this and allow 'main' to be
-    # be built with only third_party first.
-main: $(filter-out main,$(MOD_SUBDIRS))
-  else
 main: third-party
-  endif
 else
     # Windows: we need to build main (i.e. the asterisk dll) first,
     # followed by res, followed by the other directories, because
@@ -443,7 +435,6 @@ distclean: $(SUBDIRS_DIST_CLEAN) _clean
        @$(MAKE) -C menuselect dist-clean
        @$(MAKE) -C sounds dist-clean
        rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps
-       rm -f makeopts.embed_rules
        rm -f config.log config.status config.cache
        rm -rf autom4te.cache
        rm -f include/asterisk/autoconfig.h
@@ -452,7 +443,7 @@ distclean: $(SUBDIRS_DIST_CLEAN) _clean
        rm -f doc/asterisk-ng-doxygen
        rm -f build_tools/menuselect-deps
 
-datafiles: _all doc/core-en_US.xml
+datafiles: _all $(CORE_XMLDOC)
        CFLAGS="$(_ASTCFLAGS) $(ASTCFLAGS)" build_tools/mkpkgconfig "$(DESTDIR)$(libdir)/pkgconfig";
 
 #      # Recursively install contents of the static-http directory, in case
@@ -464,8 +455,10 @@ datafiles: _all doc/core-en_US.xml
                        $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/$$x" ; \
                fi \
        done
+ifneq ($(DISABLE_XMLDOC),yes)
        $(INSTALL) -m 644 doc/core-en_US.xml "$(DESTDIR)$(ASTDATADIR)/static-http";
        $(INSTALL) -m 644 doc/appdocsxml.xslt "$(DESTDIR)$(ASTDATADIR)/static-http";
+endif
        if [ -d doc/tex/asterisk ] ; then \
                $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \
                for n in doc/tex/asterisk/* ; do \
@@ -480,7 +473,9 @@ datafiles: _all doc/core-en_US.xml
                $(INSTALL) -m 644 $$x "$(DESTDIR)$(ASTDATADIR)/rest-api" ; \
        done
 
-ifneq ($(GREP),)
+ifeq ($(GREP),)
+else ifeq ($(GREP),:)
+else
   XML_core_en_US = $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
 endif
 
@@ -499,7 +494,9 @@ doc/core-en_US.xml: makeopts .lastclean $(XML_core_en_US)
        @echo
        @echo "</docs>" >> $@
 
-ifneq ($(GREP),)
+ifeq ($(GREP),)
+else ifeq ($(GREP),:)
+else
   XML_full_en_US = $(foreach dir,$(MOD_SUBDIRS),$(shell $(GREP) -l "language=\"en_US\"" $(dir)/*.c $(dir)/*.cc 2>/dev/null))
 endif
 
@@ -594,9 +591,11 @@ bininstall: _all installdirs $(SUBDIRS_INSTALL) main-bininstall
                for h in $(OLDHEADERS); do rm -f "$(DESTDIR)$(ASTHEADERDIR)/$$h"; done \
        fi
 
+ifneq ($(DISABLE_XMLDOC),yes)
        $(INSTALL) -m 644 doc/core-*.xml "$(DESTDIR)$(ASTDATADIR)/documentation"
        $(INSTALL) -m 644 doc/appdocsxml.xslt "$(DESTDIR)$(ASTDATADIR)/documentation"
        $(INSTALL) -m 644 doc/appdocsxml.dtd "$(DESTDIR)$(ASTDATADIR)/documentation"
+endif
        $(INSTALL) -m 644 doc/asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8"
        $(INSTALL) -m 644 doc/astdb*.8 "$(DESTDIR)$(ASTMANDIR)/man8"
        $(INSTALL) -m 644 contrib/scripts/astgenkey.8 "$(DESTDIR)$(ASTMANDIR)/man8"
@@ -615,7 +614,12 @@ $(SUBDIRS_INSTALL):
 
 NEWMODS:=$(foreach d,$(MOD_SUBDIRS),$(notdir $(wildcard $(d)/*.so)))
 OLDMODS=$(filter-out $(NEWMODS) $(notdir $(DESTDIR)$(ASTMODDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTMODDIR)/*.so)))
-BADMODS=$(strip $(filter-out $(shell ./build_tools/list_valid_installed_externals),$(OLDMODS)))
+ifneq ($(BASH),:)
+       FILMODS=$(filter-out $(shell ./build_tools/list_valid_installed_externals),$(OLDMODS))
+else
+       FILMODS=$(OLDMODS)
+endif
+BADMODS=$(strip $(FILMODS))
 
 oldmodcheck:
        @if [ -n "$(BADMODS)" ]; then \
@@ -636,21 +640,80 @@ oldmodcheck:
        fi
 
 ld-cache-update:
-ifneq ($(LDCONFIG),)
-       @if [ $${EUID} -eq 0 ] ; then \
-               $(LDCONFIG) "$(DESTDIR)$(ASTLIBDIR)/" ; \
+ifeq ($(LDCONFIG),)
+else ifeq ($(LDCONFIG),:)
+else
+ifeq ($(DESTDIR),)  # DESTDIR means binary archive creation; ldconfig should be run on postinst
+       @if [ $$(id -u) -eq 0 ] ; then \
+               $(LDCONFIG) "$(ASTLIBDIR)/" ; \
        else \
                echo " WARNING WARNING WARNING" ;\
                echo "" ;\
                echo " You cannot rebuild the system linker cache unless you are root. " ;\
-               echo " You MUST do one of the follwing..." ;\
+               echo " You MUST do one of the following..." ;\
                echo "  * Re-run 'make install' as root. " ;\
-               echo "  * Run 'ldconfig $(DESTDIR)$(ASTLIBDIR)' as root. " ;\
-               echo "  * Run asterisk with 'LD_LIBRARY_PATH=$(DESTDIR)$(ASTLIBDIR) asterisk' " ;\
+               echo "  * Run 'ldconfig $(ASTLIBDIR)' as root. " ;\
+               echo "  * Run asterisk with 'LD_LIBRARY_PATH=$(ASTLIBDIR) asterisk' " ;\
                echo "" ;\
                echo " WARNING WARNING WARNING" ;\
        fi
 endif
+endif
+
+export _oldlibdir =
+export _oldmoddir =
+ifeq ($(findstring 64,$(HOST_CPU)),64)
+    # Strip any trailing '/' so the dir and notdir functions work correctly
+    _current_libdir = $(patsubst %/,%,$(DESTDIR)$(ASTLIBDIR))
+
+    # Only process if the paths end in lib64 or lib.
+    # If we're installing to lib64, check lib for orphans.
+    # If we're installing to lib, check lib64 for orphans.
+    # Otherwise, leave _oldlibdir empty.
+    ifeq ($(notdir $(_current_libdir)),lib64)
+        _oldlibdir = $(dir $(_current_libdir))lib
+    else ifeq ($(notdir $(_current_libdir)),lib)
+        _oldlibdir = $(dir $(_current_libdir))lib64
+    endif
+
+    # Strip any trailing '/' so the dir and notdir functions work correctly
+    _current_moddir = $(patsubst %/,%,$(DESTDIR)$(ASTMODDIR))
+
+    # Only process if the paths contain /lib64/ or /lib/.
+    # If we're installing to lib64, check lib for orphans.
+    # If we're installing to lib, check lib64 for orphans.
+    # Otherwise, leave _oldmoddir empty.
+    ifeq ($(findstring /lib64/,$(_current_moddir)),/lib64/)
+        _oldmoddir = $(subst /lib64/,/lib/,$(_current_moddir))
+    else ifeq ($(findstring /lib/,$(_current_moddir)),/lib/)
+        _oldmoddir = $(subst /lib/,/lib64/,$(_current_moddir))
+    endif
+endif
+
+check-old-libdir:
+       @test -n "$(_oldlibdir)" -a -d "$(_oldlibdir)" || exit 0 ;\
+       oldfiles=`find "$(_oldlibdir)" -name libasterisk* -print -quit -o \( -path *asterisk/modules/* -a -name *.so \) -print -quit 2>/dev/null` ;\
+       if [ "x$$oldfiles" != "x" ] ; then \
+               echo " WARNING WARNING WARNING" ;\
+               echo "" ;\
+               echo " Installation is to: " ;\
+               echo "   $(DESTDIR)$(ASTLIBDIR)" ;\
+               echo " but there are asterisk shared libraries in: " ;\
+               echo "   $(_oldlibdir)" ;\
+               echo " or" ;\
+               echo "   $(_oldlibdir)/asterisk/modules" ;\
+               echo "" ;\
+               echo " It is unlikely that asterisk will start." ;\
+               echo "" ;\
+               echo " You should do one of the following..." ;\
+               echo "  * Run 'make uninstall' to remove the incorrect libraries" ;\
+               echo "    then run 'make install' again." ;\
+               echo "  * Manually remove the libraries from" ;\
+               echo "   $(_oldlibdir)" ;\
+               echo "   and run 'ldconfig' to rebuild the linker cache." ;\
+               echo "" ;\
+               echo " WARNING WARNING WARNING" ;\
+       fi
 
 badshell:
 ifneq ($(filter ~%,$(DESTDIR)),)
@@ -691,6 +754,7 @@ install: badshell bininstall datafiles
        @echo " +-------------------------------------------+"
        @$(MAKE) -s oldmodcheck
        @$(MAKE) -s ld-cache-update
+       @$(MAKE) -s check-old-libdir
 
 isntall: install
 
@@ -877,6 +941,14 @@ config:
                if [ -z "$(DESTDIR)" ] ; then \
                        /sbin/chkconfig --add asterisk ; \
                fi ; \
+       elif [ -f /etc/os-release ] && [ "opensuse" = "$(shell . /etc/os-release && echo $$ID)" ] ; then \
+               ./build_tools/install_subst contrib/init.d/rc.suse.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
+               if [ ! -f /etc/sysconfig/asterisk ] ; then \
+                       $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
+               fi ; \
+               if [ -z "$(DESTDIR)" ] ; then \
+                       /sbin/chkconfig --add asterisk ; \
+               fi ; \
        elif [ -f /etc/arch-release -o -f /etc/arch-release ] ; then \
                ./build_tools/install_subst contrib/init.d/rc.archlinux.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
        elif [ -d "$(DESTDIR)/Library/LaunchDaemons" ]; then \
@@ -911,6 +983,7 @@ main-binuninstall:
 
 _uninstall: $(SUBDIRS_UNINSTALL) main-binuninstall
        rm -f "$(DESTDIR)$(ASTMODDIR)/"*
+       test -n "$(_oldmoddir)" -a -d "$(_oldmoddir)" && rm -f "$(_oldmoddir)/"* || :
        rm -f "$(DESTDIR)$(ASTSBINDIR)/astgenkey"
        rm -f "$(DESTDIR)$(ASTSBINDIR)/autosupport"
        rm -rf "$(DESTDIR)$(ASTHEADERDIR)"
@@ -923,8 +996,10 @@ ifeq ($(HAVE_DAHDI),1)
        rm -f $(DESTDIR)$(DAHDI_UDEV_HOOK_DIR)/40-asterisk
 endif
        $(MAKE) -C sounds uninstall
-ifneq ($(LDCONFIG),)
-       $(LDCONFIG) || :
+ifeq ($(LDCONFIG),)
+else ifeq ($(LDCONFIG),:)
+else
+       $(LDCONFIG) "$(ASTLIBDIR)/" || :
 endif
 
 uninstall: _uninstall
@@ -943,6 +1018,7 @@ uninstall: _uninstall
 
 uninstall-all: _uninstall
        rm -rf "$(DESTDIR)$(ASTMODDIR)"
+       test -n "$(_oldmoddir)" -a -d "$(_oldmoddir)" && rm -rf "$(_oldmoddir)" || :
        rm -rf "$(DESTDIR)$(ASTVARLIBDIR)"
        rm -rf "$(DESTDIR)$(ASTDATADIR)"
        rm -rf "$(DESTDIR)$(ASTSPOOLDIR)"
@@ -999,7 +1075,7 @@ menuselect/nmenuselect: menuselect/makeopts .lastclean
 menuselect/makeopts: makeopts .lastclean
        +$(MAKE_MENUSELECT) makeopts
 
-menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc) $(wildcard $(dir)/*.xml)) build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml build_tools/embed_modules.xml utils/utils.xml agi/agi.xml configure makeopts
+menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc) $(wildcard $(dir)/*.xml)) build_tools/cflags.xml build_tools/cflags-devmode.xml sounds/sounds.xml utils/utils.xml agi/agi.xml configure makeopts
        @echo "Generating input for menuselect ..."
        @echo "<?xml version=\"1.0\"?>" > $@
        @echo >> $@
@@ -1012,7 +1088,6 @@ menuselect-tree: $(foreach dir,$(filter-out main,$(MOD_SUBDIRS)),$(wildcard $(di
        fi
        @cat utils/utils.xml >> $@
        @cat agi/agi.xml >> $@
-       @cat build_tools/embed_modules.xml >> $@
        @cat sounds/sounds.xml >> $@
        @echo "</menu>" >> $@
 
@@ -1044,11 +1119,9 @@ check-alembic: makeopts
 .PHONY: _all
 .PHONY: full
 .PHONY: _full
-.PHONY: prereqs
 .PHONY: uninstall
 .PHONY: _uninstall
 .PHONY: uninstall-all
-.PHONY: dont-optimize
 .PHONY: badshell
 .PHONY: installdirs
 .PHONY: validate-docs
@@ -1057,14 +1130,14 @@ check-alembic: makeopts
 .PHONY: basic-pbx
 .PHONY: check-alembic
 .PHONY: ld-cache-update
+.PHONY: check-old-libdir
 .PHONY: $(SUBDIRS_INSTALL)
 .PHONY: $(SUBDIRS_DIST_CLEAN)
 .PHONY: $(SUBDIRS_CLEAN)
 .PHONY: $(SUBDIRS_UNINSTALL)
 .PHONY: $(SUBDIRS)
-.PHONY: $(MOD_SUBDIRS_EMBED_LDSCRIPT)
-.PHONY: $(MOD_SUBDIRS_EMBED_LDFLAGS)
-.PHONY: $(MOD_SUBDIRS_EMBED_LIBS)
 
 FORCE:
 
+# This only stops targets within the root Makefile from building in parallel.
+.NOTPARALLEL: