Jump to content


Detect inclusion of module in build?


  • Please log in to reply
3 replies to this topic

#1 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 04 January 2012 - 04:07 PM

I want to be able to have some code compiled dependent on if a module is being compiled into the firmware.

I wrote a small "Debug" module that simply configures a com port and creates a queue to receive debug print messages that are then printed out of that com port.  I wanted this because it moves the debug output to a different thread than what I'm debugging, so it should have less of an impact on the code being debugged.  It also guarantees that debug code will not be intermingled between different threads.

In any case, I want to make some code compile to use this functionality if the module is compiled into the firmware, and I don't currently see a method to do this.  There is specific switches for e.g. the GCS module, but I don't see anything general.

I added this to the CopterControl Makefile:

CDEFS += ${foreach MOD, ${OPTMODULES}, -DUSE_${MOD}}

, which seems to work.  It adds a -DUSE_Debug, or -DUSE_GPS to the compile command line if the Debug or GPS modules are included respectively.  The only problem is that I would rather have it define -DUSE_DEBUG, but I don't see a way to convert to uppercase in GNU make.

Does this seem like something that would be generally useful to others?  Does anyone know of an existing way or better way of doing this?

#2 XXL-Wing

XXL-Wing

    Developer

  • Members
  • PipPipPip
  • 166 posts
  • LocationVienna
  • Country: flag of Austria Austria

Posted 04 January 2012 - 05:41 PM

Hello,

you can "abuse" the shell to do so.
for example:
LOWER_VAR  = $(shell echo $(VAR) | tr A-Z a-z)
UPPER_VAR  = $(shell echo $(VAR) | tr a-z A-Z)

Alternatively, if you have the GNU Standard Make Library installed you could as well use lc and uc
see http://gmsl.sourceforge.net/ for reference.

hope that helps,
Mike

Edited by XXL-Wing, 04 January 2012 - 05:43 PM.

No matter how good your backend systems are, the users will only remember your front end. Fail there and you will fail, period.   -- Tristan Louis
Don't make me think.   -- Steve Krug, usability expert

#3 Brian

Brian

    Core Developer

  • Members
  • PipPipPip
  • 567 posts
  • LocationTucson, AZ
  • Country: flag of United States United States


Posted 04 January 2012 - 08:11 PM

View PostXXL-Wing, on 04 January 2012 - 05:41 PM, said:

Hello,

you can "abuse" the shell to do so.
for example:
LOWER_VAR  = $(shell echo $(VAR) | tr A-Z a-z)
UPPER_VAR  = $(shell echo $(VAR) | tr a-z A-Z)

Alternatively, if you have the GNU Standard Make Library installed you could as well use lc and uc
see http://gmsl.sourceforge.net/ for reference.

Thanks for the feedback.

I thought about both of those options, but the first one only works on *nix.  I use MinGW on Windows, so I think it would work for me on Windows, but I don't want to add additional dependencies on the build for such a minor feature.  Same goes for GSML.  I don't think it's used already, and would add another dependency.

#4 naiiawah

naiiawah

    Core Developer

  • Members
  • PipPipPip
  • 309 posts
  • LocationNorthwest USA
  • Country: flag of United States United States


Posted 05 January 2012 - 07:04 AM

http://stackoverflow...e-to-lower-case

See the final answer.  It isn't pretty, but it works in Make on any platform without the GSML.