# makefile for crobots

OBJS =  main.o grammar.o lexanal.o compiler.o cpu.o intrins.o display.o screen.o motion.o

XOBJS =   main.o grammar.o lexanal.o compiler.o cpu.o intrins.o display.o screenx.o motion.o

SOURCES = crobots.h compiler.h tokens.h main.c grammar.y grammar.c lexanal.l lexanal.c compiler.c cpu.c intrins.c display.c screen.c screend.c screenx.c \
motion.c 

DOS = main.c grammar.c lexanal.c compiler.c cpu.c intrins.c display.c screend.c motion.c 

DOSA = main.c grammar.c lexanal.c compiler.c cpu.c intrins.c display.c screena.c motion.c 

CFLAGS = -O -DUNIX
LIBS = -lm -lcurses -ltermlib
XLIBS = -lm -lcurses -ltermlib -lX11


crobots: 	$(OBJS)
		cc -s $(CFLAGS) $(OBJS) -o crobots $(LIBS)

xcrobots: 	$(XOBJS)
		cc -s $(CFLAGS) $(XOBJS) -o xcrobots $(XLIBS)

main.o: 	crobots.h main.c
		cc $(CFLAGS) -c main.c

grammar.o: 	crobots.h compiler.h grammar.y
		yacc -d grammar.y
		cat y.tab.c >grammar.c
		rm y.tab.c
		mv y.tab.h tokens.h
		cc $(CFLAGS) -c grammar.c

lexanal.o: 	crobots.h compiler.h lexanal.l grammar.y
		lex lexanal.l
		cat lex.yy.c >lexanal.c
		rm lex.yy.c
		cc $(CFLAGS) -c lexanal.c

compiler.o: 	crobots.h compiler.h tokens.h compiler.c
		cc $(CFLAGS) -c compiler.c
	
cpu.o: 		crobots.h grammar.y cpu.c
		cc $(CFLAGS) -c cpu.c
	
intrins.o:	crobots.h intrins.c
		cc $(CFLAGS) -c intrins.c
	
display.o:	crobots.h display.c
		cc $(CFLAGS) -c display.c
	
screen.o:	crobots.h screen.c
		cc $(CFLAGS) -c screen.c
	
screenx.o:	crobots.h screenx.c
		cc $(CFLAGS) -c screenx.c
	
motion.o:	crobots.h motion.c
		cc $(CFLAGS) -c motion.c
	
dos:
		cc -s -dos -K -i -O -DDOS $(DOS) -o crobotsx.exe -lm
		/bin/rm *.o

dosa:
		cc -s -dos -K -i -O -DDOS $(DOSA) -o crobotsa.exe -lm
		/bin/rm *.o
print:
		pr -t $(SOURCES) | lpr

lint:
		lint -abc *.c | tee crobots.lint
		@echo 'lint output kept in crobots.lint'

