MODULE DswMakeMain; IMPORT Kernel, Files, Log, Strings, DswOpts, DswProcs, DswDocuments, DevCPM, DevCPT, DevCPR, DevCPS; CONST version = "0.3"; modDir = "Mod"; sysDir = "System"; maxImps = 127; maxJobs = maxImps; (* symbol values *) null = 0; times = 1; slash = 2; div = 3; mod = 4; and = 5; plus = 6; minus = 7; or = 8; eql = 9; neq = 10; lss = 11; leq = 12; gtr = 13; geq = 14; in = 15; is = 16; arrow = 17; dollar = 18; period = 19; comma = 20; colon = 21; upto = 22; rparen = 23; rbrak = 24; rbrace = 25; of = 26; then = 27; do = 28; to = 29; by = 30; not = 33; lparen = 40; lbrak = 41; lbrace = 42; becomes = 44; number = 45; nil = 46; string = 47; ident = 48; semicolon = 49; bar = 50; end = 51; else = 52; elsif = 53; until = 54; if = 55; case = 56; while = 57; repeat = 58; for = 59; loop = 60; with = 61; exit = 62; return = 63; array = 64; record = 65; pointer = 66; begin = 67; const = 68; type = 69; var = 70; out = 71; procedure = 72; close = 73; import = 74; module = 75; eof = 76; (* module state flags *) imported = 0; trace = 1; hasObj = 2; hasSym = 3; hasErrors = 4; library = 5; (* procesor types *) anymach = 0; cmach = 1; mach386 = 10; mach68k = 20; (* operation system types *) anyos = 0; linux = 1; freebsd = 2; openbsd = 3; win32 = 4; cygwin = 5; darwin = 6; (* compiler types *) anycp = 0; cpnative = 1; cpfront = 2; (* internal linker types *) anyint = 0; dev2 = 1; debugImport = FALSE; debugOrder = FALSE; debugJobs = FALSE; debugArgs = FALSE; TYPE String = POINTER TO ARRAY OF CHAR; StringList = POINTER TO ARRAY OF String; Selector = POINTER TO RECORD name: DevCPT.Name; value: BOOLEAN; next: Selector END; Module = POINTER TO RECORD name: DevCPT.Name; odc: Files.Name; depth: INTEGER; (* 0: leaf, MAX: root *) dir: DevCPM.Directory; mno: INTEGER; imp: ARRAY maxImps OF Module; flags: SET; worker: DswProcs.Process; END; VAR werr, err: INTEGER; mno, rno: INTEGER; (* num modules *) modList, lnkList, cmpList: ARRAY maxImps OF Module; def: Selector; (* with head, global list of selectors *) processor, compiler, os, linker: INTEGER; cpcExe, cplExe: String; cpcArgs, cplArgs: StringList; dirList: DevCPM.Directory; auto: BOOLEAN; trap: BOOLEAN; jobs: INTEGER; exe: String; printCompileModList: BOOLEAN; printLinkModList: BOOLEAN; printCompileFileList: BOOLEAN; PROCEDURE Error (e: INTEGER; IN p0, p1: ARRAY OF CHAR; i2: INTEGER); VAR msg, p2: ARRAY 128 OF CHAR; BEGIN CASE e OF | 0: msg := "option -D expect + or - after identifier" | 1: msg := "option -D expect identifier" | 2: msg := "option -U expect identifier" (* rm *) | 3: msg := "invalid module name" | 4: msg := "invalid integer value" | 5: msg := "unterminated string" | 6: msg := "unknown processor ^0" | 7: msg := "unknown os ^0" | 8: msg := "unknown compiler ^0" | 9: msg := "unknown linker ^0" | 10: msg := "missing argument for option ^0" | 11: msg := "unknown option ^0" | 12: msg := "compiler not selected (use option -g)" | 13: msg := "processor not selected (use option -m)" | 14: msg := "selected processor not supported by native compiler" | 15: msg := "internal linker not required for cpfront" | 16: msg := "cpfront can't produce executable file" | 17: msg := "linker not selected (use option -i)" | 18: msg := "os not selected (use option -s)" | 19: msg := "specified empty file name" | 20: msg := "recursive import of ^0 in ^1" | 21: msg := "unable to open module ^1" | 22: msg := "linker terminated with code ^2" | 23: msg := "unable to execute linker" | 24: msg := "trap occured" | 25: msg := "compiler not installed (use option -Xg to select executable)" | 26: msg := "linker not installed (use option -Xi to select executable)" ELSE Strings.IntToString(err, msg) END; Strings.IntToString(i2, p2); Log.String(Kernel.argv[0]$); Log.String(": "); Log.ParamMsg(msg, p0, p1, p2); Log.Ln; INC(err); IF trap THEN HALT(100) END END Error; (* --------- options --------- *) PROCEDURE IdentLen (IN s: ARRAY OF CHAR): INTEGER; VAR i: INTEGER; BEGIN i := 0; IF Strings.IsIdentStart(s[0]) THEN REPEAT INC(i) UNTIL ~Strings.IsIdent(s[i]) END; RETURN i END IdentLen; PROCEDURE Define (n: ARRAY OF CHAR; overwrite: BOOLEAN); VAR i: INTEGER; v: BOOLEAN; s: Selector; BEGIN i := IdentLen(n); IF i # 0 THEN IF ~((n[i] = 0X) OR (((n[i] = "+") OR (n[i] = "-")) & (n[i + 1] = 0X))) THEN Error(0, "", "", 0) END; v := n[i] # "-"; n[i] := 0X; s := def; WHILE (s.next # NIL) & (s.next.name$ # n$) DO s := s.next END; IF s.next = NIL THEN NEW(s.next); Strings.StringToUtf8(n, s.next.name, i); ASSERT(i = 0); s.next.value := v ELSIF overwrite THEN s.next.value := v END ELSE Error(1, "", "", 0) END END Define; PROCEDURE AddModule (IN n: ARRAY OF CHAR; selectors: Selector; dir: DevCPM.Directory); VAR i, res: INTEGER; m: Module; BEGIN i := IdentLen(n); IF (i # 0) & (n[i] = 0X) THEN i := 0; WHILE (i < mno) & (modList[i].name$ # n$) DO INC(i) END; IF i >= mno THEN NEW(m); Strings.StringToUtf8(n, m.name, res); ASSERT(res = 0); m.dir := dir; modList[i] := m; INC(mno) END ELSE Error(3, "", "", 0) END END AddModule; PROCEDURE StrToInt (IN s: ARRAY OF CHAR; def: INTEGER): INTEGER; VAR x, res: INTEGER; BEGIN Strings.StringToInt(s, x, res); IF res # 0 THEN Error(4, s, "", 0); x := def END; RETURN x END StrToInt; PROCEDURE NewStr (IN s: ARRAY OF CHAR): String; VAR p: String; BEGIN NEW(p, LEN(s$) + 1); p^ := s$; RETURN p END NewStr; PROCEDURE ToStringList (IN s: ARRAY OF CHAR): StringList; VAR i: INTEGER; ch, term: CHAR; pars: StringList; PROCEDURE AddChar (c: CHAR); VAR i, n, len: INTEGER; str: String; BEGIN IF pars = NIL THEN NEW(pars, 1); NEW(pars[0], 2); pars[0, 0] := c ELSE n := LEN(pars) - 1; len := LEN(pars[n]$); NEW(str, len + 2); FOR i := 0 TO len - 1 DO str[i] := pars[n, i] END; str[i] := c; pars[n] := str END END AddChar; PROCEDURE AddLine; VAR i, len: INTEGER; p: StringList; BEGIN IF pars = NIL THEN NEW(pars, 1); i := 0; ELSE len := LEN(pars); NEW(p, len + 1); FOR i := 0 TO len - 1 DO p[i] := pars[i] END; pars := p END; NEW(pars[i], 1) END AddLine; BEGIN i := 0; REPEAT ch := s[i]; INC(i) UNTIL ch # " "; WHILE ch # 0X DO CASE ch OF | '"', "'": term := ch; ch := s[i]; INC(i); WHILE (ch # term) & (ch # 0X) DO AddChar(ch); ch := s[i]; INC(i) END; IF ch # 0X THEN ch := s[i]; INC(i) ELSE Error(5, "", "", 0) END | " ": REPEAT ch := s[i]; INC(i) UNTIL ch # " "; IF ch # 0X THEN AddLine END ELSE AddChar(ch); ch := s[i]; INC(i) END END; RETURN pars END ToStringList; PROCEDURE Help; BEGIN Log.String("Usage: cpmake [options] module..."); Log.Ln; Log.String("Options:"); Log.Ln; Log.String(" -a Enable automatic dependency resolution"); Log.Ln; Log.String(" -Cg params Pass parameters to Component Pasacal compiler directly"); Log.Ln; Log.String(" -Ci params Pass parameters to internal linker directly"); Log.Ln; Log.String(' -D ident["+"|"-"] Add preprocessor selector'); Log.Ln; Log.String(" -g compiler Specify Component Pascal compiler"); Log.Ln; Log.String(" cpfront BlackBox based C code translator"); Log.Ln; Log.String(" native BlackBox based native code compiler"); Log.Ln; Log.String(" -h Print help and quit"); Log.Ln; Log.String(" -i linker Specify internal linker (native only)"); Log.Ln; Log.String(" dev2 Dev2 based ELF/PE linker"); Log.Ln; Log.String(" -II Trap on user interrupt (debug)"); Log.Ln; Log.String(" -IT Trap on first error (debug)"); Log.Ln; Log.String(" -IC Print module list for compilation and quit"); Log.Ln; Log.String(" -IL Print module list for linking and quit"); Log.Ln; Log.String(" -Ic Print file list for compilation and quit"); Log.Ln; Log.String(" -j num Specifies the number of jobs to run simultaneously"); Log.Ln; Log.String(" -m cpu Generate code for specified processor"); Log.Ln; Log.String(" none Unknown processor (cpfront only)"); Log.Ln; Log.String(" 486 Intel 486+"); Log.Ln; Log.String(" -o name Generate executable file (native only)"); Log.Ln; Log.String(" -s os Generate code for specified operation system"); Log.Ln; Log.String(" none Unknown operation system"); Log.Ln; Log.String(" freebsd FreeBSD"); Log.Ln; Log.String(" linux Linux"); Log.Ln; Log.String(" openbsd OpenBSD"); Log.Ln; Log.String(" win32 Windows"); Log.Ln; Log.String(" -V Print version and quit"); Log.Ln; Log.String(" -Xp path Use executable file for Component Pascal compiler"); Log.Ln; Log.String(" -Xi path Use executable file for internal linker (native only)"); Log.Ln; Kernel.Quit(1) END Help; PROCEDURE Version; BEGIN Log.String(version); Log.Ln; Kernel.Quit(0) END Version; PROCEDURE ParseCommandOpts; BEGIN CASE DswOpts.GetOpt("g:i:") OF | "g": cpcArgs := ToStringList(DswOpts.str); | "i": cplArgs := ToStringList(DswOpts.str); | ":": Error(10, "-C" + DswOpts.str, "", 0) | "?": Error(11, "-C" + DswOpts.str, "", 0) | 0X: Error(11, "-C", "", 0) END END ParseCommandOpts; PROCEDURE ParseExternalOpts; BEGIN CASE DswOpts.GetOpt("g:i:") OF | "g": cpcExe := DswOpts.str; | "i": cplExe := DswOpts.str; | ":": Error(10, "-X" + DswOpts.str, "", 0) | "?": Error(11, "-X" + DswOpts.str, "", 0) | 0X: Error(11, "-X", "", 0) END END ParseExternalOpts; PROCEDURE ParseInfoOpts; BEGIN CASE DswOpts.GetOpt("CLcIT") OF | "T": trap := TRUE | "I": Kernel.intTrap := TRUE | "C": printCompileModList := TRUE | "L": printLinkModList := TRUE | "c": printCompileFileList := TRUE | ":": Error(10, "-I" + DswOpts.str, "", 0) | "?": Error(11, "-I" + DswOpts.str, "", 0) | 0X: Error(11, "-I", "", 0) END END ParseInfoOpts; PROCEDURE ParseFileOpts; VAR d: DevCPM.Directory; BEGIN CASE DswOpts.GetOpt("p:") OF | "p": NEW(d); d.path := DswOpts.str$; d.legacy := TRUE; d.next := dirList; dirList := d | ":": Error(10, "-F" + DswOpts.str, "", 0) | "?": Error(11, "-F" + DswOpts.str, "", 0) | 0X: Error(11, "-F", "", 0) END END ParseFileOpts; PROCEDURE ParseArgs; VAR s: String; BEGIN exe := NIL; auto := FALSE; jobs := 1; def.next := NIL; mno := 0; rno := 0; processor := anymach; os := anyos; compiler := anycp; LOOP CASE DswOpts.GetOpt("ao:j:D:m:s:g:i:TCXIFhV") OF | "a": auto := TRUE | "o": exe := DswOpts.str | "j": jobs := MIN(MAX(StrToInt(DswOpts.str, 1), 1), maxJobs) | "m": s := DswOpts.str; Strings.ToLower(s, s); IF s$ = "none" THEN processor := anymach ELSIF s$ = "486" THEN processor := mach386 ELSIF s$ = "68k" THEN processor := mach68k ELSE Error(6, s, "", 0) END | "s": s := DswOpts.str; Strings.ToLower(s, s); IF s$ = "none" THEN os := anyos ELSIF s$ = "linux" THEN os := linux ELSIF s$ = "freebsd" THEN os := freebsd ELSIF s$ = "openbsd" THEN os := openbsd ELSIF s$ = "win32" THEN os := win32 ELSIF s$ = "cygwin" THEN os := cygwin ELSIF s$ = "darwin" THEN os := darwin ELSE Error(7, s, "", 0) END | "g": s := DswOpts.str; Strings.ToLower(s, s); IF s$ = "native" THEN compiler := cpnative ELSIF s$ = "cpfront" THEN compiler := cpfront ELSE Error(8, s, "", 0) END | "i": s := DswOpts.str; Strings.ToLower(s, s); IF s$ = "dev2" THEN linker := dev2 ELSE Error(9, s, "", 0) END | "h": Help | "V": Version | "D": Define(DswOpts.str, TRUE) | "C": ParseCommandOpts | "X": ParseExternalOpts | "I": ParseInfoOpts | "F": ParseFileOpts | ":": Error(10, "-" + DswOpts.str, "", 0) | "?": Error(11, "-" + DswOpts.str, "", 0) | "$": AddModule(DswOpts.str, def, dirList) | 0X: EXIT END END; END ParseArgs; PROCEDURE CheckParams; PROCEDURE Default (IN name: ARRAY OF CHAR; value: BOOLEAN); BEGIN IF value = TRUE THEN Define(name + "+", FALSE) ELSE Define(name + "-", FALSE) END END Default; BEGIN IF compiler = anycp THEN Error(12, "", "", 0) ELSIF compiler = cpnative THEN IF processor = anymach THEN Error(13, "", "", 0) ELSIF processor # mach386 THEN Error(14, "", "", 0) END END; IF (compiler = cpfront) & (linker # anyint) THEN Error(15, "", "", 0) END; IF (compiler = cpfront) & (exe # NIL) THEN Error(16, "", "", 0) END; IF (exe # NIL) & (compiler = cpnative) & (linker = anyint) THEN Error(17, "", "", 0) END; IF (linker = dev2) & (os = anyos) THEN Error(18, "", "", 0) END; IF (exe # NIL) & (exe^ = "") THEN Error(19, "", "", 0) END; IF (cpcExe = NIL) & (compiler # anycp) THEN IF compiler = cpnative THEN cpcExe := DswProcs.dir.GetPath("cpc486") ELSIF compiler = cpfront THEN cpcExe := DswProcs.dir.GetPath("cpfront") END; IF cpcExe = NIL THEN Error(25, "", "", 0) END END; IF (cplExe = NIL) & (linker # anyint) THEN cplExe := DswProcs.dir.GetPath("cpl486"); IF cplExe = NIL THEN Error(26, "", "", 0) END END; (* cpompiler *) Default("NATIVE", compiler = cpnative); Default("CPFRONT", compiler = cpfront); (* processor *) Default("I486", processor = mach386); Default("I386", processor = mach386); Default("M68K", processor = mach68k); (* operating system *) Default("LINUX", os = linux); Default("FREEBSD", os = freebsd); Default("OPENBSD", os = openbsd); Default("DARWIN", os = darwin); Default("WIN32", os = win32); Default("CYGWIN", os = cygwin); Default("POSIX", os IN {linux, freebsd, openbsd, darwin, cygwin}); (* linker *) Default("DEV2", linker = dev2); END CheckParams; (* --------- loader --------- *) PROCEDURE Import (m: Module; IN name: DevCPT.Name); VAR i, j: INTEGER; imp: Module; BEGIN ASSERT(m # NIL, 20); ASSERT(name # "", 21); IF debugImport THEN Log.String(" import "); Log.String(name$) END; IF name = "SYSTEM" THEN INCL(DevCPM.options, DevCPM.sysImp) ELSIF name = "COM" THEN INCL(DevCPM.options, DevCPM.com) ELSIF name = "JAVA" THEN INCL(DevCPM.options, DevCPM.java) ELSE IF debugImport THEN Log.Char(" ") END; i := 0; (* find module in local list *) WHILE (i < m.mno) & (m.imp[i].name$ # name$) DO INC(i) END; IF i >= m.mno THEN j := 0; (* find module in global list *) WHILE (j < mno) & (modList[j].name$ # name$) DO INC(j) END; IF j >= mno THEN IF ~auto THEN Log.String("module " + name + " required before " + m.name); Log.Ln; INC(werr) END; NEW(imp); imp.name := name$; modList[mno] := imp; INC(mno) ELSE imp := modList[j] END; m.imp[m.mno] := imp; INC(m.mno) ELSE DevCPM.err(1) END END; IF debugImport THEN Log.Ln END; END Import; PROCEDURE ParseModule (m: Module); VAR sym: BYTE; SelfName, impName, aliasName: DevCPT.Name; PROCEDURE err (n: SHORTINT); BEGIN DevCPM.err(n) END err; PROCEDURE CheckSym(s: SHORTINT); BEGIN IF sym = s THEN DevCPS.Get(sym) ELSE DevCPM.err(s) END END CheckSym; BEGIN IF debugImport THEN Log.String("module " + m.name); Log.Ln END; DevCPS.Init; DevCPS.Get(sym); IF sym = module THEN DevCPS.Get(sym) ELSE err(16) END; IF sym = ident THEN SelfName := DevCPS.name$; DevCPS.Get(sym); IF sym = lbrak THEN INCL(DevCPM.options, DevCPM.interface); DevCPS.Get(sym); 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) ELSE err(string) END; CheckSym(rbrak) END; CheckSym(semicolon); IF sym = import THEN DevCPS.Get(sym); LOOP IF sym = ident THEN aliasName := DevCPS.name$; impName := aliasName$; DevCPS.Get(sym); IF sym = becomes THEN DevCPS.Get(sym); IF sym = ident THEN impName := DevCPS.name$; DevCPS.Get(sym) ELSE err(ident) END END; Import(m, impName) ELSE err(ident) END; IF sym = comma THEN DevCPS.Get(sym) ELSIF sym = ident THEN err(comma) ELSE EXIT END END; CheckSym(semicolon) END; LOOP (* preprocessor must read module fully *) IF sym = end THEN DevCPS.Get(sym); IF sym = ident THEN DevCPS.Get(sym); IF sym = period THEN IF DevCPS.name # SelfName THEN err(4) END; EXIT ELSIF sym = eof THEN err(period); EXIT END ELSIF sym = eof THEN err(ident); EXIT END; ELSIF sym = eof THEN err(end); EXIT ELSE DevCPS.Get(sym); END END ELSE err(ident) END; DevCPS.str := NIL END ParseModule; PROCEDURE CheckModule (m: Module; source: String; OUT ok: BOOLEAN); VAR s: Selector; BEGIN DevCPM.Init(source); DevCPM.symList := m.dir; (*DevCPM.codePath := m.outcode;*) (*DevCPM.symPath := m.outsym;*) DevCPM.name := m.name$; INCL(DevCPM.options, DevCPM.comAware); IF trap THEN INCL(DevCPM.options, DevCPM.trap) END; (*IF oberon IN m.opts THEN INCL(DevCPM.options, DevCPM.oberon) END;*) DevCPR.Init; s := def.next; WHILE s # NIL DO DevCPR.Set(s.name, s.value); s := s.next END; ParseModule(m); DevCPR.Check; ok := DevCPM.noerr; DevCPR.Close; DevCPM.InsertMarks; DevCPM.Close; Kernel.FastCollect END CheckModule; PROCEDURE MakePath (IN dir, name: Files.Name; IN type: Files.Type; OUT path: Files.Name); BEGIN ASSERT(name # "", 21); IF dir = "" THEN path := modDir + "/" + name ELSE path := dir + "/" + modDir + "/" + name END; Kernel.MakeFileName(path, type) END MakePath; PROCEDURE Open (loc: Files.Locator; IN sub, name: Files.Name; OUT path: Files.Name; OUT text: DswDocuments.Model); VAR res: INTEGER; BEGIN ASSERT(loc # NIL, 20); ASSERT(name # "", 21); (* !!! use Kernel.MakeFileName instead ".ext" concat !!! *) MakePath(sub, name, "cp", path); DswDocuments.Open(loc, name + ".cp", text, res); IF text = NIL THEN MakePath(sub, name, "odc", path); DswDocuments.Open(loc, name + ".odc", text, res); IF (text = NIL) & (sub = "") THEN MakePath(sysDir, name, "cp", path); loc := Files.dir.This(sysDir).This(modDir); DswDocuments.Open(loc, name + ".cp", text, res); IF text = NIL THEN MakePath(sysDir, name, "odc", path); DswDocuments.Open(loc, name + ".odc", text, res); IF text = NIL THEN path := "" END END END END END Open; PROCEDURE GetSource (IN modName: ARRAY OF CHAR; list: DevCPM.Directory; OUT path: Files.Name; OUT s: String); VAR sub, name: Files.Name; loc: Files.Locator; base: DevCPM.Directory; text: DswDocuments.Model; r: DswDocuments.Reader; i, res: INTEGER; BEGIN s := NIL; path := ""; base := list; Kernel.SplitName(modName, sub, name); loc := Files.dir.This(sub).This(modDir); Open(loc, sub, name, path, text); WHILE (text = NIL) & (base # NIL) DO ASSERT(base.legacy, 100); loc := Files.dir.This(base.path).This(sub).This(modDir); Open(loc, sub, name, path, text); base := base.next END; IF text # NIL THEN NEW(s, text.Length() + 1); IF s # NIL THEN r := text.NewReader(NIL); FOR i := 0 TO text.Length() - 1 DO r.Read; s[i] := r.char END END END END GetSource; PROCEDURE Trace (m, parent: Module; VAR lno: INTEGER); VAR i: INTEGER; BEGIN IF ~(trace IN m.flags) THEN INCL(m.flags, trace); FOR i := 0 TO m.mno - 1 DO Trace(m.imp[i], m, lno); m.depth := MAX(m.depth, m.imp[i].depth + 1) END; IF ~(imported IN m.flags) THEN INCL(m.flags, imported); lnkList[lno] := m; INC(lno) END; EXCL(m.flags, trace) ELSE Error(20, m.name$, parent.name$, 0) END END Trace; PROCEDURE Sort; VAR i, j: INTEGER; m: Module; BEGIN ASSERT((mno = 0) OR (lnkList[0] # NIL), 20); cmpList := lnkList; i := 1; WHILE i < mno DO m := cmpList[i]; j := i - 1; WHILE (j >= 0) & (cmpList[j].depth > m.depth) DO cmpList[j + 1] := cmpList[j]; DEC(j) END; cmpList[j + 1] := m; INC(i) END END Sort; PROCEDURE CheckDeps; VAR i, j, num: INTEGER; m: Module; src: String; ok: BOOLEAN; BEGIN i := 0; rno := mno; WHILE (err = 0) & (i < mno) DO m := modList[i]; GetSource(m.name$, m.dir, m.odc, src); IF src # NIL THEN CheckModule(m, src, ok); IF ~ok THEN INC(err) END ELSE Error(21, m.name$, "", 0) END; INC(i) END; INC(err, werr); num := 0; FOR i := 0 TO rno - 1 DO Trace(modList[i], modList[i], num) END; ASSERT((err # 0) OR (num = mno), 100); Sort; IF debugOrder THEN Log.String("Parallel depth:"); Log.Ln; FOR i := 0 TO mno - 1 DO Log.String(" " + cmpList[i].name); Log.Int(cmpList[i].depth); Log.Ln; END END END CheckDeps; PROCEDURE IsCompiled (m: Module): BOOLEAN; CONST target = {hasSym, hasObj}; VAR i: INTEGER; ready: BOOLEAN; BEGIN ASSERT(m # NIL, 20); i := 0; ready := ~(hasErrors IN m.flags) & (m.flags * target = target); WHILE ready & (i < m.mno) DO ready := IsCompiled(m.imp[i]); INC(i) END; RETURN ready END IsCompiled; PROCEDURE Ready (m: Module): BOOLEAN; CONST target = {hasSym, hasObj}; VAR i: INTEGER; ready: BOOLEAN; BEGIN i := 0; ready := ~(hasErrors IN m.flags) & (m.flags * target # target) & (m.worker = NIL); WHILE ready & (i < m.mno) DO ready := IsCompiled(m.imp[i]); INC(i) END; RETURN ready END Ready; PROCEDURE PutParams (w: DswProcs.Process; p: StringList); VAR i: INTEGER; BEGIN ASSERT(w # NIL, 20); IF debugArgs THEN Log.String("PutParams") END; IF p # NIL THEN IF debugArgs THEN Log.String(":[" + p[0]) END; w.PutParam(p[0]); FOR i := 1 TO LEN(p) - 1 DO IF debugArgs THEN Log.String("|" + p[i]) END; w.PutParam(p[i]) END; IF debugArgs THEN Log.Char("]") END END; IF debugArgs THEN Log.Ln END END PutParams; PROCEDURE PutPathList (w: DswProcs.Process; IN par: ARRAY OF CHAR; base: DevCPM.Directory); BEGIN IF base # NIL THEN PutPathList(w, par, base.next); (* in revese order *) w.PutParam(par); w.PutParam(base.path); END END PutPathList; PROCEDURE ExecuteCompiler (m: Module): DswProcs.Process; VAR w: DswProcs.Process; ok: BOOLEAN; s: Selector; BEGIN ASSERT(m # NIL, 20); ASSERT(m.odc # "", 21); ASSERT(m.worker = NIL, 22); w := DswProcs.dir.New(); w.Program(cpcExe); IF trap THEN w.PutParam("-trap") END; w.PutParam("-legacy"); PutPathList(w, "-legacysymdir", m.dir); s := def.next; WHILE s # NIL DO IF s.value = TRUE THEN w.PutParam("-define+") ELSE w.PutParam("-define-") END; w.PutParam(s.name$); s := s.next END; PutParams(w, cpcArgs); w.PutParam(m.odc); w.Execute(ok); IF ok THEN Log.String("Compile " + m.name + " (" + m.odc + ")"); Log.Ln; ELSE w := NIL END; RETURN w END ExecuteCompiler; PROCEDURE Compile; VAR i, j, num: INTEGER; ok: BOOLEAN; m: Module; w: DswProcs.Process; BEGIN IF mno = 0 THEN RETURN END; num := 0; j := 0; WHILE (err = 0) & (num < mno) OR (j > 0) DO i := 0; WHILE (err = 0) & (i < mno) & (j < jobs) DO m := cmpList[i]; IF Ready(m) THEN w := ExecuteCompiler(m); IF debugJobs THEN Log.String("Start job " + m.name) END; IF w # NIL THEN IF debugJobs THEN Log.String(" ok") END; m.worker := w; INC(j) ELSE IF debugJobs THEN Log.String(" fail") END; INCL(m.flags, hasErrors); INC(err) END; IF debugJobs THEN Log.Ln END END; INC(i) END; WHILE (err = 0) & (j >= jobs) OR (j > 0) DO i := 0; WHILE (j > 0) & (i < mno) DO m := cmpList[i]; w := m.worker; IF (w # NIL) & w.IsTerminated() THEN IF debugJobs THEN Log.String("Stop job " + m.name); Log.Int(w.Result()); Log.Ln END; IF w.Result() = 0 THEN INCL(m.flags, hasObj); INCL(m.flags, hasSym); INC(num) ELSE INCL(m.flags, hasErrors); INC(err) END; m.worker := NIL; DEC(j) END; INC(i) END END END END Compile; PROCEDURE LinkDev2; VAR p: DswProcs.Process; i, res: INTEGER; ok: BOOLEAN; BEGIN ASSERT((exe # NIL) & (exe^ # ""), 20); ASSERT(processor = mach386, 21); ASSERT(compiler = cpnative, 22); p := DswProcs.dir.New(); p.Program(cplExe); IF trap THEN p.PutParam("-trap") END; PutPathList(p, "-legacycodedir", dirList); IF os # anyos THEN p.PutParam("-os"); CASE os OF | linux: p.PutParam("linux") | freebsd: p.PutParam("freebsd") | openbsd: p.PutParam("openbsd") | win32, cygwin: p.PutParam("win32") | darwin: p.PutParam("darwin") END END; p.PutParam("-kernel"); p.PutParam("Kernel"); p.PutParam("-main"); p.PutParam("Kernel"); p.PutParam("-legacycodedir"); p.PutParam("."); p.PutParam("-o"); p.PutParam(exe); PutParams(p, cplArgs); i := 0; WHILE i < mno DO IF ~(library IN lnkList[i].flags) THEN p.PutParam(lnkList[i].name$) END; INC(i) END; p.Execute(ok); IF ok THEN Log.String("Link "); Log.String(exe); Log.Ln; res := p.Result(); IF res # 0 THEN Error(22, "", "", res) END ELSE Error(23, "", "", 0) END END LinkDev2; PROCEDURE Link; BEGIN IF exe # NIL THEN CASE linker OF | anyint: (* do not link *) | dev2: LinkDev2 END END END Link; PROCEDURE PrintInfo; VAR i: INTEGER; BEGIN IF printCompileModList THEN FOR i := 0 TO mno - 1 DO Log.String(cmpList[i].name$); Log.Char(" ") END; Log.Ln ELSIF printLinkModList THEN FOR i := 0 TO mno - 1 DO IF ~(library IN lnkList[i].flags) THEN Log.String(lnkList[i].name$); Log.Char(" ") END END; Log.Ln ELSIF printCompileFileList THEN FOR i := 0 TO mno - 1 DO Log.String(cmpList[i].odc); Log.Char(" ") END; Log.Ln (* ELSIF printLinkFileList THEN FOR i := 0 TO mno - 1 DO IF ~(library IN lnkList[i].flags) THEN Log.String(lnkList[i].ocf); Log.Char(" ") END END; Log.Ln *) END END PrintInfo; PROCEDURE Main; BEGIN IF Kernel.trapCount = 0 THEN ParseArgs; IF err = 0 THEN IF printCompileModList OR printLinkModList OR printCompileFileList THEN auto := TRUE END; CheckParams; IF err = 0 THEN CheckDeps; IF err = 0 THEN IF printCompileModList OR printLinkModList OR printCompileFileList THEN PrintInfo ELSE Compile; IF err = 0 THEN Link END END END END END ELSE Error(24, "", "", 0) END; IF err = 0 THEN Kernel.Quit(0) ELSE Kernel.Quit(1) END END Main; BEGIN NEW(def); ASSERT(def # NIL, 100); Kernel.intTrap := FALSE; Kernel.Start(Main) END DswMakeMain.