syntax coloring - can it respect Makefile defines?

Technical questions regarding the XTC tools and programming with XMOS.
expertsleepers
Member
Posts: 12
Joined: Thu Mar 03, 2016 4:28 pm

syntax coloring - can it respect Makefile defines?

Post by expertsleepers »

Is it possible to make the C editor's syntax coloring respect the settings in the Makefile?

For example, in audiohw.xc I always see

#if defined(SPDIF_RX) || defined(ADAT_RX)
#define USE_FRACTIONAL_N 1
#endif

greyed out, even though the Makefile configuration contains

-DADAT_RX=1


User avatar
ers35
Active Member
Posts: 62
Joined: Mon Jun 10, 2013 2:14 pm

Post by ers35 »

I am not aware of a built-in Eclipse setting to accomplish this. It may be possible to write a script to parse the Makefile and add the symbols dynamically to Eclipse's index when a Makefile is loaded or saved.

A workaround is to move the defines out of the Makefile and into a header file like defines.h, including it where appropriate. You may find it useful to write #if defined() with an error case to protect against forgetting to include defines.h:

Code: Select all

// defines.h
#define ADAT_RX 1

Code: Select all

//#include "defines.h"

#if defined(ADAT_RX)
#else
#error forgot to include defines.h
#endif
expertsleepers
Member
Posts: 12
Joined: Thu Mar 03, 2016 4:28 pm

Post by expertsleepers »

Thanks. The pity of this is that XMOS's own samples (e.g. the USB audio apps) rely heavily on build configurations to turn features on and off. The fact that the syntax colouring is then wrong makes it hard going to read the sample code.
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

hard going to read the sample code.
Yes, this can be the case. There are lot of ifdefs in the USB Audio reference software.

Something that may help is to build using -save-temps (which is on by default) which generates, amongst others, .xi and .i files in the .build_.. directories.

These are pre-processed source files (with all of the #defines, #includes and #if logic done) and give you the actual source compiled. For USB Audio, you will see quite a reduced source file that is much easier to read (scroll right down to the bottom of the .xi file for xc and .i file for .c)
expertsleepers
Member
Posts: 12
Joined: Thu Mar 03, 2016 4:28 pm

Post by expertsleepers »

Top tip, thanks.