Index: Makefile
===================================================================
--- Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -26,5 +26,4 @@
 # Expansion of variables
 subdirobjs = $(foreach dir,$(subdirs),$(dir)/$(dir).o)
-CFLAGS += -Wall
 
 all: $(OUTFILE)
Index: conf.c
===================================================================
--- conf.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ conf.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -82,5 +82,5 @@
 	}
 	
-	while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:V" ) ) >= 0 )
+	while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hu:V" ) ) >= 0 )
 	/*     ^^^^ Just to make sure we skip this step from the REHASH handler. */
 	{
@@ -158,11 +158,4 @@
 			return NULL;
 		}
-		else if( opt == 'R' )
-		{
-			/* Backward compatibility; older BitlBees passed this
-			   info using a command-line flag. Allow people to
-			   upgrade from such a version for now. */
-			setenv( "_BITLBEE_RESTART_STATE", optarg, 0 );
-		}
 		else if( opt == 'u' )
 		{
Index: configure
===================================================================
--- configure	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ configure	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -184,5 +184,5 @@
 fi
 
-echo CFLAGS=$CFLAGS >> Makefile.settings
+echo CFLAGS=$CFLAGS $CPPFLAGS >> Makefile.settings
 echo CFLAGS+=-I${srcdir} -I${srcdir}/lib -I${srcdir}/protocols -I. >> Makefile.settings
 
@@ -201,4 +201,8 @@
 
 echo "CC=$CC" >> Makefile.settings;
+if echo $CC | grep -qw gcc; then
+	# Apparently -Wall is gcc-specific?
+	echo CFLAGS+=-Wall >> Makefile.settings
+fi
 
 if [ -z "$LD" ]; then
Index: irc_commands.c
===================================================================
--- irc_commands.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ irc_commands.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -38,5 +38,6 @@
 		   out we don't require it, which will break this feature.)
 		   Try to identify using the given password. */
-		return root_command( irc, send_cmd );
+		root_command( irc, send_cmd );
+		return;
 	}
 	/* Handling in pre-logged-in state, first see if this server is
Index: lib/Makefile
===================================================================
--- lib/Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ lib/Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -15,5 +15,4 @@
 objects = arc.o base64.o $(EVENT_HANDLER) ftutil.o http_client.o ini.o md5.o misc.o oauth.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o
 
-CFLAGS += -Wall
 LFLAGS += -r
 
Index: lib/md5.h
===================================================================
--- lib/md5.h	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ lib/md5.h	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -27,5 +27,9 @@
 #include <sys/types.h>
 #include <gmodule.h>
+#if(__sun)
+#include <inttypes.h>
+#else
 #include <stdint.h>
+#endif
 
 typedef uint8_t md5_byte_t;
Index: lib/oauth.c
===================================================================
--- lib/oauth.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ lib/oauth.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -60,5 +60,5 @@
 	{
 		g_snprintf( (gchar*) key, HMAC_BLOCK_SIZE + 1, "%s&%s",
-		            oi->sp->consumer_secret, oi->token_secret ? : "" );
+		            oi->sp->consumer_secret, oi->token_secret ? oi->token_secret : "" );
 	}
 	
Index: lib/sha1.h
===================================================================
--- lib/sha1.h	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ lib/sha1.h	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -24,5 +24,9 @@
 #define _SHA1_H_
 
+#if(__sun)
+#include <inttypes.h>
+#else
 #include <stdint.h>
+#endif
 #include <gmodule.h>
 
Index: lib/xmltree.c
===================================================================
--- lib/xmltree.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ lib/xmltree.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -215,5 +215,8 @@
 	
 	if( node == NULL )
-		return xt_cleanup( xt, xt->root, depth );
+	{
+		xt_cleanup( xt, xt->root, depth );
+		return;
+	}
 	
 	if( node->flags & XT_SEEN && node == xt->root )
Index: protocols/Makefile
===================================================================
--- protocols/Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -25,5 +25,4 @@
 # Expansion of variables
 subdirobjs := $(join $(subdirs),$(addprefix /,$(subdirobjs)))
-CFLAGS += -Wall
 LFLAGS += -r
 
Index: protocols/jabber/Makefile
===================================================================
--- protocols/jabber/Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/jabber/Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -15,5 +15,4 @@
 objects = conference.o io.o iq.o jabber.o jabber_util.o message.o presence.o s5bytestream.o sasl.o si.o
 
-CFLAGS += -Wall
 LFLAGS += -r
 
Index: protocols/jabber/jabber.c
===================================================================
--- protocols/jabber/jabber.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/jabber/jabber.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -381,5 +381,5 @@
 		if( bud->away_state )
 			imcb_log( ic, "Away state: %s", bud->away_state->full_name );
-		imcb_log( ic, "Status message: %s", bud->away_message ? : "(none)" );
+		imcb_log( ic, "Status message: %s", bud->away_message ? bud->away_message : "(none)" );
 		
 		bud = bud->next;
@@ -395,6 +395,8 @@
 	/* state_txt == NULL -> Not away.
 	   Unknown state -> fall back to the first defined away state. */
-	jd->away_state = state_txt ? jabber_away_state_by_name( state_txt )
-	                 ? : jabber_away_state_list : NULL;
+	if( state_txt == NULL )
+		jd->away_state = NULL;
+	else if( ( jd->away_state = jabber_away_state_by_name( state_txt ) ) == NULL )
+		jd->away_state = jabber_away_state_list;
 	
 	g_free( jd->away_message );
