Login
7 branches 0 tags
Ben (X13/Arch) Fixed `bmake` dependencies 3a09962 3 years ago 776 Commits
nujel / tools / watcom.nuj
#!/usr/bin/env nujel

[def WCC "wcc386"]
[def WLINK "wlink"]

[def WCC-OPTS " -6r -fp6 -ecf -bt=DOS -za99 -oi -ol+ -om -ot"]
[when [file/dir? "/opt/watcom/h/"]
      [set! WCC-OPTS [cat WCC-OPTS " -i=/opt/watcom/h/"]]]

[defn run [cmd]
       [def ret [popen cmd]]
       [when-not [zero? [car ret]]
                 [println [cat [ansi-red "StdOut:\n"] [cdr ret]]]
                 [throw [list :error "Subprocess return non-zero exit code" [list cmd [car ret]]]]]]

[defn watcom/compile [file]
       [def cwd [path/working-directory]]
       [println [cat [ansi-green "[CC] "] file]]
       [path/change [join [except-last-pair [split file "/"]] "/"]]
       [def cur-name [car [last-pair [split file "/"]]]]
       [def out-file [cat [path/without-extension cur-name] ".obj"]]
       [run [cat WCC WCC-OPTS " -fo=" out-file " " cur-name]]
       [path/change cwd]]

[when-not [and [file/file? "tmp/stdlib.c"]
               [file/file? "tmp/binlib.c"]]
          [println [ansi-red "Can't find tmp/stdlib.c or tmp/binlib.c, please build a native version first, which in the process creates the assets necessary."]]
          [exit 1]]

[def source-files [filter [flatten [map '["bin" "lib" "tmp" "vendor"] directory/read-recursive]]
                          [path/ext?! "c"]]]
[def object-files [map source-files [fn [α] [cat [path/without-extension α] ".obj"]]]]

[for-each object-files file/remove]
[file/remove "DOSNUJEL.EXE"]
[for-each source-files watcom/compile]

[println [cat [ref ansi-bg 2] "[LD]" ansi-bg-reset " DOSNUJEL.EXE"]]
[run [cat WLINK " SYSTEM causeway NAME DOSNUJEL OPTION STACK=1m OPTION HEAPSIZE=64m FILE " [join object-files ", "]]]