# Makefile for c++ lexer example
# Works with gmake
# All except %: default rule works with Solaris make

CC = gcc -o $@ -c
CPP = g++ -o $@ -c
LEX = flex
YAC = bison -o$*.tab.c
LD = g++ -o $@

LDFLAGS =
CFLAGS =
CPPFLAGS =
LEXFLAGS = -t -s
YACFLAGS = -d

# Recipes:

# This line makes Solaris make forget its hopeless built-in recipes
.SUFFIXES:

# Even so, it is not possible to get Solaris make to accept
# a working default rule for making a final executable. (It doesn't
# have a $^ dynamic macro.)  Use 'gmake' instead!
%:	%.o
	$(LD) $(LDFLAGS) $^

%.o:	%.c
	$(CC) $(CFLAGS) $<

%.o:	%.cpp
	$(CPP) $(CPPFLAGS) $<

%.cpp:	%.l
	$(LEX) $(LEXFLAGS) $< >$@

# Guide make to produce a .cpp, not a .c, from a .y
%.tab.cpp %.tab.h:	%.y
	$(YAC) $(YACFLAGS) $<
	rm -f $*.tab.cpp
	mv $*.tab.c $*.tab.cpp


# ---------------------------------------------------------------
# List of objectfiles (first one's name matches final executable):
OFILES = roman.o roman.tab.o

# Dependencies:
roman:	$(OFILES)

roman.cpp:	roman.l

roman.tab.cpp roman.tab.h:	roman.y

roman.o:	roman.cpp roman.tab.h globals.h

roman.tab.o:	roman.tab.cpp roman.tab.h globals.h


# pseudo-targets

clean:
	rm -f $(OFILES) roman.cpp roman.tab.cpp roman.tab.h

archive:
	tar czf roman.tgz makefile roman.l roman.y

dearchive:	clean
	tar xzf roman.tgz
