#
# C compiler makefile
#
# Rev 002 24-Feb-26 FC     Decided it was better to change PASS2.IMP and MAKEFILE to refer
#                          to the actual 8.3 filename LLOPTION.INC rather than make a copy
#                          called LLOPTIONS.INC as I did previously.  In the olden days the
#                          references to LLOPTIONS.INC got silently truncated somewhere.
# Rev 001 08-Sep-23 FC     Changed from PolyMake PVCS to GNU make with all sources in current directory.
#                          Only build .B4, not .LIF or .TSK
#

#
# Where to locate things
#
#001# WHERE_C = C:\TC2v1
WHERE_C = C:\TC2V2
WHERE_IMP = C:\TI1v4

.SUFFIXES: .imp .bin .b4 .dat .inc          #001

IMP = $(WHERE_IMP)\t4i
IRTLT4T8 = $(WHERE_IMP)\irtlt4t8.bin
IT4HARN = $(WHERE_IMP)\t4harn.bin
T4TASKHARN = $(WHERE_C)\taskharn.t4
T4TASKHARN = \tc2v1\taskharn.t4

#
# 001 The following copied/modifed from 3L BUILTINS.MAK used with PolyMake
#
# Compiling.
# Compile for the T4 by default.  Makefile can override CC, IMP macros if
# compilation for the T8 is required.
#
CC = t4c
IMP = t4i
PC = t4p
LINKC = t4clink
LINKP = t4plink
LINKI = t4ilink

.c.bin :
	$(CC) $(CFLAGS) $<

.imp.bin :
	$(IMP) $(IMPFLAGS) $<


#001# .PATH.bin = bin

FRONTEND =	pass1.bin symtab.bin include.bin egen.bin expr.bin sgen.bin \
	   	stmt.bin types.bin trees.bin error.bin decl.bin misc.bin \
		dgen.bin lex.bin icode.bin

BACKEND =	pass2.bin pass3.bin

MISC =		ccnative.bin symtool.bin fpinput.bin udivrem.bin dynstr.bin

#
# How to link the executable compiler image
#
#001 Windows now has a longer command-line limit (8192 chars), so no need to split
#001 everything up into separate lines.  Just as well, as GNU make $file cmd wasn't
#001 working for me.
#
tc.b4 : $(FRONTEND) $(BACKEND) $(MISC)
	@echo $^ >$*.in
	@echo $(IRTLT4T8) >>$*.in
	@echo $(IT4HARN) >>$*.in
	linkt @$*.in,$@

#001	linkt <@<
#001 $[s,"\n",$**]
#001 $(IRTLT4T8)
#001 $(IT4HARN)
#001 <,$@

#001 #
#001 # How to generate the Arsenal library file from the executable image
#001 #
#001 tc.lif: tc.b4
#001    %if %exists(tc.lif)
#001       erase tc.lif
#001    %endif
#001    arsenal <@<
#001 u tc.lif
#001 + tc.b4
#001 t
#001 q
#001 <

#001 tc.tsk : $(FRONTEND) $(BACKEND) $(MISC)
#001	linkt <@<
#001 $[s,"\n",$**]
#001 $(IRTLT4T8)
#001 $(T4TASKHARN)
#001 <,$@

#
# Dependencies
#
# Note that LEX.INC and ICODE.INC include DYNSTR.INC, so that anything which
# depends on LEX.INC or ICODE.INC must also depend on DYNSTR.INC
#
# 001: remove the PolyMake square brackets around all of the following dependency lists.
#

ccnative.bin :	common.inc p2p3.inc option3l.inc cc.inc misc.inc

symtool.bin :	symtool.inc

pass1.bin :	symtool.inc types.inc trees.inc lex.inc dynstr.inc events.inc \
		error.inc decl.inc streams.inc icode.inc sgen.inc \
		misc.inc cc.inc include.inc stmt.inc symtab.inc

symtab.bin :	symtool.inc symtab.inc misc.inc lex.inc dynstr.inc error.inc

include.bin :	common.inc cc.inc misc.inc error.inc streams.inc

egen.bin :	lex.inc dynstr.inc types.inc trees.inc error.inc events.inc \
		misc.inc symtab.inc icode.inc dgen.inc cc.inc egen.inc

expr.bin :	events.inc lex.inc dynstr.inc types.inc trees.inc expr.inc \
		error.inc symtab.inc decl.inc

sgen.bin :	types.inc trees.inc icode.inc lex.inc dynstr.inc egen.inc error.inc \
		symtab.inc dgen.inc misc.inc events.inc common.inc


stmt.bin :	lex.inc dynstr.inc types.inc trees.inc expr.inc decl.inc error.inc \
		events.inc stmt.inc dgen.inc egen.inc icode.inc sgen.inc \
		symtab.inc misc.inc

types.bin :	types.inc error.inc icode.inc misc.inc symtab.inc lex.inc dynstr.inc

trees.bin :	types.inc trees.inc lex.inc dynstr.inc misc.inc

error.bin :	common.inc error.inc lex.inc dynstr.inc streams.inc events.inc \
		misc.inc types.inc trees.inc include.inc cc.inc messages.inc

decl.bin :	types.inc trees.inc lex.inc dynstr.inc expr.inc events.inc error.inc \
		stmt.inc dgen.inc icode.inc sgen.inc symtab.inc misc.inc

misc.bin :	streams.inc misc.inc

dynstr.bin:     dynstr.h

dgen.bin :	types.inc trees.inc symtab.inc lex.inc dynstr.inc error.inc egen.inc \
		events.inc misc.inc icode.inc common.inc cc.inc dbgarea.inc

lex.bin :	events.inc lex.inc dynstr.inc error.inc include.inc streams.inc \
		icode.inc types.inc trees.inc expr.inc egen.inc misc.inc \
		cc.inc symtab.inc

icode.bin :	common.inc icode.inc dynstr.inc misc.inc types.inc symtab.inc \
		error.inc include.inc trees.inc

pass2.bin :	common.inc options.inc lflags.inc lloption.inc \
		opcodes.inc ops.inc perm.inc reloc.inc stream3l.inc \
		p2p3.inc dbgarea.inc dbgflags.inc

pass3.bin :	common.inc p2p3.inc ops.inc opcodes.inc tags.inc \
		perm.inc dbgarea.inc reloc.inc

#
# special: messages.inc, opcodes.inc: build from .dat using tgen
#
.dat.inc :
	tgen -file $* -output $*
