Index: compiler/ast-node-call.bas
===================================================================
--- compiler/ast-node-call.bas	(revision 5406)
+++ compiler/ast-node-call.bas	(working copy)
@@ -215,6 +215,10 @@
 
 	'' ptr..
 	else
+		if( mode = FB_FUNCMODE_CDECL andalso env.target.align16 ) then
+			bytestopop += &h456700
+		end if
+
 		vr = astLoad( p )
 		astDelNode( p )
 		if( ast.doemit ) then
Index: compiler/emit_x86.bas
===================================================================
--- compiler/emit_x86.bas	(revision 5406)
+++ compiler/emit_x86.bas	(working copy)
@@ -921,9 +921,12 @@
 
     hEmitBssHeader( )
 
+'print "emitting bss var " &  *symbGetMangledName( s )
+'print "attrib = " & hex(attrib) & " shared=" & (attrib and FB_SYMBATTRIB_SHARED) > 0
+
     '' allocation modifier
     if( (attrib and FB_SYMBATTRIB_COMMON) = 0 ) then
-      	if( (attrib and FB_SYMBATTRIB_PUBLIC) > 0 ) then
+		if( (attrib and FB_SYMBATTRIB_PUBLIC) > 0) then
        		hPUBLIC( *symbGetMangledName( s ), TRUE )
 		end if
        	alloc = ".lcomm"
@@ -1485,14 +1488,61 @@
 
     dim ostr as string
 
-    if( vreg->value.int > 0 ) then
-    	ostr = "sub esp, " + str( vreg->value.int )
+    if( vreg->value.int >= &h456700 and vreg->value.int < &h456800 ) then
+
+        '' This Mac OSX-specific code prepares the stack alignment before
+        '' function arguments are pushed
+
+        dim tmpreg as integer
+        dim tmpregname as string
+        dim nofreeregs as integer = FALSE
+
+	tmpreg = hFindFreeReg( FB_DATACLASS_INTEGER )
+	if( tmpreg = INVALID ) then
+		nofreeregs = TRUE
+
+                'assembly emitted in this case:
+                'push eax 
+                'lea eax, [esp+4]
+                '...calc aligned esp
+                'push eax
+                'xchg dword ptr [eax-4], eax
+
+                outp "push eax"
+                outp "lea eax, [esp+4]"
+        else
+        	tmpregname = *hGetRegName( FB_DATATYPE_INTEGER, tmpreg )
+                outp "mov " + tmpregname + ", esp"
+	end if
+
+    	'dim align as integer = vreg->value.int
+        dim off as integer
+        off = vreg->value.int - &h456700
+        '' add 4 bytes for pushing esp
+        off = (1024 - (off + 4)) mod 16
+        if( off ) then
+            outp "add esp, " & off
+        end if
+        outp "and esp, 0xfffffff0"
+        if( off ) then
+            outp "sub esp, " & off
+        end if
+        if( nofreeregs ) then
+            outp "push eax"
+            outp "xchg dword ptr [eax-4], eax"
+        else
+            hPUSH tmpregname
+        end if
+        
     else
-    	ostr = "add esp, " + str( -vreg->value.int )
+        if( vreg->value.int > 0 ) then
+        	ostr = "sub esp, " + str( vreg->value.int )
+        else
+        	ostr = "add esp, " + str( -vreg->value.int )
+        end if
+	outp( ostr )
     end if
 
-	outp( ostr )
-
 end sub
 
 '':::::
@@ -1531,7 +1581,10 @@
 	ostr += *symbGetMangledName( label )
 	outp( ostr )
 
-    if( bytestopop <> 0 ) then
+    if( bytestopop >= &h456700 ) then
+    	ostr = "mov esp, [esp+" & (bytestopop - &h456700) & "]"
+    	outp( ostr )
+    elseif( bytestopop > 0 ) then
     	ostr = "add esp, " + str( bytestopop )
     	outp( ostr )
     end if
@@ -1554,7 +1607,10 @@
 	ostr = "call " + src
 	outp( ostr )
 
-    if( bytestopop <> 0 ) then
+    if( bytestopop >= &h456700 ) then
+    	ostr = "mov esp, [esp+" & (bytestopop - &h456700) & "]"
+    	outp( ostr )
+    elseif( bytestopop > 0 ) then
     	ostr = "add esp, " + str( bytestopop )
     	outp( ostr )
     end if
@@ -7015,6 +7071,12 @@
 
 	outEx( ostr )
 
+/'
+	if( section = IR_SECTION_BSS and env.target.objconversion <> NULL ) then
+		outEx( ".globl bss_dummy_" + env.inf.name )
+		outp( ".lcomm bss_dummy_" + env.inf.name + ",0" )
+	end if
+'/
 end sub
 
 '':::::
Index: compiler/fb.bas
===================================================================
--- compiler/fb.bas	(revision 5406)
+++ compiler/fb.bas	(working copy)
@@ -870,7 +870,7 @@
 '':::::
 function fbGetEntryPoint( ) as string static
 
-	function = *env.target.entrypoint
+	function = env.target.entrypoint
 
 end function
 
@@ -1193,8 +1193,6 @@
 		hAddLib( "fb" )
 	end if
 
