From edd at debian.org  Sat Oct 31 20:58:52 2009
From: edd at debian.org (Dirk Eddelbuettel)
Date: Sat, 31 Oct 2009 14:58:52 -0500
Subject: [Rd] Makevars, cc files in multiple directories
In-Reply-To: <04B3F9E2-03F7-455F-A656-E934FA94383E@gmail.com>
References: <04B3F9E2-03F7-455F-A656-E934FA94383E@gmail.com>
Message-ID: <19180.38652.613966.929943@ron.nulle.part>


On 29 October 2009 at 11:47, Saptarshi Guha wrote:
| Hello,
| In the src folder of my R package I have
| 
| a.cc
| b.cc
| f/g/x.cc
| 
| my Makevars.in has
| 
| all: $(SHLIB)
| 
| upon installing only, a.o and b.o is build and the final dll is  
| comprised of a.o and b.o
| 
| How can I instruct $(SHLIB) to pick up its source files from all  
| subdirectories (or maybe a subset, though here it will be all)
| in src ?

The Matrix package by D Bates and M Maechler has one of the more complex
setups, you could study their example. I include the (short) src/Makevars
below, it uses the (appropriate) Make directive SUBDIRS. And similar to
Paul's suggestionm it seems like static libraries are used to tie the
subdirectories together.

Hth, Dirk

-----------------------------------------------------------------------------
# -*- Makefile -*-

PKG_CPPFLAGS = -I./UFconfig
## we use the BLAS and the LAPACK library:
PKG_LIBS = $(SUBLIBS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

MkInclude = $(R_HOME)/etc${R_ARCH}/Makeconf

include scripts/SOURCES_C.mkf

OBJECTS = $(SOURCES_C:.c=.o)
SUBDIRS = CHOLMOD COLAMD AMD
SUBLIBS = $(SUBDIRS:=.a)

all: $(SHLIB)
## making src/*.o and in sublibs can be done simultaneously
# for development:
#$(SHLIB): $(OBJECTS)
# for real:
$(SHLIB): $(OBJECTS) sublibs

## We have to clean here, to clean up between architectures:
## INSTALL only cleans src/*.o src/*$(SHLIB_EXT) for each arch
sublibs: subclean
	@for d in $(SUBDIRS); do \
	  (cd $${d} && CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" MkInclude="$(MkInclude)" $(MAKE) library) || exit 1; \
	done

clean: subclean
	@-rm -rf .libs _libs
	@-rm -f *.o $(SHLIB)

subclean:
	@-rm -f *.a
	@for d in $(SUBDIRS); do \
	  (cd $${d} && MkInclude="$(MkInclude)" $(MAKE) clean) || exit 1; \
	done


include scripts/DEPS.mkf
-----------------------------------------------------------------------------



-- 
Three out of two people have difficulties with fractions.



[Rd] Makevars, cc files in multiple directories
Dirk Eddelbuettel