Set a temporary environment ($PATH)

I may fall into a X-Y problem with this question and I encourage you guys to correct me if I am wrong.

I would like to configure a toolchain environment that can work on different platform and different compiler version. I initially wrote a long Perl script that generate configuration Makefile that contain only variables. I wanted to be KISS so I did not write any complexe things using automake or autoconf. Moreover I wanted the reconfiguration process to be very fast. In my case my home made ./configure does everything in less than 1 second. I am very happy with that.

However I fill I can use a better approach using environment variables. Instead to writing a Makefile with the specific variables I can set the current shell environment directly. For example:

export cc=gcc

Unfortunately some variables are already declared in the $PATH. The solution is to add the new $PATH in the front of the other:

export PATH=/new/toolchain/path:PATH

echo $PATH
/new/toolchain/path:/old/toolchain/path:/usr/bin:/bin...

I fill this is ugly I would like to remove the old path before adding the new one.

To conclude:

  1. Is it better to use the environment instead of custom makefiles to set a build configuration?
  2. How to properly adjust existing environment variables?


Source: bash

Leave a Reply