/**********************************************************************/
/*	    LCompile V1.1, Written by, Paul D. Cardwell 1992	      */
/*	    Adapted to dme by Thomas J. Moore 1992		      */
/*   This program is to either "make" or "compile" DICE C  .C files   */
/**********************************************************************/

Options Results

if ~show(l,'rexxsupport.library') then
    call addlib('rexxsupport.library',0,-30,0)

parse arg filename

dme_addr = address()
getval '$rexxport'
if result ~= dme_addr then exit 20 /* not correct dme */

options failat 100
address command "delete >nil: T:dcc.output"
options failat 5

if filename = "" then do
    getval '$fname'
    file_name = result
end
getval '$fpath'
currpath = result
makefil = ""
flag = 0
CTRLJ = '0A'X

address value dme_addr

if exists(currpath'makefile') | exists(currpath'dmakefile') then file_name = ""
if upper(file_name) = "DMAKEFILE" then file_name = ""
if upper(file_name) = "MAKEFILE" then file_name = ""
if right(upper(file_name),4) = ".LMK" then
  do
    makefil = file_name
    file_name = ""
  end

if file_name = "" then filename = "dmake"
else
  do
    if right(upper(file_name),2) ~= ".C" then
      do
       title "(I need a .c file not" file_name
       exit 0
      end
    else
      do
	getval '$filename'
	filename = result
      end
  end

getval '$modified'
if result ~= 0 then 'saveold'

if filename ~= "dmake" then
  do
   flag = 1
   xx = strip(file_name,'B','.c')
/* String = "dcc > T:dcc.output -2.0 "||filename||" -o ram:"||xx */
   "set compopt RESULT"
   String = "dcc >>T:dcc.output -ET:dcc.output "||filename||" -o ram:"||xx
   "title (Set Compile/Link options) escimm (set compopt ("String")) null"
   "getval $compopt"
   String = result
   if String = "RESULT" then Call Quit_Die
   title "(Compiling and Linking " filename "... please wait)"
/* rawkey 68 1 */
   curdir = pragma(directory)
/* TheCommand = "Path DCC:bin add" || CTRLJ */
   TheCommand = /* TheCommand || */ "CD " || d2c(34) || currpath || d2c(34) || CTRLJ
   TheCommand = TheCommand || String || CTRLJ
   TheCommand = TheCommand || " CD " || d2c(34) || curdir || d2c(34)
   Address command TheCommand
  end
else	   /* else use makefile */
  do
   flag = 1
   if makefil = "" then String = "BMAKE >con:0/24/640/150/Make/AUTO/WAIT"
   else String = "BMAKE >con:0/24/640/150/Make/AUTO/WAIT -f "||makefil
   "set compopt RESULT"
   "title (Set Make Options) escimm (set compopt ("String")) null"
   "getval $compopt"
   String = result
   if String = "RESULT" then Call Quit_Die
   "title (Running makefile...)"
/* rawkey 68 1 */
   curdir = pragma(directory)
   TheCommand = "SetEnv DCCOPTS -ET:dcc.output" || CTRLJ /* should really append this to dccopts */
/* TheCommand = TheCommand || "Path DCC:bin add" || CTRLJ */
   TheCommand = TheCommand || "CD " || d2c(34) || currpath || d2c(34) || CTRLJ
   TheCommand = TheCommand || String || CTRLJ
   TheCommand = TheCommand || "UnSetEnv DCCOPTS" || CTRLJ
   TheCommand = TheCommand || " CD " || d2c(34) || curdir || d2c(34)
   Address command TheCommand
  end


if flag = 1 then do
    flst = statef('T:dcc.output')
    parse value flst with entrytype size other
    if size > 0 then do
	"ping 1 findfile (*Compiler Errors*)"
	"getval ($filename)"
	if result ~= '*Compiler Errors*' then
	    "openwindow +0-100-0+100 chfilename (*Compiler Errors*) insfile T:dcc.output modified off pong 1"
	else
	    "findfile (*Compiler Errors*) newfile T:dcc.output chfilename (*Compiler Errors*) modified off pong 1"
	"title (dmake completed; errors detected)"
    end
    else
	"title (dmake completed)"
end

Quit_Die:
exit 0

Quit_Die : procedure
title (dmake aborted)
exit 0
