.map generation with makefile/make automatically

Viewed 272

I am working on a makefile problem where I need to auto-generate a .map file with my makefile.

A repository of the code I am working on can be found here https://github.com/smake5730/makefile_map

I have tried adding in the line

LDFLAGS = -Wl,-Map,multifile-program-distributed.map
%.o: %.c
.SECONDEXPANSION:
%.o: $$(call sourcefile,$$@) %.d | $$(@D)
    $(Q)$(CC) $(LDFLAGS) $(CFLAGS) $(DEPFLAGS) -c $< -o $@

as I believe the gcc linker, i.e. ld, requires this, and then the name multifile-program-distributed.map is set to the main target name of the whole makefile. When I do the make command I get no .map output anywhere.

I can generate a .map file using navigating to the BUILD_RESULTS folder and then using the command line command, such as found in https://interrupt.memfault.com/blog/get-the-most-out-of-the-linker-map-file .

Can anyone help me in working out what code I need for the makefile to automatically generate this .map file in the build_results folder?

Regards,

1 Answers

I solved this by adding in the $(LDFLAGS) into the correct location. It was on line 58 and the solution is shown below.

LDFLAGS += -Wl,-Map=buildresults/multifile-program-distributed.map
$(BUILDRESULTS)/multifile-program-distributed:
    $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(APP_OBJECTS) -L$(LIBDIR) -lmultifile_func -o $@
Related