-	hAddLib( "gcc" )
-
 	fbc.vtbl.getDefaultLibs( dstlist, dsthash )
 
 end sub
Index: compiler/fbc.bas
===================================================================
--- compiler/fbc.bas	(revision 5406)
+++ compiler/fbc.bas	(working copy)
@@ -30,6 +30,8 @@
 #include "bfd.bi"
 #endif
 
+dim env as FBENV
+
 declare sub fbcInit _
 	( _
 	)
@@ -158,6 +160,7 @@
 		( FBC_OPT_VERSION		, @"version"     ), _
 		( FBC_OPT_OUTPUTNAME	, @"x"           ), _
 		( FBC_OPT_MAINMODULE	, @"m"           ), _
+		( FBC_OPT_ENTRY			, @"entry"	 ), _
 		( FBC_OPT_MAPFILE		, @"map"         ), _
 		( FBC_OPT_MAXERRORS		, @"maxerr"      ), _
 		( FBC_OPT_WARNLEVEL		, @"w"           ), _
@@ -270,6 +273,7 @@
 			fbcEnd( 1 )
 		end if
 
+
 		if( fbc.compileonly ) then
 
 		else
@@ -287,10 +291,12 @@
 				end if
 
 			else
+
 				'' only add the default libraries to the LD cmd-line, and not to the
 				'' objects and static libraries, for speed/size reasons
 				getDefaultLibs( )
 
+
 				'' resource files..
 				if( compileResFiles( ) = FALSE ) then
 					delFiles( )
@@ -580,7 +586,42 @@
 
 end function
 
+
 '':::::
+private function convertObjFile _
+	( _
+		byref cmdline as string _
+	) as integer
+
+	static as string path
+	static as integer has_path = FALSE
+	static as integer res
+
+	if( has_path = FALSE ) then
+		path = fbFindBinFile( "objconv" )
+		if( len( path ) = 0 ) then
+			return FALSE
+		end if
+		has_path = TRUE
+	end if
+
+	if( fbc.verbose ) then
+		print "converting to Mach-O: ", path + " " + cmdline
+	end if
+
+	res = exec( path, cmdline )
+
+	if( res <> 0 ) then
+		if( fbc.verbose ) then
+			print "objconv failed: returned error code " & res
+		end if
+	end if
+
+	function = (res = 0)
+end function
+
+
+'':::::
 private function assembleFile_GAS _
 	( _
 		byref cmdline as string _
@@ -622,6 +663,7 @@
 	) as integer
 
 	dim as string ascline
+	dim as string outfile
 
 	function = FALSE
 
@@ -636,16 +678,32 @@
 			ascline = "--32 "
 		end if
 
+		outfile = iof->outf
+
+		if( env.target.objconversion ) then
+			outfile = outfile + "_temp.o"
+		end if
+
 		ascline += QUOTE + iof->asmf + _
 				   (QUOTE + " -o " + QUOTE) + _
-				   iof->outf + (QUOTE) + _
+				   outfile + (QUOTE) + _
                    fbc.extopt.gas
 
     	'' invoke as
 		if( assembleFile_GAS( ascline ) = FALSE ) then
+			safeKill( outfile )
 			exit function
 		end if
 
+		if( env.target.objconversion ) then
+			ascline = "-v0 -f" + *env.target.objconversion + " " + outfile + " " + iof->outf
+			if( convertObjFile( ascline ) = FALSE ) then
+				safeKill( outfile )
+				exit function
+			end if
+			safeKill( outfile )
+		end if
+
     	iof = listGetNext( iof )
     loop
 
@@ -1822,7 +1880,7 @@
 					exit function
 				end if
 
-				fbc.extopt.gas = " " + hReplace( *nxt, ",", " " ) + " "
+				fbc.extopt.gas += " " + hReplace( *nxt, ",", " " ) + " "
 
 				del_cnt += 1
 
@@ -1832,7 +1890,7 @@
 					exit function
 				end if
 
-				fbc.extopt.ld = " " + hReplace( *nxt, ",", " " ) + " "
+				fbc.extopt.ld += " " + hReplace( *nxt, ",", " " ) + " "
 
 				del_cnt += 1
 
@@ -1842,7 +1900,7 @@
 					exit function
 				end if
 
-				fbc.extopt.gcc = " " + hReplace( *nxt, ",", " " ) + " "
+				fbc.extopt.gcc += " " + hReplace( *nxt, ",", " " ) + " "
 
 				del_cnt += 1
 
@@ -1875,6 +1933,17 @@
 				fbSetOption( FB_COMPOPT_EXTRAOPT, value )
 
 				del_cnt += 1
+
+			case FBC_OPT_ENTRY
+				if( nxt = NULL ) then
+					printInvalidOpt( arg )
+					exit function
+				end if
+
+				env.target.entrypoint = *nxt
+
+				del_cnt += 1
+
 			end select
 
 			hDelArgNode( arg )
@@ -2188,6 +2257,7 @@
 			printOption( "-dylib", "Create a shared library" )
 		end if
 	end select
+	printOption( "-entry <name>", "Override the name of the entry function (default: main)" )
 	printOption( "-e", "Add error checking" )
 	printOption( "-ex", "Add error checking with RESUME support" )
 	printOption( "-exx", "Same as above plus array bounds and null-pointer checking" )
