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....?
Detect compilation for ChibiOS
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Detect compilation for ChibiOS
Hi,
There are no macros defined into the makefile, not all implementations use makefiles, you may add it yourself using -D
Giovanni
There are no macros defined into the makefile, not all implementations use makefiles, you may add it yourself using -D
Giovanni
-
- Posts: 166
- Joined: Wed Jan 09, 2019 12:37 pm
- Has thanked: 19 times
- Been thanked: 31 times
Re: Detect compilation for ChibiOS
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
#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
Who is online
Users browsing this forum: No registered users and 23 guests