# Notes:
#	make		make Scc
#	make Scc	make Scc.
#	make grammar	make a grammar file (stripped from antlr source file)
#	make install	make Scc.
#			Copy Scc to BINDIR and target headers to INCDIR.
#	make clean	Remove various temporary files from the current
#			directory, but not the executable or grammar file.
#	make distclean	make clean.  Remove executable and grammar file.
#	make uninstall	Remove Scc from BINDIR and target headers from INCDIR.

### Installation Directories and Permissions:
# Define these for the machine on which Scc will be installed and run.

# BINDIR is where the Scc executable will be placed once it is built.
# For multi-user systems, this should be a publicly accesible place.
#BINDIR=/home/min/b/rfisher/Private/Research/bin
BINDIR=/usr/local/bin

# BINPERM is the permission mode that will be assigned to the Scc executable
# when it is installed.  It must be executable by whomever should be allowed to
# use Scc.
BINPERM=755

# INCDIR is where the Scc target macro files will be placed, and where Scc
# will expect to find them once it has been built.
# For multi-user systems, this should be a publicly accesible place.
#INCDIR=/home/min/b/rfisher/Private/Research/include
INCDIR=/usr/local/include

# INCDIRPERM is the permission mode that will be assigned to the directory
# $INCDIR during installation.  It must be executable by
# whomever should be allowed to use Scc.
INCDIRPERM=775

# INCPERM is the permission mode that will be assigned to the target-specific
# header files when they are installed.  They must be readable by whomever
# should be allowed to use Scc.
INCPERM=644


### PCCTS Directories:
# Define these for the machine on which Scc will be built.

#H=/home/min/b/rfisher/Private/Research/include/pccts
#DLG=/home/min/b/rfisher/Private/Research/bin/dlg
#ANTLR=/home/min/b/rfisher/Private/Research/bin/antlr
H=/usr/local/include/pccts
DLG=/usr/local/bin/dlg
ANTLR=/usr/local/bin/antlr


### C preprocessor and compiler locations to be built into executable ###
# Define these for the machine on which Scc will eventually be run.

#TARG_CPP=/usr/bin/cpp
TARG_CPP=${BINDIR}/prephack
#TARG_GCC=/home/min/b/rfisher/Private/Research/bin/gcc
TARG_GCC=/usr/bin/gcc
#TARG_GCC=/usr/local/bin/gcc


### Location of C compiler to use to build the Scc executable ###
# Define this for the machine on which Scc will be built.
#CC=/home/min/b/rfisher/Private/Research/bin/gcc
CC=/usr/bin/gcc
#CC=/usr/local/bin/gcc


### Default target definition to be built into the Scc executable ###
# Define this for the machine on which Scc will eventually be run by
#  uncommenting the corresponding target identifier.
# This only defines the default target for Scc; other targets can be chosen on
#  the Scc command line.
# You MUST have one of these uncommented or the build will fail.

DTARG=GenericIA32
#DTARG=GenericMMX
#DTARG=K6
#DTARG=K6_2
#DTARG=K6_3
#DTARG=Athlon
#DTARG=MII
#DTARG=_6x86MX
#DTARG=PentiumII
#DTARG=PentiumMMX
#DTARG=PARISC2
#DTARG=AltiVec



### DO NOT CHANGE ANYTHING BELOW THIS LINE #####################################
SRC=scan.c swarc.c err.c messages.c main.c ir.c showir.c sym.c coercer.c fragmenter.c scheduler.c tuplegen.c tuple_immed.c tuple_binop.c tuple_trinop.c cpool.c output.c oputils.c fe_optimizer.c be_optimizer.c spool.c pseudoregs.c
OBJ=scan.o swarc.o err.o messages.o main.o ir.o showir.o sym.o coercer.o fragmenter.o scheduler.o tuplegen.o tuple_immed.o tuple_binop.o tuple_trinop.o cpool.o output.o oputils.o fe_optimizer.o be_optimizer.o spool.o pseudoregs.o
LIB=Libstdswar/libstdswar.a

CFLAGS=-Wall -I. -I$(H) -DCPP=$(S_CPP) -DGCC=$(S_GCC) -DDEFAULT_TARGET=$(DTARG) -DINCDIR=\"$(INCDIR)\"
AFLAGS=-ga -k 2 -gh

S_CPP=\"$(TARG_CPP)\"
S_GCC=\"$(TARG_GCC)\"
P_GCC=\\\"$(TARG_GCC)\\\"

HEADERS=swartypes.h Scc_mmx.h Scc_3dnow.h Scc_xmmx.h Scc_ia32.h Scc_sse.h \
	Scc_max.h Scc_athlon.h Scc_altivec.h

all: Scc Prephack/prephack

Prephack/prephack: Prephack/prephack.c
	(cd Prephack; make TARG_GCC=${P_GCC})

