###############################################################################
#
#
# Filename: Makefile
#
# Author:   Robert Thornburrow
# Project:  Cycle
# Created:  30th June 2003
#
# Purpose:  Makefile for Cycle compiler.
#
# (c) Copyright R.H.Thornburrow, 2003
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
#
###############################################################################
#
# Set OUTDIR and JAVAVM to suit your platform.
#
###############################################################################

OUTDIR=cygwin32

CYCLE=cycle.exe


## Debug build
#CFLAGS=-D_DEBUG

## Release build
CFLAGS=-O3

SRC=cycle.c     cyclex.l    cycpars.y     cycdefs.c \
    codegen.c   dumpgen.c   errors.c      hashtable.c \
    semantic.c  transform.c

OBJ=$(OUTDIR)/cycle.o        $(OUTDIR)/cyclex.o \
	$(OUTDIR)/cycpars.o      $(OUTDIR)/cycdefs.o \
	$(OUTDIR)/codegen.o      $(OUTDIR)/dumpgen.o \
	$(OUTDIR)/errors.o       $(OUTDIR)/hashtable.o \
	$(OUTDIR)/semantic.o     $(OUTDIR)/transform.o

.SUFFIXES: .c .o .l .y

all: $(OUTDIR) $(OUTDIR)/$(CYCLE)

clean:
	-rm -f $(OUTDIR)/*.o $(OUTDIR)/$(CYCLE)

realclean: clean
	-rm -f cyclex.c cycpars.c cycpars.h

$(OUTDIR):
	if [ ! -d $(OUTDIR) ] ; then mkdir $(OUTDIR); fi

$(OUTDIR)/$(CYCLE): $(OBJ)
	gcc -O1 -o $(OUTDIR)/$(CYCLE) $(OBJ)


###############################
# Generic rules (GNU make only)

$(OUTDIR)/%.o: %.c
	gcc -c $(CFLAGS) -o $@ $<

%.c: %.l
	flex -L -d $<
	-rm $@
	mv lex.yy.c $@

%.c %.h: %.y
	bison -v -d -t -o $*.c $<


##################################
# Build .c's and .h's for cygwin32

cyclex.c: cyclex.l
cycpars.c cycpars.h: cycpars.y


#########################
# Build .o's for cygwin32

$(OUTDIR)/cycle.o: cycle.c config.h cycdefs.h cycpars.h errors.h
$(OUTDIR)/cyclex.o: cyclex.c cycdefs.h cycpars.h
$(OUTDIR)/cycpars.o: cycpars.c cycdefs.h cycpars.h errors.h
$(OUTDIR)/cycdefs.o: cycdefs.c cycdefs.h errors.h config.h hashtable.h
$(OUTDIR)/codegen.o: codegen.c cycdefs.h errors.h
$(OUTDIR)/dumpgen.o: dumpgen.c cycdefs.h
$(OUTDIR)/errors.o: errors.c errors.h cycdefs.h config.h
$(OUTDIR)/hashtable.o: hashtable.c hashtable.h
$(OUTDIR)/semantic.o: semantic.c cycdefs.h errors.h
$(OUTDIR)/transform.o: transform.c cycdefs.h errors.h
