include $(ALLIANCE_TOP)/etc/$(ALLIANCE_OS).mk
include $(ALLIANCE_TOP)/etc/libraries.mk
include ../local.mk

LAX_INC		= lax100.h
LAX_SRC		= laxparam.c laxgram.c laxscan.c
LAX_OBJ		= $(LAX_SRC:.c=.o)
LAX_LIB		= $(TARGET_LIB)/libLax100.a

LAX_INCDIR	= -I$(TARGET_INCLUDE) -I$(ALLIANCE_INCLUDE)
LAX_LIBDIR	= -L$(TARGET_LIB) -L$(ALLIANCE_LIB)    

LAX_DEFINES	= -DMUT_H='<$(MUT_H)>' -DBFL_H='<$(BFL_H)>' \
	  	  -DLAX_H='"lax100.h"'
LAX_LIBRARIES	= -lLax100 $(BFL_L) $(MUT_L)

.c.o	:
	$(CC) -c $(CFLAGS) $(LAX_INCDIR) $(LAX_DEFINES) $<

all : $(LAX_LIB)

$(LAX_LIB) : $(LAX_OBJ) $(LAX_INC)
	$(AR) $(ARFLAGS) $(LAX_LIB) $(LAX_OBJ)
	$(RANLIB) $(LAX_LIB)
	$(CP) $(LAX_INC) $(TARGET_INCLUDE)

dep	:
	$(CC) -MM $(LAX_INCDIR) $(LAX_DEFINES) $(LAX_SRC) > .depend 

clean	:
	$(RM) -f *.o .depend core *~
	$(RM) -f laxgram.c laxgram.h laxscan.c
	$(RM) -f testlax

realclean : clean
	$(RM) -f $(LAX_LIB)
	$(RM) -f $(TARGET_INCLUDE)/$(LAX_INC)

laxgram.c laxgram.h : laxgram.y
	$(YACC) -y -d laxgram.y
	$(SED) -e 's/YY/LAX_/g' -e 's/yy/lax_/g' y.tab.c > laxgram.c
	$(RM) y.tab.c
	$(SED) -e 's/YY/LAX_/g' -e 's/yy/lax_/g' y.tab.h > laxgram.h
	$(RM) y.tab.h

laxscan.c : laxgram.h laxscan.l
	$(LEX) -i laxscan.l
	$(SED) -e 's/YY/LAX_/g' -e 's/yy/lax_/g' lex.yy.c > laxscan.c
	$(RM) lex.yy.c

test	: testlax

testlax : install testlax.o
	$(CC) $(CFLAGS) -o testlax testlax.o $(LAX_LIBDIR) $(LAX_LIBRARIES)

-include .depend
