O = ${o}
A = ${a}
EXE = ${exe}
PARROTLIB = ${blib_lib_libparrot_a}

RM_F = ${rm_f}

INC=../../include/parrot

H_FILES = $(INC)/parrot.h imc.h stacks.h cfg.h \
	instructions.h cfg.h debug.h sets.h symreg.h \
	pbc.h optimizer.h parser.h imcparser.h


IMCC_O_FILES = imcparser$(O) imclexer$(O) imc$(O) stacks$(O) symreg$(O) \
	instructions$(O) cfg$(O) sets$(O) debug$(O) \
	optimizer$(O) pbc$(O) main$(O) parser_util$(O) jit$(O) pcc$(O)


O_FILES = $(IMCC_O_FILES) ../../$(PARROTLIB)

#DO NOT ADD C COMPILER FLAGS HERE
#Add them in Configure.pl--look for the
#comment 'ADD C COMPILER FLAGS HERE'

CFLAGS = ${ccflags} ${cc_debug} ${ccwarn} ${cc_hasjit} ${cg_flag}  -I../../include

C_LIBS = ${libs}

CC = ${cc}
PERL = ${perl}
YACC = ${yacc}
LEX = ${lex}
TOUCH  = perl -e ${PQ}open(A,q{>>},$$_) or die foreach @ARGV${PQ}

LD = ${ld}
LD_SHARED = ${ld_shared}
LD_OUT = ${ld_out}
LINK = ${link}
LINKFLAGS=${linkflags} ${ld_debug}

#
# This is set to  MAKE=$make if your $make command doesn't
# do it for you.
#
${make_set_make}


all : flags_dummy imcc${exe}

flags_dummy:
	echo Compiling with:
	@$(PERL) ../../tools/dev/cc_flags.pl ./CFLAGS echo $(CFLAGS) xx$(O) -c xx.c

../../$(PARROTLIB):
	cd ..${slash}.. && $(MAKE) $(PARROTLIB) && cd languages${slash}imcc

# The .flag files are needed because we are keeping some derived files in CVS,
# which does not keep accurate timestamps on the files, relative to each other.
# Note that YACC or LEX may be null commands, so we must `touch` all the
# target files, instead of just the .flag files.
imcc.y.flag imcparser.c imcparser.h: imcc.y
	$(YACC) imcc.y -d -o imcparser.c
	$(TOUCH) imcc.y.flag imcparser.c imcparser.h

imcc.l.flag imclexer.c: imcc.l
	$(LEX) imcc.l
	$(TOUCH) imcc.l.flag imclexer.c

.c$(O):
	@$(PERL) ../../tools/dev/cc_flags.pl ./CFLAGS $(CC) $(CFLAGS) ${cc_exe_out}$@ -c $<

$(IMCC_O_FILES) : $(H_FILES)

clean:
	$(RM_F) core \
	        $(IMCC_O_FILES) \
	        imcparser.output \
	        imcc${exe} \
	        t/*/*.out t/*/*.imc \
		t/*/*.pbc t/*/*.o t/*/*.stabs.s t/*/*.pasm

realclean: clean
	$(RM_F) a.pasm \
	        imcparser.* \
	        imclexer.*

imcc${exe}: $(O_FILES)
	$(LINK) $(LD_OUT)imcc${exe} $(LINKFLAGS) $(O_FILES) $(C_LIBS)

test:	imcc${exe}
	$(PERL) t/harness

