## -*- mode: Makefile; tab-width: 8 -*-
##
## Makevars.in for littler
## Based on older Makefile.am
##
## Copyright (C) 2006 - 2016  Jeffrey Horner and Dirk Eddelbuettel, GNU GPL'ed

RPROG=@RPROG@
ROPTS = --silent --vanilla --slave

CC=@CC@
PKG_CFLAGS=@AM_CFLAGS@
PKG_LDFLAGS=@AM_LDFLAGS@ @EXTRA_LDFLAGS@

RUN_NAMETOOL=@RUN_NAMETOOL@

SRCS = littler.c
TGT = r$(EXEEXT)

# By setting OBJECTS to "" we avoid having littler.so built
OBJECTS=

all:    $(SHLIB) $(TGT)

prog:   littler.c

# Main r build rule, with suitable extension where needed (as eg on OS X)
$(TGT): $(SRCS)
	@$(RPROG) $(ROPTS) --file=scripts/autoloads.R > autoloads.h
	@$(RPROG) $(ROPTS) --file=scripts/littler.R > littler.h
	$(CC) -o $(TGT) $(PKG_CFLAGS) $(SRCS) $(PKG_LDFLAGS)
	$(RUN_NAMETOOL)
	@mkdir -p ../inst/bin$(R_ARCH)
	@cp -a $(TGT) ../inst/bin$(R_ARCH)
	@echo "*"
	@echo "* new binary $(TGT) installed in bin/ subdirectory"
	@echo "* consider adding a symbolic link from, e.g., /usr/local/bin"
	@echo "* on OS X, you may have to name this 'lr' instead"
	@echo "* see the littler-faq vignette for more details"
	@echo "*"
