pass variables in to the command line compiler

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

pass variables in to the command line compiler

2,707 Views
mayfly
Contributor III
Hi,

I'd like to pass in a variable (e.g. 'my_variable') to the compiler via the command line.  I can't seem to get it.  Here's the general idea of what I'd like to do:
C:\CmdIDE.exe myproject.mcp /b my_variable=3

I tried setting it as an environment variable -env"my_variable=3", but that didn't seem to work either.

If possible, please reply with the correct command.


Labels (1)
Tags (1)
0 Kudos
Reply
5 Replies

1,098 Views
mayfly
Contributor III
Hi,

We are working with MC9S08DZ60 microcontrollers but if anyone can provide a working solution for any of the 8/16 bit microcontrollers we would appreciate it.

I should have mentioned that I had already referred to the HC(S)08 compiler reference manual but the solution did not present itself to me.  So if someone has experience using the command line for compiling, I'd really like to hear how we can pass in a variable through the command line (not through the prm file or some other kludgy way).

Thanks.


0 Kudos
Reply

1,098 Views
CompilerGuru
NXP Employee
NXP Employee
The ide does not just build all files, it also maintains the state of which files have been built with which options.
Just adding some options in some build setups is therefore problematic, at least if not all the code should be always rebuilt.
What are you trying to archive? What you can do with the cmdide build driver is to select a particular build target, and then that build target can contain any kind build target specific options.
Otherwise there is always the way to build with makefiles instead of using the ide, then you obviously have full control over the build process. With the ide, one way would also be to create an header file which is then included in the build process, the ide can then use the modification date of that file to properly rebuild the dependent files.

Daniel
0 Kudos
Reply

1,098 Views
mayfly
Contributor III
Hi,

I'm going to assume that when you said "archive" you actually meant "achieve". 

Sorry if it was not clear in my earlier posts, but we would like to call the compiler from a different program and pass the compiler a variable that could be passed on to the main program.  So, not exactly, but close enough in concept to, something like main(argc, argv) where we could pass in some variables from the command line via argc/argv when the program is called.

Have to go.  Will add later.
0 Kudos
Reply

1,098 Views
mayfly
Contributor III
cont'd...
One of the advantages of the IDE is that it keeps track of all the files, etc, so you don't have to worry about maintaining makefiles, etc (which I really don't want to have to do just because I simply just want to pass a variable to the compiler). 

One workaround is to create a batch file that saves the variable to a *.c file then call the CmdIDE.exe that contains that *.c file within the project.  It works, but I don't really like this method.  I would just rather pass the variable as a compiler argument.  Can anyone help?

Here is a sample batch file as described above <mybatch.bat>:
//------------------------------------------
@echo off

rem The [%1] argument gives the path & filename for the file you want to define the variable in (e.g. "C\myfile.c")
rem The [%2] is your intended value of the variable
rem Also, this batch file assumes that <myfile.h> contains: extern const unsigned int myvariable;
rem Example: mybatch.bat "c:\test directory\myfile.c" 4

if exist %1 del %1
echo #include "myfile.h" >> %1
echo const unsigned int myvariable %2 >> %1

<COMPILER_PATH>CmdIDE.exe /f n /b /c /q <PROJECT_PATH>my_project.mcp
//------------------------------------------------


0 Kudos
Reply

1,098 Views
J2MEJediMaster
Specialist I
I don't know what processor you're targeting, but I can try to generalize. Look in the CodeWarrior Targeting Manual for the processor and consult the chapter titled Command-Line Tools. This chapter has information on what is possible using the command line tools.

---Tom

0 Kudos
Reply