-- $Source$
-- $State$

local d = ROOTDIR.."lang/cem/cemcom.ansi/"

local extract_parameters = simple {
	outputs = {
		"%U%/lint.h",
		"%U%/pathlength.h",
		"%U%/errout.h",
		"%U%/idfsize.h",
		"%U%/numsize.h",
		"%U%/nparams.h",
		"%U%/ifdepth.h",
		"%U%/density.h",
		"%U%/macbuf.h",
		"%U%/strsize.h",
		"%U%/trgt_sizes.h",
		"%U%/botch_free.h",
		"%U%/dataflow.h",
		"%U%/debug.h",
		"%U%/use_tmp.h",
		"%U%/parbufsize.h",
		"%U%/textsize.h",
		"%U%/inputtype.h",
		"%U%/nopp.h",
		"%U%/nobitfield.h",
		"%U%/spec_arith.h",
		"%U%/static.h",
		"%U%/nocross.h",
		"%U%/regcount.h",
		"%U%/dbsymtab.h",		
	},
	
	command = {
		"cd %out[1]:dirname% && %in[1]% %in[2]%"
	},
	
	file (d.."make.hfiles"),
	file (d.."BigPars")
}

local lpars = LLgen {
	simple {
		outputs = {"%U%/tokenfile.g"},
		command = {
			"%in[1]% < %in[2]% > %out[1]%"
		},
		file (d.."make.tokfile"),
		file (d.."tokenname.c")
	},
	file (d.."program.g"),
	file (d.."declar.g"),
	file (d.."expression.g"),
	file (d.."statement.g"),
	file (d.."ival.g"),
}

local allocd_header = simple {
	class = "allocd_header",
	command = {
		"%in[1]% < %in[2]% > %out[1]%"
	},
	
	file (d.."make.allocd")
}
	
local cfile_with_headers = cfile {
	class = "cfile_with_headers",
	dynamicheaders = {
		file (d),
		extract_parameters,
		allocd_header { outputs = {"%U%/code.h"},          (d.."code.str") },
		allocd_header { outputs = {"%U%/declar.h"},        (d.."declar.str") },
		allocd_header { outputs = {"%U%/def.h"},           (d.."def.str") },
		allocd_header { outputs = {"%U%/expr.h"},          (d.."expr.str") },
		allocd_header { outputs = {"%U%/field.h"},         (d.."field.str") },
		allocd_header { outputs = {"%U%/estack.h"},        (d.."estack.str") },
		allocd_header { outputs = {"%U%/util.h"},          (d.."util.str") },
		allocd_header { outputs = {"%U%/proto.h"},         (d.."proto.str") },
		allocd_header { outputs = {"%U%/replace.h"},       (d.."replace.str") },
		allocd_header { outputs = {"%U%/idf.h"},           (d.."idf.str") },
		allocd_header { outputs = {"%U%/macro.h"},         (d.."macro.str") },
		allocd_header { outputs = {"%U%/stack.h"},         (d.."stack.str") },
		allocd_header { outputs = {"%U%/stmt.h"},          (d.."stmt.str") },
		allocd_header { outputs = {"%U%/struct.h"},        (d.."struct.str") },
		allocd_header { outputs = {"%U%/switch.h"},        (d.."switch.str") },
		allocd_header { outputs = {"%U%/type.h"},          (d.."type.str") },
		allocd_header { outputs = {"%U%/l_brace.h"},       (d.."l_brace.str") },
		allocd_header { outputs = {"%U%/l_state.h"},       (d.."l_state.str") },
		allocd_header { outputs = {"%U%/l_outdef.h"},      (d.."l_outdef.str") },
		lpars
	}
}
	
