# -*- mode: Makefile; tab-width: 8 -*- 
#
# Makefile for Rcpp 
#
# Copyright (C) 2008    Dirk Eddelbuettel <edd@debian.org>
# Copyright (C) 2008    Simon Urbanek <simon.urbanek@r-project.org>

## $(SHLIB) is the usual default target that is built automatically from all source 
## files in this directory. userLibrary is an additional target for the second library
## that will be installed in ../inst/lib$(R_ARCH) and which users can link against.

PKG_CPPFLAGS=-I$(LIB_GSL)/include
PKG_LIBS=-L$(LIB_GSL)/lib -lgsl -lgslcblas
#PKG_LIBS=-L/usr/local/gsl/1.13/lib -lgsl -lgslcblas

all: 		$(SHLIB) userLibrary

USERLIB	=	libMvRcpp$(DYLIB_EXT)
USERLIBST =	libMvRcpp.a
USERDIR =	../inst/lib

userLibrary: 	$(USERLIB) $(USERLIBST)
		-@if test ! -e $(USERDIR)$(R_ARCH); then mkdir -p $(USERDIR)$(R_ARCH); fi
		cp $(USERLIB) $(USERDIR)$(R_ARCH)
		cp mvRcpp.h $(USERDIR)$(R_ARCH)
		cp $(USERLIBST) $(USERDIR)$(R_ARCH)
		rm $(USERLIB) $(USERLIBST)

$(USERLIB): 	mvRcpp.o
		$(SHLIB_CXXLD) -o $(USERLIB) $^ $(SHLIB_CXXLDFLAGS) $(ALL_LIBS)
		@if test -e "/usr/bin/install_name_tool"; then /usr/bin/install_name_tool -id $(R_PACKAGE_DIR)/lib$(R_ARCH)/$(USERLIB) $(USERLIB); fi

$(USERLIBST): 	mvRcpp.o
		$(AR) qc $(USERLIBST) mvRcpp.o
		@if test -n "$(RANLIB)"; then $(RANLIB) $(USERLIBST); fi

.PHONY: 	all clean userLibrary 

clean:
		rm -f $(OBJECTS) $(SHLIB) $(USERLIB) $(USERLIBST)

