Quite often someone will ask where to set an environment variable for their Platform Builder project. That is really a difficult question to answer without knowing a lot about the project, the BSP and the environment variable. So I thought that I would look into the many ways that an environment variable can be set. My hope is that with an understanding of how to set environment variables that choosing the best way will be easier.
The following are ways that I can think of to set environment variables, let me know if you think of others:
·         BSP.bat file – The BSP.bat file is a batch file in the BSP with the same name as the BSP. Example Platform\MainstoneIII\MainstoneIII.bat. This file should limit the environment variables that it sets to variables that need to be set for every project that builds the BSP. If, like me, you build several projects for every BSP, then you would want to carefully set variables here to avoid setting variables that aren’t needed by every project. On the other hand, if you have a one to one relationship between BSPs and projects, then set any variables here that you want.
·         Catalog file – the catalog file defines the BSP for Platform Builder. Variables set here can be set and cleared by simply adding or removing components from the project. This is a good way to provide optional build variables for a BSP. I have written about IMGRAM64 in Platform Builder: IMGRAM64 and noted that I don’t think that IMGRAM64 should be set in the Platform Options, but instead should be in the catalog. If IMGRAM64, IMGRAM32 and any other sizes were in the catalog, the user could easily pick the one that is appropriate for the project.
·         Project properties – The Project Properties or Settings dialog provides a way to set environment variables for a project. Personally, I think that this is a good way to hide environment variables, and I don’t like hidden variables. So I don’t set variables using this dialog.
·         Cesysgen.bat – The project’s cesysgen.bat is used to set environment variables used during sysgen and therefore can be used to set environment variables. I avoid setting variables here, but it can be a good place to override the settings in CEBASE.
·         Cebasesysgen.bat – Cebasesysgen.bat is run during cebuild, which is run when you run Sysgen.   This batch file can be used to set environment variables, but I recommend against it because the variables will not be set if you build the BSP from the command line using build.exe. See Platform Builder: IXP46x, 128 MB RAM, CEBaseCESysgen.bat - System Fails to Boot for more.
·         Sources file – A sources file can be used to set environment variables that effect the build of a directory. These will be short lived environment variables and typically only used by nmake when processing the makefile.
·         Developr\<username>\setenv.bat – This batch file should be used carefully. Variables can be set here, but they will only affect the builds for the user whose user account matches the directory name. I strongly recommend that only variables that do not affect the outcome of building the project be set here. Examples of variables that I set here can be found in Platform Builder: Using Your Developr Batch File.
Copyright © 2009 – Bruce Eitman
All Rights Reserved