From: DeaDDooMER Date: Tue, 4 Aug 2020 15:57:57 +0000 (+0300) Subject: cpmake: pass library list to build and link scripts X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=b97dcad79a88aa341f22ffce94a4b5c72ed857ea;p=cpc.git cpmake: pass library list to build and link scripts --- diff --git a/src/generic/Dsw/Mod/MakeMain.cp b/src/generic/Dsw/Mod/MakeMain.cp index acf9619..b88795d 100644 --- a/src/generic/Dsw/Mod/MakeMain.cp +++ b/src/generic/Dsw/Mod/MakeMain.cp @@ -37,6 +37,8 @@ MODULE DswMakeMain; debugJobs = FALSE; TYPE + Name = ARRAY 256 OF CHAR; + String = POINTER TO ARRAY OF CHAR; Selector = POINTER TO RECORD @@ -47,6 +49,7 @@ MODULE DswMakeMain; Module = POINTER TO RECORD name: DevCPT.Name; + library: DevCPT.Name; odc: Files.Name; depth: INTEGER; (* 0: leaf, MAX: root *) dir: DevCPM.Directory; @@ -56,6 +59,12 @@ MODULE DswMakeMain; worker: DswProcs.Process; END; + Library = POINTER TO RECORD + name: Name; + library: Name; + next: Library; + END; + VAR (* options *) auto, trap, clean, symonly, nocode1, nocode2: BOOLEAN; exe, target, base: String; @@ -67,6 +76,7 @@ MODULE DswMakeMain; modList, lnkList, cmpList: ARRAY maxImps OF Module; def: Selector; (* with head, global list of selectors *) dirList: DevCPM.Directory; + libList: Library; PROCEDURE Error (IN str, p0, p1: ARRAY OF CHAR; i2: INTEGER); VAR p2: ARRAY 32 OF CHAR; @@ -133,6 +143,49 @@ MODULE DswMakeMain; END END AddModule; + PROCEDURE AddLibrary (IN key, val: ARRAY OF CHAR); + VAR x: Library; + BEGIN + x := libList; + WHILE (x # NIL) & (x.name$ # key$) DO x := x.next END; + IF x # NIL THEN x.library := val$ + ELSE NEW(x); x.name := key$; x.library := val$; x.next := libList; libList := x + END + END AddLibrary; + + PROCEDURE AddLib (IN s: ARRAY OF CHAR); + VAR key, val: Name; i, j: INTEGER; + BEGIN + i := 0; j := 0; + WHILE (s[i] # 0X) & (s[i] # "=") DO + key[j] := s[i]; + INC(j); + INC(i) + END; + key[j] := 0X; + j := 0; + IF s[i] = "=" THEN + INC(i); + WHILE s[i] # 0X DO + val[j] := s[i]; + INC(j); + INC(i) + END + END; + val[j] := 0X; + IF key # "" THEN AddLibrary(key, val) + ELSE Error("empty library key", "", "", 0) + END + END AddLib; + + PROCEDURE FindLib (IN key: ARRAY OF CHAR): Library; + VAR x: Library; + BEGIN + x := libList; + WHILE (x # NIL) & (x.name$ # key$) DO x := x.next END; + RETURN x + END FindLib; + PROCEDURE StrToInt (IN s: ARRAY OF CHAR; def: INTEGER): INTEGER; VAR x, res: INTEGER; BEGIN @@ -161,6 +214,7 @@ MODULE DswMakeMain; Log.String(" -c Remove all generated files"); Log.Ln; Log.String(" -s Generate symbol files only"); Log.Ln; Log.String(" -d selector Add selector"); Log.Ln; + Log.String(" -r lib[=s] Replace library name on link stage"); Log.Ln; Log.String(" -t target Specify target rules"); Log.Ln; Log.String(" -o file Generate object file"); Log.Ln; Log.String(" -j num Specifies the number of jobs to run simultaneously"); Log.Ln; @@ -175,7 +229,7 @@ MODULE DswMakeMain; exe := NIL; auto := FALSE; jobs := 1; def.next := NIL; mno := 0; rno := 0; target := NewStr("default"); base := NewStr("cprules"); LOOP - CASE DswOpts.GetOpt("acbxd:sgGo:t:j:f:") OF + CASE DswOpts.GetOpt("acbxd:sgGo:t:j:f:r:h") OF | "a": auto := TRUE | "b": nocode1 := TRUE | "x": nocode2 := TRUE @@ -185,6 +239,7 @@ MODULE DswMakeMain; | "s": symonly := TRUE | "f": base := DswOpts.str | "d": Define(DswOpts.str, TRUE) + | "r": AddLib(DswOpts.str) | "h": Help | "j": jobs := MIN(MAX(StrToInt(DswOpts.str, 1), 1), maxJobs) | "o": exe := DswOpts.str @@ -287,7 +342,7 @@ MODULE DswMakeMain; IF sym = eql THEN DevCPS.Get(sym) ELSE INCL(DevCPM.options, DevCPM.noCode) END; - IF sym = string THEN INCL(m.flags, library); DevCPS.Get(sym) + IF sym = string THEN INCL(m.flags, library); m.library := DevCPS.str$; DevCPS.Get(sym) ELSE err(string) END; CheckSym(rbrak) @@ -523,8 +578,39 @@ MODULE DswMakeMain; RETURN ready END Ready; + PROCEDURE PrepareCompilerDeps (m: Module; p: DswProcs.Process; root, libsOnly: BOOLEAN); + VAR i: INTEGER; s: ARRAY 3 OF CHAR; lib: Library; + BEGIN + IF ~(trace IN m.flags) THEN + INCL(m.flags, trace); + FOR i := 0 TO m.mno - 1 DO + PrepareCompilerDeps(m.imp[i], p, FALSE, libsOnly) + END; + IF ~libsOnly OR (library IN m.flags) THEN + IF library IN m.flags THEN s := "-l" ELSE s := "-m" END; + IF root THEN s[1] := CAP(s[1]) END; + IF library IN m.flags THEN + lib := FindLib(m.library$); + IF lib # NIL THEN + IF lib.library$ # "" THEN + p.PutParam(s); + p.PutParam(lib.library$) + END + ELSE + p.PutParam(s); + p.PutParam(m.library$) + END + ELSE + p.PutParam(s); + p.PutParam(m.name$) + END + END; + EXCL(m.flags, trace) + END + END PrepareCompilerDeps; + PROCEDURE PrepareCompiler (m: Module): DswProcs.Process; - VAR p: DswProcs.Process; s: Selector; + VAR p: DswProcs.Process; s: Selector; i: INTEGER; BEGIN ASSERT(m # NIL, 20); ASSERT(m.odc # "", 21); @@ -542,6 +628,9 @@ MODULE DswMakeMain; p.PutParam(s.name$); s := s.next END; + FOR i := 0 TO m.mno - 1 DO + PrepareCompilerDeps(m.imp[i], p, TRUE, FALSE); + END; RETURN p END PrepareCompiler; @@ -608,6 +697,11 @@ MODULE DswMakeMain; p.PutParam(lnkList[i].name$) END END; + FOR i := 0 TO mno - 1 DO + IF library IN lnkList[i].flags THEN + PrepareCompilerDeps(lnkList[i], p, FALSE, TRUE) + END + END; p.Execute(ok); IF ok THEN p.Wait;