SHELL=/bin/sh

# makefile for the LOESS module
#
# required libraries: libblas, liblapack, libf2c
# (you may have to set soft links so that linker finds them)
#
# the makefile calls python-config to get the compilation flags and include path.
# you may override the corresponding variables on the command line or by environment variables:
#
# PYTHON_INC: specify additional include directories. each dir must start with -I prefix.
# PYTHON_CFLAGS: specify the C compiler flags.
#
# see the top-level makefile for additional information.

.SUFFIXES:
.SUFFIXES: .c .cpp .cxx .exe .f .h .i .o .py .pyf .so .x
.PHONY: all loess test gas madeup ethanol air galaxy

OBJ=loessc.o loess.o predict.o misc.o loessf.o dqrsl.o dsvdc.o fix_main.o

FFLAGS?=-O
LIB=-lblas -lm -lf2c
LIBPATH?=
CC?=gcc
CCOPTS?=
SWIG?=swig
SWIGOPTS?=
PYTHON?=python
PYTHONOPTS?=
PYTHON_CONFIG = ${PYTHON}-config
#PYTHON_LIB ?= $(shell ${PYTHON_CONFIG} --libs)
#PYTHON_INC ?= $(shell ${PYTHON_CONFIG} --includes)
PYTHON_INC ?=
PYTHON_CFLAGS ?= $(shell ${PYTHON_CONFIG} --cflags)
#PYTHON_LDFLAGS ?= $(shell ${PYTHON_CONFIG} --ldflags)

all: loess

loess: _loess.so

loess.py _loess.so: loess.c loess.i
	$(PYTHON) $(PYTHONOPTS) setup.py build_ext --inplace

examples: gas madeup ethanol air galaxy

gas: gas.x

gas.x: gas.o $(OBJ)
	$(CC) -o gas.x gas.o $(OBJ) $(LIB)

madeup: madeup.x

madeup.x: madeup.o $(OBJ)
	$(CC) -o madeup.x madeup.o $(OBJ) $(LIB)

ethanol: ethanol.x

ethanol.x: ethanol.o $(OBJ)
	$(CC) -o ethanol.x ethanol.o $(OBJ) $(LIB)

air: air.x

air.x: air.o $(OBJ)
	$(CC) -o air.x air.o $(OBJ) $(LIB)

galaxy: galaxy.x

galaxy.x: galaxy.o $(OBJ)
	$(CC) -o galaxy.x galaxy.o $(OBJ) $(LIB)

clean:
	rm -f *.o *.so *.x core *.pyc
	rm -f loess.py loess_wrap.c
