topsrc = @top_srcdir@

CC = @CC@
CFLAGS = @CFLAGS@
MAKE = @MAKE@
INSTALL = @INSTALL@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
datadir = @datadir@
localedir = $(datadir)/locale

have_readline = @have_readline@
READLINE_LIBS = @READLINE_LIBS@
READLINE_CFLAGS = @READLINE_CFLAGS@

ifeq ($(CC),)
  CC = gcc
endif
ifeq ($(INSTALL_PROGRAM),)
  INSTALL_PROGRAM = $(INSTALL) -m 755
endif
ifeq ($(have_readline),yes)
  RL_OBJ = complete.o
endif

GRETLLIB = ../lib/libgretl-1.0.la

# Working directories
tooldir = $(topsrc)/tools
libsrc = $(topsrc)/lib/src

vpath %.c $(topsrc)/cli

#### End of system configuration section. ####

SRCS = gretlcli.c complete.c
OBJS = gretlcli.o $(RL_OBJ)

DEFS = -DLOCALEDIR=\"$(localedir)\" -DHAVE_CONFIG_H

override CFLAGS += -I.. -I$(topsrc) -I$(libsrc) $(READLINE_CFLAGS) $(DEFS)

CLI = gretlcli
LIBTOOL = ../libtool

%.o: %.c
	$(CC) -c $(CFLAGS) $<
	$(CC) $(CFLAGS) -MM $< > .deps/$*.d 

$(CLI): .deps $(OBJS)
	$(LIBTOOL) --mode=link $(CC) -o $@ $(OBJS) $(GRETLLIB) $(READLINE_LIBS) 

.deps:
	mkdir $@

-include .deps/*.d

.PHONY :

install: $(CLI) installdirs
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $(CLI) $(bindir)/$(CLI)

install-strip: $(CLI) installdirs
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) -s $(CLI) $(bindir)/$(CLI)

installdirs: $(tooldir)/mkinstalldirs
	$(tooldir)/mkinstalldirs $(bindir)

clean:
	rm -f *.o $(CLI)
	rm -rf .libs .deps

distclean: clean
	rm -f Makefile debug
