application/octet-stream
•
1.91 KB
•
48 lines
#!/usr/bin/env nujel
[def WCC "wcc386"]
[def WLINK "wlink"]
[def WCC-OPTS " -6r -fp6 -ecf -bt=DOS -za99 -ol -ol+ -om -ot"]
[when [file/dir? "/opt/watcom/h/"]
[set! WCC-OPTS [cat WCC-OPTS " -i=/opt/watcom/h/"]]]
[defun 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]]]]]]
[defun 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]]
[defun directory/read-relative [path]
[map [directory/read path]
[\ [α] [cat path "/" α]]]]
[defun directory/read-recursive [path]
[flatten [map [directory/read-relative path]
[\ [A] [if [file/dir? A]
[directory/read-recursive A]
A]]]]]
[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"]]]
[for-each source-files watcom/compile]
[def object-files [map source-files [\ [A] [cat [path/without-extension A] ".obj"]]]]
[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 ", "]]]