Pārlūkot izejas kodu

+ support for {$linkframework x} to link to framework x (Darwin only)
+ support for {$frameworkpath x} and -Ffx to add x to the directories to
search for frameworks (Darwin only)

git-svn-id: trunk@8165 -

Jonas Maebe 18 gadi atpakaļ
vecāks
revīzija
a3c9dc5ec6

+ 2 - 0
.gitattributes

@@ -6852,6 +6852,8 @@ tests/test/tfpu3.pp svneol=native#text/plain
 tests/test/tfpu4.pp svneol=native#text/plain
 tests/test/tfpu4.pp svneol=native#text/plain
 tests/test/tfpu5.pp svneol=native#text/plain
 tests/test/tfpu5.pp svneol=native#text/plain
 tests/test/tfpuover.pp svneol=native#text/plain
 tests/test/tfpuover.pp svneol=native#text/plain
+tests/test/tfwork1.pp svneol=native#text/plain
+tests/test/tfwork2.pp svneol=native#text/plain
 tests/test/tgeneric1.pp svneol=native#text/plain
 tests/test/tgeneric1.pp svneol=native#text/plain
 tests/test/tgeneric10.pp svneol=native#text/plain
 tests/test/tgeneric10.pp svneol=native#text/plain
 tests/test/tgeneric11.pp svneol=native#text/plain
 tests/test/tgeneric11.pp svneol=native#text/plain

+ 10 - 2
compiler/fmodule.pas

@@ -142,7 +142,8 @@ interface
         linkunitsharedlibs,
         linkunitsharedlibs,
         linkotherofiles,           { objects,libs loaded from the source }
         linkotherofiles,           { objects,libs loaded from the source }
         linkothersharedlibs,       { using $L or $LINKLIB or import lib (for linux) }
         linkothersharedlibs,       { using $L or $LINKLIB or import lib (for linux) }
-        linkotherstaticlibs  : tlinkcontainer;
+        linkotherstaticlibs,
+        linkotherframeworks  : tlinkcontainer;
 
 
         used_units           : tlinkedlist;
         used_units           : tlinkedlist;
         dependent_units      : tlinkedlist;
         dependent_units      : tlinkedlist;
@@ -150,7 +151,8 @@ interface
         localunitsearchpath,           { local searchpaths }
         localunitsearchpath,           { local searchpaths }
         localobjectsearchpath,
         localobjectsearchpath,
         localincludesearchpath,
         localincludesearchpath,
