Config.in file for "make menuconfig"

I was following example 2 of the OpenWRT examples (https://github.com/mwarning/openwrt-examples) and have a question about the config.in in this example.

Contents of config.in:

menu "Configuration"
	depends on PACKAGE_example2a

config EXAMPLE2_ENABLE_FOO
	bool "Enable Feature Foo"
	depends on PACKAGE_example2a
	default y

config EXAMPLE2_ENABLE_BAR
	bool "Enable feature Bar"
	depends on PACKAGE_example2a
	default n

endmenu

The application Example2 contains the following:

#include <stdio.h>

int main(int argc, char **argv)
{
	printf("Hi, this is example2.\n");

#if defined(FOO)
	printf("Feature foo was selected.\n");
#endif

#if defined(BAR)
	printf("Feature bar was selected.\n");
#endif
}

Based on the description in the example and what I see, this gives 2 sub-options Foo and Bar when running "make menuconfig" and select the Example2 package.

However, after selecting an option (either Foo or Bar), after "make" and run the program (in a VDI image running Virtual Box), it always prints only the first line ("this is example 2"), and none of the "Feature X was selected" lines was printed.

Am I correct in expecting that once you select an option (Foo or Bar), this would become a flag at compilation time so the compiled code would contain the corresponding "Feature X was selected" line ?

And why am I not seeing "Feature X was selected" regardless of the option I chose ?

Thanks

1 Like

That example is bad. MAKE_FLAGS is defined, sure, but then it's not actually used in Build/Compile - stage at all, so of course it's also not going to do anything. Besides that, -DFOO and -DBAR aren't make-flags to begin with; you don't supply defines to make, you supply them to gcc and should be using TARGET_CFLAGS or TARGET_CPPFLAGS instead.

Change MAKE_FLAGS += -DFOO to TARGET_CFLAGS += -DFOO and similarly for the other option and it should work.

1 Like

Thanks WereCatf. I followed your suggestions and it worked.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.