
CC=gcc # Requires gcc.
CFLAGS=-g -O2
LIBS=#-lefence
LD=$(CC)
LFLAGS=

all: alpha-fast alpha-aggressive alpha-debug

alpha-fast: main.o fast-exe.o fast-asm-lex.o fast-asm-parse.o
	$(CC) -o alpha-fast $^ $(LIBS)

alpha-aggressive: main.o aggressive-exe.o aggressive-asm-lex.o aggressive-asm-parse.o aggressive-cli-lex.o aggressive-cli-parse.o
	$(CC) -o alpha-aggressive $^ $(LIBS)

alpha-debug: main.o debug-exe.o debug-asm-lex.o debug-asm-parse.o debug-cli-lex.o debug-cli-parse.o
	$(CC) -o alpha-debug $^ $(LIBS)

asm-lex.c: asm-lex.l
	flex -t -Pasm asm-lex.l > asm-lex.c

asm-parse.h asm-parse.c: asm-parse.y
	bison -d -o asm-parse.c -p asm -t asm-parse.y

cli-lex.c: cli-lex.l
	flex -I -8 -t -Pcli cli-lex.l > cli-lex.c

cli-parse.h cli-parse.c: cli-parse.y
	bison -d -o cli-parse.c -p cli -t cli-parse.y

fast-asm-lex.o: asm-lex.c asm-parse.h
	$(CC) $(CFLAGS) -DFAST -c -o $@ $<
fast-asm-parse.o: asm-parse.c exe.h insns.h
	$(CC) $(CFLAGS) -DFAST -c -o $@ $<
fast-exe.o: exe.c exe.h insns.h
	$(CC) $(CFLAGS) -DFAST -c -o $@ $<

aggressive-cli-lex.o: cli-lex.c cli-parse.h
	$(CC) $(CFLAGS) -DAGGRESSIVE -c -o $@ $<
aggressive-cli-parse.o: cli-parse.c exe.h insns.h
	$(CC) $(CFLAGS) -DAGGRESSIVE -c -o $@ $<
aggressive-asm-lex.o: asm-lex.c asm-parse.h
	$(CC) $(CFLAGS) -DAGGRESSIVE -c -o $@ $<
aggressive-asm-parse.o: asm-parse.c exe.h insns.h
	$(CC) $(CFLAGS) -DAGGRESSIVE -c -o $@ $<
aggressive-exe.o: exe.c exe.h insns.h
	$(CC) $(CFLAGS) -DAGGRESSIVE -c -o $@ $<

debug-cli-lex.o: cli-lex.c cli-parse.h
	$(CC) $(CFLAGS) -DDEBUG -c -o $@ $<
debug-cli-parse.o: cli-parse.c exe.h insns.h
	$(CC) $(CFLAGS) -DDEBUG -c -o $@ $<
debug-asm-lex.o: asm-lex.c asm-parse.h
	$(CC) $(CFLAGS) -DDEBUG -c -o $@ $<
debug-asm-parse.o: asm-parse.c exe.h insns.h
	$(CC) $(CFLAGS) -DDEBUG -c -o $@ $<
debug-exe.o: exe.c exe.h insns.h
	$(CC) $(CFLAGS) -DDEBUG -c -o $@ $<

main.o: main.c exe.h insns.h
	$(CC) $(CFLAGS) -c -o $@ $<

TAGS: $(OBJS)
	etags *.h *.c


clean:
	rm -f core *~ *.o *.a \#* # asm-lex.c asm-parse.c asm-parse.h cli-lex.c
