OpenWrt Forum Archive

Topic: Detect OpenWRT at compile time (conditional compilation)?

The content of this topic has been archived on 28 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have a program which I've written which builds and runs successfully under OpenWRT, but there are a few tweaks I would like to make when it's being built for WRT versus when it's being built for standard Linux (changing some default file locations, number of devices to cache, etc). It more or less all boils down to changing some variables depending on what kind of system it's being built for.

I would like it to happen as transparently as possible, so my idea was to use some conditional compilation setup to change a few variables based on the compiler used. I have been reading up on #ifdef and using compiler macros to determine things like the OS and architecture, but I can't figure out how to apply this to OpenWRT.

Is there any accepted way to do this? Should I just check for non-x86 architectures? Is there a macro I can check for that will correspond to the cross-compiler?

In the OpenWrt Makefile for your package, why not define something in cflags that you can use?

TARGET_CFLAGS += -DOPENWRT_BUILD

Good point, that certainly works. Just didn't know if this is something that was common and had an accepted convention. Thanks.

The OpenWRT Makefile under the root directory has a line to check OPENWRT_BUILD variable.

The discussion might have continued from here.