News for hackers. Stuff that matters.
Re:Embedded Programming Without the IDE by oieoeireoes on Sunday October 25, 2020 @06:20PM (#24890516)
It always bothers me when otherwise well-meaning educational materials are untested and completely miss major points they seem to be making.

Case in point, where it explains how to teach make to compile C files into object files, and then provides a rule to compile all files _from source_ rather than from object files.

    # Tell make how to compile your *.c files into *.o files 
    %.o: %.c
        gcc -c -o $@ $< $(CFLAGS)

    # Finally, tell make how to build the whole project
    final_binary.elf: $(SRCS)
        gcc $(INCLUDE) $(CFLAGS) $(LFLAGS) $^ -o $@
This compiles the final binary from the sources, not using the object files and the rule above it.

(And clearly the leading example was never tested as it also missed the closing parentheses after "$(CFLAGS"!)

Anyway to take advantage of the c->object rule, the sources of last line should be changed to use files like this:

    # Finally, tell make how to build the whole project
    final_binary.elf: $(SRCS:.c=.o)
        gcc $(INCLUDE) $(LFLAGS) $^ -o $@
To be pedantic, the above will recompile faster but will not necessarily be correct when header files change, so with that change it would be good to integrate automatic dependency generation [1] as well (for the object files).

[1]: https://www.gnu.org/software/make/manual/html_node/Automatic...

There are no comments on this comment yet.