.NOTPARALLEL:

TOPDIR = ..

include Makefile.defs.fe
include $(TOPDIR)/mf/common.defs

all: allfe allfegcc allbe 

test: all
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  run Tests                                         +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfe; $(MAKE) -f RealMakefile test-ser
	cd buildfegcc; $(MAKE) -f RealMakefile test-ser
	cd buildbe; $(MAKE) -f RealMakefile test-par

packtest: all
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  run packTests                                     +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfe; $(MAKE) -f RealMakefile packtest-ser
	cd buildfegcc; $(MAKE) -f RealMakefile packtest-ser
	cd buildbe; $(MAKE) -f RealMakefile packtest-par

install: installfe installfegcc installbe 

installtests: install installtestsfe installtestsbe

checkinst: install checkinstfe checkinstbe

clean: cleanfe cleanfegcc cleanbe

relink: setupfe mklinksfe chklinksfe setupfegcc mklinksfegcc chklinksfegcc setupbe mklinksbe chklinksbe

setup: setupfe setupfegcc setupbe

setupfe:
	@if test ! -d buildfe; then ${MAKE} setupfe-real; fi

setupfe-real: mk-build-dirfe buildfe/lndir mklinksfe

mk-build-dirfe:
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Initializing Shadow Frontend  Build Directories   +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	-mkdir buildfe

mklinksfe:
	cd buildfe; ./lndir ../../src
	-mkdir buildfe/mf
	cd buildfe/mf; ../lndir ../../../mf
	cd buildfe; rm -f RealMakefile; ln -s ../../mf/RealMakefile .
	cd buildfe; rm -f GNUmakefile; ln -s RealMakefile GNUmakefile
	cd buildfe; rm -f Makefile; \
		ln -s ../../mf/Makefile.redirect Makefile
	cd buildfe; rm -f Makefile.defs; \
		echo "DSUF=/fe" > Makefile.defs; \
		echo 'include $$(TOPDIR)/../Makefile.defs.fe' >> Makefile.defs
	-mkdir buildfe/examples
	cd buildfe/examples; ../lndir ../../../examples
	-mkdir buildfe/test
	cd buildfe/test; ../lndir ../../../test

chklinksfe:
	$(TOPDIR)/config/cleanlinks.sh buildfe

setupfegcc:
	@if test ! -d buildfegcc; then ${MAKE} setupfegcc-real; fi

setupfegcc-real: mk-build-dirfegcc buildfegcc/lndir mklinksfegcc

mk-build-dirfegcc:
	@echo ""
	@echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Initializing Shadow Frontend  Build Directories (GCC)  +"
	@echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	-mkdir buildfegcc

mklinksfegcc:
	cd buildfegcc; ./lndir ../../src
	-mkdir buildfegcc/mf
	cd buildfegcc/mf; ../lndir ../../../mf
	cd buildfegcc; rm -f RealMakefile; ln -s ../../mf/RealMakefile .
	cd buildfegcc; rm -f GNUmakefile; ln -s RealMakefile GNUmakefile
	cd buildfegcc; rm -f Makefile; \
		ln -s ../../mf/Makefile.redirect Makefile
	cd buildfegcc; rm -f Makefile.defs; \
		echo "DSUF=/fegcc" > Makefile.defs; \
		echo 'include $$(TOPDIR)/../Makefile.defs.fegcc' >> Makefile.defs
	-mkdir buildfegcc/test
	cd buildfegcc/test; ../lndir ../../../test

chklinksfegcc:
	$(TOPDIR)/config/cleanlinks.sh buildfegcc

setupbe:
	@if test ! -d buildbe; then ${MAKE} setupbe-real; fi

setupbe-real: mk-build-dirbe buildbe/lndir mklinksbe

mk-build-dirbe:
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Initializing Shadow Backend  Build Directories    +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	-mkdir buildbe

mklinksbe:
	cd buildbe; ../buildfe/lndir ../../src
	-mkdir buildbe/mf
	cd buildbe/mf; ../lndir ../../../mf
	cd buildbe; rm -f RealMakefile; ln -s ../../mf/RealMakefile .
	cd buildbe; rm -f GNUmakefile; ln -s RealMakefile GNUmakefile
	cd buildbe; rm -f Makefile; \
		ln -s ../../config/Makefile.redirect Makefile
	cd buildbe; rm -f Makefile.defs; \
		echo "DSUF=/be" > Makefile.defs; \
		echo 'include $$(TOPDIR)/../Makefile.defs.be' >> Makefile.defs
	-mkdir buildbe/test
	cd buildbe/test; ../lndir ../../../test

chklinksbe:
	$(TOPDIR)/config/cleanlinks.sh buildbe

buildfe/lndir: $(TOPDIR)/config/lndir.c
	$(CC) $(TOPDIR)/config/lndir.c -o buildfe/lndir

buildfegcc/lndir: $(TOPDIR)/config/lndir.c
	$(CC) $(TOPDIR)/config/lndir.c -o buildfegcc/lndir

buildbe/lndir: $(TOPDIR)/config/lndir.c
	$(CC) $(TOPDIR)/config/lndir.c -o buildbe/lndir

realclean:
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Removing Shadow Build Directories                 +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	rm -rf buildfe buildbe

allfe: setupfe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Building Front-End Version                        +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfe; $(MAKE) -f RealMakefile all-fe DSUF="/fe"

installfe: allfe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Installing Front-End Version                      +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfe; $(MAKE) -f RealMakefile install-fe DSUF="/fe"

installtestsfe: installfe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Installing Front-End Version Tests                +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfe; $(MAKE) -f RealMakefile installtests-fe DSUF="/fe"

checkinstfe: installtestsfe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Check Installation Front-End                       +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildbe; $(MAKE) -f RealMakefile checkinst-fe DSUF="/fe"

cleanfe: 
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  cleaning Front-End Version                        +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfe; $(MAKE) -f RealMakefile clean DSUF="/fe"

allfegcc: setupfegcc
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Building Front-End Version (GCC)                  +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfegcc; $(MAKE) -f RealMakefile all-fegcc DSUF="/fe"

installfegcc: allfegcc
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Installing Front-End Version (GCC)                +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfegcc; $(MAKE) -f RealMakefile install-fegcc DSUF="/fegcc"

cleanfegcc: 
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  cleaning Front-End Version (GCC)                  +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildfegcc; $(MAKE) -f RealMakefile clean DSUF="/fegcc"

allbe: setupbe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Building Back-End Version                         +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildbe; $(MAKE) -f RealMakefile all-be DSUF="/be"

installbe: allbe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Installing Back-End Version                       +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildbe; $(MAKE) -f RealMakefile install-be DSUF="/be"

installtestsbe: installbe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Installing Back-End Version Tests                 +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildbe; $(MAKE) -f RealMakefile installtests-be DSUF="/be"

checkinstbe: installtestsbe
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  Check Installation Back-End                       +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildbe; $(MAKE) -f RealMakefile checkinst-be DSUF="/be"

cleanbe: 
	@echo ""
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo "+  cleaning Back-End Version                         +"
	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@echo ""
	cd buildbe; $(MAKE) -f RealMakefile clean DSUF="/be"

