include ../../config.mak

ifeq ($(BUILD_STATIC), yes)
  LDFLAGS += -static
endif

LDFLAGS +=
CXXFLAGS += -O2 -fpermissive

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


gue: main.cc guess.o $(LIB_PATH)/auttools.o $(LIB_PATH)/word.o \
      cmdline.c common_guess.o common.o
	$(CXX) $(CXXFLAGS)  main.cc guess.o \
	$(LIB_PATH)/auttools.o $(LIB_PATH)/word.o cmdline.c common.o common_guess.o \
	-o gue $(LDFLAGS)

guess.o: guess.h guess.cc
	$(CXX) $(CXXFLAGS) -c guess.cc

common_guess.o: cmdline.h  common_guess.cc common_guess.h
	$(CXX) $(CXXFLAGS) -c common_guess.cc

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

cmdline.c cmdline.h: cmdline.ggo
	$(GENGETOPT) -i cmdline.ggo --conf-parser

cmdline.ggo: cmdline_guess.ggo $(COMMON_PATH)/cmdline_common.ggo
	cat cmdline_guess.ggo $(COMMON_PATH)/cmdline_common.ggo > cmdline.ggo


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

clean.cmdline:
	rm cmdline.* || true

.PHONY: install
install:
ifdef BIN_DIR
	install -m 0755 gue $(BIN_DIR)
endif

.PHONY: uninstall
uninstall:
ifdef BIN_DIR
	rm $(BIN_DIR)/gue
endif
