LDFLAGS += -static
CXXFLAGS += -O2 -fpermissive

LIB_PATH=../lib
COMMON_PATH=../common
CMDLINE_FILE='"../lem/cmdline.h"'


lem: main.cc lem.o  $(LIB_PATH)/auttools.o $(LIB_PATH)/word.o \
      cmdline.c common_lem.o common.o symtab.o
	g++ $(CXXFLAGS) $(LDFLAGS) -D _CMDLINE_FILE=$(CMDLINE_FILE) \
	main.cc lem.o $(LIB_PATH)/auttools.o \
	$(LIB_PATH)/word.o cmdline.c common.o common_lem.o \
	symtab.o -o lem

lem.o: lem.h lem.cc
	g++ $(CXXFLAGS) -c -D _CMDLINE_FILE=$(CMDLINE_FILE) lem.cc

common.o: $(COMMON_PATH)/cmdline_common.ggo $(COMMON_PATH)/common.cc \
	 $(COMMON_PATH)/common.h
	g++ $(CXXFLAGS) -c -D _CMDLINE_FILE=$(CMDLINE_FILE) $(COMMON_PATH)/common.cc

common_lem.o: cmdline.h common_lem.h common_lem.cc
	g++ $(CXXFLAGS) -c -D _CMDLINE_FILE=$(CMDLINE_FILE) common_lem.cc

cmdline.c cmdline.h: cmdline.ggo
	gengetopt -i cmdline.ggo --conf-parser

cmdline.ggo: cmdline_lem.ggo ../common/cmdline_common.ggo
	cat cmdline_lem.ggo ../common/cmdline_common.ggo > cmdline.ggo

symtab.o: $(LIB_PATH)/symtab.h $(LIB_PATH)/symtab.cc
	g++ $(CXXFLAGS) -c $(LIB_PATH)/symtab.cc

clean: clean.cmdline
	rm *.o || true
	rm lem || true

clean.cmdline:
	rm cmdline.* || true

copy:
ifdef UTT_BIN_DIR
	cp lem $(UTT_BIN_DIR)
endif
