Преглед изворни кода

+ 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 година
родитељ
комит
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/tfpu5.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/tgeneric10.pp svneol=native#text/plain
 tests/test/tgeneric11.pp svneol=native#text/plain

+ 10 - 2
compiler/fmodule.pas

@@ -142,7 +142,8 @@ interface
         linkunitsharedlibs,
         linkotherofiles,           { objects,libs loaded from the source }
         linkothersharedlibs,       { using $L or $LINKLIB or import lib (for linux) }
-        linkotherstaticlibs  : tlinkcontainer;
+        linkotherstaticlibs,
+        linkotherframeworks  : tlinkcontainer;
 
         used_units           : tlinkedlist;
         dependent_units      : tlinkedlist;
@@ -150,7 +151,8 @@ interface
         localunitsearchpath,           { local searchpaths }
         localobjectsearchpath,
         localincludesearchpath,
-        locallibrarysearchpath : TSearchPathList;
+        locallibrarysearchpath,
+        localframeworksearchpath : TSearchPathList;
 
         {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
@@ -433,6 +435,7 @@ implementation
         localobjectsearchpath:=TSearchPathList.Create;
         localincludesearchpath:=TSearchPathList.Create;
         locallibrarysearchpath:=TSearchPathList.Create;
+        localframeworksearchpath:=TSearchPathList.Create;
         used_units:=TLinkedList.Create;
         dependent_units:=TLinkedList.Create;
         resourcefiles:=TCmdStrList.Create;
@@ -442,6 +445,7 @@ implementation
         linkotherofiles:=TLinkContainer.Create;
         linkotherstaticlibs:=TLinkContainer.Create;
         linkothersharedlibs:=TLinkContainer.Create;
+        linkotherframeworks:=TLinkContainer.Create;
         FImportLibraryList:=TFPHashObjectList.Create(true);
         crc:=0;
         interface_crc:=0;
@@ -533,6 +537,7 @@ implementation
         linkotherofiles.Free;
         linkotherstaticlibs.Free;
         linkothersharedlibs.Free;
+        linkotherframeworks.Free;
         FImportLibraryList.Free;
         stringdispose(objfilename);
         stringdispose(asmfilename);
@@ -550,6 +555,7 @@ implementation
         localobjectsearchpath.free;
         localincludesearchpath.free;
         locallibrarysearchpath.free;
+        localframeworksearchpath.free;
 {$ifdef MEMDEBUG}
         memsymtable.start;
 {$endif}
@@ -672,6 +678,8 @@ implementation
         linkotherstaticlibs:=TLinkContainer.Create;
         linkothersharedlibs.Free;
         linkothersharedlibs:=TLinkContainer.Create;
+        linkotherframeworks.Free;
+        linkotherframeworks:=TLinkContainer.Create;
         FImportLibraryList.Free;
         FImportLibraryList:=TFPHashObjectList.Create;
         do_compile:=false;

+ 4 - 1
compiler/globals.pas

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

+ 16 - 1
compiler/link.pas

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

+ 4 - 1
compiler/msg/errore.msg

@@ -125,7 +125,7 @@ general_i_number_of_notes=01023_I_$1 note(s) issued
 #
 # Scanner
 #
-# 02063 is the last used one
+# 02084 is the last used one
 #
 % \section{Scanner messages.}
 % 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.
 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.
+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}
 #
 # Parser
@@ -2522,6 +2524,7 @@ S*2Aas_assemble using GNU AS
 **2FC<x>_sets RC compiler binary name to <x>
 **2FD<x>_sets the directory where to search for compiler utilities
 **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>
 **2Fi<x>_adds <x> to include path
 **2Fl<x>_adds <x> to library path

+ 3 - 2
compiler/msgidx.inc

@@ -103,6 +103,7 @@ const
   scan_e_only_packset=02080;
   scan_w_pic_ignored=02081;
   scan_w_unsupported_switch_by_target=02082;
