topsrc = @top_srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
CC = @CC@
CFLAGS = @CFLAGS@
MAKE = @MAKE@
INSTALL = @INSTALL@
LN = @LN_S@
XML_CFLAGS = @XML_CFLAGS@
XML_LIBS = @XML_LIBS@
GLIB_CFLAGS = @GLIB_CFLAGS@
GLIB_LIBS = @GLIB_LIBS@
GMP_CFLAGS = @GMP_CFLAGS@
GMP_LIBS = @GMP_LIBS@
LAPACK_LIBS = @LAPACK_LIBS@

CURRENT=@LIBGRETL_CURRENT@
REVISION=@LIBGRETL_REVISION@
AGE=@LIBGRETL_AGE@

have_gtk = @have_gtk@

ifeq ($(INSTALL_PROGRAM),)
  INSTALL_PROGRAM = $(INSTALL) -m 755
endif
ifeq ($(INSTALL_DATA),)
  INSTALL_DATA = $(INSTALL) -m 644
endif
ifeq ($(LN),)
  LN = ln -sf
endif

# Installation directories
libdir = $(prefix)/lib
includedir = $(prefix)/include/gretl
aclocaldir = $(prefix)/share/aclocal
pkgconfigdir = $(libdir)/pkgconfig

INSTALLDIRS = $(libdir) $(includedir) $(aclocaldir)

LIBGRETL = libgretl-1.0.la 

# Libraries:
ifeq ($(have_gtk),2.0)
  INSTALLDIRS += $(pkgconfigdir)
  INSTALL_CFG = install-cfg-new
else
  INSTALL_CFG = install-cfg-old
endif

# hard-coded -L/usr/local/lib is a bodge!!

LIBS = $(LAPACK_LIBS) -lm -ldl -L/usr/local/lib -lz $(XML_LIBS) \
	$(GLIB_LIBS) $(GMP_LIBS)

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

libsrc  = $(topsrc)/lib/src
cephessrc = $(topsrc)/cephes
minpacksrc = $(topsrc)/minpack
VPATH = $(libsrc):$(cephessrc):$(minpacksrc)

PUBLIC_HDRS = \
	bhhh_max.h \
	calendar.h \
	compare.h \
	compat.h \
	dataio.h \
	dataset.h \
	dbread.h \
	describe.h \
	discrete.h \
	estimate.h \
	forecast.h \
	generate.h \
	genstack.h \
	graphing.h \
	gretl_commands.h \
	gretl_errors.h \
	gretl_func.h \
	gretl_intl.h \
	gretl_list.h \
	gretl_matrix.h \
	gretl_model.h \
	gretl_paths.h \
	gretl_prn.h \
	gretl_restrict.h \
	gretl_string_table.h \
	gretl_utils.h \
	gretl_win32.h \
	interact.h \
	libgretl.h \
	libset.h \
	missing.h \
	modelprint.h \
	modelspec.h \
	monte_carlo.h \
	nls.h \
	nonparam.h \
	options.h \
	plugins.h \
	printout.h \
	pvalues.h \
	qr_estimate.h \
	random.h \
	strutils.h \
	subsample.h \
	system.h \
	texprint.h \
	transforms.h \
	var.h

SRCS = bhhh_max.c \
	calendar.c \
	compare.c \
	compat.c \
	dataio.c \
	dataset.c \
	dbread.c \
	dbwrite.c \
	describe.c \
	discrete.c \
	estimate.c \
	forecast.c \
	generate.c \
	genstack.c \
	graphing.c \
	gretl_commands.c \
	gretl_errors.c \
	gretl_func.c \
	gretl_intl.c \
	gretl_list.c \
	gretl_matrix.c \
	gretl_model.c \
	gretl_paths.c \
	gretl_prn.c \
	gretl_restrict.c \
	gretl_string_table.c \
	gretl_utils.c \
	interact.c \
	libset.c \
	missing.c \
	modelprint.c \
	modelspec.c \
	monte_carlo.c \
	nls.c \
	nonparam.c \
	options.c \
	plugins.c \
	printout.c \
	pvalues.c \
	qr_estimate.c \
	random.c \
	strutils.c \
	subsample.c \
	system.c \
	texprint.c \
	transforms.c \
	var.c

CEPHES_SRC = bdtr.c btdtr.c chbevl.c chdtr.c const.c expx2.c \
	   fdtr.c gamma.c gdtr.c igam.c igami.c incbet.c incbi.c \
	   mtherr.c nbdtr.c ndtr.c ndtri.c pdtr.c polevl.c \
	   stdtr.c unity.c 

MINPACK_SRC = chkder.c dpmpar.c enorm.c fdjac2.c lmder.c lmder1.c lmdif.c lmpar.c \
	qrfac.c qrsolv.c dlog10.c

LOBJS = $(SRCS:.c=.lo)
AUX_LOBJ = $(CEPHES_SRC:.c=.lo) $(MINPACK_SRC:.c=.lo)

LIBTOOL = ../libtool

override CFLAGS += -I.. -I$(topsrc) -I$(libsrc) $(XML_CFLAGS) $(GLIB_CFLAGS) \
	$(GMP_CFLAGS) -DHAVE_CONFIG_H

COMPILE = $(LIBTOOL) --mode=compile $(CC) -c $(CFLAGS) 

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

$(LIBGRETL): .deps $(LOBJS) $(AUX_LOBJ)
	$(LIBTOOL) --mode=link $(CC) -o $@ $(LOBJS) $(AUX_LOBJ) \
	-rpath $(prefix)/lib $(LIBS) \
	-version-info $(CURRENT):$(REVISION):$(AGE)

.deps:
	mkdir $@

-include .deps/*.d

.PHONY: 

install: $(LIBGRETL) install-data
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $< $(libdir)/$<

install-strip: $(LIBGRETL) install-data
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) -s $< $(libdir)/$<

install-data: installdirs $(INSTALL_CFG)
	for f in $(PUBLIC_HDRS) ; do \
	$(INSTALL_DATA) $(libsrc)/$$f $(includedir) ; done

install-cfg-old: ../gretl-config
	$(INSTALL_PROGRAM) ../gretl-config $(bindir)
	$(INSTALL_DATA) $(topsrc)/gretl.m4 $(aclocaldir)

install-cfg-new: ../gretl.pc
	$(INSTALL_DATA) ../gretl.pc $(pkgconfigdir)

installdirs:
	$(topsrc)/tools/mkinstalldirs $(INSTALLDIRS)

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

distclean: clean
	rm -f Makefile

tags:
	$(MAKE) -C $(topsrc) tags