@@ -2330,9 +2400,9 @@
 	dim as FBS_LIB ptr libp = listGetHead( @fbc.ld_libpathlist )
 	do while( libp <> NULL )
 		if( right( *libp->name, 1 ) = FB_HOST_PATHDIV ) then
-    		list += " -L " + QUOTE + left( *libp->name, len(*libp->name) - 1 ) + QUOTE
+    		list += " -L" + QUOTE + left( *libp->name, len(*libp->name) - 1 ) + QUOTE
 		else
-    		list += " -L " + QUOTE + *libp->name + QUOTE
+    		list += " -L" + QUOTE + *libp->name + QUOTE
 		end if
     	libp = listGetNext( libp )
     loop
Index: compiler/fbc_cyg.bas
===================================================================
--- compiler/fbc_cyg.bas	(revision 5406)
+++ compiler/fbc_cyg.bas	(working copy)
@@ -436,6 +436,7 @@
 	symbAddLibEx( dstlist, dsthash, libname, TRUE )
 #endmacro
 
+	hAddLib( "gcc" )
 	hAddLib( "cygwin" )
 	hAddLib( "kernel32" )
 	hAddLib( "supc++" )
@@ -500,7 +501,7 @@
 
 	env.target.targetdir = @"cygwin"
 	env.target.define = @"__FB_CYGWIN__"
-	env.target.entrypoint = @"main"
+	env.target.entrypoint = "main"
 	env.target.underprefix = TRUE
 	env.target.constsection = @"rdata"
 	env.target.allowstdcall = TRUE
Index: compiler/fbc_darwin.bas
===================================================================
--- compiler/fbc_darwin.bas	(revision 5406)
+++ compiler/fbc_darwin.bas	(working copy)
@@ -28,13 +28,10 @@
 
 enum GCC_LIB
 	CRT1_O
-	CRTBEGIN_O
-	CRTEND_O
-	CRTI_O
-	CRTN_O
 	GCRT1_O
-	LIBGCC_A
+'	LIBGCC_A
 	LIBSUPC_A
+	OPERATORNEW_O
 	GCC_LIBS
 end enum
 
@@ -117,7 +114,7 @@
 	''
 	if( fbGetOption( FB_COMPOPT_DEBUG ) = FALSE ) then
 		if( fbGetOption( FB_COMPOPT_PROFILE ) = FALSE ) then
-			ldcline += " -s"
+			ldcline += " -x -S"
 		end if
 	end if
 
@@ -127,14 +124,14 @@
 	'' crt init stuff
 	if( fbGetOption( FB_COMPOPT_OUTTYPE ) = FB_OUTTYPE_EXECUTABLE) then
 		if( fbGetOption( FB_COMPOPT_PROFILE ) ) then
-			ldcline += " " + QUOTE + fbGetGccLib( GCRT1_O ) + QUOTE
+			ldcline += " " + QUOTE + fbGetGccLib( GCRT1_O ) + QUOTE + " "
 		else
-			ldcline += " " + QUOTE + fbGetGccLib( CRT1_O ) + QUOTE
+			ldcline += " " + QUOTE + fbGetGccLib( CRT1_O ) + QUOTE + " "
 		end if
 	end if
 
-	ldcline += " " + QUOTE + fbGetGccLib( CRTI_O ) + QUOTE
-	ldcline += " " + QUOTE + fbGetGccLib( CRTBEGIN_O ) + QUOTE + " "
+	'' operator new hack
+	ldcline += QUOTE + fbGetGccLib( OPERATORNEW_O ) + QUOTE + " "
 
 	'' add objects from output list
 	dim as FBC_IOFILE ptr iof = listGetHead( @fbc.inoutlist )
@@ -151,27 +148,16 @@
 	loop
 
 	'' set executable name
-	ldcline += "-o " + QUOTE + fbc.outname + QUOTE
+	ldcline += "-o " + QUOTE + fbc.outname + QUOTE + " "
 
-	'' init lib group
-	ldcline += " -( "
-
 	'' add libraries from cmm-line and found when parsing
 	ldcline += *fbcGetLibList( dllname )
 
 	if( fbGetOption( FB_COMPOPT_NODEFLIBS ) = FALSE ) then
-		'' rtlib initialization and termination (must be included in the group or
-		'' dlopen() will fail because fb_hRtExit() will be undefined)
+		'' rtlib initialization and termination
 		ldcline += QUOTE + fbGetPath( FB_PATH_LIB ) + "fbrt0.o" + QUOTE + " "
 	end if
 
-	'' end lib group
-	ldcline += "-) "
-
-	'' crt end stuff
-	ldcline += QUOTE + fbGetGccLib( CRTEND_O ) + QUOTE
-	ldcline += " " + QUOTE + fbGetGccLib( CRTN_O ) + QUOTE
-
    	'' extra options
    	ldcline += fbc.extopt.ld
 
@@ -221,7 +207,7 @@
 	dim as integer outstr_count, buffer_len, state, label
 	dim as ubyte ptr p
 	dim as string * 4096 chunk
-	dim as string aspath, iconsrc, buffer, outstr()
+	dim as string aspath, objconvpath, iconsrc, icontempobj, buffer, outstr()
 	dim as integer res = any
 
 	function = FALSE