+  scan_w_frameworks_darwin_only=02084;
   parser_e_syntax_error=03000;
   parser_e_dont_nest_interrupt=03004;
   parser_w_proc_directive_ignored=03005;
@@ -729,9 +730,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 43827;
+  MsgTxtSize = 43950;
 
   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
   );

Разлика између датотеке није приказан због своје велике величине
+ 296 - 297
compiler/msgtxt.inc


+ 13 - 1
compiler/options.pas

@@ -40,7 +40,8 @@ Type
     ParaIncludePath,
     ParaUnitPath,
     ParaObjectPath,
-    ParaLibraryPath : TSearchPathList;
+    ParaLibraryPath,
+    ParaFrameworkPath : TSearchPathList;
     ParaAlignment   : TAlignmentInfo;
     Constructor Create;
     Destructor Destroy;override;
@@ -712,6 +713,14 @@ begin
                    SetRedirectFile(More);
                  'E' :
                    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' :
                    begin
                      if ispara then
@@ -1886,6 +1895,7 @@ begin
   ParaObjectPath:=TSearchPathList.Create;
   ParaUnitPath:=TSearchPathList.Create;
   ParaLibraryPath:=TSearchPathList.Create;
+  ParaFrameworkPath:=TSearchPathList.Create;
   FillChar(ParaAlignment,sizeof(ParaAlignment),0);
 end;
 
@@ -1896,6 +1906,7 @@ begin
   ParaObjectPath.Free;
   ParaUnitPath.Free;
   ParaLibraryPath.Free;
+  ParaFrameworkPath.Free;
 end;
 
 
@@ -2257,6 +2268,7 @@ begin
   ObjectSearchPath.AddList(option.ParaObjectPath,true);
   IncludeSearchPath.AddList(option.ParaIncludePath,true);
   LibrarySearchPath.AddList(option.ParaLibraryPath,true);
+  FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
 
   { add unit environment and exepath to the unit search path }
   if inputfilepath<>'' then

+ 38 - 0
compiler/scandir.pas

@@ -389,6 +389,23 @@ implementation
         def_system_macro('FPU'+fputypestr[current_settings.fputype]);
      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;
       begin
         do_moduleswitch(cs_support_goto);
@@ -495,6 +512,25 @@ implementation
         current_module.linkotherofiles.add(s,link_always);
       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;
       type
         tLinkMode=(lm_shared,lm_static);
@@ -1258,6 +1294,7 @@ implementation
         AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
         AddDirective('FATAL',directive_all, @dir_fatal);
         AddDirective('FPUTYPE',directive_all, @dir_fputype);
+        AddDirective('FRAMEWORKPATH',directive_all, @dir_frameworkpath);
         AddDirective('GOTO',directive_all, @dir_goto);
         AddDirective('HINT',directive_all, @dir_hint);
         AddDirective('HINTS',directive_all, @dir_hints);
@@ -1273,6 +1310,7 @@ implementation
         AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
         AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
         AddDirective('LINK',directive_all, @dir_link);
+        AddDirective('LINKFRAMEWORK',directive_all, @dir_linkframework);
         AddDirective('LINKLIB',directive_all, @dir_linklib);
         AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
         AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);

+ 22 - 0
compiler/systems/t_bsd.pas

@@ -397,6 +397,22 @@ begin
      HPath:=TCmdStrListItem(HPath.Next);
    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
     LinkRes.Add('INPUT(');
   { add objectfiles, start with prt0 always }
@@ -475,6 +491,12 @@ begin
      if not LdSupportsNoResponseFile then
        LinkRes.Add(')');
    end;
+   
+  { frameworks for Darwin }
+  if IsDarwin then
+    while not FrameworkFiles.empty do
+      LinkRes.Add('-framework '+FrameworkFiles.GetFirst);
+     
   { objects which must be at the end }
   if linklibc and
      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.

Неке датотеке нису приказане због велике количине промена