diff --git a/Makefile b/Makefile
index c9229574889d565892caafe811f8337ca5fdab8c..2457ea8acb29b475d3e46c758ed86562633bc29d 100755
--- a/Makefile
+++ b/Makefile
@@ -27,8 +27,15 @@ PROC=k8
 OPTIONS+=-m64
 endif
 ifeq ($(PROC),sparc64)
+#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
+#This works for even old (2.96) versions of gcc and provides a small boost either way.
+#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
+#So we go lowest common available by gcc and go a step down, still a step up from
+#the default as we now have a better instruction set to work with. - Belgarath
 PROC=ultrasparc
-CFLAGS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
+OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
+OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
+OPTIONS+=-fomit-frame-pointer
 endif
 
 endif
@@ -55,7 +62,7 @@ PWD=$(shell pwd)
 #K6OPT  = -DK6OPT
 
 #Tell gcc to optimize the asterisk's code
-OPTIMIZE=-O6
+OPTIMIZE+=-O6
 
 #Include debug symbols in the executables (-g) and profiling info (-pg)
 DEBUG=-g #-pg
diff --git a/cdr/Makefile b/cdr/Makefile
index d2ba09cac80bbc207a574debf2070432a2bb6e7c..5430f5c5fb6909632187aaecb55820b84f87741c 100755
--- a/cdr/Makefile
+++ b/cdr/Makefile
@@ -17,11 +17,23 @@ MODS=cdr_csv.so cdr_manager.so
 
 CFLAGS+=-fPIC
 
+PROC=$(shell uname -m)
 OSARCH=$(shell uname -s)
+
 ifeq (${OSARCH},FreeBSD)
 SOLINK+=-L/usr/local/lib
 endif
 
+#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
+#This works for even old (2.96) versions of gcc and provides a small boost either way.
+#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
+#So we go lowest common available by gcc and go a step down, still a step up from
+#the default as we now have a better instruction set to work with. - Belgarath
+ifeq ($(PROC),sparc64)
+PROC=ultrasparc
+CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
+endif
+
 #
 # unixODBC stuff...
 #
diff --git a/channels/Makefile b/channels/Makefile
index d9b6709993bc46687f9c9be3efbdffde6432b943..f73ce058c938db708f12905d4b527abaf8cf55c7 100755
--- a/channels/Makefile
+++ b/channels/Makefile
@@ -7,11 +7,15 @@
 #
 # Mark Spencer <markster@linux-support.net>
 #
+# Edited By Belgarath <> Aug 28 2004
+# Added bare bones ultrasparc-linux support.
+#
 # This program is free software, distributed under the terms of
 # the GNU General Public License
 #
 
 OSARCH=$(shell uname -s)
+PROC=$(shell uname -m)
 
 USE_MYSQL_FRIENDS=0
 USE_SIP_MYSQL_FRIENDS=0
@@ -45,6 +49,12 @@ MYSQLLIB=-L/usr/lib/mysql -lmysqlclient
 PTLIB=-lpt_linux_x86_r
 H323LIB=-lh323_linux_x86_r
 CHANH323LIB=-ldl
+
+ifeq ($(PROC),sparc64)
+PROC=ultrasparc
+CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
+endif
+
 endif
 ifeq (${OSARCH},FreeBSD)
 PTLIB=-lpt_FreeBSD_x86_r
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 86675b791d8fcd41cf11ad30713762b4a5d0e384..59dbf32800b7824d5643dba2be56e19faf2c6522 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -3685,21 +3685,19 @@ static void initreqprep(struct sip_request *req, struct sip_pvt *p, char *cmd, c
 	} else {
 		snprintf(invite, sizeof(invite), "sip:%s", p->tohost);
 	}
+	if (!ast_strlen_zero(p->extraparams)) {
+		strncat(invite, ";", sizeof(invite) - strlen(invite));
+		strncat(invite, p->extraparams, sizeof(invite) - strlen(invite));
+	}
 	strncpy(p->uri, invite, sizeof(p->uri) - 1);
 	/* If there is a VXML URL append it to the SIP URL */
 	if (vxml_url)
 	{
-		if (strlen(p->extraparams))
-			snprintf(to, sizeof(to), "<%s;%s>;%s", invite, p->extraparams, vxml_url);
-		else
-			snprintf(to, sizeof(to), "<%s>;%s", invite, vxml_url);
+		snprintf(to, sizeof(to), "<%s>;%s", invite, vxml_url);
 	}
 	else
 	{
-		if (strlen(p->extraparams))
-			snprintf(to, sizeof(to), "<%s;%s>", invite, p->extraparams);
-		else
-			snprintf(to, sizeof(to), "<%s>", invite);
+		snprintf(to, sizeof(to), "<%s>", invite);
 	}
 	memset(req, 0, sizeof(struct sip_request));
 	init_req(req, cmd, invite);
diff --git a/codecs/gsm/Makefile b/codecs/gsm/Makefile
index 572f61e128a35fe4cb8e923cba8bfd55c86ccab5..a21bd7e52f7c944c64d3f1f8697442bc8672fc28 100755
--- a/codecs/gsm/Makefile
+++ b/codecs/gsm/Makefile
@@ -49,6 +49,15 @@ endif
 endif
 endif
 
+#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
+#This works for even old (2.96) versions of gcc and provides a small boost either way.
+#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
+#So we go lowest common available by gcc and go a step down, still a step up from
+#the default as we now have a better instruction set to work with. - Belgarath
+ifeq (${PROC},ultrasparc)
+OPTIMIZE+=-mcpu=v8 -mtune=$(PROC) -O3 -fomit-frame-pointer
+endif
+
 PG =
 #PG = -g -pg
 ######### Profiling flags.  If you don't know what that means, leave it blank.
diff --git a/codecs/lpc10/Makefile b/codecs/lpc10/Makefile
index f747e64a5b0e3ce910de19b3c168e1378d3c1f64..23d6886e840463be2fc3d099a1a5e189948e71de 100755
--- a/codecs/lpc10/Makefile
+++ b/codecs/lpc10/Makefile
@@ -31,8 +31,13 @@ ifneq ($(findstring BSD,${OSARCH}),BSD)
 ifneq ($(PROC),ppc)
 ifneq ($(PROC),x86_64)
 ifneq ($(PROC),alpha)
+#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
+#This works for even old (2.96) versions of gcc and provides a small boost either way.
+#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn.t support it.
+#So we go lowest common available by gcc and go a step down, still a step up from
+#the default as we now have a better instruction set to work with. - Belgarath
 ifeq ($(PROC),ultrasparc)
-        CFLAGS+= -mtune=$(PROC)
+        CFLAGS+= -mtune=$(PROC) -mcpu=v8 -O3 -fomit-frame-pointer
 else
         CFLAGS+= -march=$(PROC)
 endif
diff --git a/db1-ast/Makefile b/db1-ast/Makefile
index 0bb8ea5c5812de7622540ba3dd9be5bf860c2c1e..f8192f795996e99e66486b114eed2a5e3de77f99 100755
--- a/db1-ast/Makefile
+++ b/db1-ast/Makefile
@@ -7,6 +7,12 @@ SOVER=2.1
 else
 SOVER=2
 endif
+#Added support for UltraSparc - Belgarath
+ifeq ($(ARCH),sparc64)
+PROC=ultrasparc
+CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
+endif
+
 LIBDBSO=libdb.so.$(SOVER)
 PROG=	db_dump185
 OBJ1=	hash.o hash_bigkey.o hash_buf.o hash_func.o hash_log2.o hash_page.o \