Passing TARGET to XC

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Passing TARGET to XC

Post by aclassifier »

I want to write the TARGET specification only once in the makefile. Not like this:

Code: Select all

TARGET = XCORE-200-EXPLORER
XCC_FLAGS = -O2 -g -fxscope -save-temps -DMYTARGET=XCORE-200-EXPLORER
In code, it works:

Code: Select all

#if (MYTARGET == STARTKIT)
    #warning STARTKIT
#elif (MYTARGET == XCORE-200-EXPLORER)
    #warning XCORE-200-EXPLORER
#else
    #error NO TARGET?
#endif
Really, I'd like to test directly on TARGET in the code. I have tried several syntax (and searched to read myself up), but cant' find out how to do it.

Alternatively pass the TARGET value to MYTARGET. How do I do it? Not $TARGET at least

Update: Picking up TARGET-value "as is" makes sense for the preprocessor, but if (IS_MYTARGET == XCORE-200-EXPLORER) {myval=1;} makes little sense to the compiler (with the '-' in the names). So I probably have to make a level of indirection like below. At least this works:

Code: Select all

#define IS_MYTARGET_VOID               0
#define IS_MYTARGET_STARTKIT           1
#define IS_MYTARGET_XCORE_200_EXPLORER 2

#if (MYTARGET == STARTKIT)
    #define IS_MYTARGET IS_MYTARGET_STARTKIT
#elif (MYTARGET == XCORE-200-EXPLORER)
    #define IS_MYTARGET IS_MYTARGET_XCORE_200_EXPLORER
#else
    #define IS_MYTARGET IS_MYTARGET_VOID
#endif


--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
User avatar
andrewxcav
Active Member
Posts: 62
Joined: Wed Feb 17, 2016 5:10 pm
Contact:

Post by andrewxcav »

I would see if you can put the logic from your final code block into the Makefile itself.

Something like this (sorry for using different boards, but didn't want to risk a costly transcription error!):

Code: Select all

ifeq ($(CONFIG),SMART_MIC)
    TARGET = mic_array_ref
else ifeq ($(CONFIG),ETHERNET)
    TARGET = MIC-ARRAY-1V0
endif

XCC_FLAGS_SMART_MIC = $(SHARED_FLAGS) -DSMART_MIC=1
XCC_FLAGS_ETHERNET = $(SHARED_FLAGS) -DETHERNET=1

XCC_FLAGS = -O2 -g -fxscope -save-temps

I know you are looking for something cleaner / more automated, but this at least achieves locality!
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Post by aclassifier »

Thanks for setting me on track (again!)

However, looking in the make doc [1] etc. I still only get the below to work. But that's really what I asked for! I now can comment STARTKIT or EXPLORER in and out, and that's all:

Code: Select all

#TARGET = STARTKIT
TARGET = XCORE-200-EXPLORER

ifeq ($(TARGET),STARTKIT)
XCC_FLAGS = -O2 -g -fxscope -save-temps -DMYTARGET=STARKIT -DWARNINGS=1
else ifeq ($(TARGET),XCORE-200-EXPLORER)
XCC_FLAGS = -O2 -g -fxscope -save-temps -DMYTARGET=XCORE-200-EXPLORER -DWARNINGS=1
else
XCC_FLAGS = -O2 -g -fxscope -save-temps -DWARNINGS=0
endif
And here is the C code:

Code: Select all

#if (MYTARGET == STARTKIT)
    // ..
#elif (MYTARGET == XCORE-200-EXPLORER)
    // ..
#else
    // ...
#endif
I tried to make only one XCC_FLAGS line with a parameter like -DMYTARGET=TARGET or -DMYTARGET=$(TARGET) but no.

Even changing -DMYTARGET=XCORE-200-EXPLORER that works to -DMYTARGET=XCORE200EXPLORER or -DMYTARGET=XCORE_200_EXPLORER both fail. When I worked with make for some period in the nineties there was all the fuzz about tabs in makefiles. I guess this is some problem that I deeply haven't grasped. I guess make is something one try to hold at an unhealthy arm's distance.

I don't cross this off as SOLVED before after some time since I'd now also really like to see some wiseties to the problems described above. Or maybe the solution lies in your $(SHARED_FLAGS) that I don't grasp?

[1] https://ftp.gnu.org/old-gnu/Manuals/mak ... ake_7.html
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
User avatar
andrewxcav
Active Member
Posts: 62
Joined: Wed Feb 17, 2016 5:10 pm
Contact:

Post by andrewxcav »

As confusing as make can be, rest assured that there is some magic happening with xmake to possibly add to your confusion ;-)

I should also mention that in my example I was using the names of the .xn files (minus the .xn part) for my targets, which may be treated ever so slightly different from the list of "installed targets."
Post Reply