@@ -329,8 +315,14 @@
 	if( len( aspath ) = 0 ) then
 		exit function
 	end if
+	objconvpath = fbFindBinFile( "objconv" )
+	if( len( objconvpath ) = 0 ) then
+		exit function
+	end if
 
-	res = exec( aspath, iconsrc + " -o " + hStripExt( iconsrc ) + ".o" )
+	icontempobj = "temp_" + hStripExt( iconsrc ) + ".o"
+
+	res = exec( aspath, iconsrc + " -o " + icontempobj )
 	if( res <> 0 ) then
 		if( fbc.verbose ) then
 			print "compiling XPM icon resource failed: error code " & res
@@ -341,6 +333,18 @@
 
 	kill( iconsrc )
 
+	res = exec( objconvpath, " -v0 -fmacho " + icontempobj + " " _
+	                         + hStripExt( iconsrc ) + ".o ")
+	if( res <> 0 ) then
+		if( fbc.verbose ) then
+			print "converting XPM icon resource failed: error code " & res
+		end if
+		kill( icontempobj )
+		exit function
+	end if
+
+	kill( icontempobj )
+
 	'' add to obj list
 	dim as string ptr objf = listNewNode( @fbc.objlist )
 	*objf = hStripExt( iconsrc ) + ".o"
@@ -404,6 +408,8 @@
 #endmacro
 
 	hAddLib( "System" )
+	hAddLib( "ncurses" )
+	hAddLib( "gcc_s.1" )
 
 end sub
 
@@ -452,24 +458,24 @@
 	xpmfile = ""
 
 	fbAddGccLib( @"crt1.o", CRT1_O )
-	fbAddGccLib( @"crtbegin.o", CRTBEGIN_O )
-	fbAddGccLib( @"crtend.o", CRTEND_O )
-	fbAddGccLib( @"crti.o", CRTI_O )
-	fbAddGccLib( @"crtn.o", CRTN_O )
 	fbAddGccLib( @"gcrt1.o", GCRT1_O )
-	fbAddGccLib( @"libgcc.a", LIBGCC_A )
+'	fbAddGccLib( @"libgcc.a", LIBGCC_A )
 	fbAddGccLib( @"libsupc++.a", LIBSUPC_A )
+	fbAddGccLib( @"operatornew.o", OPERATORNEW_O )
 
 	env.target.wchar.type = FB_DATATYPE_UINT
 	env.target.wchar.size = FB_INTEGERSIZE
 
 	env.target.targetdir = @"darwin"
 	env.target.define = @"__FB_DARWIN__"
-	env.target.entrypoint = @"main"
-	env.target.underprefix = FALSE
-	env.target.constsection = @"const"
+	env.target.entrypoint = "main"
+	env.target.underprefix = TRUE
+	env.target.constsection = @"rodata"
 	env.target.allowstdcall = FALSE
-	env.target.omitsectiondirective = TRUE
+	env.target.omitsectiondirective = FALSE
+	env.target.align16 = TRUE
+	env.target.objconversion = @"macho"
+	env.target.nojumptables = TRUE
 
 	return TRUE
 
Index: compiler/fbc_dos.bas
===================================================================
--- compiler/fbc_dos.bas	(revision 5406)
+++ compiler/fbc_dos.bas	(working copy)
@@ -259,6 +259,7 @@
 	symbAddLibEx( dstlist, dsthash, libname, TRUE )
 #endmacro
 
+	hAddLib( "gcc" )
 	hAddLib( "c" )
 	hAddLib( "m" )
 	hAddLib( "supcx" )
@@ -311,7 +312,7 @@
 
 	env.target.targetdir = @"dos"
 	env.target.define = @"__FB_DOS__"
-	env.target.entrypoint = @"main"
+	env.target.entrypoint = "main"
 	env.target.underprefix = TRUE
 	env.target.constsection = @"rdata"
 	env.target.allowstdcall = FALSE
Index: compiler/fbc_freebsd.bas
===================================================================
--- compiler/fbc_freebsd.bas	(revision 5406)
+++ compiler/fbc_freebsd.bas	(working copy)
@@ -402,6 +402,7 @@
 	symbAddLibEx( dstlist, dsthash, libname, TRUE )
 #endmacro
 
+	hAddLib( "gcc" )
 	hAddLib( "c" )
 	hAddLib( "m" )
 	hAddLib( "pthread" )
@@ -478,7 +479,7 @@
 
 	env.target.targetdir = @"freebsd"
 	env.target.define = @"__FB_FREEBSD__"
-	env.target.entrypoint = @"main"
+	env.target.entrypoint = "main"
 	env.target.underprefix = FALSE
 	env.target.constsection = @"rodata"
 	env.target.allowstdcall = FALSE
Index: compiler/fbc_linux.bas
===================================================================
--- compiler/fbc_linux.bas	(revision 5406)
+++ compiler/fbc_linux.bas	(working copy)
@@ -415,6 +415,7 @@
 	symbAddLibEx( dstlist, dsthash, libname, TRUE )
 #endmacro
 
+	hAddLib( "gcc" )
 	hAddLib( "c" )
 	hAddLib( "m" )
 	hAddLib( "pthread" )
