2
0
Эх сурвалжийг харах

* 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 жил өмнө
parent
commit
811f471334

+ 19 - 9
compiler/link.pas

@@ -53,7 +53,7 @@ Type
        Destructor Done;
        procedure AddModuleFiles(hp:pmodule);
        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 AddStaticLibrary(const S : String);
        Procedure AddSharedLibrary(S : String);
@@ -347,10 +347,9 @@ end;
 
 
 { 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
+  found:=false;
   findlibraryfile:='';
   if s='' then
    exit;
@@ -358,6 +357,7 @@ begin
    s:=s+ext;
   if FileExists(s) then
    begin
+     found:=true;
      FindLibraryFile:=s;
      exit;
    end;
@@ -374,8 +374,6 @@ begin
    findlibraryfile:=librarysearchpath.FindFile(s,found)+s;
   if (not found) then
    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;
 
 
@@ -399,8 +397,14 @@ end;
 
 
 Procedure TLinker.AddStaticLibrary(const S:String);
+var
+  ns : string;
+  found : boolean;
 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;
 
 
@@ -563,7 +567,13 @@ end;
 end.
 {
   $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
     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
@@ -651,4 +661,4 @@ end.
   Revision 1.62  1999/07/27 11:05:51  peter
     * glibc 2.1.2 support
 
-}
+}

+ 36 - 6
compiler/scandir.inc

@@ -642,7 +642,7 @@ const
             if hs='FPCTARGET' then
              hs:=target_cpu_string
            else
-            hs:=getenv(hs);
+             hs:=getenv(hs);
            if hs='' then
             Message1(scan_w_include_env_not_found,path);
            { make it a stringconst }
@@ -731,7 +731,7 @@ const
                 valint(pattern,minor,error);
                 if error<>0 then
                   begin
-                    Message(scan_w_wrong_version_ignored);
+                    Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
                     exit;
                   end;
                 dllmajor:=major;
@@ -783,15 +783,39 @@ const
 
 
     procedure dir_linklib(t:tdirectivetoken);
+      var
+        s : string;
+        quote : char;
       begin
         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}
         current_module^.linkOtherSharedLibs.
-         insert(new(Plinkitem,init(orgpattern,link_allways)));
+         insert(new(Plinkitem,init(s,link_allways)));
       {$ELSE}
         current_module^.linkOtherSharedLibs.
-         insert(orgpattern,link_allways);
+         insert(s,link_allways);
       {$ENDIF}
       end;
 
@@ -1308,7 +1332,13 @@ const
 
 {
   $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
 
   Revision 1.76  2000/02/28 17:23:57  daniel

+ 38 - 5
compiler/t_win32.pas

@@ -25,7 +25,8 @@ unit t_win32;
 
   interface
 
-  uses import,export,link;
+  uses
+    import,export,link;
 
   const
      winstackpagesize = 4096;
@@ -612,6 +613,7 @@ unit t_win32;
                               TLINKERWIN32
 ****************************************************************************}
 
+
 Constructor TLinkerWin32.Init;
 begin
   Inherited Init;
@@ -651,8 +653,8 @@ Var
 {$ELSE}
   HPath    : PStringQueueItem;
 {$ENDIF NEWST}
-  s        : string;
-  linklibc : boolean;
+  s,s2        : string;
+  found,linklibc : boolean;
 begin
   WriteResponseFile:=False;
 
@@ -708,6 +710,21 @@ begin
      While not SharedLibFiles.Empty do
       begin
         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
          begin
            i:=Pos(target_os.sharedlibext,S);
@@ -976,6 +993,7 @@ type
   end;
 var
   f : file;
+  cmdstr : string;
   dosheader : tdosheader;
   peheader : tpeheader;
   firstsecpos,
@@ -989,6 +1007,15 @@ begin
   { when -s is used or it's a dll then quit }
   if (cs_link_extern in aktglobalswitches) then
    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;
      exit;
    end;
@@ -1039,7 +1066,7 @@ begin
   maxfillsize:=0;
   firstsecpos:=0;
   secroot:=nil;
-  for l:=1to peheader.NumberOfSections do
+  for l:=1 to peheader.NumberOfSections do
    begin
      blockread(f,coffsec,sizeof(tcoffsechdr));
      if coffsec.datapos>0 then
@@ -1087,7 +1114,13 @@ end;
 end.
 {
   $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
 
   Revision 1.20  2000/02/28 17:23:57  daniel