#
#  Makefile.fpc for Free Pascal units, which participates in the tests
#

[target]

[install]
fpcpackage=y

[clean]
units = erroru popuperr ptest

[compiler]
targetdir=$(FULL_TARGET)

[default]
fpcdir=../..

[rules]
.PHONY: rtl extra all clean cleanrtl clean_ctest

#############################
# RTL
#

DUMMYINSTALLDIR=$(BASEDIR)/tmp
INSTALLOPT=INSTALL_PREFIX=$(DUMMYINSTALLDIR) INSTALL_UNITDIR=$(BASEDIR)/$(COMPILER_TARGETDIR)

rtl-stamp.$(FULL_TARGET):
        $(MAKE) -C ../../rtl all "OPT=$(OPT) -n"
        $(DELTREE) $(COMPILER_TARGETDIR)
        $(MAKE) -C ../../rtl install $(INSTALLOPT)
        $(ECHO) Compiled > rtl-stamp.$(FULL_TARGET)

cleanrtl:
        $(DELTREE) $(COMPILER_TARGETDIR)
        $(DELTREE) $(DUMMYINSTALLDIR)
        -$(DEL) rtl-stamp.$(FULL_TARGET)

rtl : rtl-stamp.$(FULL_TARGET)


#############################
# Extra units
#


TESTOPT=-n -FE$(COMPILER_TARGETDIR) -T$(OS_TARGET) $(OPT)
ifneq ($(BINUTILSPREFIX),)
override TESTOPT+=-XP$(BINUTILSPREFIX) -Xc
endif
TESTCOMPILER=$(FPC) $(TESTOPT)

erroru$(PPUEXT) : erroru.pp
        $(TESTCOMPILER) erroru.pp

ptest$(PPUEXT) : ../test/cg/ptest.pp
        $(TESTCOMPILER) ../test/cg/ptest.pp

popuperr$(PPUEXT) : popuperr.pp
        $(TESTCOMPILER) popuperr.pp

ifdef CCOMPILER
../test/cg/obj/$(OS_TARGET)/$(CPU_TARGET)/ctest.o : ../test/cg/obj/ctest.c
        $(CCOMPILER) -c -o ../test/cg/obj/$(OS_TARGET)/$(CPU_TARGET)/ctest.o ../test/cg/obj/ctest.c
endif


extra : erroru$(PPUEXT) ptest$(PPUEXT) popuperr$(PPUEXT) ../test/cg/obj/$(OS_TARGET)/$(CPU_TARGET)/ctest.o



#############################
# Main rules
#

all : rtl  extra

clean : cleanrtl cleanall

clean_ctest :
        -$(DEL) ../test/cg/obj/$(OS_TARGET)/$(CPU_TARGET)/ctest.o
