Makefile include 'common.mk' does not apply UDEFS to simulator builds

NB: This is using SDK version 1.10.0.

In Makefile-driven builds — I haven't seen this issue with CMake — it seems that only builds for device pass the UDEFS flags through to completion. This is important because I can't define -DFLAG_XYZ=1 (and therefore use FLAG_XYZ in the C portion of my project) unless I modify the SDK's included common.mk file (which I'd rather not do, if it becomes overridden in a future SDK update).

I noticed this when my build flags were working via CMake but I was trying out Nova (which using Make for C + Lua).

The creation of the OS-specific pdex.{dylib,so} file do not pass CPFLAGS (this combines DEFS which, itself, combines DDEFS with UDEFS).

On line 136, the for-device completion includes $(CPFLAGS), whereas on line 158 for simulator builds it does not.

134 | $(OBJDIR)/%.o : %.c | OBJDIR DEPDIR
135 |     mkdir -p `dirname $@`
136 |     $(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
157 | $(OBJDIR)/pdex.${DYLIB_EXT}: OBJDIR
158 |     $(SIMCOMPILER) $(DYLIB_FLAGS) -lm -DTARGET_SIMULATOR=1 -DTARGET_EXTENSION=1 $(INCDIR) -o $(OBJDIR)/pdex.${DYLIB_EXT} $(SRC)

Edit: As a workaround, I was able to set up Nova to use the "pdc (Lua only)" build type and I added a pre-build shell script execution as follows:

mkdir build
cd build
cmake ..
make

This becomes part of the full contents of of .nova/Tasks/Playdate Simulator.json:

File Contents
{
  "actions" : {
    "build" : {
      "preActions" : [
        {
          "script" : "mkdir build\ncd build\ncmake ..\nmake",
          "type" : "runScript"
        }
      ]
    },
    "clean" : {
      "postActions" : [
        {
          "script" : "rm -rf build\/ source\/pdex.*",
          "type" : "runScript"
        }
      ]
    }
  },
  "extension" : {
    "identifier" : "com.panic.Playdate",
    "name" : "Playdate"
  },
  "extensionTemplate" : "simulator",
  "extensionValues" : {
    "playdate.build-type" : "pdc"
  }
}

Thanks!

1 Like