[C API] Some makefile features don't work for simulator source files

common.mk treats source files for the target and for the simulator differently.

target source files have rules to turn .c into .o and the final binary has a rule to link all those object files. This allows make to apply rules to source files like when using VPATH for example. Source files are search in the prerequisite directories and if found, the path is updated to reflect where the source file was found.

Simulator source files have their path hardcoded by using $(SRC) directly in the link rule:

$(OBJDIR)/pdex.${DYLIB_EXT}: OBJDIR
	$(SIMCOMPILER) $(DYLIB_FLAGS) -lm -DTARGET_SIMULATOR=1 -DTARGET_EXTENSION=1 $(INCDIR) -o $(OBJDIR)/pdex.${DYLIB_EXT} $(SRC)

which means, again using the VPATH example, that source files can be found on a target build and not found on a simulator build.

I propose to change this to the following:

_SYMOBJS = $(SRC:.c=.symo)
SYMOBJS  = $(addprefix $(OBJDIR)/, $(_SYMOBJS))

$(OBJDIR)/%.symo : %.c | OBJDIR DEPDIR
	clang -c $(SYM_CPFLAGS) -DTARGET_SIMULATOR=1 -DTARGET_EXTENSION=1 $(UDEFS) $(INCDIR) -o $@ $<
	
$(OBJDIR)/pdex.${DYLIB_EXT}: OBJDIR $(SYMOBJS)
	$(SIMCOMPILER) $(DYLIB_FLAGS) -lm -DTARGET_SIMULATOR=1 -DTARGET_EXTENSION=1 $(INCDIR) -o $(OBJDIR)/pdex.${DYLIB_EXT} $(SYMOBJS)

This results in the simulator source files being treated the same as the target ones.

It introduces a new variable SYM_CPFLAGS in order to pass compilation flags which may be different to the ones used for the linker in DYLIB_FLAGS.

I don't have access to a Windows or Linux machine so we would of course have to make sure this change doesn't break anything there.

I added the UDEFS defines to the command line for the simulator. This was missing in the current common.mk too and is described in [C API] Missing UDEFS for simulator code in common.mk