lang_cem_ansi_compiler = cprogram {
	cfile_with_headers (d.."LLlex.c"),
	cfile_with_headers (d.."LLmessage.c"),
	cfile_with_headers (d.."arith.c"),
	cfile_with_headers (d.."blocks.c"),
	cfile_with_headers (d.."ch3.c"),
	cfile_with_headers (d.."ch3bin.c"),
	cfile_with_headers (d.."ch3mon.c"),
	cfile_with_headers (d.."code.c"),
	cfile_with_headers (d.."conversion.c"),
	cfile_with_headers (d.."cstoper.c"),
	cfile_with_headers (d.."dataflow.c"),
	cfile_with_headers (d.."declarator.c"),
	cfile_with_headers (d.."decspecs.c"),
	cfile_with_headers (d.."domacro.c"),
	cfile_with_headers (d.."dumpidf.c"),
	cfile_with_headers (d.."error.c"),
	cfile_with_headers (d.."eval.c"),
	cfile_with_headers (d.."expr.c"),
	cfile_with_headers (d.."field.c"),
	cfile_with_headers (d.."fltcstoper.c"),
	cfile_with_headers (d.."idf.c"),
	cfile_with_headers (d.."init.c"),
	cfile_with_headers (d.."input.c"),
	cfile_with_headers (d.."l_comment.c"),
	cfile_with_headers (d.."l_ev_ord.c"),
	cfile_with_headers (d.."l_lint.c"),
	cfile_with_headers (d.."l_misc.c"),
	cfile_with_headers (d.."l_outdef.c"),
	cfile_with_headers (d.."l_states.c"),
	cfile_with_headers (d.."label.c"),
	cfile_with_headers (d.."main.c"),
	cfile_with_headers (d.."options.c"),
	cfile_with_headers (d.."pragma.c"),
	cfile_with_headers (d.."proto.c"),
	cfile_with_headers (d.."replace.c"),
	cfile_with_headers (d.."skip.c"),
	cfile_with_headers (d.."stab.c"),
	cfile_with_headers (d.."stack.c"),
	cfile_with_headers (d.."struct.c"),
	cfile_with_headers (d.."switch.c"),
	cfile_with_headers (d.."tokenname.c"),
	cfile_with_headers (d.."type.c"),
	cfile_with_headers (d.."util.c"),

	foreach {
		rule = cfile_with_headers,
		ith { lpars, from=2 }
	},

	cfile_with_headers {
		simple {
			outputs = {"%U%-symbol2str.c"},
			command = {
				"%in[1]% < %in[2]% > %out[1]%"
			},
			
			file (d.."make.tokcase"),
			file (d.."tokenname.c")
		}
	},
	
	cfile_with_headers {
		CINCLUDES = {PARENT, d},
		tabgen (d.."char.tab")
	},

	cfile_with_headers {
		simple {
			outputs = {"%U%-next.c"},
			command = {
				"%in% > %out%"
			},
			
			file (d.."make.next"),
			
			file (d.."code.str"),
			file (d.."declar.str"),
			file (d.."def.str"),
			file (d.."expr.str"),
			file (d.."field.str"),
			file (d.."estack.str"),
			file (d.."util.str"),
			file (d.."proto.str"),
			file (d.."replace.str"),
			file (d.."idf.str"),
			file (d.."macro.str"),
			file (d.."stack.str"),
			file (d.."stmt.str"),
			file (d.."struct.str"),
			file (d.."switch.str"),
			file (d.."type.str"),
			file (d.."l_brace.str"),
			file (d.."l_state.str"),
			file (d.."l_outdef.str"),
		}
	},

	lib_em_mes,
	lib_emk,
	lib_em_data,
	lib_input,
	lib_assert,
	lib_alloc,
	lib_flt_arith,
	lib_print,
	lib_system,
	lib_string,
	
	outputs = {"%U%/em_cemcom.ansi"},
	install = {
		pm.install(                    BINDIR..PLATDEP.."/em_cemcom.ansi"),
		pm.install(d.."cemcom.ansi.1", BINDIR.."/man/man1/cemcom.ansi.1"),
	}
}
