Detect compilation for ChibiOS

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

avrhack
Posts: 127
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 10 times
Been thanked: 2 times

Detect compilation for ChibiOS

Postby avrhack » Thu Oct 15, 2020 10:42 am

Sure this is a simple one but struggling to figure it out from the various makefiles.....

I have a library routine (.h and .c) that needs to use e.g. chsnprintf instead of sprintf when compiled for ChibiOS. I can obviously add my own macro and conditional compilation, but I note that _CHIBIOS_HAL_ is defined when using the HAL, and streams that contain chsnprintf is part of the HAL.

Problem is that this macro seems to be defined in the hal.h file so you can't use _CHIBIOS_HAL_ macro to conditionally compile the hal.h and associated headers that don't exist for non-ChibiOS builds.

I had expected there to be some macro defined in the makefiles specific to ChibiOS, which would then allow me to conditionally pull in the relevant ChibiIOS-specifics header files like hal.h and also pick up chsnprintf instead of snprintf but I can't see how to do that.

Thoughts anyone on the elegant way to do this, before I just go adding my own specific PREPROC define in the makefile and look for that in my code....?

User avatar
Giovanni
Site Admin
Posts: 13063
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 757 times
Been thanked: 636 times
Contact:

Re: Detect compilation for ChibiOS

Postby Giovanni » Thu Oct 15, 2020 10:46 am

Hi,

There are no macros defined into the makefile, not all implementations use makefiles, you may add it yourself using -D

Giovanni

mikeprotts
Posts: 150
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 19 times
Been thanked: 22 times

Re: Detect compilation for ChibiOS

Postby mikeprotts » Thu Oct 15, 2020 2:21 pm

Not entirely elegant, but would this work, coding everything as chsnprintf etc and:

#if !defined(chsnprintf)
#define chsnprintf snprintf
#endif

or maybe use your own mysnprintf that maps as:

#if defined(chsnprintf)
#define myprintf chsnprintf
#else
#define myprintf snprintf
#endif

or else use a prefix (e.g. MYPREFIXsnprintf) with:
#if defined(chsnprintf)
#define MYPREFIX ch
#else
#define MYPREFIX
#endif

Mike


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 3 guests