@@ -493,10 +494,11 @@
 
 	env.target.targetdir = @"linux"
 	env.target.define = @"__FB_LINUX__"
-	env.target.entrypoint = @"main"
+	env.target.entrypoint = "main"
 	env.target.underprefix = FALSE
 	env.target.constsection = @"rodata"
 	env.target.allowstdcall = FALSE
+'        env.target.align16 = TRUE
 
 	return TRUE
 
Index: compiler/fbc_netbsd.bas
===================================================================
--- compiler/fbc_netbsd.bas	(revision 5406)
+++ compiler/fbc_netbsd.bas	(working copy)
@@ -409,7 +409,9 @@
 #endmacro
 
 	'' TODO
+	hAddLib( "gcc" )
 
+
 end sub
 
 
@@ -480,7 +482,7 @@
 
 	env.target.targetdir = @"netbsd"
 	env.target.define = @"__FB_NETBSD__"
-	env.target.entrypoint = @"main"
+	env.target.entrypoint = "main"
 	env.target.underprefix = FALSE
 	env.target.constsection = @"rodata"
 	env.target.allowstdcall = FALSE
Index: compiler/fbc_openbsd.bas
===================================================================
--- compiler/fbc_openbsd.bas	(revision 5406)
+++ compiler/fbc_openbsd.bas	(working copy)
@@ -394,6 +394,7 @@
 	symbAddLibEx( dstlist, dsthash, libname, TRUE )
 #endmacro
 
+	hAddLib( "gcc" )
 	hAddLib( "c" )
 	hAddLib( "m" )
 	hAddLib( "pthread" )
@@ -468,7 +469,7 @@
 
 	env.target.targetdir = @"openbsd"
 	env.target.define = @"__FB_OPENBSD__"
-	env.target.entrypoint = @"main"
+	env.target.entrypoint = "main"
 	env.target.underprefix = FALSE
 	env.target.constsection = @"rodata"
 	env.target.allowstdcall = FALSE
Index: compiler/fbc_win32.bas
===================================================================
--- compiler/fbc_win32.bas	(revision 5406)
+++ compiler/fbc_win32.bas	(working copy)
@@ -550,6 +550,7 @@
 	symbAddLibEx( dstlist, dsthash, libname, TRUE )
 #endmacro
 
+	hAddLib( "gcc" )
 	hAddLib( "msvcrt" )
 	hAddLib( "kernel32" )
 	hAddLib( "mingw32" )
@@ -617,7 +618,7 @@
 
 	env.target.targetdir = @"win32"
 	env.target.define = @"__FB_WIN32__"
-	env.target.entrypoint = @"main"
+	env.target.entrypoint = "main"
 	env.target.underprefix = TRUE
 	env.target.constsection = @"rdata"
 	env.target.allowstdcall = TRUE
Index: compiler/fbc_xbox.bas
===================================================================
--- compiler/fbc_xbox.bas	(revision 5406)
+++ compiler/fbc_xbox.bas	(working copy)
@@ -353,6 +353,7 @@
 	symbAddLibEx( dstlist, dsthash, libname, TRUE )
 #endmacro
 
+	hAddLib( "gcc" )
 	hAddLib( "fbgfx" )
 	hAddLib( "openxdk" )
 	hAddLib( "hal" )
@@ -418,7 +419,7 @@
 
 	env.target.targetdir = @"xbox"
 	env.target.define = @"__FB_XBOX__"
-	env.target.entrypoint = @"XBoxStartup"
+	env.target.entrypoint = "XBoxStartup"
 	env.target.underprefix = TRUE
 	env.target.constsection = @"rdata"
 	env.target.allowstdcall = FALSE
Index: compiler/hlp.bas
===================================================================
--- compiler/hlp.bas	(revision 5406)
+++ compiler/hlp.bas	(working copy)
@@ -271,9 +271,9 @@
 		byval src as zstring ptr _
 	) static
 
-    dim as zstring ptr p
+    dim as ubyte ptr p
 
-	p = src
+	p = @src[0]
 
 	do
 		select case as const *p
Index: compiler/inc/fbc.bi
===================================================================
--- compiler/inc/fbc.bi	(revision 5406)
+++ compiler/inc/fbc.bi	(working copy)
@@ -83,6 +83,7 @@
 	FBC_OPT_PREFIX
 	FBC_OPT_OPTIMIZE
 	FBC_OPT_EXTRAOPT
+	FBC_OPT_ENTRY
 
 	FBC_OPTS
 end enum
Index: compiler/inc/fbint.bi
===================================================================
--- compiler/inc/fbint.bi	(revision 5406)
+++ compiler/inc/fbint.bi	(working copy)
@@ -598,11 +598,14 @@
 	wchar			as FBTARGET_WCHAR
 	targetdir		as zstring ptr				'' directory to look for target bin, lib, etc.
 	define		as zstring ptr				'' __FB_target__ preprocessor define name
-	entrypoint		as zstring ptr				'' entry point of executable (usually "main")
+	entrypoint		as string				'' entry point of executable (usually "main")
 	underprefix		as integer					'' whether symbols are prefixed with an underscore
 	constsection	as zstring ptr				'' linker section to use for constant data
 	allowstdcall	as integer					'' whether stdcall calling convention should be allowed (if false, treat as CDECL)
 	omitsectiondirective	as integer					'' whether to omit .section before section names in the assembly output
