include ../../config.mak

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

LDFLAGS +=
CFLAGS += -O2

tok: lex.yy.c
	$(CC) $(CFLAGS) -lfl -o tok lex.yy.c $(LDFLAGS)

lex.yy.c: tok_cmdline.h tok_cmdline.c
	$(FLEX) tok.l

tok_cmdline.h tok_cmdline.c:
	$(GENGETOPT) -i tok_cmdline.ggo --conf-parser --file=tok_cmdline

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

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

clean: clean.cmdline clean.flex
	rm tok || true

clean.cmdline:
	rm tok_cmdline.c || true
	rm tok_cmdline.h || true

clean.flex:
	rm lex.yy.c || true
