// --------------------------------------------------------------------------- // WMAKE.AML // Support for running Watcom C/C++ WMAKE targets from within Aurora. // By: Gered King , December 2017 // // To install: // 1. Copy WMAKE.AML to C:\PATH\TO\AURORA\MACRO\WMAKE.AML // 2. Compile WMAKE.AML via Macro -> Compile Macro (enter "WMAKE.AML") // 3. Run WMAKE.X once to install it. Macro -> Run Macro (enter "WMAKE.X"). // Should see "WMAKE installed." on the top status bar. // (If it was already installed you will see "WMAKE already installed.") // // To execute a WMAKE target via this macro, execute the following macro // expression somewhere: // // sendobject "wmake" "WMAKE" "makefile-target(s)-here" "wmake options" // // Additionally, to refocus the "Build Errors" window (if it wasn't closed) // you can run: // // sendobject "wmake" "ShowWMAKEErrors" // // You will likely want to bind the above macro expressions to keybindings // and/or menu items for convenience. // // Add the following somewhere in your USER.AML to have the WMAKE macro // load automatically when Aurora starts up: // // runmacro "C:\\path\\to\\aurora\\macro\\wmake.x" // // Notes: // - When this macro runs, it temporarily sets the working directory to that // of the currently active editor or file manager window. // - Currently WMAKE.EXE is run with the assumption that your makefile is // located in this working directory and is named "MAKEFILE". // - A "Build Errors" window is shown once WMAKE has finished, containing // the error output from WMAKE.EXE. No other output capture support is // present. If there is no error output, the "Build Errors" window is not // shown once the command finishes. // --------------------------------------------------------------------------- include bootpath 'define.aml' constant debug = 0 if not debug then if (object? prf.wmake) then say "WMAKE already installed." return else prf.wmake = (getcurrobj) endif endif resident ON object wmake(win) // --------------------------------------------------------------------------- private function GetWindowDirectory (window) if (wintype? "edit" window) or (wintype? "fmgr" window) then title = (gettitle '' window) return (getpath title) endif end // creates and returns a new errors window with content from buf private function CreateErrorsWindow (buf) prf.wmake_window = createwindow setframe ">bvh" settitle "WMAKE Build Errors" setwinctrl "ð" 2 setborder "1" setshadow 2 1 setcolor 0 127 setcolor 5 112 height = 7 x1 = 0 y1 = (getvidrows) - 1 - height x2 = (getvidcols) - 1 y2 = (getvidrows) - 1 sizewindow x1 y1 x2 y2 "ad" prf.wmake_buf = buf prf.wmake_curs = (createcursor '' prf.wmake_buf) setwincurs prf.wmake_curs end // shows errors window with the build error messages from buf private function ShowErrorsWindow (buf) if not prf.wmake_window then CreateErrorsWindow (buf) else curs = (createcursor '' buf) setwincurs curs prf.wmake_window prf.wmake_buf = buf prf.wmake_curs = curs endif currwin prf.wmake_window end private function DoLineAction (line) // TODO gotoerror end function close if prf.wmake_window then prf.wmake_window = '' prf.wmake_curs = '' prf.wmake_buf = '' pass endif end event if (getregion) == 1 then trackmouse line = (gettext) DoLineAction line end pass end function 'ð' close end private function CombineFiles (path filespec) variable resultbuf, files_list files_list = (loadbuf path + "\\" + filespec '' '' "fsv") if files_list then if (getlinelen 1 files_list) > 0 then resultbuf = (createbuf) for i = 1 to (getlines files_list) do filename = (gettext '' '' i files_list) insertbuf (path + "\\" + filename) resultbuf '' '' '' '' (getlines resultbuf) endfor delline 1 1 resultbuf endif end if files_list then destroybuf files_list endif return resultbuf end private function IsBufferEmpty (buf) if not buf then return 1 endif if (getlines buf) < 2 and (getlinelen 1 buf) == 0 then return 1 else return 0 endif end // --------------------------------------------------------------------------- // shows the "WMAKE Build Errors" window if it exists and has errors to show public function ShowWMAKEErrors if prf.wmake_window then currwin prf.wmake_window else say "No errors." endif end // runs "wmake" using the makefile target(s) specified and any additional // wmake options. "wmake.exe" is assumed to be somewhere in the system PATH. // // * targets - space separated string specifing makefile targets // * opts - string containing raw wmake.exe options public function WMAKE (targets opts) if (length opts) == 0 then opts = "/e" endif // set up working directory to be the same as the current window // (regardless of if it's a file manager or edit window) cp = (getcurrpath) currpath (GetWindowDirectory (getcurrwin)) if not (file? "MAKEFILE" (getcurrpath)) then msgbox "No MAKEFILE found in current window directory." return endif // run WMAKE cmdline = ((getenv "COMSPEC") + " /c wmake " + opts + " " + targets) r = (system cmdline "ck") // read any compile errors from .err files in working directory and show // them if there was any. // the watcom compiler automatically writes compile errors to .err files // and i don't think there is any way to disable this behaviour? so it is // probably safe to rely on ... errorsbuf = (CombineFiles (getcurrpath) "*.err") if not (IsBufferEmpty errorsbuf) then ShowErrorsWindow errorsbuf else if errorsbuf then destroybuf errorsbuf endif endif // restore original working directory currpath cp end // --------------------------------------------------------------------------- say "WMAKE installed."