+	align16		as integer 				'' align stack to 16 bytes at cdecl function call
+	objconversion	as zstring ptr				'' if objconv is required, name of the binary format to convert to
+	nojumptables	as integer 				'' don't emit jump tables
 end type
 
 type FBOPTION
@@ -686,6 +689,7 @@
 ''
 '' super globals
 ''
-common shared as FBENV env
+'common shared as FBENV env
+extern env as FBENV 
 
 #endif ''__FBINT_BI__
Index: compiler/ir-tac.bas
===================================================================
--- compiler/ir-tac.bas	(revision 5406)
+++ compiler/ir-tac.bas	(working copy)
@@ -169,7 +169,12 @@
 	( _
 	)
 
+declare sub _emitStackAlign _
+	( _
+		byval bytes as integer _
+	)
 
+
 '' globals
 	dim shared ctx as IRTAC_CTX
 
@@ -770,9 +775,15 @@
 '':::::
 private sub hEmitCallArgs _
 	( _
-		byval arg_list as IR_CALL_ARG_LIST ptr _
+		byval arg_list as IR_CALL_ARG_LIST ptr, _
+		byval bytestopop as integer _
 	)
 
+
+        if( bytestopop >= &h456700 ) then
+            _emitStackAlign( bytestopop )
+        end if
+
 	if( arg_list = NULL ) then
 		return
 	end if
@@ -801,8 +812,18 @@
 		byval vr as IRVREG ptr _
 	)
 
-	hEmitCallArgs( arg_list )
+	if( symbGetProcMode( proc ) = FB_FUNCMODE_CDECL ) then
+		'' if this func is VARARG, astCALL() already set the size
+		if( bytestopop = 0 ) then
+			bytestopop = symbGetProcParamsLen( proc )
+		end if
+		if( env.target.align16 ) then
+			bytestopop += &h456700
+		end if
+	end if
 
+	hEmitCallArgs( arg_list, bytestopop )
+
 	_emit( AST_OP_CALLFUNCT, NULL, NULL, vr, proc, bytestopop )
 
 end sub
@@ -816,7 +837,7 @@
 		byval bytestopop as integer _
 	)
 
-	hEmitCallArgs( arg_list )
+	hEmitCallArgs( arg_list, bytestopop )
 
 	_emit( AST_OP_CALLPTR, v1, NULL, vr, NULL, bytestopop )
 
@@ -1691,10 +1712,7 @@
 		'' pop up the stack if needed
 		select case symbGetProcMode( proc )
 		case FB_FUNCMODE_CDECL
-			'' if this func is VARARG, astCALL() already set the size
-			if( bytestopop = 0 ) then
-				bytestopop = symbGetProcParamsLen( proc )
-			end if
+			'' nothing to do, bytestopop calculated in _emitCall
 
 		case FB_FUNCMODE_STDCALL, FB_FUNCMODE_STDCALL_MS
 			'' nothing to pop, unless -nostdcall was used
Index: compiler/parser-compound-select.bas
===================================================================
--- compiler/parser-compound-select.bas	(revision 5406)
+++ compiler/parser-compound-select.bas	(working copy)
@@ -92,12 +92,14 @@
 
 		'' CONST?
 		if( hMatch( FB_TK_CONST ) ) then
-			return cSelConstStmtBegin( )
+			if( env.target.nojumptables = FALSE ) then
+				return cSelConstStmtBegin( )
+			end if
+		else
+			if( errReport( FB_ERRMSG_SYNTAXERROR ) = FALSE ) then
+			    exit function
+			end if
 		end if
-
-		if( errReport( FB_ERRMSG_SYNTAXERROR ) = FALSE ) then
-			exit function
-		end if
 	end if
 
 	'' Expression
Index: compiler/parser-decl-symb-init.bas
===================================================================
--- compiler/parser-decl-symb-init.bas	(revision 5406)
+++ compiler/parser-decl-symb-init.bas	(working copy)
@@ -159,7 +159,7 @@
     dim as integer isarray = any, dtype = any
     dim as FBVARDIM ptr old_dim = any
     dim as FBSYMBOL ptr subtype = any
-	static as FBARRAYDIM dTB(0 to FB_MAXARRAYDIMS - 1)
+	static as FBARRAYDIM dTB(-1 to FB_MAXARRAYDIMS - 1)
 
 	function = FALSE
 
Index: compiler/pp-cond.bas
===================================================================
--- compiler/pp-cond.bas	(revision 5406)
+++ compiler/pp-cond.bas	(working copy)
@@ -83,7 +83,6 @@
 
 '' globals
 	dim shared pptb(1 to FB_PP_MAXRECLEVEL) as LEXPP_REC
-
 ''::::
 sub ppCondInit( )
 
Index: rtlib/darwin/fb_darwin.h
===================================================================
--- rtlib/darwin/fb_darwin.h	(revision 5406)
+++ rtlib/darwin/fb_darwin.h	(working copy)
@@ -39,4 +39,7 @@
 #ifndef __FB_DARWIN_H__
 #define __FB_DARWIN_H__
 