Index: protocols/jabber/message.c
===================================================================
--- protocols/jabber/message.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/jabber/message.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -59,5 +59,6 @@
 			{
 				room = from;
-				from = xt_find_attr( inv, "from" ) ? : from;
+				if( ( from = xt_find_attr( inv, "from" ) ) == NULL )
+					from = room;
 
 				g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Invitation to chatroom %s >>\n", room );
@@ -72,5 +73,5 @@
 			{
 				bud->last_msg = time( NULL );
-				from = bud->ext_jid ? : bud->bare_jid;
+				from = bud->ext_jid ? bud->ext_jid : bud->bare_jid;
 			}
 			else
Index: protocols/msn/Makefile
===================================================================
--- protocols/msn/Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/msn/Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -15,5 +15,4 @@
 objects = msn.o msn_util.o ns.o passport.o sb.o tables.o
 
-CFLAGS += -Wall
 LFLAGS += -r
 
Index: protocols/msn/msn.c
===================================================================
--- protocols/msn/msn.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/msn/msn.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -176,9 +176,8 @@
 	struct msn_data *md = ic->proto_data;
 	
-	if( state )
-		md->away_state = msn_away_state_by_name( state ) ? :
-		                 msn_away_state_list + 1;
-	else
+	if( state == NULL )
 		md->away_state = msn_away_state_list;
+	else if( ( md->away_state = msn_away_state_by_name( state ) ) == NULL )
+		md->away_state = msn_away_state_list + 1;
 	
 	g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, md->away_state->code );
Index: protocols/nogaim.c
===================================================================
--- protocols/nogaim.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/nogaim.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -468,5 +468,5 @@
 	
 	s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.",
-	                     handle, realname_ ?: "" );
+	                     handle, realname_ ? realname_ : "" );
 	
 	g_free( realname_ );
@@ -491,5 +491,5 @@
 	cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL );
 	
-	return imcb_ask_add_cb_no( data );
+	imcb_ask_add_cb_no( data );
 }
 
Index: protocols/nogaim.h
===================================================================
--- protocols/nogaim.h	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/nogaim.h	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -39,5 +39,11 @@
 #define _NOGAIM_H
 
+#if(__sun)
+#include <inttypes.h>
+#else
 #include <stdint.h>
+#endif
+
+#include "lib/events.h"
 
 #include "bitlbee.h"
Index: protocols/oscar/Makefile
===================================================================
--- protocols/oscar/Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/oscar/Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -16,5 +16,4 @@
 objects = admin.o auth.o bos.o buddylist.o chat.o chatnav.o conn.o icq.o im.o info.o misc.o msgcookie.o rxhandlers.o rxqueue.o search.o service.o snac.o ssi.o stats.o tlv.o txqueue.o oscar_util.o oscar.o
 
-CFLAGS += -Wall
 LFLAGS += -r
 
Index: protocols/twitter/Makefile
===================================================================
--- protocols/twitter/Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/twitter/Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -15,5 +15,4 @@
 objects = twitter.o twitter_http.o twitter_lib.o
 
-CFLAGS += -Wall
 LFLAGS += -r
 
Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/twitter/twitter_lib.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -23,5 +23,8 @@
 
 /* For strptime(): */
+#if(__sun)
+#else
 #define _XOPEN_SOURCE
+#endif
 
 #include "twitter_http.h"
Index: protocols/yahoo/Makefile
===================================================================
--- protocols/yahoo/Makefile	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/yahoo/Makefile	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -15,5 +15,5 @@
 objects = yahoo.o crypt.o libyahoo2.o yahoo_fn.o yahoo_httplib.o yahoo_util.o
 
-CFLAGS += -Wall -DSTDC_HEADERS -DHAVE_STRING_H -DHAVE_STRCHR -DHAVE_MEMCPY -DHAVE_GLIB
+CFLAGS += -DSTDC_HEADERS -DHAVE_STRING_H -DHAVE_STRCHR -DHAVE_MEMCPY -DHAVE_GLIB
 LFLAGS += -r
 
Index: protocols/yahoo/libyahoo2.c
===================================================================
--- protocols/yahoo/libyahoo2.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ protocols/yahoo/libyahoo2.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -1859,5 +1859,6 @@
 	}
 	
-	return yahoo_https_auth_init(had);
+	yahoo_https_auth_init(had);
+	return;
 	
 fail:
Index: unix.c
===================================================================
--- unix.c	(revision 289bd2d47ff58f42879ad50ebbc1b193831e4a78)
+++ unix.c	(revision daae10fbfe16bac26f74af91faf253d377f1b166)
@@ -159,10 +159,13 @@
 	{
 		char *fn = ipc_master_save_state();
+		char *env;
+		
+		env = g_strdup_printf( "_BITLBEE_RESTART_STATE=%s", fn );
+		putenv( env );
+		g_free( fn );
+		/* Looks like env should *not* be freed here as putenv
+		   doesn't make a copy. Odd. */
 		
 		chdir( old_cwd );
-		
-		setenv( "_BITLBEE_RESTART_STATE", fn, 1 );
-		g_free( fn );
-		
 		close( global.listen_socket );
 		