-        locallibrarysearchpath : TSearchPathList;
+        locallibrarysearchpath,
+        localframeworksearchpath : TSearchPathList;
 
 
         {create creates a new module which name is stored in 's'. LoadedFrom
         {create creates a new module which name is stored in 's'. LoadedFrom
         points to the module calling it. It is nil for the first compiled
         points to the module calling it. It is nil for the first compiled
@@ -433,6 +435,7 @@ implementation
         localobjectsearchpath:=TSearchPathList.Create;
         localobjectsearchpath:=TSearchPathList.Create;
         localincludesearchpath:=TSearchPathList.Create;
         localincludesearchpath:=TSearchPathList.Create;
         locallibrarysearchpath:=TSearchPathList.Create;
         locallibrarysearchpath:=TSearchPathList.Create;
+        localframeworksearchpath:=TSearchPathList.Create;
         used_units:=TLinkedList.Create;
         used_units:=TLinkedList.Create;
         dependent_units:=TLinkedList.Create;
         dependent_units:=TLinkedList.Create;
         resourcefiles:=TCmdStrList.Create;
         resourcefiles:=TCmdStrList.Create;
@@ -442,6 +445,7 @@ implementation
         linkotherofiles:=TLinkContainer.Create;
         linkotherofiles:=TLinkContainer.Create;
         linkotherstaticlibs:=TLinkContainer.Create;
         linkotherstaticlibs:=TLinkContainer.Create;
         linkothersharedlibs:=TLinkContainer.Create;
         linkothersharedlibs:=TLinkContainer.Create;
+        linkotherframeworks:=TLinkContainer.Create;
         FImportLibraryList:=TFPHashObjectList.Create(true);
         FImportLibraryList:=TFPHashObjectList.Create(true);
         crc:=0;
         crc:=0;
         interface_crc:=0;
         interface_crc:=0;
@@ -533,6 +537,7 @@ implementation
         linkotherofiles.Free;
         linkotherofiles.Free;
         linkotherstaticlibs.Free;
         linkotherstaticlibs.Free;
         linkothersharedlibs.Free;
         linkothersharedlibs.Free;
+        linkotherframeworks.Free;
         FImportLibraryList.Free;
         FImportLibraryList.Free;
         stringdispose(objfilename);
         stringdispose(objfilename);
         stringdispose(asmfilename);
         stringdispose(asmfilename);
@@ -550,6 +555,7 @@ implementation
         localobjectsearchpath.free;
         localobjectsearchpath.free;
         localincludesearchpath.free;
         localincludesearchpath.free;
         locallibrarysearchpath.free;
         locallibrarysearchpath.free;
+        localframeworksearchpath.free;
 {$ifdef MEMDEBUG}
 {$ifdef MEMDEBUG}
         memsymtable.start;
         memsymtable.start;
 {$endif}
 {$endif}
@@ -672,6 +678,8 @@ implementation
         linkotherstaticlibs:=TLinkContainer.Create;
         linkotherstaticlibs:=TLinkContainer.Create;
         linkothersharedlibs.Free;
         linkothersharedlibs.Free;
         linkothersharedlibs:=TLinkContainer.Create;
         linkothersharedlibs:=TLinkContainer.Create;
+        linkotherframeworks.Free;
+        linkotherframeworks:=TLinkContainer.Create;
         FImportLibraryList.Free;
         FImportLibraryList.Free;
         FImportLibraryList:=TFPHashObjectList.Create;
         FImportLibraryList:=TFPHashObjectList.Create;
         do_compile:=false;
         do_compile:=false;

+ 4 - 1
compiler/globals.pas

@@ -199,7 +199,8 @@ interface
        librarysearchpath,
        librarysearchpath,
        unitsearchpath,
        unitsearchpath,
        objectsearchpath,
        objectsearchpath,
-       includesearchpath  : TSearchPathList;
+       includesearchpath,
+       frameworksearchpath  : TSearchPathList;
        autoloadunits      : string;
        autoloadunits      : string;
 
 
        { linking }
        { linking }
@@ -1064,6 +1065,7 @@ implementation
        unitsearchpath.Free;
        unitsearchpath.Free;
        objectsearchpath.Free;
        objectsearchpath.Free;
        includesearchpath.Free;
        includesearchpath.Free;
+       frameworksearchpath.Free;
        LinkLibraryAliases.Free;
        LinkLibraryAliases.Free;
        LinkLibraryOrder.Free;
        LinkLibraryOrder.Free;
      end;
      end;
@@ -1102,6 +1104,7 @@ implementation
         unitsearchpath:=TSearchPathList.Create;
         unitsearchpath:=TSearchPathList.Create;
         includesearchpath:=TSearchPathList.Create;
         includesearchpath:=TSearchPathList.Create;
         objectsearchpath:=TSearchPathList.Create;
         objectsearchpath:=TSearchPathList.Create;
+        frameworksearchpath:=TSearchPathList.Create;
 
 
         { Def file }
         { Def file }
         usewindowapi:=false;
         usewindowapi:=false;

+ 16 - 1
compiler/link.pas

@@ -51,7 +51,8 @@ interface
          SysInitUnit     : string[20];
          SysInitUnit     : string[20];
          ObjectFiles,
          ObjectFiles,
          SharedLibFiles,
          SharedLibFiles,
-         StaticLibFiles  : TCmdStrList;
+         StaticLibFiles,
+         FrameworkFiles  : TCmdStrList;
          Constructor Create;virtual;
          Constructor Create;virtual;
          Destructor Destroy;override;
          Destructor Destroy;override;
          procedure AddModuleFiles(hp:tmodule);
          procedure AddModuleFiles(hp:tmodule);
@@ -60,6 +61,7 @@ interface
          Procedure AddSharedLibrary(S : TCmdStr);
          Procedure AddSharedLibrary(S : TCmdStr);
          Procedure AddStaticCLibrary(const S : TCmdStr);
          Procedure AddStaticCLibrary(const S : TCmdStr);
          Procedure AddSharedCLibrary(S : TCmdStr);
          Procedure AddSharedCLibrary(S : TCmdStr);
+         Procedure AddFramework(S : TCmdStr);
          procedure AddImportSymbol(const libname,symname:TCmdStr;OrdNr: longint;isvar:boolean);virtual;
          procedure AddImportSymbol(const libname,symname:TCmdStr;OrdNr: longint;isvar:boolean);virtual;
          Procedure InitSysInitUnitName;virtual;
          Procedure InitSysInitUnitName;virtual;
          Function  MakeExecutable:boolean;virtual;
          Function  MakeExecutable:boolean;virtual;
@@ -290,6 +292,7 @@ Implementation
         ObjectFiles:=TCmdStrList.Create_no_double;
         ObjectFiles:=TCmdStrList.Create_no_double;
         SharedLibFiles:=TCmdStrList.Create_no_double;
         SharedLibFiles:=TCmdStrList.Create_no_double;
         StaticLibFiles:=TCmdStrList.Create_no_double;
         StaticLibFiles:=TCmdStrList.Create_no_double;
+        FrameworkFiles:=TCmdStrList.Create_no_double;
       end;
       end;
 
 
 
 
@@ -298,6 +301,7 @@ Implementation
         ObjectFiles.Free;
         ObjectFiles.Free;
         SharedLibFiles.Free;
         SharedLibFiles.Free;
         StaticLibFiles.Free;
         StaticLibFiles.Free;
+        FrameworkFiles.Free;
       end;
       end;
 
 
 
 
@@ -386,6 +390,8 @@ Implementation
             AddStaticCLibrary(linkotherstaticlibs.Getusemask(mask));
             AddStaticCLibrary(linkotherstaticlibs.Getusemask(mask));
            while not linkothersharedlibs.empty do
            while not linkothersharedlibs.empty do
             AddSharedCLibrary(linkothersharedlibs.Getusemask(mask));
             AddSharedCLibrary(linkothersharedlibs.Getusemask(mask));
+           while not linkotherframeworks.empty do
+             AddFramework(linkotherframeworks.Getusemask(mask));
            { Known Library/DLL Imports }
            { Known Library/DLL Imports }
            for i:=0 to ImportLibraryList.Count-1 do
            for i:=0 to ImportLibraryList.Count-1 do
              begin
              begin
@@ -455,6 +461,15 @@ Implementation
       end;
       end;
 
 
 
 
+    Procedure TLinker.AddFramework(S:TCmdStr);
+      begin
+        if s='' then
+          exit;
+        { ready to be added }
+        FrameworkFiles.Concat(S);
+      end;
+
+
     Procedure TLinker.AddStaticCLibrary(const S:TCmdStr);
     Procedure TLinker.AddStaticCLibrary(const S:TCmdStr);
       var
       var
         ns : TCmdStr;
         ns : TCmdStr;

+ 4 - 1
compiler/msg/errore.msg

@@ -125,7 +125,7 @@ general_i_number_of_notes=01023_I_$1 note(s) issued
 #
 #
 # Scanner
 # Scanner
 #
 #
-# 02063 is the last used one
+# 02084 is the last used one
 #
 #
 % \section{Scanner messages.}
 % \section{Scanner messages.}
 % This section lists the messages that the scanner emits. The scanner takes
 % This section lists the messages that the scanner emits. The scanner takes
@@ -350,6 +350,8 @@ scan_w_pic_ignored=02081_W_PIC directive or switch ignored
 % ignored.
 % ignored.
 scan_w_unsupported_switch_by_target=02082_W_The switch "$1" is not supported by the currently selected target
 scan_w_unsupported_switch_by_target=02082_W_The switch "$1" is not supported by the currently selected target
 % Some compiler switches like $E are not supported by all targets.
 % Some compiler switches like $E are not supported by all targets.
+scan_w_frameworks_darwin_only=02084_W_Framework-related options are only supported for Darwin/Mac OS X
+% Frameworks are not a known concept, or at least not supported by FPC, on operating systems other than Darwin/Mac OS X.
 % \end{description}
 % \end{description}
 #
 #
 # Parser
 # Parser
@@ -2522,6 +2524,7 @@ S*2Aas_assemble using GNU AS
 **2FC<x>_sets RC compiler binary name to <x>
 **2FC<x>_sets RC compiler binary name to <x>
 **2FD<x>_sets the directory where to search for compiler utilities
 **2FD<x>_sets the directory where to search for compiler utilities
 **2Fe<x>_redirect error output to <x>
 **2Fe<x>_redirect error output to <x>
+**2Ff<x>_adds <x> to framework path (Darwin only)
 **2FE<x>_set exe/unit output path to <x>
 **2FE<x>_set exe/unit output path to <x>
 **2Fi<x>_adds <x> to include path
 **2Fi<x>_adds <x> to include path
 **2Fl<x>_adds <x> to library path
 **2Fl<x>_adds <x> to library path

+ 3 - 2
compiler/msgidx.inc

@@ -103,6 +103,7 @@ const
   scan_e_only_packset=02080;
   scan_e_only_packset=02080;
   scan_w_pic_ignored=02081;
   scan_w_pic_ignored=02081;
   scan_w_unsupported_switch_by_target=02082;
   scan_w_unsupported_switch_by_target=02082;
+  scan_w_frameworks_darwin_only=02084;
   parser_e_syntax_error=03000;
   parser_e_syntax_error=03000;
   parser_e_dont_nest_interrupt=03004;
   parser_e_dont_nest_interrupt=03004;
   parser_w_proc_directive_ignored=03005;
   parser_w_proc_directive_ignored=03005;
@@ -729,9 +730,9 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 43827;
+  MsgTxtSize = 43950;
 
 
   MsgIdxMax : array[1..20] of longint=(
   MsgIdxMax : array[1..20] of longint=(
-    24,83,237,83,63,49,107,22,135,60,
+    24,85,237,83,63,49,107,22,135,60,
     42,1,1,1,1,1,1,1,1,1
     42,1,1,1,1,1,1,1,1,1
   );
   );

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 296 - 297
compiler/msgtxt.inc


+ 13 - 1
compiler/options.pas

@@ -40,7 +40,8 @@ Type
     ParaIncludePath,
     ParaIncludePath,
     ParaUnitPath,
     ParaUnitPath,
     ParaObjectPath,
     ParaObjectPath,
-    ParaLibraryPath : TSearchPathList;
+    ParaLibraryPath,
+    ParaFrameworkPath : TSearchPathList;
     ParaAlignment   : TAlignmentInfo;
     ParaAlignment   : TAlignmentInfo;
     Constructor Create;
     Constructor Create;
     Destructor Destroy;override;
     Destructor Destroy;override;
@@ -712,6 +713,14 @@ begin
                    SetRedirectFile(More);
                    SetRedirectFile(More);
                  'E' :
                  'E' :
                    OutputExeDir:=FixPath(More,true);
                    OutputExeDir:=FixPath(More,true);
+                 'f' :
+                     if (target_info.system in systems_darwin) then
+                       if ispara then
+                         ParaFrameworkPath.AddPath(More,false)
+                       else
+                         frameworksearchpath.AddPath(More,true)
+                     else
+                       IllegalPara(opt);
                  'i' :
                  'i' :
                    begin
                    begin
                      if ispara then
                      if ispara then
@@ -1886,6 +1895,7 @@ begin
   ParaObjectPath:=TSearchPathList.Create;
   ParaObjectPath:=TSearchPathList.Create;
   ParaUnitPath:=TSearchPathList.Create;
   ParaUnitPath:=TSearchPathList.Create;
   ParaLibraryPath:=TSearchPathList.Create;
   ParaLibraryPath:=TSearchPathList.Create;
+  ParaFrameworkPath:=TSearchPathList.Create;
   FillChar(ParaAlignment,sizeof(ParaAlignment),0);
   FillChar(ParaAlignment,sizeof(ParaAlignment),0);
 end;
 end;
 
 
@@ -1896,6 +1906,7 @@ begin
   ParaObjectPath.Free;
   ParaObjectPath.Free;
   ParaUnitPath.Free;
   ParaUnitPath.Free;
   ParaLibraryPath.Free;
   ParaLibraryPath.Free;
+  ParaFrameworkPath.Free;
 end;
 end;
 
 
 
 
@@ -2257,6 +2268,7 @@ begin
   ObjectSearchPath.AddList(option.ParaObjectPath,true);
   ObjectSearchPath.AddList(option.ParaObjectPath,true);
   IncludeSearchPath.AddList(option.ParaIncludePath,true);
   IncludeSearchPath.AddList(option.ParaIncludePath,true);
   LibrarySearchPath.AddList(option.ParaLibraryPath,true);
   LibrarySearchPath.AddList(option.ParaLibraryPath,true);
+  FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
 
 
   { add unit environment and exepath to the unit search path }
   { add unit environment and exepath to the unit search path }
   if inputfilepath<>'' then
   if inputfilepath<>'' then

+ 38 - 0
compiler/scandir.pas

@@ -389,6 +389,23 @@ implementation
         def_system_macro('FPU'+fputypestr[current_settings.fputype]);
         def_system_macro('FPU'+fputypestr[current_settings.fputype]);
      end;
      end;
 
 
+    procedure dir_frameworkpath;
+      begin
+        if not current_module.in_global then
+         Message(scan_w_switch_is_global)
+        else if not(target_info.system in systems_darwin) then
+          begin
+            Message(scan_w_frameworks_darwin_only);
+            current_scanner.skipspace;
+            current_scanner.readcomment
+          end
+        else
+          begin
+            current_scanner.skipspace;
+            current_module.localframeworksearchpath.AddPath(current_scanner.readcomment,false);
+          end;
+      end;
+
     procedure dir_goto;
     procedure dir_goto;
       begin
       begin
         do_moduleswitch(cs_support_goto);
         do_moduleswitch(cs_support_goto);
@@ -495,6 +512,25 @@ implementation
         current_module.linkotherofiles.add(s,link_always);
         current_module.linkotherofiles.add(s,link_always);
       end;
       end;
 
 
+    procedure dir_linkframework;
+      var
+        s : string;
+      begin
+        current_scanner.skipspace;
+        if scanner.c = '''' then
+          begin
+            s:= current_scanner.readquotedstring;
+            current_scanner.readcomment
+          end
+        else
+          s:= trimspace(current_scanner.readcomment);
+        s:=FixFileName(s);
+        if (target_info.system in systems_darwin) then
+          current_module.linkotherframeworks.add(s,link_always)
+        else
+          Message(scan_w_frameworks_darwin_only);
+      end;
+
     procedure dir_linklib;
     procedure dir_linklib;
       type
       type
         tLinkMode=(lm_shared,lm_static);
         tLinkMode=(lm_shared,lm_static);
@@ -1258,6 +1294,7 @@ implementation
         AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
         AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
         AddDirective('FATAL',directive_all, @dir_fatal);
         AddDirective('FATAL',directive_all, @dir_fatal);
         AddDirective('FPUTYPE',directive_all, @dir_fputype);
         AddDirective('FPUTYPE',directive_all, @dir_fputype);
+        AddDirective('FRAMEWORKPATH',directive_all, @dir_frameworkpath);
         AddDirective('GOTO',directive_all, @dir_goto);
         AddDirective('GOTO',directive_all, @dir_goto);
         AddDirective('HINT',directive_all, @dir_hint);
         AddDirective('HINT',directive_all, @dir_hint);
         AddDirective('HINTS',directive_all, @dir_hints);
         AddDirective('HINTS',directive_all, @dir_hints);
@@ -1273,6 +1310,7 @@ implementation
         AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
         AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
         AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
         AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
         AddDirective('LINK',directive_all, @dir_link);
         AddDirective('LINK',directive_all, @dir_link);
+        AddDirective('LINKFRAMEWORK',directive_all, @dir_linkframework);
         AddDirective('LINKLIB',directive_all, @dir_linklib);
         AddDirective('LINKLIB',directive_all, @dir_linklib);
         AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
         AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
         AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
         AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);

+ 22 - 0
compiler/systems/t_bsd.pas

@@ -397,6 +397,22 @@ begin
      HPath:=TCmdStrListItem(HPath.Next);
      HPath:=TCmdStrListItem(HPath.Next);
    end;
    end;
 
 
+  if (target_info.system in systems_darwin) then
+    begin
+      HPath:=TCmdStrListItem(current_module.localframeworksearchpath.First);
+      while assigned(HPath) do
+       begin
+         LinkRes.Add(maybequoted('-F'+HPath.Str));
+         HPath:=TCmdStrListItem(HPath.Next);
+       end;
+      HPath:=TCmdStrListItem(FrameworkSearchPath.First);
+      while assigned(HPath) do
+       begin
+         LinkRes.Add(maybequoted('-F'+HPath.Str));
+         HPath:=TCmdStrListItem(HPath.Next);
+       end;
+    end;
+
   if not LdSupportsNoResponseFile then
   if not LdSupportsNoResponseFile then
     LinkRes.Add('INPUT(');
     LinkRes.Add('INPUT(');
   { add objectfiles, start with prt0 always }
   { add objectfiles, start with prt0 always }
@@ -475,6 +491,12 @@ begin
      if not LdSupportsNoResponseFile then
      if not LdSupportsNoResponseFile then
        LinkRes.Add(')');
        LinkRes.Add(')');
    end;
    end;
+   
+  { frameworks for Darwin }
+  if IsDarwin then
+    while not FrameworkFiles.empty do
+      LinkRes.Add('-framework '+FrameworkFiles.GetFirst);
+     
   { objects which must be at the end }
   { objects which must be at the end }
   if linklibc and
   if linklibc and
      not IsDarwin Then
      not IsDarwin Then

+ 13 - 0
tests/test/tfwork1.pp

@@ -0,0 +1,13 @@
+{ %target=darwin }
+{ %cpu=i386,powerpc }
+
+{$linkframework Carbon}
+
+type
+  CFStringRef = pointer;
+
+function CFSTR( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString'; mwpascal;
+
+begin
+  CFSTR('hello');  
+end.

+ 16 - 0
tests/test/tfwork2.pp

@@ -0,0 +1,16 @@
+{ %target=linux,solaris,freebsd,win32 }
+{ %fail }
+{ %opt=-Sew }
+
+{ just some random non-darwin targets }
+
+{$linkframework Carbon}
+
+type
+  CFStringRef = pointer;
+
+function CFSTR( c: PChar ): CFStringRef; external name '___CFStringMakeConstantString'; mwpascal;
+
+begin
+  CFSTR('hello');  
+end.

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels