Yes, it doesn’t sound that straightforward. Think about how different all the web browsers are... it’s the same with the different platforms. It’s good that when we think of microcontrollers - many of them are ARM based which means that more or less they are similar and it would be easy to migrate your code from Raspberry Pi toOlinuxino for example.
This is why in Agilart we have different drivers for the GPIOs and the other hardware widgets in the different platforms - for now Raspberry and Olimexino Micro. However we want to make super easy for everybody to get started using the platform therefore we want to be able to able to compile just the drivers you need but not everything.
Here is how we managed to cope with this.
Detecting the underlying OS
To detect the underlying Operating System you can use the shell command uname. In order to view the underlying platform, you need to add the -n option. Here is what we can do inside the make file:
UNAME := $(shell uname -n)
ifeq ($(UNAME), raspberrypi)
# add additioanl libraries, etc.
endif
ifeq ($(UNAME), alarm)
# add additioanl libraries, etc.
endif
Define a macro in makefile?
Next inside the code, in Agilart we would need to know which driver is for Raspberry Pi and which is for Olimex. We can do this using #define macrosses.
Read the whole post here: http://www.agilart.com/blog/programing-for-multiple-platforms