How to shadow the base gcc/g++ from external apps so they use egcc/eg++ unkowningly?


#1

I'm porting Dart to OpenBSD but outside the ports ecosystem this time around. I know ports have MODGCC4 which properly hides the base compilers and uses gcc4 from ports.

I want to essentially do the same outside the ports tree as I have to work on the master branch to add proper OpenBSD support in dart.

So far I had great progress by just setting the $CXX environment variable to eg++ and setting $CC to egcc but there is a spot in the build that seems to hard call g++ that I'm having issue localizing.

The issue is reported upstream but I would like to continue moving forward with the port while waiting for an answer.


#2

From gcc4.port.mk:

.if !empty(_MODGCC4_LINKS)
. if “${USE_CCACHE:L}” == “yes” && “${NO_CCACHE:L}” != “yes”
. for _src _dest in ${_MODGCC4_LINKS}
MODGCC4_post-patch += rm -f ${WRKDIR}/bin/${_dest};
MODGCC4_post-patch += echo ‘#!/bin/sh’ >${WRKDIR}/bin/${_dest};
MODGCC4_post-patch += echo exec ccache ${LOCALBASE}/bin/${_src} "$$@"
MODGCC4_post-patch += >>${WRKDIR}/bin/${_dest};
MODGCC4_post-patch += chmod +x ${WRKDIR}/bin/${_dest};
. endfor
. else
. for _src _dest in ${_MODGCC4_LINKS}
MODGCC4_post-patch += ln -sf ${LOCALBASE}/bin/${_src} ${WRKDIR}/bin/${_dest};
. endfor
. endif
.endif

This will link in the compilers and set the PATH variable so that ${WRKDIR}/bin resolves first.

Obviously
this isn’t available out side of the ports infrastructure… but a
similar thing can be done in your with local environment vars.


#3

This answer essentially unblocked me. Thank you.

Here is what I did.

make a pbin directory.

Create symlinks to egcc, gcc, eg++ & g++ in it

$ ln -sf `which egcc` egcc
$ ln -sf `which egcc` gcc
$ ln -sf `which eg++` eg++
$ ln -sf `which eg++` g++  
$ ls -l
total 16
-rw-r--r--  1 mulander  mulander  104 Sep  4 19:38 README.txt
lrwxr-xr-x  1 mulander  mulander   19 Sep  4 19:39 eg++ -> /usr/local/bin/eg++
lrwxr-xr-x  1 mulander  mulander   19 Sep  4 19:38 egcc -> /usr/local/bin/egcc
lrwxr-xr-x  1 mulander  mulander   19 Sep  4 19:39 g++ -> /usr/local/bin/eg++
lrwxr-xr-x  1 mulander  mulander   19 Sep  4 19:39 gcc -> /usr/local/bin/egcc


Next add it to path:

$ export PATH=`pwd`/pbin:$PATH

$ gcc --version
gcc (GCC) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
g++ (GCC) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Resume porting! :D