Scc: $(OBJ) $(SRC) swarc.h tokens.h
	(cd Libstdswar; make)
	(cd Prephack; make TARG_GCC=${P_GCC})
	(cd Utilities; make)
	gcc -o Scc $(OBJ) $(LIB)

swarc.c err.c parser.dlg stdpccts.h : swarc.g swarc.h
	$(ANTLR) $(AFLAGS) swarc.g

tokens.h scan.c : parser.dlg
	$(DLG) -ga -C2 parser.dlg scan.c

main.o: main.c stdpccts.h messages.h showir.h output.h
	gcc $(CFLAGS) -c main.c -O

messages.o: messages.c stdpccts.h
	gcc $(CFLAGS) -c messages.c -O

ir.o: ir.c stdpccts.h ir.h coercer.h fe_optimizer.h sym.h
	gcc $(CFLAGS) -c ir.c -O

showir.o: showir.c stdpccts.h showir.h
	gcc $(CFLAGS) -c showir.c -O

sym.o: sym.c stdpccts.h
	gcc $(CFLAGS) -c sym.c -O

coercer.o: coercer.c stdpccts.h
	gcc $(CFLAGS) -c coercer.c -O

tuple.h:	stdpccts.h
	touch tuple.h

fragmenter.o: fragmenter.c stdpccts.h swartypes.h tuple.h oputils.h sym.h output.h scheduler.h
	gcc $(CFLAGS) -c fragmenter.c -O

scheduler.o: scheduler.c stdpccts.h swartypes.h tuple.h oputils.h scheduler.h spool.h pseudoregs.h showir.h
	gcc $(CFLAGS) -c scheduler.c -O

tuplegen.o: tuplegen.c swartypes.h tuple.h tokens.h scheduler.h be_optimizer.h oputils.h
	gcc $(CFLAGS) -c tuplegen.c -O

tuple_immed.o: tuple_immed.c swartypes.h tuple.h tokens.h scheduler.h be_optimizer.h
	gcc $(CFLAGS) -c tuple_immed.c -O

tuple_binop.o: tuple_binop.c swartypes.h tuple.h tokens.h scheduler.h be_optimizer.h
	gcc $(CFLAGS) -c tuple_binop.c -O

tuple_trinop.o: tuple_trinop.c swartypes.h tuple.h tokens.h scheduler.h be_optimizer.h
	gcc $(CFLAGS) -c tuple_trinop.c -O

cpool.o: cpool.c stdpccts.h swartypes.h tuple.h cpool.h
	gcc $(CFLAGS) -c cpool.c -O

output.o: output.c swarc.h output.h
	gcc $(CFLAGS) -c output.c -O

oputils.o: oputils.c stdpccts.h swartypes.h tuple.h tokens.h
	gcc $(CFLAGS) -c oputils.c -O

fe_optimizer.o: fe_optimizer.c stdpccts.h
	gcc $(CFLAGS) -c fe_optimizer.c -O

be_optimizer.o: be_optimizer.c
	gcc $(CFLAGS) -c be_optimizer.c -O

spool.o: spool.c stdpccts.h swartypes.h tuple.h scheduler.h spool.h
	gcc $(CFLAGS) -c spool.c -O

pseudoregs.o: pseudoregs.c stdpccts.h swartypes.h scheduler.h spool.h pseudoregs.h
	gcc $(CFLAGS) -c pseudoregs.c -O


grammar:
	$(ANTLR) -p swarc.g >grammar


install: Scc
	mkdir -p $(BINDIR)
	cp Scc $(BINDIR)
	-chmod $(BINPERM) $(BINDIR)/Scc
	cp Prephack/prephack $(BINDIR)
	-chmod $(BINPERM) $(BINDIR)/prephack
	mkdir -p $(INCDIR)
	(cd TargetHeaders; cp ${HEADERS} $(INCDIR))
	-chmod $(INCDIRPERM) $(INCDIR)
	(cd $(INCDIR); chmod $(INCPERM) ${HEADERS})

uninstall:
	rm -f $(BINDIR)/Scc
	rm -f $(BINDIR)/prephack
	(cd $(INCDIR); rm -f ${HEADERS})

cleanthis:
	rm -f tokens.h remap.h mode.h stdpccts.h
	rm -f scan.c swarc.c err.c
	rm -f parser.dlg
	rm -f *.Si
	rm -f *.i
	rm -f *.o
	rm -f core

clean: cleanthis
	(cd Examples; make clean)
	(cd Figures; make clean)
	(cd Libstdswar; make clean)
	(cd Prephack; make clean)
	(cd Utilities; make clean)

distclean: cleanthis
	rm -f Scc
	rm -f grammar
	rm -f make.err
	(cd Examples; make distclean)
	(cd Figures; make distclean)
	(cd Libstdswar; make distclean)
	(cd Prephack; make distclean)
	(cd Utilities; make distclean)

