# determine compiler/system
# currently supported:
# cc on Mac OS X Darwin
# cygwin's and djgpp's gcc on Windows
# otherwise will try to use gcc

UNAME = $(shell uname)
RENAMELEX = 

ifeq ($(UNAME),Darwin)
        CC = cc
	CFLAGS = -g -Wall
else
	CC = gcc
ifneq (,$(findstring CYGWIN,$(UNAME)))
	CFLAGS = -g -s -Wall -mno-cygwin
else
ifdef DJGPP
	CFLAGS = -g -s -Wall
	# djgpp flex creates lexyy.c instead of lex.yy.c
	RENAMELEX = mv lexyy.c lex.yy.c
else
	CFLAGS = -g -Wall
endif
endif
endif

# end of compiler specific code

DEBUG = --debug

LIBS = -lz

OFILES = flasm.o unflasm.o endian.o lex.yy.o assembler.tab.o

all: flasm

clean:
	-rm -f ${OFILES} assembler.tab.* lex.yy.c core test

flasm:	${OFILES}
	${CC} $(CFLAGS) -o flasm ${OFILES} ${LIBS}

assembler.tab.c: assembler.y
	bison assembler.y

assembler.tab.h: assembler.y
	bison --defines ${DEBUG} assembler.y

lex.yy.o: lex.yy.c

lex.yy.c: assembler.flex assembler.tab.h
	flex -i assembler.flex
	$(RENAMELEX)
