diff --git a/compiler/globals.pas b/compiler/globals.pas index 132701e1ab..6b33e467a8 100644 --- a/compiler/globals.pas +++ b/compiler/globals.pas @@ -288,6 +288,10 @@ interface syscall_convention : string = 'LEGACY'; {$endif powerpc} + { default name of the C-style "main" procedure of the library/program } + { (this will be prefixed with the target_info.cprefix) } + mainaliasname : string = 'main'; + procedure abstract; function bstoslash(const s : string) : string; diff --git a/compiler/options.pas b/compiler/options.pas index 7f6c1a6654..be848f1986 100644 --- a/compiler/options.pas +++ b/compiler/options.pas @@ -1223,6 +1223,11 @@ begin exclude(initglobalswitches,cs_link_shared); LinkTypeSetExplicitly:=true; end; + 'M' : + begin + mainaliasname:=Copy(more,2,length(More)-1); + More:=''; + end; '-' : begin exclude(initglobalswitches,cs_link_staticflag); @@ -1784,6 +1789,8 @@ begin def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr); { Temporary defines, until things settle down } + { "main" symbol is generated in the main program, and left out of the system unit } + def_system_macro('FPC_DARWIN_PASCALMAIN'); if pocall_default = pocall_register then def_system_macro('REGCALL'); diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index 73886c5533..60d2644bf0 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -1447,26 +1447,24 @@ implementation { The program intialization needs an alias, so it can be called from the bootstrap code.} - if islibrary or - (target_info.system in [system_powerpc_macos,system_powerpc_darwin]) then + + if islibrary then begin - pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'main'),potype_proginit,st); + pd:=create_main_proc(make_mangledname('',current_module.localsymtable,mainaliasname),potype_proginit,st); { Win32 startup code needs a single name } // if (target_info.system in [system_i386_win32,system_i386_wdosx]) then pd.aliasnames.insert('PASCALMAIN'); end - else - begin - if (target_info.system = system_i386_netware) or - (target_info.system = system_i386_netwlibc) then - begin - pd:=create_main_proc('PASCALMAIN',potype_proginit,st); { main is need by the netware rtl } - end else - begin - pd:=create_main_proc('main',potype_proginit,st); - pd.aliasnames.insert('PASCALMAIN'); - end; - end; + else if (target_info.system = system_i386_netware) or + (target_info.system = system_i386_netwlibc) then + begin + pd:=create_main_proc('PASCALMAIN',potype_proginit,st); { main is need by the netware rtl } + end + else + begin + pd:=create_main_proc(mainaliasname,potype_proginit,st); + pd.aliasnames.insert('PASCALMAIN'); + end; tcgprocinfo(current_procinfo).parse_body; tcgprocinfo(current_procinfo).generate_code; tcgprocinfo(current_procinfo).resetprocdef; diff --git a/rtl/bsd/system.pp b/rtl/bsd/system.pp index a05ca7870a..126af52786 100644 --- a/rtl/bsd/system.pp +++ b/rtl/bsd/system.pp @@ -216,16 +216,23 @@ end; { can also be used with other BSD's if they use the system's crtX instead of prtX } {$ifdef Darwin} + +{$ifndef FPC_DARWIN_PASCALMAIN} procedure pascalmain; external name 'PASCALMAIN'; { Main entry point in C style, needed to capture program parameters. } procedure main(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public]; +{$else FPC_DARWIN_PASCALMAIN} +procedure FPC_SYSTEMMAIN(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public]; +{$endif FPC_DARWIN_PASCALMAIN} begin argc:= argcparam; argv:= argvparam; envp:= envpparam; +{$ifndef FPC_DARWIN_PASCALMAIN} pascalmain; {run the pascal main program} +{$endif FPC_DARWIN_PASCALMAIN} end; {$endif Darwin} {$endif FPC_USE_LIBC}