Missing/incorrect dependencies for simulator DYLIB rule in common.mk

In the SDK's common.mk the rule to generate a dylib for the simulator is as follows:

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

I believe there is a typo and OBJDIR should really be $(OBJDIR) to prevent the dylib from getting rebuilt constantly even when no changes were made.

I'm not very fluent in make. Does giving a folder as a dependency work? Should that be $(OBJS) instead?

Actually I see what is going on here. The main issue here is the lack of $() around OBJDIR to force the variable to evaluate the variable. Otherwise it thinks OJBDIR is the name of a target and because it is also a target (targets and variables should really have different names for clarity), it rebuilds all the time.

$(OBJS) won't work because those are the Playdate objects, not the simulator.

Probably should be $(SRC) which is the list of source files for the project as used on the command line for compiling the simulator dylib.

Related, there's another long-standing problem I need to fix in common.mk: The pdc rule only depends on simulator and not device, which means if you're doing a parallel built it can run that before pdex.bin is finished compiling. If you're not paying attention you get a zero-byte pdex.bin and a CAPI handler function wasn't located in loaded data error when you load the game.

I'll make sure both these are fixed in 1.13.1.

ohhhh okay, I get it now. OBJDIR was given as a dependency because that's the rule to create the folder $(OBJDIR) before compiling into it. Since that forces compilation it dodges the problem that we don't have any dependency on the source files. After changing the dylib dependency from OBJDIR to $(SRC) we now have the problem that the build folder is missing. So here's my new fix, after renaming the OBJDIR rule to MKOBJDIR:

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

Looks like that does the trick. :sweat_smile:

Yep. I didn't catch the extra MKOBJDIR on the dylib rule because the arm object rules were already creating it for me :man_facepalming:t2:. This is correct though.

Don't forget to rename OBJDIR on those two other rules too:

$(OBJDIR)/%.o : %.c | MKOBJDIR DEPDIR
	mkdir -p `dirname $@`
	$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@

$(OBJDIR)/%.o : %.s | MKOBJDIR DEPDIR
	$(AS) -c $(ASFLAGS) $< -o $@

and just for completion's sake, I would also separate DEPDIR into DEPDIR and MKDEPDIR.

Thanks! :pray:t2: