In the code below, I would like the value of THE_VERSION_STRING to be taken from the value of the environment variable MY_VERSION at compile time
namespace myPluginStrings {
const char* pluginVendor = "me";
const char* pluginRequires = THE_VERSION_STRING;
};
So that if I type:
export MY_VERSION="2010.4"
pluginRequires will be set at "2010.4", even if MY_VERSION is set to something else at run time.
UPDATE: (feb 21) Thanks for your help everyone. It works.
As I'm using Rake as a build system, each of my CFLAGS is a ruby variable. Also the values need to end up in quotes. Therefore the gcc command line for me needs to look like this:
gcc file.c -o file -D"PLUGIN_VERSION=\"6.5\""
Which means this is in my Rakefile:
"-D\"PLUGIN_VERSION=\\\"#{ENV['MY_VERSION']}\\\"\""
If I recall correctly, you can use the command line parameter -D with gcc to #define a value at compile time.
i.e.:
$ gcc file.c -o file -D"THE_VERSION_STRING=${THE_VERSION_STRING}"
In the code below, I would like the value of THE_VERSION_STRING to be taken from the value of the environment variable MY_VERSION at compile time
No, you can't do it like this. The only way to extract environment variables is at runtime with the getenv() function. You will need to explicitly extract the value and copy it to pluginRequires.
If you want the effect of a compile-time constant, then you'll have to specify the definition on the compiler commandline as Seth suggests.
Related
Many Python tools these days are using pyproject.toml as a config file, and mirror the tool's command line arguments with config file keys. Tools may have command line flags that are not passed any arguments:
sometool --some-flag
Now, I am trying to place this --some-flag into a pyproject.toml config file and can't figure out how to have a key without any value.
[tool.sometool]
# Both of the below are invalid
some-flag
some-flag =
In TOML, is it possible to have a key without a value?
This is not possible.
It'd depend on the tool how they are doing this, so please refer to their documentation. I would guess they are treating those flags as a boolean.
[tool.sometool]
some-flag = true
I am trying to bring net-console in uboot. For that, I first added 'ncip' in "uboot-imx/include/configs/imx8mm_evk.h" as following. Later, DFMC_SWUG is called at the end of CONFIG_EXTRA_ENV_SETTINGS.
#define DFMC_SWUG \
"setenv ncip 192.168.100.98 \0" \
"ethaddr=00:80:A3:CA:B5:77 \0" \
"swugip=192.168.100.16 \0" \
"ipaddr=192.168.100.2 \0" \
"serverip=192.168.100.16 \0" \
"bootdelay=3\0" \
#define CONFIG_EXTRA_ENV_SETTINGS \
CONFIG_MFG_ENV_SETTINGS \
JAILHOUSE_ENV \
"script=boot.scr\0" \
--
--
--
"fi;\0" \
DFMC_SWUG
Interestingly, I was able to set 'ethaddr', "swugip" and other variables except "ncip". I guess, I am doing some formatting mistakes in line --> "setenv ncip 192.168.100.98 \0" \
Later I tried setting some dummy variables named dummy_var_1, dummy_var_2, dummy_var_3. Even they are not getting set.
Can some one please guide me here?
The U-Boot environment consists of strings in the form <env_var>=<string value><null> (and preceded with a CRC32 word).
So strings for environment variables have to conform to that template when predefining them in code using CONFIG_EXTRA_ENV_SETTINGS.
That also means that you cannot install raw commands in the environment such as "setenv ncip 192.168.100.98 \0".
The U-Boot documentation is clear on this topic.
Note the last sentence of the warning.
- Default Environment:
CONFIG_EXTRA_ENV_SETTINGS
Define this to contain any number of null terminated
strings (variable = value pairs) that will be part of
the default environment compiled into the boot image.
For example, place something like this in your
board's config file:
#define CONFIG_EXTRA_ENV_SETTINGS \
"myvar1=value1\0" \
"myvar2=value2\0"
Warning: This method is based on knowledge about the
internal format how the environment is stored by the
U-Boot code. This is NOT an official, exported
interface! Although it is unlikely that this format
will change soon, there is no guarantee either.
You better know what you are doing here.
I did try "ncip=192.168.100.98" ...
That looks almost correct, but needs the explicit null terminator.
Interestingly, I was able to set 'ethaddr', "swugip" and other variables except "ncip".
...
Later I tried setting some dummy variables named dummy_var_1, dummy_var_2, dummy_var_3. Even they are not getting set.
You have only provided your vague summations of the actual results.
Did you inspect any .o object files to check what text strings were stored?
Did you perform a strings u-boot.bin | less on the U-Boot image file to review the default environment embedded in the image?
Note that you could be making an additional mistake.
The environment variables defined in CONFIG_EXTRA_ENV_SETTINGS will only (initially) exist in the default environment of U-Boot.
You have been very parsimonious with details, and neglect to mention your setup. If there is an existing and valid stored environment in the nonvolatile boot medium, then specific procedures need to be performed to suppress the existing stored environment in order to revert to the default environment with the "new" environment variables.
Failure to disable/delete an existing stored environment when installing a new/different version of u-boot.bin will conceal the new/different default environment and all the new/different variables in it. If U-Boot does not issue the message similar to:
Loading Environment from xxx... *** Warning - bad CRC, using default environment
then you can be assured that your new/different environment variables are not in the current runtime environment.
IOW you want to see this warning message on (initial) boot.
If one wishes to compile u-boot with netconsole then following changes have to be done for the file in uboot-imx/include/configs/imx8mm_evk.h
Add ‘ncip’ i.e., IP address of the computer/device which holds net console along with other network settings. Please note that every variable in u-boot will be null terminated string.
Also add a variable (in following case it is dfmcswug) which will set the standard input, output and error reporting over netconsole. This variable will be called later.
Include the DFMC_SWUG macro inside CONFIG_EXTRA_ENV_SETTINGS macro so that our new settings will be added along with other environmental settings.
Add dfmcswug variable in CONFIG_BOOTCOMMAND so that it will get executed by tool chain during run time.
With the above steps, u-boot should output its console over netconsole.
On the client-side use Or similar.
nc -u -l -p 6666 <ip_address_of_uboot_host>
I want to know how to define C++ preprocessor macro using qmake DEFINES variable. I have tried to do the following:
Project file
TEMPLATE = app
CONFIG += c++14 console
SOURCES += main.cpp
DEFINES += "TEMPORARY_UNUSED(x)=\"(void)x;\""
DEFINES += "BASE_CLASS_UNUSED(x)=\"(void)x;\""
Main.cpp file
int main() {
int hello;
TEMPORARY_UNUSED(hello)
BASE_CLASS_UNUSED(hello)
}
But this resulted in following error: [main.o] Error 2. I have no idea how macro definition (very simple by the way) could cause errors in build process.
This is macro definitions using c++'s #define. They work just as I expected
#define TEMPORARY_UNUSED(x) (void)x;
#define BASE_CLASS_UNUSED(x) (void)x;
The question is: how do I define c++ preprocessor macro using qmake DEFINES and how my macro was able to cause compilation errors.
P.S. I'm perfectly aware of Q_UNUSED macro but I prefer to have a macro that indicates not only that the variable is unused but also why it is unused.
P.S. Code that I have posted is 100% of my project, there no more files that define/redefine anything else.
You need to escape the parentheses and the semicolon with backslashes:
DEFINES += TEMPORARY_UNUSED\\(x\\)=\\(void\\)x\\;
Otherwise the () and the ; in the -D compiler argument will be interpreted as parts of a more complex command.
Note that the /D option of MSVC does not support function-like macro definitions. To overcome this restriction, write your preprocessor directives into a header file and include it with the /FI compiler switch.
I have a variable set in a bbclass file like:
#some-class.bbclass
PROC ??= ""
In a recipe inheriting the class, I have a bash function where I modify that variable and immediately read its value. But, the value never gets updated.
#some-bb-file.bb
inherit some-class.bbclass
some_configure() {
PROC=$(grep -r "Processor.*${cpu_id}" ... something)
bbnote "PROC is ${PROC}"
}
I always get "PROC is " in the logs. I have tried printing the output of "(grep -r "Processor.*${cpu_id}" ... something)" and it returns a valid string. Can someone please tell me what I am missing?
Usage of bitbake and shell variables in your code snippet is mixed. Your bbnote line should omit the curly braces to access the shell variable, i.e.:
bbnote "PROC is $PROC"
Explanation: The bitbake and local shell variables are different. If you are in the shell function, then ${PROC} is the variable defined in some-class.bbclass. That variable isn't redefined when you do PROC="foo". If you use $PROC, the shell variable defined by PROC="foo" is used.
And your question in the title - I'm not sure if it is possible to update datastore variable from shell. You can get and set datastore variables in Python functions (using d.getVar and d.setVar).
Datastore variables can be read from Shell using :
${#d.getVar('PROC')}
In case you have to use others operations, then switch to Python
I guess you missed backticks
PROC=`grep -r "Processor.*${cpu_id}" ... something`
bbnote "PROC is ${PROC}"
I have this custom build which invokes matlab to compile a .slx file into a .dll file.
function(BUILD_SIMULINK model)
set(EXECUTE_COMMAND matlab -r "rtwbuild( ${model} )" )
add_custom_target(
${model} ALL
COMMAND ${EXECUTE_COMMAND}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${model}.slx
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${model}.dll
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Building: ${model}"
)
endfunction(BUILD_SIMULINK)
However my problem is that whenever I use cmake --build ., this command will always be executed.
How can I prevent this command from executing when the DEPENDS hasn't changed and the OUTPUT exists? What I'm looking for is similar to how cmake avoids re-compiling c/cpp files when the source hasn't changed and the appropriate object file exists.
See add_custom_target() command documentation:
The target has no output file and is always considered out of date even if the commands try to create a file with the name of the target. Use the add_custom_command() command to generate a file with dependencies.
There is not OUTPUT keyword. I think its only accepted because CMake sees OUTPUT as a dependency. Actually I get an CMake warning when I run your code:
...
This project specifies custom command DEPENDS on files in the build tree
that are not specified as the OUTPUT or BYPRODUCTS of any
add_custom_command or add_custom_target:
test_model.dll
You need to use add_custom_command():
cmake_minimum_required(VERSION 2.6)
project(TestCustomTargetWithDependency NONE)
function(BUILD_SIMULINK model)
#set(EXECUTE_COMMAND matlab -r "rtwbuild( ${model} )" )
set(EXECUTE_COMMAND "${CMAKE_COMMAND}" -E touch "${model}.dll")
add_custom_command(
OUTPUT "${model}.dll"
COMMAND ${EXECUTE_COMMAND}
DEPENDS "${model}.slx"
COMMENT "Building: ${model}"
)
add_custom_target(
${model} ALL
DEPENDS "${model}.dll"
)
endfunction(BUILD_SIMULINK)
file(WRITE "test_model.slx" "")
BUILD_SIMULINK(test_model)
𝓝𝓸𝓽𝓮: Sources/Dependencies default is CMAKE_CURRENT_SOURCE_DIR and outputs default is CMAKE_CURRENT_BINARY_DIR. No need to explicitly prefix those.