[M3devel] host vs. target naming?

Jay jayk123 at hotmail.com
Mon Mar 17 09:32:38 CET 2008


host vs. target naming
 
I think this stuff is mildly messed up.Currently slashes and foo.lib vs. libfoo.a "go together".
I contend that this is suspicous.
The "slash" character is pretty much always related to the host.If a cross build stops at some point and gets copied from one machineto another and resumed, and the slash character changes en route,that is interesting. However, in this case, I think the pathswritten to .m3ship etc. should probably be host and target-independent.Either use arrays of path elements, or declare that one or the otheror both slash characters are the "abstract" representation, and convertas needed at runtime. Or, just always use a forward slash. They always work.But avoid presenting to them to the Win32 user.
The "naming" conventions: kernel32.lib vs. libkernel32.a  foo.exe vs. foo  foo.dll vs. foo.so 
The last two are strictly a function of target.A Linux-hosted NT386-targeted config should write foo.exe and foo.dll. Never (by default) foo and foo.so.
A NT386-hosted Linux-targeted config should write foo and foo.so. Never (by default) foo.exe and foo.dll.
The first is a function of toolset, and tendencies go both ways I think.I think mainly they go with the host. That is..almost none of this stuffvaries in any build, but in one example I have, NT386 targeting NT386GNU,the cm3 "host" is sort of "cross", but the backend is really "native",and the files are libkernel32.a, etc.
I suggest that in M3Path.m3, Prefix and Suffix always be indexed by "target" (i.e. FALSE).Directory and volume separator code unchanged.
Something like the following, which also switches NT386GNU to Unix naming conventions.
Probably Target.m3 should hardcode the target naming conventions, andthe value be exposed perhaps to Quake (for the likes of my NT386.common). That is not done here.Using something other than numbers might be good too -- "Unix", "GrumpyUnix", "Win32".
 Index: src/Builder.m3===================================================================RCS file: /usr/cvs/cm3/m3-sys/cm3/src/Builder.m3,vretrieving revision 1.18diff -c -r1.18 Builder.m3*** src/Builder.m3 24 Feb 2008 16:36:44 -0000 1.18--- src/Builder.m3 17 Mar 2008 08:11:01 -0000****************** 12,17 ****--- 12,18 ----  IMPORT Msg, Arg, Utils, M3Path, M3Backend, M3Compiler;  IMPORT Quake, QMachine, QValue, QVal, QVSeq;  IMPORT M3Loc, M3Unit, M3Options, MxConfig AS M3Config;+ IMPORT QIdent;  FROM Target IMPORT M3BackendMode_t, BackendAssembly;    TYPE****************** 101,108 ****      main          : M3ID.T;             (* "Main" *)      m3env         : Env;                (* the compiler's environment closure *)      target        : TEXT;               (* target machine *)!     host_os       : M3Path.OSKind;      (* host system *)!     target_os     : M3Path.OSKind;      (* target os *)      m3backend_mode: M3BackendMode_t;    (* tells how to turn M3CG -> object *)      m3backend     : ConfigProc;         (* translate M3CG -> ASM or OBJ *)      c_compiler    : ConfigProc;         (* compile C code *)--- 102,108 ----      main          : M3ID.T;             (* "Main" *)      m3env         : Env;                (* the compiler's environment closure *)      target        : TEXT;               (* target machine *)!     target_os    := M3Path.OSKind.Unix; (* target os *)      m3backend_mode: M3BackendMode_t;    (* tells how to turn M3CG -> object *)      m3backend     : ConfigProc;         (* translate M3CG -> ASM or OBJ *)      c_compiler    : ConfigProc;         (* compile C code *)****************** 139,153 ****    END;    PROCEDURE SetupNamingConventionsInternal (VAR s : State; mach : Quake.Machine) =    BEGIN      s.machine       := mach;!     s.host_os := GetOSType (s, "NAMING_CONVENTIONS");!     IF (GetDefn (s, "TARGET_NAMING") = NIL)!       THEN s.target_os := s.host_os;!       ELSE s.target_os := GetOSType (s, "TARGET_NAMING");      END;!     M3Path.SetOS (s.host_os, host := TRUE);!     M3Path.SetOS (s.target_os, host := FALSE);    END SetupNamingConventionsInternal;    PROCEDURE SetupNamingConventions (mach : Quake.Machine) =--- 139,166 ----    END;    PROCEDURE SetupNamingConventionsInternal (VAR s : State; mach : Quake.Machine) =+   VAR+     value : QValue.Binding;    BEGIN      s.machine       := mach;! !     value := GetDefn (s, "NAMING_CONVENTIONS");!     IF value # NIL THEN!       WITH host_os = GetOSType (s, value) DO!         s.target_os := host_os;!         M3Path.SetOS (host_os, host := TRUE);!         M3Path.SetOS (host_os, host := FALSE);!       END;!     END;! !     value := GetDefn (s, "TARGET_NAMING");!     IF value # NIL THEN!       WITH target_os = GetOSType (s, value) DO!         s.target_os := target_os;!         M3Path.SetOS (target_os, host := FALSE);!       END;      END;!     END SetupNamingConventionsInternal;    PROCEDURE SetupNamingConventions (mach : Quake.Machine) =****************** 230,261 ****      RETURN s;    END CompileUnits;  ! PROCEDURE GetOSType (s: State;  sym: TEXT): M3Path.OSKind =!   VAR val := GetConfigItem (s, sym);    BEGIN!     IF    Text.Equal (val, "0")   THEN RETURN M3Path.OSKind.Unix;!     ELSIF Text.Equal (val, "1")   THEN RETURN M3Path.OSKind.GrumpyUnix;!     ELSIF Text.Equal (val, "2")   THEN RETURN M3Path.OSKind.Win32;      END;!     ConfigErr (s, sym, "unrecognized naming convention: " & val);      RETURN M3Path.OSKind.Unix;    END GetOSType;  ! PROCEDURE GetConfigItem (s: State;  symbol: TEXT; default: TEXT := NIL): TEXT =!   VAR bind := GetDefn (s, symbol);    BEGIN      IF bind = NIL THEN        IF default # NIL THEN          RETURN default;        END;      END;-     IF (bind = NIL) THEN ConfigErr (s, symbol, "not defined"); END;      TRY        RETURN QVal.ToText (s.machine, bind.value);      EXCEPT Quake.Error (msg) =>!       ConfigErr (s, symbol, msg);      END;      RETURN NIL;    END GetConfigItem;    PROCEDURE GetConfigProc (s: State;  symbol: TEXT;--- 243,282 ----      RETURN s;    END CompileUnits;  ! PROCEDURE GetOSType (s: State; bind: QValue.Binding): M3Path.OSKind =!   VAR val := BindingToText (s, bind);    BEGIN!     IF Text.Length (val) = 1 THEN!       CASE (Text.GetChar (val, 0)) OF!         | '0' => RETURN M3Path.OSKind.Unix;!         | '1' => RETURN M3Path.OSKind.GrumpyUnix;!         | '2' => RETURN M3Path.OSKind.Win32;!         ELSE!       END;      END;!     ConfigErr (s, s.machine.map.id2txt(bind.name), "unrecognized naming convention: " & val);      RETURN M3Path.OSKind.Unix;    END GetOSType;  ! PROCEDURE BindingToText (s: State; bind: QValue.Binding; default: TEXT := NIL): TEXT =    BEGIN      IF bind = NIL THEN        IF default # NIL THEN          RETURN default;        END;+       ConfigErr (s, s.machine.map.id2txt(bind.name), "not defined");      END;      TRY        RETURN QVal.ToText (s.machine, bind.value);      EXCEPT Quake.Error (msg) =>!       ConfigErr (s, s.machine.map.id2txt(bind.name), msg);      END;      RETURN NIL;+   END BindingToText;+ + PROCEDURE GetConfigItem (s: State;  symbol: TEXT; default: TEXT := NIL): TEXT =+   BEGIN+     RETURN BindingToText (s, GetDefn (s, symbol), default);    END GetConfigItem;    PROCEDURE GetConfigProc (s: State;  symbol: TEXT;Index: src/M3Path.i3===================================================================RCS file: /usr/cvs/cm3/m3-sys/cm3/src/M3Path.i3,vretrieving revision 1.2diff -c -r1.2 M3Path.i3*** src/M3Path.i3 18 Feb 2008 03:53:19 -0000 1.2--- src/M3Path.i3 17 Mar 2008 08:11:02 -0000****************** 14,20 ****    END;    VAR (* possibly changed at initialization and then CONST *)-   SlashChar := '/';    SlashText := "/";    TYPE--- 14,19 ----Index: src/M3Path.m3===================================================================RCS file: /usr/cvs/cm3/m3-sys/cm3/src/M3Path.m3,vretrieving revision 1.28diff -c -r1.28 M3Path.m3*** src/M3Path.m3 25 Feb 2008 18:31:18 -0000 1.28--- src/M3Path.m3 17 Mar 2008 08:11:02 -0000****************** 9,15 ****    MODULE M3Path;  ! IMPORT Pathname, Text, Env;  IMPORT RTIO, Process;    CONST--- 9,15 ----    MODULE M3Path;  ! IMPORT Pathname, Text;  IMPORT RTIO, Process;    CONST****************** 114,124 ****    PROCEDURE Join (dir, base: TEXT;  k: Kind;  host: BOOLEAN): TEXT =    VAR!     os       := os_map [host];!     pre      := Prefix [os][k];!     ext      := Suffix [os][k];!     d_sep    := DirSep [os];!     v_sep    := VolSep [os];      ch       : CHAR;      buf      : ARRAY [0..255] OF CHAR;      dir_len  := 0;--- 114,125 ----    PROCEDURE Join (dir, base: TEXT;  k: Kind;  host: BOOLEAN): TEXT =    VAR!     host_os  := os_map [host];!     target_os := os_map [FALSE];!     pre      := Prefix [target_os][k];!     ext      := Suffix [target_os][k];!     d_sep    := DirSep [host_os];!     v_sep    := VolSep [host_os];      ch       : CHAR;      buf      : ARRAY [0..255] OF CHAR;      dir_len  := 0;****************** 191,199 ****      d_index := -1;      v_index := -1;      start   := 0;!     os      := os_map [host];!     d_sep   := DirSep [os];!     v_sep   := VolSep [os];      ext     : TEXT;      ext_len : INTEGER;      pre     : TEXT;--- 192,201 ----      d_index := -1;      v_index := -1;      start   := 0;!     host_os := os_map [host];!     target_os := os_map [FALSE];!     d_sep   := DirSep [host_os];!     v_sep   := VolSep [host_os];      ext     : TEXT;      ext_len : INTEGER;      pre     : TEXT;****************** 222,228 ****        t.dir := Text.FromChars (SUBARRAY (nm, 0, v_index+1));        start := v_index + 1;      ELSIF (d_index = 0) THEN!       t.dir := DirSepText [os];        start := 1;      ELSE        t.dir := Text.FromChars (SUBARRAY (nm, 0, d_index));--- 224,230 ----        t.dir := Text.FromChars (SUBARRAY (nm, 0, v_index+1));        start := v_index + 1;      ELSIF (d_index = 0) THEN!       t.dir := DirSepText [host_os];        start := 1;      ELSE        t.dir := Text.FromChars (SUBARRAY (nm, 0, d_index));****************** 234,241 ****      t.kind := Kind.Unknown;      ext_len := 0;      FOR k := FIRST (Kind) TO LAST (Kind) DO!       ext := Suffix [os][k];!       IF ExtMatch (nm_txt, ext, os) THEN          ext_len := Text.Length (ext);          t.kind := k;          EXIT;--- 236,243 ----      t.kind := Kind.Unknown;      ext_len := 0;      FOR k := FIRST (Kind) TO LAST (Kind) DO!       ext := Suffix [target_os][k];!       IF ExtMatch (nm_txt, ext, host_os) THEN          ext_len := Text.Length (ext);          t.kind := k;          EXIT;****************** 245,252 ****      (* extract the base component *)      t.base := Text.FromChars (SUBARRAY (nm, start, base_len - ext_len));  !     pre := Prefix[os][t.kind];!     IF (Text.Length (pre) > 0) AND PrefixMatch (t.base, pre, os) THEN        t.base := Text.Sub (t.base, Text.Length (pre));      END;  --- 247,254 ----      (* extract the base component *)      t.base := Text.FromChars (SUBARRAY (nm, start, base_len - ext_len));  !     pre := Prefix[target_os][t.kind];!     IF (Text.Length (pre) > 0) AND PrefixMatch (t.base, pre, host_os) THEN        t.base := Text.Sub (t.base, Text.Length (pre));      END;  ****************** 321,337 ****--- 323,343 ----    PROCEDURE DefaultProgram (host: BOOLEAN): TEXT =    BEGIN+     host := FALSE;      RETURN Default_pgm [os_map [host]];    END DefaultProgram;    PROCEDURE ProgramName (base: TEXT;  host: BOOLEAN): TEXT =    BEGIN+     host := FALSE;      RETURN base & Suffix[os_map [host]][Kind.PGM];    END ProgramName;    PROCEDURE LibraryName (base: TEXT;  host: BOOLEAN): TEXT =    VAR os := os_map [host];    BEGIN+     host := FALSE;+     os := os_map [host];      RETURN Prefix[os][Kind.LIB] & base & Suffix[os][Kind.LIB];    END LibraryName;  ****************** 764,786 ****      lcase[i] := VAL (ORD (i) - ORD ('A') + ORD ('a'), CHAR);    END;  !  (* OSKind is determined from "naming conventions"!     which are mostly about foo.lib vs. libfoo.a, foo.dll vs. libfoo.so, foo vs. foo.exe.!     "Naming conventions" also determines the slash, however NT386GNU uses!     Win32 "naming conventions" (currently) but forward slashes. In reality,!     forward slashes work almost anywhere, but at this time we are not pushing!     through the change to use forward slashes more on regular NT386.!     What we do here is probe our runtime for its slash as was already being!     done to set the Quake SL variable, but applying the result to more code.! !     In general this run-time/compile-time determinations probably need better abstraction.!     At least in other places, where the way time works is used to determine if the runtime is Unix.!     In this case, the slash could be fed in at build time, or set in Quake, however!     how to get his data from Quake efficiently (and early enough?), is to be determined.    *)    IF Text.GetChar (Pathname.Join ("a", "b"), 1) = BackSlash THEN  -     SlashChar := BackSlash;      SlashText := "\\";      os_map [TRUE]  := OSKind.Win32;      os_map [FALSE] := OSKind.Win32;--- 770,780 ----      lcase[i] := VAL (ORD (i) - ORD ('A') + ORD ('a'), CHAR);    END;  !  (* Probe the host for what slash it uses, and default host and!     target "naming conventions" based on that.    *)    IF Text.GetChar (Pathname.Join ("a", "b"), 1) = BackSlash THEN        SlashText := "\\";      os_map [TRUE]  := OSKind.Win32;      os_map [FALSE] := OSKind.Win32;****************** 789,809 ****        lcase [Slash] := BackSlash;  -   ELSE- -     WITH OS = Env.Get("OS") DO-       IF OS # NIL AND Text.Equal (OS, "Windows_NT") THEN- -         (* NT386GNU uses foo.lib instead of libfoo.a (at least for now), and forward slashes. *)- -         os_map [TRUE]  := OSKind.Win32;-         os_map [FALSE] := OSKind.Win32;-         DirSep [OSKind.Win32] := DirSep [OSKind.Unix]; (* Slash *)-         DirSepText [OSKind.Win32] := DirSepText [OSKind.Unix]; (* "//" *)-         VolSep [OSKind.Win32] := VolSep [OSKind.Unix]; (* Null *)- -      END;-     END;    END;      (* Test (); *)--- 783,788 ----
 - Jay 
_________________________________________________________________
Need to know the score, the latest news, or you need your Hotmail®-get your "fix".
http://www.msnmobilefix.com/Default.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080317/e8b6311e/attachment-0001.html>


More information about the M3devel mailing list