Search code examples
eclipsebuildmakefileenvironment-variableseclipse-cdt

What are Eclipse's Build Variables and how do they differ from the Environment Variables?


Using ARM DS-5 environment, based on Eclipse 4.3.2, I defined a C project and using a Makefile to build it. The Makefile contains a few module selection variables, which are set to Y or N depending on whether we want to include the module or not.

I am trying to set these variables from the project settings. Thus, I use the following construct to have a default setting in the Makefile:

Module_1 ?= Y
Module_2 ?= Y

Now, I want to add a project variable Module_1 set to Y or N. It happens that there are Build Variables and Environment Variables under C/C++ Build. When I add Module_1 N to the Environment Variables, it overrides the default setting. However, When I do the same in the Build Variables it has no effect.

What is the difference between the two types of variables?


Solution

  • As far as I understand:

    • Build variables can be accessed within Eclipse only. They may influence other Eclipse components. You can also reference those variables in Eclipse make targets e.g.:

      make ${name_of_variable} (note the braces)

      where "name_of_variable" would be declared in the "Build Variables" menu of Eclipse. Those variables can be passed as arguments to external tools, but they are not part of the shell environment of those tools.

    • Environment variables can be accessed from external tools launched during the build process (e.g. GNU make: if you declare "env_variable" in the "Environment Variables" of Eclipse, you can use it in a makefile using the syntax $(env_variable) (note the parenthesis)). They become part of the shell environment of the external tool. Note that they can also be used as build variables within Eclipse. In addition you can invoke build variables in the declaration of environment variables, e.g. my_env_var = ${my_build_var} and vice-versa.

    The misleading point is that when you tick "Show system variables" in the "Build variables" configuration page of Eclipse, you see the environment variables of the Eclipse IDE itself, plus the environment variables that you defined within Eclipse.

    I'm not a developer of Eclipse so I cannot justify the rationale for the above behavior. I suspect that the intent is to avoid collisions between variables that are useful internally to the IDE only, and variables that should propagate to the environment of the external tools. I would have preferred to have a single variable type in Eclipse, and a choice to export them or not (by ticking a checkbox "export" for example). It would have made more sense.