topsrc = @top_srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
CC = @CC@
CFLAGS = @CFLAGS@
MAKE = @MAKE@
INSTALL = @INSTALL@
LN_S = @LN_S@
have_readline = @have_readline@
have_zlib = @have_zlib@
have_gnome = @have_gnome@
gnome_prefix = @gnome_prefix@

GNOME_CFLAGS = @GNOME_CFLAGS@
GNOME_LIBS = @GNOME_LIBS@
GTK_CFLAGS = @GTK_CFLAGS@
GTK_LIBS = @GTK_LIBS@
GTK_EXTRA_CFLAGS = @GTK_EXTRA_CFLAGS@
GTK_EXTRA_LIBS = @GTK_EXTRA_LIBS@
PNG_CFLAGS = @PNG_CFLAGS@
PNG_LIBS = @PNG_LIBS@
GDK_PIXBUF_CFLAGS = @GDK_PIXBUF_CFLAGS@
GDK_PIXBUF_LIBS = @GDK_PIXBUF_LIBS@
USE_NLS = @USE_NLS@
INETLIB = @INETLIB@

ifeq ($(CC),)
  CC = gcc
endif
ifeq ($(INSTALL_PROGRAM),)
  INSTALL_PROGRAM = $(INSTALL) -m 755
endif
ifeq ($(INSTALL_DATA),)
  INSTALL_DATA = $(INSTALL) -m 644
endif

ifeq ($(GTK_EXTRA_LIBS),)
  GTK_EXTRA_CFLAGS = -I.
  GTK_EXTRA_LIBS = -L./gtkextra-lite -lgtkextra-lite
  query_gtkextra_lib = gtkextra-lib
endif

ifeq ($(gnome_prefix),)
  gnome_prefix = `gnome-config --prefix`
endif
ifeq ($(have_gnome),1.4)
  LIBS = $(GNOME_LIBS) $(GTK_EXTRA_LIBS) ../lib/libgretl-1.0.la
  GUI_CFLAGS = $(GNOME_CFLAGS) $(GTK_EXTRA_CFLAGS)
  query_install_gnome = install-gnome
else
  LIBS = $(GTK_LIBS) $(GTK_EXTRA_LIBS) ../lib/libgretl-1.0.la
  GUI_CFLAGS = $(GTK_CFLAGS) $(GTK_EXTRA_CFLAGS)
endif
ifeq ($(USE_NLS),yes)
  datadir = @datadir@
  localedir = $(datadir)/locale
  DEFS = -DLOCALEDIR=\"$(localedir)\"
endif

override CFLAGS += -I.. -I$(libsrc) $(GUI_CFLAGS) $(PNG_CFLAGS) \
	$(GDK_PIXBUF_CFLAGS) $(DEFS)
override LIBS += $(PNG_LIBS) $(GDK_PIXBUF_LIBS)

# Directories
bindir	= $(prefix)/bin
gretldir = $(prefix)/share/gretl
tooldir = $(topsrc)/tools
libsrc = $(topsrc)/lib/src
clisrc = $(topsrc)/cli
docdir = $(topsrc)/doc

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

SHELL = /bin/sh
LIBTOOL = ../libtool
PROG  = gretl_x11

vpath %.c = $(topsrc)/gui
vpath %.h = $(topsrc)/gui

SRCS = about.c \
	boxplots.c \
	calculator.c \
	callbacks.c \
	clipboard.c \
	cmdstack.c \
	console.c  \
	database.c \
	datafiles.c \
	dialogs.c \
	dlgutils.c \
	filelists.c \
	fileselect.c \
	gpt_control.c \
	gpt_dialog.c \
	graph_page.c \
	gretl.c \
	guiprint.c \
	gui_utils.c \
	helpfiles.c \
	library.c \
	menustate.c \
	model_table.c \
	obsbutton.c \
	objectsave.c \
	selector.c \
	series_view.c \
	session.c \
	settings.c \
	ssheet.c \
	textbuf.c \
	textutil.c \
	toolbar.c \
	webget.c 

OBJS = $(SRCS:.c=.o)

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

$(PROG): .deps $(query_gtkextra_lib) $(OBJS) 
	$(LIBTOOL) --mode=link $(CC) -o $@ $(OBJS) $(LIBS) $(INETLIB)

.deps:
	mkdir $@

-include .deps/*.d

.PHONY:

gtkextra-lib: 
	rm -f ./gtkextra && $(LN_S) ./gtkextra-lite ./gtkextra
	make -C gtkextra-lite

install: $(PROG) install-data $(query_install_gnome)
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $(PROG) $(bindir)/$(PROG)

install-strip: $(PROG) install-data $(query_install_gnome)
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) -s $(PROG) $(bindir)/$(PROG)

install-data: installdirs
	$(INSTALL_PROGRAM) ../gretl_sh $(bindir)/gretl
	$(INSTALL_DATA) $(topsrc)/pixmaps/gretl-logo.xpm $(gretldir)
	$(INSTALL_DATA) $(topsrc)/COPYING $(gretldir)

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

install-gnome: $(PROG) installdirs 
	$(MAKE) -C ../gnome install

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

clean:
	rm -f *.o $(PROG)
	rm -rf .libs .deps
	make -C gtkextra-lite clean

distclean: clean
	rm -f Makefile debug

