Преглед на файлове

* partial linklib change
I could not use Pavel's code because it broke the current way
linklib is used, which is messy :(
+ add postw32 call if external linking on win32

pierre преди 25 години
родител
ревизия
811f471334
променени са 3 файла, в които са добавени 93 реда и са изтрити 20 реда
  1. 19 9
      compiler/link.pas
  2. 36 6
      compiler/scandir.inc
  3. 38 5
      compiler/t_win32.pas

+ 19 - 9
compiler/link.pas

@@ -53,7 +53,7 @@ Type
        Destructor Done;
        Destructor Done;
        procedure AddModuleFiles(hp:pmodule);
        procedure AddModuleFiles(hp:pmodule);
        function  FindObjectFile(s : string) : string;
        function  FindObjectFile(s : string) : string;
-       function  FindLibraryFile(s:string;const ext:string) : string;
+       function  FindLibraryFile(s:string;const ext:string;var found : boolean) : string;
        Procedure AddObject(const S : String);
        Procedure AddObject(const S : String);
        Procedure AddStaticLibrary(const S : String);
        Procedure AddStaticLibrary(const S : String);
        Procedure AddSharedLibrary(S : String);
        Procedure AddSharedLibrary(S : String);
@@ -347,10 +347,9 @@ end;
 
 
 
 
 { searches an library file }
 { searches an library file }
-function TLinker.FindLibraryFile(s:string;const ext:string) : string;
-var
-  found : boolean;
+function TLinker.FindLibraryFile(s:string;const ext:string;var found : boolean) : string;
 begin
 begin
+  found:=false;
   findlibraryfile:='';
   findlibraryfile:='';
   if s='' then
   if s='' then
    exit;
    exit;
@@ -358,6 +357,7 @@ begin
    s:=s+ext;
    s:=s+ext;
   if FileExists(s) then
   if FileExists(s) then
    begin
    begin
+     found:=true;
      FindLibraryFile:=s;
      FindLibraryFile:=s;
      exit;
      exit;
    end;
    end;
@@ -374,8 +374,6 @@ begin
    findlibraryfile:=librarysearchpath.FindFile(s,found)+s;
    findlibraryfile:=librarysearchpath.FindFile(s,found)+s;
   if (not found) then
   if (not found) then
    findlibraryfile:=FindFile(s,exepath,found)+s;
    findlibraryfile:=FindFile(s,exepath,found)+s;
-  if not(cs_link_extern in aktglobalswitches) and (not found) then
-   Message1(exec_w_libfile_not_found,s);
 end;
 end;
 
 
 
 
@@ -399,8 +397,14 @@ end;
 
 
 
 
 Procedure TLinker.AddStaticLibrary(const S:String);
 Procedure TLinker.AddStaticLibrary(const S:String);
+var
+  ns : string;
+  found : boolean;
 begin
 begin
-  StaticLibFiles.Insert(FindLibraryFile(s,target_os.staticlibext));
+  ns:=FindLibraryFile(s,target_os.staticlibext,found);
+  if not(cs_link_extern in aktglobalswitches) and (not found) then
+   Message1(exec_w_libfile_not_found,s);
+  StaticLibFiles.Insert(ns);
 end;
 end;
 
 
 
 
@@ -563,7 +567,13 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.85  2000-02-28 17:23:57  daniel
+  Revision 1.86  2000-04-14 11:16:10  pierre
+    * partial linklib change
+      I could not use Pavel's code because it broke the current way
+      linklib is used, which is messy :(
+    + add postw32 call if external linking on win32
+
+  Revision 1.85  2000/02/28 17:23:57  daniel
   * Current work of symtable integration committed. The symtable can be
   * Current work of symtable integration committed. The symtable can be
     activated by defining 'newst', but doesn't compile yet. Changes in type
     activated by defining 'newst', but doesn't compile yet. Changes in type
     checking and oop are completed. What is left is to write a new
     checking and oop are completed. What is left is to write a new
@@ -651,4 +661,4 @@ end.
   Revision 1.62  1999/07/27 11:05:51  peter
   Revision 1.62  1999/07/27 11:05:51  peter
     * glibc 2.1.2 support
     * glibc 2.1.2 support
 
 
-}
+}