+// On darwin, FBCALL is cdecl with non-aligned stack.
+#define FBCALL __attribute__((force_align_arg_pointer))
+
 #endif
Index: rtlib/darwin/libfb_hexit.c
===================================================================
--- rtlib/darwin/libfb_hexit.c	(revision 0)
+++ rtlib/darwin/libfb_hexit.c	(revision 0)
@@ -0,0 +1,45 @@
+/*
+ *  libfb - FreeBASIC's runtime library
+ *	Copyright (C) 2004-2010 The FreeBASIC development team.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  As a special exception, the copyright holders of this library give
+ *  you permission to link this library with independent modules to
+ *  produce an executable, regardless of the license terms of these
+ *  independent modules, and to copy and distribute the resulting
+ *  executable under terms of your choice, provided that you also meet,
+ *  for each linked independent module, the terms and conditions of the
+ *  license of that module. An independent module is a module which is
+ *  not derived from or based on this library. If you modify this library,
+ *  you may extend this exception to your version of the library, but
+ *  you are not obligated to do so. If you do not wish to do so, delete
+ *  this exception statement from your version.
+ */
+
+/*
+ * exit.c -- end helper for FreeBSD
+ *
+ * chng: sep/2007 written [DrV]
+ *
+ */
+
+#include "fb.h"
+
+/*:::::*/
+void fb_hEnd ( int unused )
+{
+	fb_unix_hEnd( unused );
+}
Index: rtlib/darwin/libfb_hinit.c
===================================================================
--- rtlib/darwin/libfb_hinit.c	(revision 0)
+++ rtlib/darwin/libfb_hinit.c	(revision 0)
@@ -0,0 +1,45 @@
+/*
+ *  libfb - FreeBASIC's runtime library
+ *	Copyright (C) 2004-2010 The FreeBASIC development team.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  As a special exception, the copyright holders of this library give
+ *  you permission to link this library with independent modules to
+ *  produce an executable, regardless of the license terms of these
+ *  independent modules, and to copy and distribute the resulting
+ *  executable under terms of your choice, provided that you also meet,
+ *  for each linked independent module, the terms and conditions of the
+ *  license of that module. An independent module is a module which is
+ *  not derived from or based on this library. If you modify this library,
+ *  you may extend this exception to your version of the library, but
+ *  you are not obligated to do so. If you do not wish to do so, delete
+ *  this exception statement from your version.
+ */
+
+/*
+ * init.c -- libfb initialization for FreeBSD
+ *
+ * chng: sep/2007 written [DrV]
+ *
+ */
+
+#include "fb.h"
+
+/*:::::*/
+void fb_hInit ( void )
+{
+	fb_unix_hInit( );
+}
Index: rtlib/darwin/libfb_io_mouse.c
===================================================================
--- rtlib/darwin/libfb_io_mouse.c	(revision 0)
+++ rtlib/darwin/libfb_io_mouse.c	(revision 0)
@@ -0,0 +1,52 @@
+/*
+ *  libfb - FreeBASIC's runtime library
+ *	Copyright (C) 2004-2010 The FreeBASIC development team.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  As a special exception, the copyright holders of this library give
+ *  you permission to link this library with independent modules to
+ *  produce an executable, regardless of the license terms of these
+ *  independent modules, and to copy and distribute the resulting
+ *  executable under terms of your choice, provided that you also meet,
+ *  for each linked independent module, the terms and conditions of the
+ *  license of that module. An independent module is a module which is
+ *  not derived from or based on this library. If you modify this library,
+ *  you may extend this exception to your version of the library, but
+ *  you are not obligated to do so. If you do not wish to do so, delete
+ *  this exception statement from your version.
+ */
+
+/*
+ * io_mouse.c -- FreeBSD console mouse functions implementation
+ *
+ * chng: / written []
+ *
+ */
+
+#include "fb.h"
+
+/*:::::*/
+int fb_ConsoleGetMouse(int *x, int *y, int *z, int *buttons, int *clip)
+{
+	return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
+}
+
+
+/*:::::*/
+int fb_ConsoleSetMouse(int x, int y, int cursor, int clip)
+{
+	return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
+}
Index: rtlib/darwin/libfb_io_multikey.c
===================================================================
--- rtlib/darwin/libfb_io_multikey.c	(revision 0)
+++ rtlib/darwin/libfb_io_multikey.c	(revision 0)
@@ -0,0 +1,46 @@
+/*
+ *  libfb - FreeBASIC's runtime library
+ *	Copyright (C) 2004-2010 The FreeBASIC development team.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  As a special exception, the copyright holders of this library give
+ *  you permission to link this library with independent modules to
+ *  produce an executable, regardless of the license terms of these
+ *  independent modules, and to copy and distribute the resulting
+ *  executable under terms of your choice, provided that you also meet,
+ *  for each linked independent module, the terms and conditions of the
+ *  license of that module. An independent module is a module which is
+ *  not derived from or based on this library. If you modify this library,
+ *  you may extend this exception to your version of the library, but
+ *  you are not obligated to do so. If you do not wish to do so, delete
+ *  this exception statement from your version.
+ */
+
+/*
+ * io_multikey.c -- FreeBSD console multikey function implementation
+ *
+ * chng: / written []
+ *
+ */
+
+#include "fb.h"
+
+
+/*:::::*/
+int fb_ConsoleMultikey(int scancode)
+{
+	return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
+}
Index: rtlib/darwin/libfb_sys_fmem.c
===================================================================
--- rtlib/darwin/libfb_sys_fmem.c	(revision 0)
+++ rtlib/darwin/libfb_sys_fmem.c	(revision 0)
@@ -0,0 +1,61 @@
+/*
+ *  libfb - FreeBASIC's runtime library
+ *	Copyright (C) 2004-2010 The FreeBASIC development team.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  As a special exception, the copyright holders of this library give
+ *  you permission to link this library with independent modules to
+ *  produce an executable, regardless of the license terms of these
+ *  independent modules, and to copy and distribute the resulting
+ *  executable under terms of your choice, provided that you also meet,
+ *  for each linked independent module, the terms and conditions of the
+ *  license of that module. An independent module is a module which is
+ *  not derived from or based on this library. If you modify this library,
+ *  you may extend this exception to your version of the library, but
+ *  you are not obligated to do so. If you do not wish to do so, delete
+ *  this exception statement from your version.
+ */
+
+/*
+ * sys_fmem.c -- fre function for FreeBSD
+ *
+ * chng: jan/2008 written [DrV]
+ *
+ */
+
+#include "fb.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/vmmeter.h>
+#include <mach/vm_param.h>
+
+/*:::::*/
+FBCALL unsigned int fb_GetMemAvail ( int mode )
+{
+	int mib[2];
+	struct vmtotal vmt;
+	size_t size;
+	
+	mib[0] = CTL_VM;
+	mib[1] = VM_METER;
+	size = sizeof(struct vmtotal);
+	
+	if( sysctl( mib, 2, &vmt, &size, NULL, 0 ) )
+	  return 0;
+
+	return vmt.t_free * sysconf( _SC_PAGE_SIZE );
+}
Index: rtlib/darwin/libfb_sys_getexename.c
===================================================================
--- rtlib/darwin/libfb_sys_getexename.c	(revision 0)
+++ rtlib/darwin/libfb_sys_getexename.c	(revision 0)
@@ -0,0 +1,58 @@
+/*
+ *  libfb - FreeBASIC's runtime library
+ *	Copyright (C) 2004-2010 The FreeBASIC development team.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  As a special exception, the copyright holders of this library give
+ *  you permission to link this library with independent modules to
+ *  produce an executable, regardless of the license terms of these
+ *  independent modules, and to copy and distribute the resulting
+ *  executable under terms of your choice, provided that you also meet,
+ *  for each linked independent module, the terms and conditions of the
+ *  license of that module. An independent module is a module which is
+ *  not derived from or based on this library. If you modify this library,
+ *  you may extend this exception to your version of the library, but
+ *  you are not obligated to do so. If you do not wish to do so, delete
+ *  this exception statement from your version.
+ */
+
+/*
+ * sys_getexename.c -- get the executable's name for FreeBSD
+ *
+ * chng: sep/2007 written [DrV]
+ *
+ */
+
+#include "fb.h"
+#include <string.h>
+
+/*:::::*/
+char *fb_hGetExeName( char *dst, int maxlen )
+{
+	const char *p;
+
+	p = strrchr( __fb_ctx.argv[0], '/' );
+	if( p )
+	{
+		strlcpy( dst, p + 1, maxlen );
+	}
+	else
+	{
+		strlcpy( dst, __fb_ctx.argv[0], maxlen );
+	}
+
+	return dst;
+}
Index: rtlib/darwin/libfb_sys_getexepath.c
===================================================================
--- rtlib/darwin/libfb_sys_getexepath.c	(revision 0)
+++ rtlib/darwin/libfb_sys_getexepath.c	(revision 0)
@@ -0,0 +1,63 @@
+/*
+ *  libfb - FreeBASIC's runtime library
+ *	Copyright (C) 2004-2010 The FreeBASIC development team.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  As a special exception, the copyright holders of this library give
+ *  you permission to link this library with independent modules to
+ *  produce an executable, regardless of the license terms of these
+ *  independent modules, and to copy and distribute the resulting
+ *  executable under terms of your choice, provided that you also meet,
+ *  for each linked independent module, the terms and conditions of the
+ *  license of that module. An independent module is a module which is
+ *  not derived from or based on this library. If you modify this library,
+ *  you may extend this exception to your version of the library, but
+ *  you are not obligated to do so. If you do not wish to do so, delete
+ *  this exception statement from your version.
+ */
+
+/*
+ * sys_getexepath.c -- get the executable path for Darwin
+ *
+ * chng: oct/2010 written [tmc]
+ *
+ */
+
+#include "fb.h"
+#include <string.h>
+#include <mach-o/dyld.h>
+
+/*:::::*/
+char *fb_hGetExePath( char *dst, int maxlen )
+{
+	char *p;
+
+	uint32_t pathsz = maxlen;
+	if( _NSGetExecutablePath(dst, &pathsz) )
+	{
+		//maxlen too small
+		*dst = '\0';
+		return dst;
+	}
+
+	p = strrchr( dst, '/' );
+	if( p )
+	{
+		*p = '\0';
+	}
+
+	return dst;
+}
