# Generate Makefile code to compile .c -> .o, output printed
# same as com_var.tmpasm plus extra -I's for grammar files
# Arguments:
#  /local/comp/OBJS_C89   list of .o files (assuming each have at least a .c)
#  /local/comp/OBJS_C99   list of .o files (assuming each have at least a .c), for non-c89 compilation
#  /local/comp/C89FLAGS   cflags for c89 compilation
#  /local/comp/C99FLAGS   cflags for c99 compilation

print {
### explicit rules for .c -> .o ###
}

append /local/comp/C89FLAGS {}
append /local/comp/C99FLAGS {}

append /local/comp/OBJS_C89 {}
foreach /local/o in /local/comp/OBJS_C89
put /local/c /local/o
sub /local/c {.o$} {.c}
switch /local/c
	case {.*_y[.]c}
		put /local/extinc [@ -I@/local/c@@]
		sub /local/extinc {/[^/]*$} {}
		end
	case {.*_l[.]c}
		put /local/extinc [@ -I@/local/c@@]
		sub /local/extinc {/[^/]*$} {}
		end
	default
		put /local/extinc {}
		end
end
print [@
@/local/o@: @/local/c@
	$(CC) -c @/local/comp/C89FLAGS@@/local/extinc@ -o @/local/o@ $<
@]
end

append /local/comp/OBJS_C99 {}
foreach /local/o in /local/comp/OBJS_C99
put /local/c /local/o
sub /local/c {.o$} {.c}
switch /local/c
	case {.*_y[.]c}
		put /local/extinc [@ -I@/local/c@@]
		sub /local/extinc {/[^/]*$} {}
		end
	case {.*_l[.]c}
		put /local/extinc [@ -I@/local/c@@]
		sub /local/extinc {/[^/]*$} {}
		end
	default
		put /local/extinc {}
		end
end
print [@
@/local/o@: @/local/c@
	$(CC) -c @/local/comp/C99FLAGS@@/local/extinc@ -o @/local/o@ $<
@]
end

# clean arguments and local temp vars for safe reuse
put /local/comp/OBJS_C89 {}
put /local/comp/OBJS_C99 {}
put /local/comp/C89FLAGS {}
put /local/comp/C99FLAGS {}
put /local/extinc {}
