From edeveaud at pasteur.fr  Tue Sep 27 15:23:57 2016
From: edeveaud at pasteur.fr (Eric Deveaud)
Date: Tue, 27 Sep 2016 15:23:57 +0200
Subject: [Rd] src/Makevars ignored ?
In-Reply-To: <22506.22668.727653.313373@max.nulle.part>
References: <5abedec3-552a-b141-a9e2-ef74e212b893@pasteur.fr>
	<22506.22668.727653.313373@max.nulle.part>
Message-ID: <b11e2a62-95bd-0d2f-66ba-2d6177f62bb9@pasteur.fr>

Le 27/09/16 ? 13:31, Dirk Eddelbuettel a ?crit :
>
> On 27 September 2016 at 09:37, Eric Deveaud wrote:
> |      Hello,
> |
> | I'm tring to install a Rpackage that holds some C//C++ code
> |
> | as far as I understood the R library generic compilation mechanism,
> | compilation of C//C++ sources is controled
> |
> | 1) at system level by the ocntentos RHOME/etc/Makeconf
> | 2) at user level by the content of ~/.R/Makevars
> | 3) at package level by the content of src/Makevars
> |
> | Problem I have is that src/Makevars is ignored
> |
> |
> | see following example:
> |
> | R is compiled and use the following CC and CFLAGS definition
> |
> | bigmess:epactsR/src > R CMD config CC
> | gcc -std=gnu99
> | bigmess:epactsR/src > R CMD config CFLAGS
> | -Wall -g
> |
> | so building C sources lead to the following
> |
> | bigmess:epactsR/src > R CMD SHLIB index.c
> | gcc -std=gnu99 -I/local/gensoft2/adm/lib64/R/include -DNDEBUG
> | -I/usr/local/include    -fpic  -Wall -g  -c index.c -o index.o
> |
> | normal, it uses defintion from RHOME/etc/Makeconf
> |
> |
> | when I set upp a ~/.R/Makevars that overwrite CC and CFLAGS definition.
> |
> | bigmess:epactsR/src > cat ~/.R/Makevars
> | CC=gcc
> | CFLAGS=-O3
> | bigmess:epactsR/src > R CMD SHLIB index.c
> | gcc -I/local/gensoft2/adm/lib64/R/include -DNDEBUG  -I/usr/local/include
> |     -fpic  -O3 -c index.c -o index.o
> | gcc -std=gnu99 -shared -L/usr/local/lib64 -o index.so index.o
> |
> |
> | OK CC and CFLAGS are honored and set accordingly to ~/.R/Makevars
> |
> |
> | but when I try to use src/Makevars, it is ignored
> |
> | bigmess:epactsR/src > cat ~/.R/Makevars
> | cat: /home/edeveaud/.R/Makevars: No such file or directory
> | bigmess:epactsR/src > cat ./Makevars
> | CC = gcc
> | CFLAGS=-O3
> | bigmess:epactsR/src > R CMD SHLIB index.c
> | gcc -std=gnu99 -I/local/gensoft2/adm/lib64/R/include -DNDEBUG
> | -I/usr/local/include    -fpic  -Wall -g  -c index.c -o index.o
> |
> |
> | is there something I have missed, misunderstood or is there something
> | wrong ?
>
> You have not demonstrated that src/Makevars is ignored -- as it clearly
> isn't, given how thousands of CRAN packages use it.
>
> What you have done is demonstrate that you _cannot change CC and CXX_ in
> src/Makevars.  And I think that was known, though maybe not as widely.


     Hello Dirk,


so why ~/R/Makevars allows to change CC and not src/Makevars ?

this is pretty confusing.

in unix world mechanism of overwriting system default in user and 
package order is something standadr and consistent given the level

priority is package specific stuff overwrite user configuration that 
overwrite system default

mechanism of Makevars is NOT consistent


furthermore diggng in $RHOME/bin/config one can see the following


if test "${site}" = "yes"; then
: ${R_MAKEVARS_SITE="${R_HOME}/etc${R_ARCH}/Makevars.site"}
   if test -f "${R_MAKEVARS_SITE}"; then
     makefiles="${makefiles} -f ${R_MAKEVARS_SITE}"
   fi
fi
if test "${personal}" = "yes"; then
   if test "${R_OSTYPE}" = "windows"; then
     if test -f "${R_MAKEVARS_USER}"; then
       makefiles="${makefiles} -f ${R_MAKEVARS_USER}"
     elif test ${R_ARCH} = "/x64" -a -f "${HOME}/.R/Makevars.win64"; then
       makefiles="${makefiles} -f ${HOME}/.R/Makevars.win64"
     elif test -f "${HOME}/.R/Makevars.win"; then
       makefiles="${makefiles} -f ${HOME}/.R/Makevars.win"
     elif test -f "${HOME}/.R/Makevars"; then
       makefiles="${makefiles} -f ${HOME}/.R/Makevars"
     fi
   else
     . ${R_HOME}/etc${R_ARCH}/Renviron
     if test -f "${R_MAKEVARS_USER}"; then
       makefiles="${makefiles} -f ${R_MAKEVARS_USER}"
     elif test -f "${HOME}/.R/Makevars-${R_PLATFORM}"; then
       makefiles="${makefiles} -f ${HOME}/.R/Makevars-${R_PLATFORM}"
     elif test -f "${HOME}/.R/Makevars"; then
       makefiles="${makefiles} -f ${HOME}/.R/Makevars"
     fi
   fi
fi

it checks and honours R_MAKEVARS_USER, ~/.R/Makevars, but not src/Makevars
I'm not really familiar with the R policy about code comilation, but I 
consider this a bug but maybee I'm wrong


as a side note I solved the problem of overwritting CC for this 
particular package using MAKEFLAGS="CC=gcc" R CMD INSTALL package


     best regards

     Eric



[Rd] src/Makevars ignored ?
Eric Deveaud