+ 36 - 6
compiler/scandir.inc

@@ -642,7 +642,7 @@ const
             if hs='FPCTARGET' then
             if hs='FPCTARGET' then
              hs:=target_cpu_string
              hs:=target_cpu_string
            else
            else
-            hs:=getenv(hs);
+             hs:=getenv(hs);
            if hs='' then
            if hs='' then
             Message1(scan_w_include_env_not_found,path);
             Message1(scan_w_include_env_not_found,path);
            { make it a stringconst }
            { make it a stringconst }
@@ -731,7 +731,7 @@ const
                 valint(pattern,minor,error);
                 valint(pattern,minor,error);
                 if error<>0 then
                 if error<>0 then
                   begin
                   begin
-                    Message(scan_w_wrong_version_ignored);
+                    Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
                     exit;
                     exit;
                   end;
                   end;
                 dllmajor:=major;
                 dllmajor:=major;
@@ -783,15 +783,39 @@ const
 
 
 
 
     procedure dir_linklib(t:tdirectivetoken);
     procedure dir_linklib(t:tdirectivetoken);
+      var
+        s : string;
+        quote : char;
       begin
       begin
         current_scanner^.skipspace;
         current_scanner^.skipspace;
-        current_scanner^.readstring;
+        { This way spaces are also allowed in library names
+          if quoted PM }
+        if (c='''') or (c='"') then
+          begin
+            quote:=c;
+            current_scanner^.readchar;
+            s:=current_scanner^.readcomment;
+            if pos(quote,s)>0 then
+              s:=copy(s,1,pos(quote,s)-1);
+          end
+        else
+          begin
+            current_scanner^.readstring;
+            s:=orgpattern;
+            if c='.' then
+              begin
+                s:=s+'.';
+                current_scanner^.readchar;
+                current_scanner^.readstring;
+                s:=s+orgpattern;
+              end;
+          end;
       {$IFDEF NEWST}
       {$IFDEF NEWST}
         current_module^.linkOtherSharedLibs.
         current_module^.linkOtherSharedLibs.
-         insert(new(Plinkitem,init(orgpattern,link_allways)));
+         insert(new(Plinkitem,init(s,link_allways)));
       {$ELSE}
       {$ELSE}
         current_module^.linkOtherSharedLibs.
         current_module^.linkOtherSharedLibs.
-         insert(orgpattern,link_allways);
+         insert(s,link_allways);
       {$ENDIF}
       {$ENDIF}
       end;
       end;
 
 
@@ -1308,7 +1332,13 @@ const
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.77  2000-04-08 20:18:53  michael
+  Revision 1.78  2000-04-14 11:16:10  pierre
+    * partial linklib change
+      I could not use Pavel's code because it broke the current way
+      linklib is used, which is messy :(
+    + add postw32 call if external linking on win32
+
+  Revision 1.77  2000/04/08 20:18:53  michael
   * Fixed bug in readcomment that was dropping * characters
   * Fixed bug in readcomment that was dropping * characters
 
 
   Revision 1.76  2000/02/28 17:23:57  daniel
   Revision 1.76  2000/02/28 17:23:57  daniel

+ 38 - 5
compiler/t_win32.pas

@@ -25,7 +25,8 @@ unit t_win32;
 
 
   interface
   interface
 
 
-  uses import,export,link;
+  uses
+    import,export,link;
 
 
   const
   const
      winstackpagesize = 4096;
      winstackpagesize = 4096;
@@ -612,6 +613,7 @@ unit t_win32;
                               TLINKERWIN32
                               TLINKERWIN32
 ****************************************************************************}
 ****************************************************************************}
 
 
+
 Constructor TLinkerWin32.Init;
 Constructor TLinkerWin32.Init;
 begin
 begin
   Inherited Init;
   Inherited Init;
@@ -651,8 +653,8 @@ Var
 {$ELSE}
 {$ELSE}
   HPath    : PStringQueueItem;
   HPath    : PStringQueueItem;
 {$ENDIF NEWST}
 {$ENDIF NEWST}
-  s        : string;
-  linklibc : boolean;
+  s,s2        : string;
+  found,linklibc : boolean;
 begin
 begin
   WriteResponseFile:=False;
   WriteResponseFile:=False;
 
 
@@ -708,6 +710,21 @@ begin
      While not SharedLibFiles.Empty do
      While not SharedLibFiles.Empty do
       begin
       begin
         S:=SharedLibFiles.Get;
         S:=SharedLibFiles.Get;
+        if pos('.',s)=0 then
+          { we never directly link a DLL
+            its allways through an import library PM }
+          { libraries created by C compilers have .a extensions }
+          s2:=s+'.a'{ target_os.sharedlibext }
+        else
+          s2:=s;
+        s2:=FindLibraryFile(s2,'',found);
+        if found then
+          begin
+            LinkRes.Add(s2);
+            continue;
+          end;
+        if pos(target_os.libprefix,s)=1 then
+          s:=copy(s,length(target_os.libprefix)+1,255);
         if s<>'c' then
         if s<>'c' then
          begin
          begin
            i:=Pos(target_os.sharedlibext,S);
            i:=Pos(target_os.sharedlibext,S);
@@ -976,6 +993,7 @@ type
   end;
   end;
 var
 var
   f : file;
   f : file;
+  cmdstr : string;
   dosheader : tdosheader;
   dosheader : tdosheader;
   peheader : tpeheader;
   peheader : tpeheader;
   firstsecpos,
   firstsecpos,
@@ -989,6 +1007,15 @@ begin
   { when -s is used or it's a dll then quit }
   { when -s is used or it's a dll then quit }
   if (cs_link_extern in aktglobalswitches) then
   if (cs_link_extern in aktglobalswitches) then
    begin
    begin
+     if apptype=at_gui then
+       cmdstr:='--subsystem gui'
+     else if apptype=at_cui then
+       cmdstr:='--subsystem console';
+     if dllversion<>'' then
+       cmdstr:=cmdstr+' --version '+dllversion;
+     cmdstr:=cmdstr+' --input '+fn;
+     cmdstr:=cmdstr+' --stack '+tostr(stacksize);
+     DoExec(FindUtil('postw32'),cmdstr,false,false);
      postprocessexecutable:=true;
      postprocessexecutable:=true;
      exit;
      exit;
    end;
    end;
@@ -1039,7 +1066,7 @@ begin
   maxfillsize:=0;
   maxfillsize:=0;
   firstsecpos:=0;
   firstsecpos:=0;
   secroot:=nil;
   secroot:=nil;
-  for l:=1to peheader.NumberOfSections do
+  for l:=1 to peheader.NumberOfSections do
    begin
    begin
      blockread(f,coffsec,sizeof(tcoffsechdr));
      blockread(f,coffsec,sizeof(tcoffsechdr));
      if coffsec.datapos>0 then
      if coffsec.datapos>0 then
@@ -1087,7 +1114,13 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.21  2000-03-10 09:14:40  pierre
+  Revision 1.22  2000-04-14 11:16:10  pierre
+    * partial linklib change
+      I could not use Pavel's code because it broke the current way
+      linklib is used, which is messy :(
+    + add postw32 call if external linking on win32
+
+  Revision 1.21  2000/03/10 09:14:40  pierre
    * dlltool is also needed if we use DefFile
    * dlltool is also needed if we use DefFile
 
 
   Revision 1.20  2000/02/28 17:23:57  daniel
   Revision 1.20  2000/02/28 17:23:57  daniel